Toggle Switch
After this confirmation we just need to replicate the Tabler html into a function.
tabler_switch <- function(inputId, label, value = FALSE, width = NULL) {
# Recovers any possible bookmarked
value <- restoreInput(id = inputId, default = value)
# main wrapper creation
input_wrapper <- tags$label(
class = "form-check form-switch",
style = if (!is.null(width)) {
paste0("width: ", validateCssUnit(width), ";")
}
)
# Defining the input tag to be find by the binding
# with form-check-input from Tabler
input_tag <- tags$input(
id = inputId,
type = "checkbox",
class = "form-check-input"
)
# Confirms if the switch needs to be active by default
if (!is.null(value) && value) {
input_tag <- tagAppendAttributes(input_tag, checked = "checked")
}
tagAppendChildren(
input_wrapper,
input_tag,
span(class = "form-check-label", label)
)
}