-
Notifications
You must be signed in to change notification settings - Fork 65
feat: Add toolbar buttons #1256
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: feat/toolbar-epic
Are you sure you want to change the base?
Changes from all commits
374f757
ed1a07e
04bd68b
8f6d6f1
6389307
c7d70e6
3f8b630
1abed04
5fd9254
c2289a3
b23fc17
d2eb240
0836374
a55d03f
0afabf4
e6e9d88
626af55
180319a
478f5e1
0340d21
f898670
899b644
6a3ccfe
88f00d8
df309bf
d69e3e8
ef468d1
78372c1
652a061
0c0f895
3ce0b20
cf585de
a6250a6
8f3ab2d
fa866ba
06177d6
b49322b
c5f3dd6
cd2a746
cc601fb
25c6027
e6fac9a
c5d9e38
37b9855
16acb76
5ed4321
85bad5e
5531572
b8d66d5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,25 +4,114 @@ | |
| #' A toolbar which can contain buttons, inputs, and other UI elements in a small | ||
| #' form suitable for inclusion in card headers, footers, and other small places. | ||
| #' | ||
| #' @examplesIf rlang::is_interactive() | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can just be |
||
| #' toolbar( | ||
| #' align = "right", | ||
| #' toolbar_input_button(id = "see", icon = icon("eye")), | ||
| #' toolbar_input_button(id = "save", icon = icon("save")), | ||
| #' toolbar_input_button(id = "edit", icon = icon("pencil")) | ||
|
Comment on lines
+10
to
+12
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seeing this example reminded me that I the current API doesn't do a great job of guiding people to fall into the pit of accessibility success. It might be better to force people to provide either
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. note: this would also impact our determination of
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So right now based on the Mac native voiceover functionality, here's what happens: Based on this, I actually think our implementation of tooltip might be more accessible than the non-tooltipped version. Two potential options I'm thinking of:
Thoughts? |
||
| #' ) | ||
| #' | ||
| #' @param ... UI elements for the toolbar. | ||
| #' @param align Determines if toolbar should be aligned to the `"right"` or | ||
| #' `"left"`. | ||
| #' @param gap A CSS length unit defining the gap (i.e., spacing) between | ||
| #' elements in the toolbar. Defaults to `0` (no gap). | ||
| #' @return Returns a toolbar element. | ||
| #' | ||
| #' @family Toolbar components | ||
| #' @export | ||
| toolbar <- function( | ||
| ..., | ||
| align = c("right", "left") | ||
| align = c("right", "left"), | ||
| gap = NULL | ||
| ) { | ||
| align <- rlang::arg_match(align) | ||
| gap <- validateCssUnit(gap) | ||
|
|
||
| tag <- div( | ||
| class = "bslib-toolbar bslib-gap-spacing", | ||
| "data-align" = align, | ||
| style = css(gap = gap), | ||
| ..., | ||
| component_dependencies() | ||
| ) | ||
|
|
||
| tag_require(tag, version = 5, caller = "toolbar()") | ||
| as_fragment(tag) | ||
| } | ||
|
|
||
| #' Add toolbar button input | ||
| #' | ||
| #' @description | ||
| #' A button designed to fit well in small places such as in a [toolbar()]. | ||
| #' | ||
| #' @examplesIf rlang::is_interactive() | ||
| #' toolbar( | ||
| #' align = "right", | ||
| #' toolbar_input_button(id = "see", icon = icon("eye")), | ||
| #' toolbar_input_button(id = "save", label = "Save")), | ||
| #' toolbar_input_button(id = "edit", icon = icon("pencil"), label="Edit") | ||
| #' ) | ||
| #' | ||
elnelson575 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| #' @param id The input ID. | ||
| #' @param icon An icon to display in the button. (One of icon or label must be | ||
| #' supplied.) | ||
| #' @param label The label to display in the button. (One of icon or label must | ||
| #' be supplied.) | ||
| #' @param tooltip An optional [tooltip()] to display when hovering over the | ||
| #' button. | ||
| #' @param disabled If `TRUE`, the button will not be clickable. Use | ||
| #' [shiny::updateActionButton()] to dynamically enable/disable the button. | ||
| #' @param border Whether to show a border around the button. | ||
| #' @param ... UI elements for the button. | ||
| #' | ||
| #' @return Returns a button suitable for use in a toolbar. | ||
elnelson575 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| #' | ||
elnelson575 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| #' @family Toolbar components | ||
| #' @export | ||
|
|
||
| toolbar_input_button <- function( | ||
| id, | ||
| icon = NULL, | ||
| label = NULL, | ||
| tooltip = NULL, | ||
| ..., | ||
| disabled = FALSE, | ||
| border = FALSE | ||
| ) { | ||
| if (is.null(icon) && is.null(label)) { | ||
| stop( | ||
| "At least one of 'icon' or 'label' must be provided.", | ||
| call. = TRUE | ||
| ) | ||
| } | ||
| has_icon <- !is.null(icon) | ||
| has_label <- !is.null(label) | ||
|
|
||
| btn_type <- | ||
| if (has_icon && !has_label) { | ||
| "icon" | ||
| } else if (has_label && !has_icon) { | ||
| "label" | ||
| } else { | ||
| # Can't both be missing (checked above) | ||
| "both" | ||
| } | ||
|
|
||
elnelson575 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| button <- shiny::actionButton( | ||
| id, | ||
| label = label, | ||
| icon = icon, | ||
| disabled = disabled, | ||
| class = "bslib-toolbar-input-button btn-sm", | ||
| class = if (!border) "border-0" else "border-1", | ||
| "data-type" = btn_type, | ||
| ... | ||
| ) | ||
|
|
||
| if (!is.null(tooltip)) { | ||
| button <- tooltip(button, tooltip, placement = "bottom") | ||
| } | ||
| button | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,6 +31,8 @@ | |
| flex-direction: row; | ||
| align-items: center; | ||
| align-self: stretch; | ||
| min-height: 2.5rem; | ||
| padding-block: 4px; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is likely the right final value, but I think we should see if we can hook this into a Bootstrap CSS variable |
||
| gap: 0.25rem; | ||
|
|
||
| // Give the nav flex: 1 so that if the card header contains a nav, it will take all the available space | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oops,
shinyshould stay underSuggests. You can just move this line back down to be betweenrmarkdownandtestthat.