-
Notifications
You must be signed in to change notification settings - Fork 1k
USWDS - Button: Add basic support for usa-icon in buttons #5398
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
7fa6bda
Add basic support for usa-icon in buttons
110559a
Improve label for icon name control
c32391d
Merge branch 'develop' of github.com:uswds/uswds into jm-enhancement-…
eb23a05
Update button story labels
87fc766
Create a macro to fix display inconsistencies
aacb83b
Update packages/usa-button/src/usa-button.stories.js
3c3684e
Add note about duplicate icon name in icon control
03082ea
Use flexbox for button alignment
558ba4f
Merge branch 'develop' of github.com:uswds/uswds into jm-enhancement-…
e943206
Use justify-content in favor of text align
77d9316
Reset unstyled button content
b71814e
Fix button attributes
e157121
Fix regression in header's nav link buttons
a5854af
Rename button gap setting
fe2eaea
Add centered text back into buttons
94cd0f4
Update name of icon setting in storybookJS
b630276
Merge branch 'develop' into jm-enhancement-button-icons
thisisdano File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,11 @@ import { | |
UnstyledContent, | ||
} from "./content"; | ||
|
||
import { icons } from "../../usa-icon/src/usa-icon.json"; | ||
|
||
const iconItems = icons.items; | ||
const iconNames = iconItems.map((item) => item.name); | ||
|
||
export default { | ||
title: "Components/Button", | ||
argTypes: { | ||
|
@@ -31,6 +36,20 @@ export default { | |
options: ["button", "reset", "submit"], | ||
control: { type: "radio" }, | ||
}, | ||
icon_included: { | ||
name: "Icon included", | ||
mejiaj marked this conversation as resolved.
Show resolved
Hide resolved
|
||
defaultValue: false, | ||
type: "boolean", | ||
}, | ||
icon_name: { | ||
name: "Icon name", | ||
control: { | ||
type: "select", | ||
options: iconNames, | ||
defaultValue: "add_circle_outline", | ||
}, | ||
if: { arg: "icon_included" }, | ||
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. Nice! Love a conditional Storybook control. Cool find. |
||
}, | ||
}, | ||
}; | ||
|
||
|
@@ -51,6 +70,13 @@ Base.args = BaseContent; | |
export const Big = Template.bind({}); | ||
Big.args = BigContent; | ||
|
||
export const Icon = Template.bind({}); | ||
Icon.args = { | ||
...DefaultContent, | ||
icon_included: true, | ||
icon_name: "add_circle_outline", | ||
amyleadem marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}; | ||
|
||
export const Outline = Template.bind({}); | ||
Outline.args = OutlineContent; | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 do you think about using flexbox for alignment on
usa-button
elements instead of creating a rule with negative margins here? I’d have to do some testing to confirm, but a quick experiment showed that it created more consistently centered elements at varying font and icon sizes, as well as allowed for buttons to be the same height when placed next to each other. It also didn't seem to impact visual display if a single button had no icon added.For example, in this PR buttons in a segmented button group do not have a consistent height if icons are added to only some buttons in a row.
Additionally, I was looking at the open PR for button group wrap alignment, and it got me thinking that
display: inline-flex
andalign-items: stretch
might offer the answer to both scenarios.I just did some quick poking and it looks like adding the style rules below would result in the following. Curious to hear what you think.
For reference, the HTML I used:
Uh oh!
There was an error while loading. Please reload this page.
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.
@amyleadem
Re: display:
inline-flex
. Because this is such a widely used button ― I wanted to minimize any potentially breaking changes as much as possible.Since we already specify
inline-block
, I don't think the switch toinline-flex
is as drastic as I imagined. Double-checking MDN display - CSS: Cascading Style Sheets | MDN and there should be very little display difference at all.This addition improves the experience, but might require a new theme setting for the column gap. I'll play with this.
I've added flex box and a new column gap setting in 03082ea. For now, items are centered. I'd like to keep the button group changes separate, if possible. This would keep the scope of our testing more manageable.
Example with icons on both sides (for testing only)

Small screens
