Skip to content

Commit

Permalink
awesome checkbox and radio themeable
Browse files Browse the repository at this point in the history
  • Loading branch information
pvictor committed Feb 11, 2021
1 parent 19cb278 commit f5b689e
Show file tree
Hide file tree
Showing 36 changed files with 1,983 additions and 27 deletions.
56 changes: 48 additions & 8 deletions R/dependencies.R
Original file line number Diff line number Diff line change
Expand Up @@ -134,19 +134,59 @@ html_dependency_shinyWidgets <- function() {
#' )
#'
html_dependency_awesome <- function() {
htmlDependency(
bslib::bs_dependency_defer(awesomeDependencyCSS)
}

#' @importFrom sass sass_file
#' @importFrom bslib bs_dependency
awesomeDependencyCSS <- function(theme) {
if (!bslib::is_bs_theme(theme)) {
return(htmlDependency(
name = "awesome-bootstrap",
version = "0.3.7",
src = c(
href = "shinyWidgets/awesome-bootstrap-checkbox",
file = "assets/awesome-bootstrap-checkbox"
),
package = "shinyWidgets",
stylesheet = "awesome-bootstrap-checkbox.min.css",
all_files = FALSE
))
}

sass_input <- list(
list(
"fa-var-check" = "\"\\f00c\"",
"input-bg-disabled" = "$gray-300",
"brand-primary" = "$primary",
"brand-info" = "$info",
"brand-success" = "$success",
"brand-warning" = "$warning",
"brand-danger" = "$danger",
"awesome-label-inline-margin-left" = "10px"
),
# sass::sass_file(
# system.file(package = "shinyWidgets", "assets/awesome-bootstrap-checkbox/_variables.scss")
# ),
sass::sass_file(
system.file(package = "shinyWidgets", "assets/awesome-bootstrap-checkbox/_mixins.scss")
),
sass::sass_file(
system.file(package = "shinyWidgets", "assets/awesome-bootstrap-checkbox/awesome-bootstrap-checkbox.scss")
)
)

bslib::bs_dependency(
input = sass_input,
theme = theme,
name = "awesome-bootstrap",
version = "0.3.7",
src = c(
href = "shinyWidgets/awesome-bootstrap-checkbox",
file = "assets/awesome-bootstrap-checkbox"
),
package = "shinyWidgets",
stylesheet = "awesome-bootstrap-checkbox.min.css",
all_files = FALSE
cache_key_extra = packageVersion("shinyWidgets")
)
}



#' @export
#' @rdname html-dependencies
html_dependency_bttn <- function() {
Expand Down
21 changes: 15 additions & 6 deletions R/input-awesomecheckbox.R
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,19 @@ generateAwesomeOptions <- function(inputId, choices, selected, inline, status) {
inputTag$attribs$checked <- "checked"
if (inline) {
tags$div(
class = paste0("awesome-checkbox checkbox-inline checkbox-", status),
class = paste0("awesome-checkbox checkbox-inline form-check-inline checkbox-", status),
inputTag,
tags$label(name, `for` = paste0(inputId, value))
tags$label(
name,
`for` = paste0(inputId, value),
class = "form-check-label form-check-label-inline"
)
)
}
else {
} else {
tags$div(
class = paste0("awesome-checkbox checkbox-", status),
inputTag,
tags$label(name, `for` = paste0(inputId, value))
tags$label(name, `for` = paste0(inputId, value), class = "form-check-label")
)
}
}, SIMPLIFY = FALSE, USE.NAMES = FALSE
Expand Down Expand Up @@ -178,7 +181,13 @@ awesomeCheckboxGroup <- function(inputId,
style = if (!is.null(width))
paste0("width: ", validateCssUnit(width), ";"),
class = divClass,
tags$label(label, `for` = inputId, style = "margin-bottom: 10px;"),
tags$label(
class = "control-label",
label,
`for` = inputId,
style = "margin-bottom: 10px;",
class = if (is.null(label)) "shiny-label-null"
),
options
)
# Dep
Expand Down
17 changes: 9 additions & 8 deletions R/input-awesomeradio.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ radioAlone <- function(id,
}
if (inline)
# if (!checkbox)
divClass <- paste(divClass, "radio-inline radio-inline")
divClass <- paste(divClass, "radio-inline radio-inline form-check-inline")
# else
# divClass <- paste(divClass, "checkbox-inline checkbox-inline")
inputTag <- tags$input(name=name, id=id, value=value, type="radio")
Expand Down Expand Up @@ -133,18 +133,19 @@ awesomeRadio <- function(inputId,
} else {
as.character(selected)
}
tagLabel <- tags$label(
class = "control-label",
`for` = inputId,
label, style = "margin-bottom: 5px;"
)
awesomeRadioTag <- tags$div(
id = inputId,
class = "form-group shiny-input-radiogroup awesome-bootstrap-radio shiny-input-container",
class = if(inline) "shiny-input-container-inline",
class = if (inline) "shiny-input-container-inline",
style = if (!is.null(width))
paste0("width: ", validateCssUnit(width), ";"),
if (!is.null(label)) tagLabel,
tags$label(
class = "control-label",
`for` = inputId,
label,
style = "margin-bottom: 5px;",
class = if (is.null(label)) "shiny-label-null"
),
if (!is.null(label) & !inline) tags$div(style = "height: 7px;"),
generateAwesomeRadio(inputId, choices, selected, inline, status, checkbox)
)
Expand Down
40 changes: 40 additions & 0 deletions inst/assets/awesome-bootstrap-checkbox/_mixins.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Mixins
// --------------------------------------------------

// Utilities
@import "mixins/hide-text";
@import "mixins/opacity";
@import "mixins/image";
@import "mixins/labels";
@import "mixins/reset-filter";
@import "mixins/resize";
@import "mixins/responsive-visibility";
@import "mixins/size";
@import "mixins/tab-focus";
@import "mixins/reset-text";
@import "mixins/text-emphasis";
@import "mixins/text-overflow";
@import "mixins/vendor-prefixes";

// Components
@import "mixins/alerts";
@import "mixins/buttons";
@import "mixins/panels";
@import "mixins/pagination";
@import "mixins/list-group";
@import "mixins/nav-divider";
@import "mixins/forms";
@import "mixins/progress-bar";
@import "mixins/table-row";

// Skins
@import "mixins/background-variant";
@import "mixins/border-radius";
@import "mixins/gradients";

// Layout
@import "mixins/clearfix";
@import "mixins/center-block";
@import "mixins/nav-vertical-align";
@import "mixins/grid-framework";
@import "mixins/grid";
Loading

0 comments on commit f5b689e

Please sign in to comment.