-
Notifications
You must be signed in to change notification settings - Fork 65
feat: Add toolbar input select #1260
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
478f5e1
0340d21
f898670
899b644
6a3ccfe
88f00d8
df309bf
68b7006
3a9b59e
12db810
10ba431
87cbf1d
9c04578
6be96cb
6371c2f
d16f727
3d7d9f0
3cc95fe
d9a5bf0
d3dd5c3
e8da8d9
606c7d0
2e7dc65
183d8af
2ceb201
8171052
03f9e8f
eda7660
5479ad3
1e68375
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 | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -26,3 +26,57 @@ toolbar <- function( | |||||||||||||||||||||||||
| tag_require(tag, version = 5, caller = "toolbar()") | ||||||||||||||||||||||||||
| as_fragment(tag) | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| #' Toolbar Input Select | ||||||||||||||||||||||||||
| #' | ||||||||||||||||||||||||||
| #' @description | ||||||||||||||||||||||||||
| #' Create a select list input control that can be used to choose a single item | ||||||||||||||||||||||||||
| #' from a list of values, suitable for use within a [toolbar()]. This is a | ||||||||||||||||||||||||||
| #' wrapper around [shiny::selectInput()] with `selectize = FALSE` and | ||||||||||||||||||||||||||
| #' appropriate styling for toolbar usage. | ||||||||||||||||||||||||||
| #' | ||||||||||||||||||||||||||
| #' @examplesIf rlang::is_interactive() | ||||||||||||||||||||||||||
| #' toolbar( | ||||||||||||||||||||||||||
| #' align = "right", | ||||||||||||||||||||||||||
| #' toolbar_input_select( | ||||||||||||||||||||||||||
| #' id = "select", | ||||||||||||||||||||||||||
| #' choices = c("Option 1", "Option 2", "Option 3"), | ||||||||||||||||||||||||||
| #' selected = "Option 2" | ||||||||||||||||||||||||||
| #' ) | ||||||||||||||||||||||||||
| #' ) | ||||||||||||||||||||||||||
| #' | ||||||||||||||||||||||||||
| #' @param id The input ID. | ||||||||||||||||||||||||||
| #' @param choices List of values to select from. If elements of the list are | ||||||||||||||||||||||||||
| #' named, then that name - rather than the value - is displayed to the user. | ||||||||||||||||||||||||||
| #' It's also possible to group related inputs by providing a named list whose | ||||||||||||||||||||||||||
| #' elements are (either named or unnamed) lists, vectors, or factors. In this | ||||||||||||||||||||||||||
| #' case, the outermost names will be used as the group labels (leveraging the | ||||||||||||||||||||||||||
| #' `<optgroup>` HTML tag) for the elements in the respective sublist. | ||||||||||||||||||||||||||
| #' @param selected The initially selected value. If not specified then defaults | ||||||||||||||||||||||||||
| #' to the first value. | ||||||||||||||||||||||||||
| #' @param width The width of the input, e.g. '400px', or '100%'; see | ||||||||||||||||||||||||||
| #' [validateCssUnit()]. | ||||||||||||||||||||||||||
| #' | ||||||||||||||||||||||||||
| #' @return Returns a select input control suitable for use in a toolbar. | ||||||||||||||||||||||||||
| #' | ||||||||||||||||||||||||||
| #' @family Toolbar components | ||||||||||||||||||||||||||
| #' @export | ||||||||||||||||||||||||||
| toolbar_input_select <- function( | ||||||||||||||||||||||||||
| id, | ||||||||||||||||||||||||||
| choices, | ||||||||||||||||||||||||||
| selected = NULL, | ||||||||||||||||||||||||||
| width = NULL | ||||||||||||||||||||||||||
| ) { | ||||||||||||||||||||||||||
| htmltools::div( | ||||||||||||||||||||||||||
| class = "bslib-toolbar-input-select form-select-sm", | ||||||||||||||||||||||||||
|
Comment on lines
+68
to
+71
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. I think we might want to allow
Suggested change
|
||||||||||||||||||||||||||
| shiny::selectInput( | ||||||||||||||||||||||||||
| id, | ||||||||||||||||||||||||||
| label = NULL, # Removed for slimline input component | ||||||||||||||||||||||||||
|
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. We probably need to keep |
||||||||||||||||||||||||||
| choices = choices, | ||||||||||||||||||||||||||
| selected = selected, | ||||||||||||||||||||||||||
| multiple = FALSE, | ||||||||||||||||||||||||||
| selectize = FALSE, | ||||||||||||||||||||||||||
| width = width | ||||||||||||||||||||||||||
|
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.
Suggested change
|
||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
This file was deleted.
| 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; | ||
|
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. This is only to match what we currently have in the buttons PR
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 includes both |
||
| padding-block: 4px; | ||
| gap: 0.25rem; | ||
|
|
||
| // Give the nav flex: 1 so that if the card header contains a nav, it will take all the available space | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,35 +2,84 @@ | |
| .bslib-toolbar { | ||
| display: flex; | ||
| align-items: center; | ||
| gap: 0; | ||
|
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. Same with these changes to toolbar.scss for the .bslib-toolbar (Also just to match what's in buttons) |
||
|
|
||
| /* ---- Toolbar options ---- */ | ||
|
|
||
| &[data-align="left"] { | ||
| margin-right: auto; | ||
| justify-content: start; | ||
| } | ||
|
|
||
| &[data-align="right"] { | ||
| margin-left: auto; | ||
| justify-content: end; | ||
| } | ||
|
|
||
| /* ---- Adjustments to other elements ---- */ | ||
|
|
||
| // Ensures uniformity of font sizing in elements and sub-elements (e.g., input select) | ||
| &, | ||
| & * { | ||
| font-size: 0.8rem; | ||
| font-size: 0.9rem; | ||
| } | ||
|
|
||
| &>* { | ||
| margin-bottom: 0 !important; | ||
| width: auto; | ||
| align-self: center; | ||
| } | ||
| } | ||
|
|
||
| /* Toolbar Select Input */ | ||
| .bslib-toolbar-input-select { | ||
| // Decrease this to keep header slim and leave a margin between select & border | ||
| padding-block: 2px; | ||
|
|
||
| .form-group.shiny-input-container { | ||
| width: auto; | ||
|
|
||
| select { | ||
| width: auto; | ||
| } | ||
| } | ||
|
|
||
| /* Remove the select label visually */ | ||
| #select-label { | ||
| display: none; | ||
| } | ||
|
|
||
| /* Make children take width=auto to size to content */ | ||
| &>* { | ||
| width: auto; | ||
| } | ||
|
|
||
| select { | ||
| appearance: auto; | ||
| padding-block: 3px; // Decreased to slim down select to fit in header | ||
| /* .form-controls takes away the drop-down arrow, this ensures it shows up */ | ||
|
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. I think I understand what this comment is saying, but I'm not sure. Some things to clarify:
|
||
| border: none; | ||
| transition: background-color 120ms ease, color 120ms ease; | ||
| } | ||
|
|
||
| // Hover, active, and focus styling to highlight the select and options on interaction | ||
| // because default styles are disabled to make the input slimmer | ||
| & select:hover { | ||
| background-color: rgba(var(--bs-emphasis-color-rgb, 0, 0, 0), 0.08); | ||
| } | ||
|
|
||
| & select:active { | ||
| background-color: rgba(var(--bs-emphasis-color-rgb, 0, 0, 0), 0.16); | ||
| } | ||
|
|
||
| & select:focus, | ||
| select:focus-visible { | ||
| background-color: rgba(var(--bs-emphasis-color-rgb, 0, 0, 0), 0.12); | ||
| } | ||
|
|
||
| // Card header is flex by default, but card footer is not and must be in order for | ||
| // toolbar alignment to work | ||
| .card-footer:has(> &) { | ||
| display: flex; | ||
| align-items: center; | ||
| & select option:hover, | ||
| & select option:focus, | ||
| & select option:checked { | ||
| background-color: rgba(var(--bs-emphasis-color-rgb, 0, 0, 0), 0.12) !important; | ||
| } | ||
| } | ||
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.
This is probably sufficient; it looks like this documentation was copied from
selectInput()anyway.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.
If you want to keep documentation local to
toolbar_input_select()--widthmight be one case -- you can keep the@paramdocs here.