Skip to content

Commit

Permalink
f7Segment apply button-round to all buttons when rounded is TRUE
Browse files Browse the repository at this point in the history
  • Loading branch information
DivadNojnarg committed May 5, 2024
1 parent b929cab commit d1c8426
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 25 deletions.
31 changes: 18 additions & 13 deletions R/f7Button.R
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ updateF7Button <- function(inputId, label = NULL, color = NULL,
#'
#' shinyApp(
#' ui = f7Page(
#' options = list(dark = FALSE),
#' title = "Button Segments",
#' f7SingleLayout(
#' navbar = f7Navbar(title = "f7Segment, f7Button"),
Expand Down Expand Up @@ -156,18 +157,6 @@ updateF7Button <- function(inputId, label = NULL, color = NULL,
#' f7Button(label = "My button", fill = FALSE),
#' f7Button(label = "My button", fill = FALSE),
#' f7Button(label = "My button", fill = FALSE, active = TRUE)
#' ),
#' f7BlockTitle(title = "Rounded Buttons in a segment container"),
#' f7Segment(
#' f7Button(color = "blue", label = "My button", rounded = TRUE),
#' f7Button(color = "green", label = "My button", rounded = TRUE),
#' f7Button(color = "yellow", label = "My button", rounded = TRUE)
#' ),
#' f7BlockTitle(title = "Raised buttons in a segment container"),
#' f7Segment(
#' f7Button(color = "blue", label = "My button", shadow = TRUE),
#' f7Button(color = "green", label = "My button", shadow = TRUE),
#' f7Button(color = "yellow", label = "My button", shadow = TRUE)
#' )
#' )
#' ),
Expand Down Expand Up @@ -197,11 +186,27 @@ f7Segment <- function(
if (rounded) containerCl <- paste0(containerCl, " segmented-round")
if (strong) containerCl <- paste0(containerCl, " segmented-strong")

# Note: there's a inconsistency in the Framework7 API where the segment can
# have the segmented-round class. This actually does not change the button
# appearance (only the container).
# Instead, we'll apply the button-round class to all buttons within
# the segment, if not already done.
btns <- list(...)
if (rounded) {
btns <- lapply(btns, \(btn) {
is_rounded <- grepl("button-round", btn$attribs$class)
if (!is_rounded) {
btn <- tagAppendAttributes(btn, class = "button-round")
}
btn
})
}

shiny::tags$div(
class = "block",
shiny::tags$p(
class = containerCl,
...,
btns,
if (strong) shiny::span(class = "segmented-highlight")
)
)
Expand Down
13 changes: 1 addition & 12 deletions man/button.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d1c8426

Please sign in to comment.