Added methods for manipulating element classes and improved the optional/required when fieldset is used
This commit is contained in:
@@ -3,12 +3,15 @@
|
|||||||
export(htmlAddBoxAttributes)
|
export(htmlAddBoxAttributes)
|
||||||
export(htmlAddBoxHelpLink)
|
export(htmlAddBoxHelpLink)
|
||||||
export(htmlAddBoxRegionFromTitle)
|
export(htmlAddBoxRegionFromTitle)
|
||||||
|
export(htmlAddClasses)
|
||||||
|
export(htmlButtonStyle)
|
||||||
export(htmlDisableAutocomplete)
|
export(htmlDisableAutocomplete)
|
||||||
export(htmlFixBoxCollapseButtonAria)
|
export(htmlFixBoxCollapseButtonAria)
|
||||||
export(htmlMarkOptional)
|
export(htmlMarkOptional)
|
||||||
export(htmlMarkRequired)
|
export(htmlMarkRequired)
|
||||||
export(htmlRemoveAttributes)
|
export(htmlRemoveAttributes)
|
||||||
export(htmlRemoveBoxTitle)
|
export(htmlRemoveBoxTitle)
|
||||||
|
export(htmlRemoveClasses)
|
||||||
export(htmlReplaceBoxTitleLevel)
|
export(htmlReplaceBoxTitleLevel)
|
||||||
export(htmlSetMaxLength)
|
export(htmlSetMaxLength)
|
||||||
export(htmlSetMinLength)
|
export(htmlSetMinLength)
|
||||||
|
|||||||
49
R/htmlClassManipulation.R
Normal file
49
R/htmlClassManipulation.R
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
#' Add classes to an HTML element
|
||||||
|
#'
|
||||||
|
#' @param el The element to add the class(es) to
|
||||||
|
#' @param classes The class(es) to be added
|
||||||
|
#'
|
||||||
|
#' @return The modified element
|
||||||
|
#' @export
|
||||||
|
#'
|
||||||
|
#' @examples
|
||||||
|
#' x <- shiny::tags$div()
|
||||||
|
#' htmlAddClasses(x, "btn-warning")
|
||||||
|
htmlAddClasses <- function(el, classes) {
|
||||||
|
htmltools::tagQuery(el)$addClass(classes)$allTags()
|
||||||
|
}
|
||||||
|
|
||||||
|
#' Remove classes from an HTML element
|
||||||
|
#'
|
||||||
|
#' @param el The element to remove the class(es) from
|
||||||
|
#' @param classes The class(es) to be added
|
||||||
|
#'
|
||||||
|
#' @return The modified element
|
||||||
|
#' @export
|
||||||
|
#'
|
||||||
|
#' @examples
|
||||||
|
#' x <- shiny::tags$div(class = "btn btn-warning")
|
||||||
|
#' htmlRemoveClasses(x, "btn-warning")
|
||||||
|
htmlRemoveClasses <- function(el, classes) {
|
||||||
|
htmltools::tagQuery(el)$removeClass(classes)$allTags()
|
||||||
|
}
|
||||||
|
|
||||||
|
#' Changes the style of a button from btn-default to another style
|
||||||
|
#'
|
||||||
|
#' @param el The button
|
||||||
|
#' @param style The style to change the button on
|
||||||
|
#'
|
||||||
|
#' @return The modified element
|
||||||
|
#' @export
|
||||||
|
#'
|
||||||
|
#' @examples
|
||||||
|
#' x <- shiny::tags$div(class = "btn btn-warning")
|
||||||
|
#' htmlButtonStyle(x, "warning")
|
||||||
|
htmlButtonStyle <- function(el, style) {
|
||||||
|
stopifnot(style %in% c(
|
||||||
|
"default", "primary", "info", "warning", "success", "danger", "link"
|
||||||
|
))
|
||||||
|
el <- htmlRemoveClasses(el, "btn-default")
|
||||||
|
el <- htmlAddClasses(el, paste0("btn-", style))
|
||||||
|
el
|
||||||
|
}
|
||||||
@@ -12,7 +12,9 @@
|
|||||||
htmlMarkOptional <- function(input, optClass = "text-muted font-italic") {
|
htmlMarkOptional <- function(input, optClass = "text-muted font-italic") {
|
||||||
opt_span <- htmltools::tags$span(class = optClass, " (optional)")
|
opt_span <- htmltools::tags$span(class = optClass, " (optional)")
|
||||||
tq <- htmltools::tagQuery(input)
|
tq <- htmltools::tagQuery(input)
|
||||||
if (tq$hasClass("shiny-input-checkboxgroup")) {
|
if (tq$find("legend")$length() > 0) {
|
||||||
|
tq <- tq$children("legend")$append(opt_span)$reset()
|
||||||
|
} else if (tq$hasClass("shiny-input-checkboxgroup")) {
|
||||||
tq <- tq$children("label")$append(opt_span)$reset()
|
tq <- tq$children("label")$append(opt_span)$reset()
|
||||||
} else if (tq$find(".shiny-options-group")$length() > 0) {
|
} else if (tq$find(".shiny-options-group")$length() > 0) {
|
||||||
tq <- tq$children("label")$append(opt_span)$reset()
|
tq <- tq$children("label")$append(opt_span)$reset()
|
||||||
|
|||||||
@@ -12,12 +12,17 @@
|
|||||||
htmlMarkRequired <- function(input, reqClass = "text-danger required") {
|
htmlMarkRequired <- function(input, reqClass = "text-danger required") {
|
||||||
req_span <- htmltools::tags$span(class = reqClass, "*")
|
req_span <- htmltools::tags$span(class = reqClass, "*")
|
||||||
tq <- htmltools::tagQuery(input)
|
tq <- htmltools::tagQuery(input)
|
||||||
if (tq$hasClass("shiny-input-checkboxgroup")) {
|
if (tq$find("legend")$length() > 0) {
|
||||||
|
tq <- tq$children("legend")$append(req_span)$reset()
|
||||||
|
tq <- tq$find("input")$addAttr(
|
||||||
|
required = "true", `aria-required` = "true"
|
||||||
|
)$reset()
|
||||||
|
} else if (tq$hasClass("shiny-input-checkboxgroup")) {
|
||||||
tq <- tq$addAttr(`aria-required` = "true")$reset()
|
tq <- tq$addAttr(`aria-required` = "true")$reset()
|
||||||
tq <- tq$children("label")$append(req_span)$reset()
|
tq <- tq$children("label")$append(req_span)$reset()
|
||||||
} else if (tq$find(".shiny-options-group")$length() > 0) {
|
} else if (tq$find(".shiny-options-group")$length() > 0) {
|
||||||
tq <- tq$children("label")$append(req_span)$reset()
|
|
||||||
tq <- tq$addAttr(`aria-required` = "true")$reset()
|
tq <- tq$addAttr(`aria-required` = "true")$reset()
|
||||||
|
tq <- tq$children("label")$append(req_span)$reset()
|
||||||
tq <- tq$find("input")$addAttr(
|
tq <- tq$find("input")$addAttr(
|
||||||
required = "true", `aria-required` = "true"
|
required = "true", `aria-required` = "true"
|
||||||
)$reset()
|
)$reset()
|
||||||
|
|||||||
23
man/htmlAddClasses.Rd
Normal file
23
man/htmlAddClasses.Rd
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
% Generated by roxygen2: do not edit by hand
|
||||||
|
% Please edit documentation in R/htmlClassManipulation.R
|
||||||
|
\name{htmlAddClasses}
|
||||||
|
\alias{htmlAddClasses}
|
||||||
|
\title{Add classes to an HTML element}
|
||||||
|
\usage{
|
||||||
|
htmlAddClasses(el, classes)
|
||||||
|
}
|
||||||
|
\arguments{
|
||||||
|
\item{el}{The element to add the class(es) to}
|
||||||
|
|
||||||
|
\item{classes}{The class(es) to be added}
|
||||||
|
}
|
||||||
|
\value{
|
||||||
|
The modified element
|
||||||
|
}
|
||||||
|
\description{
|
||||||
|
Add classes to an HTML element
|
||||||
|
}
|
||||||
|
\examples{
|
||||||
|
x <- shiny::tags$div()
|
||||||
|
htmlAddClasses(x, "btn-warning")
|
||||||
|
}
|
||||||
23
man/htmlButtonStyle.Rd
Normal file
23
man/htmlButtonStyle.Rd
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
% Generated by roxygen2: do not edit by hand
|
||||||
|
% Please edit documentation in R/htmlClassManipulation.R
|
||||||
|
\name{htmlButtonStyle}
|
||||||
|
\alias{htmlButtonStyle}
|
||||||
|
\title{Changes the style of a button from btn-default to another style}
|
||||||
|
\usage{
|
||||||
|
htmlButtonStyle(el, style)
|
||||||
|
}
|
||||||
|
\arguments{
|
||||||
|
\item{el}{The button}
|
||||||
|
|
||||||
|
\item{style}{The style to change the button on}
|
||||||
|
}
|
||||||
|
\value{
|
||||||
|
The modified element
|
||||||
|
}
|
||||||
|
\description{
|
||||||
|
Changes the style of a button from btn-default to another style
|
||||||
|
}
|
||||||
|
\examples{
|
||||||
|
x <- shiny::tags$div(class = "btn btn-warning")
|
||||||
|
htmlButtonStyle(x, "warning")
|
||||||
|
}
|
||||||
23
man/htmlRemoveClasses.Rd
Normal file
23
man/htmlRemoveClasses.Rd
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
% Generated by roxygen2: do not edit by hand
|
||||||
|
% Please edit documentation in R/htmlClassManipulation.R
|
||||||
|
\name{htmlRemoveClasses}
|
||||||
|
\alias{htmlRemoveClasses}
|
||||||
|
\title{Remove classes from an HTML element}
|
||||||
|
\usage{
|
||||||
|
htmlRemoveClasses(el, classes)
|
||||||
|
}
|
||||||
|
\arguments{
|
||||||
|
\item{el}{The element to remove the class(es) from}
|
||||||
|
|
||||||
|
\item{classes}{The class(es) to be added}
|
||||||
|
}
|
||||||
|
\value{
|
||||||
|
The modified element
|
||||||
|
}
|
||||||
|
\description{
|
||||||
|
Remove classes from an HTML element
|
||||||
|
}
|
||||||
|
\examples{
|
||||||
|
x <- shiny::tags$div(class = "btn btn-warning")
|
||||||
|
htmlRemoveClasses(x, "btn-warning")
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user