Skip to content

Commit 487a9e7

Browse files
JoshBowdenConceptsJoshua Bowdenrezrah
authored
Created a Medium Button Style (#78)
* Created a Medium Button Style * Create cuddly-peas-try.md * Fixed css variable usage and prop implementation * Reverted size to ternary * updated snapshots * Update .changeset/cuddly-peas-try.md Co-authored-by: Rez <[email protected]> * Update .changeset/cuddly-peas-try.md Co-authored-by: Rez <[email protected]> * Update cuddly-peas-try.md Co-authored-by: Joshua Bowden <[email protected]> Co-authored-by: Rez <[email protected]>
1 parent 9ef5e8e commit 487a9e7

17 files changed

+48
-5
lines changed

.changeset/cuddly-peas-try.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
"@primer/react-brand": minor
3+
---
4+
5+
Added a new `size` prop to `Button` and a `medium` sized variant, making the previous `large` size optional.
6+
7+
⚠️ This update should be considered a breaking change, despite being issued in a `minor` release.
8+
9+
Selectable values: `medium` (default) and `large`.
10+
11+
**Upgrade steps:**
12+
13+
```diff
14+
- <Button>before</Button>
15+
+ <Button size="large">after</Button>
16+
```

src/Button/Button.module.css

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
display: inline-flex;
66
align-items: center;
77
justify-content: center;
8-
padding: 1rem 1.5rem;
98
transition: box-shadow 0.2s;
109
text-decoration: none;
1110
border-radius: 6px;
@@ -50,3 +49,11 @@
5049
.Button--secondary:hover {
5150
box-shadow: inset 0 0 0 2px var(--brand-color-neutral-emphasisPlus);
5251
}
52+
53+
.Button--size-medium {
54+
padding: var(--base-size-16) var(--base-size-24);
55+
}
56+
57+
.Button--size-large {
58+
padding: var(--base-size-16) var(--base-size-32);
59+
}

src/Button/Button.module.css.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ declare const styles: {
55
readonly "Button--primary": string;
66
readonly "Button--label-primary": string;
77
readonly "Button--secondary": string;
8+
readonly "Button--size-medium": string;
9+
readonly "Button--size-large": string;
810
};
911
export = styles;
1012

src/Button/Button.stories.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export const Primary = Template.bind({})
1313
Primary.args = {
1414
as: 'a',
1515
variant: 'primary',
16+
size: 'medium',
1617
href: '#',
1718
children: 'Primary action'
1819
}
@@ -25,6 +26,15 @@ Secondary.args = {
2526
children: 'Secondary action'
2627
}
2728

29+
export const Large = Template.bind({})
30+
Large.args = {
31+
as: 'a',
32+
size: 'large',
33+
variant: 'primary',
34+
href: '#',
35+
children: 'Large Action'
36+
}
37+
2838
export const Polymorphism = Template.bind({})
2939
Polymorphism.args = {
3040
as: 'button',

src/Button/Button.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@ import styles from './Button.module.css'
99
export type ButtonProps<C extends React.ElementType> = BaseProps<C> & {
1010
as?: C
1111
variant?: 'primary' | 'secondary'
12+
size?: 'medium' | 'large'
1213
} & React.ComponentPropsWithoutRef<C>
1314

1415
export const Button = forwardRef(
1516
<C extends React.ElementType>(
1617
{
1718
as,
1819
variant = 'secondary',
20+
size = 'medium',
1921
className,
2022
children,
2123
onMouseEnter,
@@ -33,7 +35,7 @@ export const Button = forwardRef(
3335
return (
3436
<Component
3537
ref={ref}
36-
className={clsx(styles.Button, styles[`Button--${variant}`], className)}
38+
className={clsx(styles.Button, styles[`Button--${variant}`], styles[`Button--size-${size}`], className)}
3739
onMouseEnter={event => {
3840
setIsHovered(true)
3941
onMouseEnter?.(event)
@@ -54,7 +56,7 @@ export const Button = forwardRef(
5456
>
5557
<Text
5658
as="span"
57-
size="400"
59+
size={size === 'medium' ? '300' : '400'}
5860
className={clsx(styles['Button--label'], variant === 'primary' && styles['Button--label-primary'])}
5961
>
6062
{children}

src/Button/Button.visual.spec.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ test.describe('Visual Comparison: Button', () => {
1919
expect(await page.screenshot()).toMatchSnapshot()
2020
})
2121

22+
test('Button / Large', async ({page}) => {
23+
await page.goto('http://localhost:6006/iframe.html?args=&id=components-button--large&viewMode=story')
24+
25+
expect(await page.screenshot()).toMatchSnapshot()
26+
})
27+
2228
test('Button / Polymorphism', async ({page}) => {
2329
await page.goto('http://localhost:6006/iframe.html?args=&id=components-button--polymorphism&viewMode=story')
2430

8.83 KB
Loading
-658 Bytes
Loading
-604 Bytes
Loading
-707 Bytes
Loading

0 commit comments

Comments
 (0)