Skip to content

Button v2: Fix icon positions for block buttons #1733

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

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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/button2-block-position.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@primer/react': patch
---

Button 2: Fix icon positions for block buttons
4 changes: 4 additions & 0 deletions src/NewButton/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ export const getButtonStyles = (theme?: Theme) => {
...getBaseStyles(theme),
display: 'grid',
gridTemplateAreas: '"leadingIcon text trailingIcon"',
gridTemplateColumns: 'min-content 1fr min-content',
Copy link
Contributor

Choose a reason for hiding this comment

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

If we decide to go with the center-aligned approach I recommended, we can remove this style and just add justify-content: center;

'& > :not(:last-child)': {
mr: '2'
},
Expand All @@ -228,6 +229,9 @@ export const getButtonStyles = (theme?: Theme) => {
},
'[data-component="trailingIcon"]': {
gridArea: 'trailingIcon'
},
'[data-component="leadingIcon"] + [data-component="text"]': {
textAlign: 'left'
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure if this leftAlign is required tbh.

Copy link
Member Author

@siddharthkp siddharthkp Dec 15, 2021

Choose a reason for hiding this comment

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

fair, how do we make it easier for the user to override this with left align?

this would be the override, not sure if requires knowing the internal details?

<Button
  leadingIcon={EyeIcon}
  trailingIcon={TriangleDownIcon}
  sx={{ '[data-component="text"]': { textAlign: 'left' } }}
>
  Watch
</Button>

Copy link
Contributor

Choose a reason for hiding this comment

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

True :( This is where composite components would be handy. Maybe such an override usecase means we want to open up the API?

Copy link
Contributor

Choose a reason for hiding this comment

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

If we go with the center-aligned approach I recommended, we can get rid of this style block.

}
}
return styles
Expand Down
25 changes: 25 additions & 0 deletions src/__tests__/__snapshots__/NewButton.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ exports[`Button renders consistently 1`] = `
text-align: center;
display: grid;
grid-template-areas: "leadingIcon text trailingIcon";
grid-template-columns: min-content 1fr min-content;
padding-top: 5px;
padding-bottom: 5px;
padding-left: 16px;
Expand Down Expand Up @@ -63,6 +64,10 @@ exports[`Button renders consistently 1`] = `
grid-area: trailingIcon;
}

.c0 [data-component="leadingIcon"] + [data-component="text"] {
text-align: left;
}

.c0 [data-component="ButtonCounter"] {
font-size: 14px;
}
Expand Down Expand Up @@ -111,6 +116,7 @@ exports[`Button styles danger button appropriately 1`] = `
text-align: center;
display: grid;
grid-template-areas: "leadingIcon text trailingIcon";
grid-template-columns: min-content 1fr min-content;
padding-top: 5px;
padding-bottom: 5px;
padding-left: 16px;
Expand Down Expand Up @@ -156,6 +162,10 @@ exports[`Button styles danger button appropriately 1`] = `
grid-area: trailingIcon;
}

.c0 [data-component="leadingIcon"] + [data-component="text"] {
text-align: left;
}

.c0 [data-component="ButtonCounter"] {
font-size: 14px;
color: btn.danger.text;
Expand Down Expand Up @@ -219,6 +229,7 @@ exports[`Button styles invisible button appropriately 1`] = `
text-align: center;
display: grid;
grid-template-areas: "leadingIcon text trailingIcon";
grid-template-columns: min-content 1fr min-content;
padding-top: 6px;
padding-bottom: 6px;
padding-left: 16px;
Expand Down Expand Up @@ -258,6 +269,10 @@ exports[`Button styles invisible button appropriately 1`] = `
grid-area: trailingIcon;
}

.c0 [data-component="leadingIcon"] + [data-component="text"] {
text-align: left;
}

.c0 [data-component="ButtonCounter"] {
font-size: 14px;
}
Expand Down Expand Up @@ -307,6 +322,7 @@ exports[`Button styles outline button appropriately 1`] = `
text-align: center;
display: grid;
grid-template-areas: "leadingIcon text trailingIcon";
grid-template-columns: min-content 1fr min-content;
padding-top: 5px;
padding-bottom: 5px;
padding-left: 16px;
Expand Down Expand Up @@ -351,6 +367,10 @@ exports[`Button styles outline button appropriately 1`] = `
grid-area: trailingIcon;
}

.c0 [data-component="leadingIcon"] + [data-component="text"] {
text-align: left;
}

.c0 [data-component="ButtonCounter"] {
font-size: 14px;
background-color: btn.outline.counterBg;
Expand Down Expand Up @@ -415,6 +435,7 @@ exports[`Button styles primary button appropriately 1`] = `
text-align: center;
display: grid;
grid-template-areas: "leadingIcon text trailingIcon";
grid-template-columns: min-content 1fr min-content;
padding-top: 5px;
padding-bottom: 5px;
padding-left: 16px;
Expand Down Expand Up @@ -455,6 +476,10 @@ exports[`Button styles primary button appropriately 1`] = `
grid-area: trailingIcon;
}

.c0 [data-component="leadingIcon"] + [data-component="text"] {
text-align: left;
}

.c0 [data-component="ButtonCounter"] {
font-size: 14px;
background-color: btn.primary.counterBg;
Expand Down
17 changes: 14 additions & 3 deletions src/stories/NewButton.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,20 @@ export const caretButton = ({...args}: ButtonProps) => {

export const blockButton = ({...args}: ButtonProps) => {
return (
<Button {...args} sx={{width: '100%'}}>
Block
</Button>
<>
<Button {...args} sx={{width: '100%', mb: 2}}>
Block
</Button>
<Button leadingIcon={EyeIcon} trailingIcon={TriangleDownIcon} {...args} sx={{width: '100%', mb: 2}}>
Watch
</Button>
<Button trailingIcon={TriangleDownIcon} {...args} sx={{width: '100%', mb: 2}}>
Watch
</Button>
<Button leadingIcon={EyeIcon} {...args} sx={{width: '100%'}}>
Watch
</Button>
</>
)
}

Expand Down