-
Notifications
You must be signed in to change notification settings - Fork 1k
NEW ToggleGroup component #7172
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
Conversation
Signed-off-by: Brittany Archibeque <brittanyarchibeque@Brittanys-MacBook-Pro-2.local>
|
Signed-off-by: Brittany Archibeque <brittanyarchibeque@Brittanys-MacBook-Pro-2.local>
Signed-off-by: Brittany Archibeque <brittanyarchibeque@Brittanys-MacBook-Pro-2.local>
Signed-off-by: Brittany Archibeque <brittanyarchibeque@Brittanys-MacBook-Pro-2.local>
src/js/components/ToggleButtonGroup/__tests__/ToggleButtonGroup-test.tsx
Outdated
Show resolved
Hide resolved
src/js/components/ToggleButtonGroup/__tests__/ToggleButtonGroup-test.tsx
Outdated
Show resolved
Hide resolved
src/js/components/ToggleButtonGroup/__tests__/ToggleButtonGroup-test.tsx
Outdated
Show resolved
Hide resolved
src/js/components/ToggleButtonGroup/__tests__/ToggleButtonGroup-test.tsx
Outdated
Show resolved
Hide resolved
src/js/components/ToggleButtonGroup/__tests__/ToggleButtonGroup-test.tsx
Outdated
Show resolved
Hide resolved
|
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.
Functionality is looking good.
I think we need some story cleanup.
src/js/themes/base.js
Outdated
iconOnly: { | ||
pad: { | ||
horizontal: 'small', | ||
vertical: 'small', |
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.
I'm wondering if the height should always be consistent?
vertical: 'small', | |
vertical: 'xsmall', |
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.
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.
Agree they should. I'll update
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.
Refined padding, see "What determined the base.js toggleGroup.button.pad?" in PR description.
Dismissing my review, I noticed the button pad + border of container is causing the height to be 2px higher than usual button. Should we be subtracting border width from pad? or should caller be responsible for the calculation? |
After offline discussion, we will align with how Button works --> For "base" theme, the caller is responsible for managing the padding + border calculations. For "kind" themes (like HPE), the button handles the subtraction of border-width from padding. So, for "base" theme, ToggleGroup will base leave responsible for managing. |
: themePad; | ||
return edgeStyle('padding', pad, false, undefined, props.theme); | ||
}} | ||
// remove hover style from StyledButton/StyledButtonKind theme |
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.
👍
What does this PR do?
This is a proposal for a ToggleGroup component to follow on which design work that has been done.
The ToggleGroup is a Box with Buttons within it. The default type is a user can select one option from the group as far as if a user wants more options they pass
multiple
similar to how Select uses themultiple
prop. This component provides the layout of the container which has rounded edges, direction='row', and a right border that is served as a separator sincegap='none
.Rationale for certain naming/behavior decisions
What: ToggleGroup is a specialized group of buttons that supports single and multiple selection/toggling.
Theming approach: Because ToggleGroup is built with buttons, inherit a theme’s button styling as is and minimize the custom overrides that ToggleGroup applies to the buttons. For any overrides, honor the “button” theme mentalities (API, any logic/conditional styling/etc.).
Necessary overrides:
Stylistic overrides:
What determined the base.js toggleGroup.button.pad?
Icon-only cases are the main use case for the ToggleGroup. In grommet theme, icon-only and labelled buttons have different dimensions. In order to lean towards the 80% case for ToggleGroup use cases and maintain consistency across different combinations of ToggleGroup
options
, aligning the dimensions for all ToggleGroups to that of base.js icon-only button (48px tall).Why named “ToggleGroup”?
When viewing Google search trends it was found that toggleGroup was used more across the wider region.
Another downside to using ToggleButtonGroup is how long the word is and in many places in the code base we would need to disable eslint for the imports since the line would be over a amount of characters.
Did button actually have any meaning even though this component was made with a Button this did not necessarily need to be made known to the user.
Why enforce a value once one is selected in single selection?
80% of use cases all have one selected option for a toggleGroup. For our specific need for this component a use case was toggling through either a map list or data view where at least one of those needed to be selected.
Why
onToggle
?This handler is called any time a button is clicked, effectively "toggling" an individual button. Initially we had
onChange
, but this felt in accurate and misaligned with the general Grommet mentality to honor native HTML events. In this case, it's not a change event but just a click event.Where should the reviewer start?
ToggleGroup.js
What testing has been done on this PR?
storybook. Additional test code for HPE vs Grommet theming:
How should this be manually tested?
storybook
Do Jest tests follow these best practices?
screen
is used for querying.asFragment()
is used for snapshot testing.Any background context you want to provide?
NEW ToggleGroup component was needed
What are the relevant issues?
closes #grommet/hpe-design-system#3739
Screenshots (if appropriate)
Do the grommet docs need to be updated?
yes
Should this PR be mentioned in the release notes?
yes
Is this change backwards compatible or is it a breaking change?
backwards compatible