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
refactor(button): Simplify Button components and prep for theming #471
Conversation
Test summaryRun details
View run in Cypress Dashboard ➡️ This comment has been generated by cypress-bot as a result of this project's GitHub integration settings. You can manage this integration in this project's settings in the Cypress Dashboard |
What about adding a I did this with a bit of hacking: https://codesandbox.io/s/hyperlinkbutton-jh7re Basically the ask is an anchor tag with the styling of a button. |
@NicholasBoll Yeah we already have an issue open for this: #87. I definitely think it would be good to add, but not sure it should happen in this PR. |
@lychyi Re #378 - Now that we've removed our dependency on |
4f6202b
to
bdfd860
Compare
7d0340b
to
f268170
Compare
bdfd860
to
a500335
Compare
Test summaryRun details
View run in Cypress Dashboard ➡️ This comment has been generated by cypress-bot as a result of this project's GitHub integration settings. You can manage this integration in this project's settings in the Cypress Dashboard |
@anicholls Yup, for now I don't think we need Babel for button transpilation. It may require removing some of the files made just for that build process so the change may not be that straight forward. If we want to add Emotion 11 into v4, then we can once again use component selectors with the babel plugin. In addition, Babel provides us an opportunity to transpile using other plugins so we may end up going that route anyway. Personally, I don't mind leaving it. But if we want a clean slate and switch to |
d468dee
to
1b78e9d
Compare
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 think this is a great refactor. I'm deferring to the button experts though: @mannycarrera4 ?
20317ee
to
74ac320
Compare
Summary
Refactor our Button components to simplify logic and prep for theming.
Closes #468
Blocked on #481
Todo:
IconButton
IconButtonToggleGroup
(refactor: Rename and move IconButtonToggleGroup to SegmentedControl #505)Breaking changes:
DeleteButton
, andHighlightButton
are now separate components with their own interface. Here are some of the invalid prop combinations that are no longer possible:Required changes:
<Button variant={Button.Variant.Delete}>
><DeleteButton>
<Button variant={Button.Variant.Highlight}>
><HighlightButton>
<Button variant={Button.Variant.OutlineSecondary}>
><OutlineButton>
<Button variant={Button.Variant.OutlinePrimary}>
><OutlineButton variant={OutlineButton.Variant.Primary}>
<Button variant={Button.Variant.OutlineInverse}>
><OutlineButton variant={OutlineButton.Variant.Inverse}>
BaseButtonProps
is no longer available as each button variant has their own interface.TextButton
now only allowsTextButtonSize.Small
andTextButtonSize.Medium
.Required changes:
TextButtonSize.Medium
>"medium"
orTextButtonSize.Small
TextButtonSize.Large
>"small"
orTextButtonSize.Medium
Required changes:
<TextButton variant={TextButton.Variant.AllCaps}>
><TextButton allCaps={true}>
<TextButton variant={TextButton.Variant.InverseAllCaps}>
><TextButton variant={TextButton.Variant.Inverse} allCaps={true}>
Quality of Life changes:
With the new components for variants and the simpler types for sizes, the code for complex buttons is much more concise.
Before:
After:
Open questions:
Explanation
Alright - here goes.
First of all, I decided to split up some of the buttons into their own components to avoid invalid API combinations. For example, delete buttons shouldn't allow icons or data labels, but it was still technically possible to do with the old API. We have quite a few cases like this with the old API because we're trying to use the same base interface for everything. Each component now has its own interface specific to its API. We now have
Button
,DeleteButton
,DropdownButton
,HighlightButton
,TextButton
, anddeprecated_Button
. Note: We will need discussions with design on how to align these with their IA model.In the old module, the spread of styling functions/data across many files made it really hard to follow what styles were coming from where. Rather than simply duplicating all of that logic for each component, I wanted a way that could keep the CSS for the basic button shape shared, while improving the clarity of what's happening. This led me to strip out ALL of the extra functions, generic styles objects, etc. and rely on React composition + the existing color objects we were already using.
What this means in reality is we now have a
ButtonContainer
element that accepts a color object of typeButtonColors
, which houses all the underlying shared CSS. Each exported button component makes use of this container to share the styling logic. I updated the button color object for more clarity. It now looks like this. Since theButtonContainer
just accepts a color object, this should make it really easy to theme buttons.In terms of the React composition that I mentioned, gone is the
ButtonBase
file with all of the label, icon, and data components. The new file structure is very clear, and has one component per file. Other than the shared CSS inButtonContainer
, each component/file houses all of the styling/coloring that it needs. After removing all of the functions, style object files, etc. the file structure is very easy to understand at a quick glance:The
deprecated_Button
is also completely isolated from the new button styles 🎉 .Finally, I also refactored some of the styling to remove redundant styles and pull all of the spacing, size and font styling logic out of the labels and into the button container itself.
Any questions or feedback are welcome!