Skip to content
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

Corrects styling on Buttons that only have a count and icon #5448

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/brave-penguins-clap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@primer/react": minor
---

Corrects horizontal padding of `<Button>` when the button only contains an icon and a counter label (no button text label).
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 1 addition & 3 deletions packages/react/src/Button/Button.features.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,7 @@ export const TrailingCounter = () => {
)
}

export const TrailingCounterWithNoText = () => {
return <Button leadingVisual={CommentIcon} count={3} />
}
export const TrailingCounterWithNoText = () => <Button leadingVisual={CommentIcon} count={3} />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add an aria-label or a Tooltip to this example?


export const TrailingCounterAllVariants = () => {
const [count, setCount] = useState(0)
Expand Down
14 changes: 14 additions & 0 deletions packages/react/src/Button/ButtonBase.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,20 @@
color: inherit !important;
}
}

/* Icon-only + Counter */

&:where([data-has-count]):has([data-component='leadingVisual']):not(:has([data-component='text'])) {
padding-inline: var(--control-medium-paddingInline-condensed);

&:where([data-size='small']) {
padding-inline: var(--control-xsmall-paddingInline-condensed);
}

&:where([data-size='large']) {
padding-inline: var(--control-large-paddingInline-normal);
}
}
Comment on lines +511 to +521
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
&:where([data-has-count]):has([data-component='leadingVisual']):not(:has([data-component='text'])) {
padding-inline: var(--control-medium-paddingInline-condensed);
&:where([data-size='small']) {
padding-inline: var(--control-xsmall-paddingInline-condensed);
}
&:where([data-size='large']) {
padding-inline: var(--control-large-paddingInline-normal);
}
}
&:where([data-has-count]):has([data-component='leadingVisual']):not(:has([data-component='text'])) {
/* stylelint-disable-next-line primer/spacing */
padding-inline: var(--control-medium-paddingInline-condensed);
&:where([data-size='small']) {
/* stylelint-disable-next-line primer/spacing */
padding-inline: var(--control-xsmall-paddingInline-condensed);
}
&:where([data-size='large']) {
/* stylelint-disable-next-line primer/spacing */
padding-inline: var(--control-large-paddingInline-normal);
}
}

I think this will work for lint but the formatting might be off

}

.ConditionalWrapper {
Expand Down
2 changes: 2 additions & 0 deletions packages/react/src/Button/ButtonBase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ const ButtonBase = forwardRef(
data-size={size}
data-variant={variant}
data-label-wrap={labelWrap}
data-has-count={count !== undefined ? true : undefined}
aria-describedby={[loadingAnnouncementID, ariaDescribedBy]
.filter(descriptionID => Boolean(descriptionID))
.join(' ')}
Expand Down Expand Up @@ -225,6 +226,7 @@ const ButtonBase = forwardRef(
data-size={size}
data-variant={variant}
data-label-wrap={labelWrap}
data-has-count={count !== undefined ? true : undefined}
aria-describedby={[loadingAnnouncementID, ariaDescribedBy]
.filter(descriptionID => Boolean(descriptionID))
.join(' ')}
Expand Down
Loading