Skip to content

Commit 010578b

Browse files
Add small Label option (#946)
1 parent b11c431 commit 010578b

File tree

9 files changed

+41
-17
lines changed

9 files changed

+41
-17
lines changed

.changeset/rich-rules-fix.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@primer/react-brand': patch
3+
---
4+
5+
Added a new `small` size option for `Label`
6+
7+
🔗 [See documentation for usage examples](https://primer.style/brand/components/Label/react#sizes)

apps/docs/content/components/Label/react.mdx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,11 @@ This is the default variant for the Label component. It corresponds to the `m
3030

3131
### Sizes
3232

33-
Use the `size` prop to change the size of the `Label` component. The `medium` size is recommended for small titles or headings and the `large` size is recommended for large titles or section intros.
33+
Use the `size` prop to adjust the size of the `Label` component. The `small` size is ideal for body text. The `medium` size is recommended for small headings and `large` is suitable for large headings or section intros.
3434

3535
```jsx live
3636
<Stack direction="horizontal" alignItems="flex-start" padding="none">
37+
<Label size="small">Small</Label>
3738
<Label size="medium">Medium</Label>
3839
<Label size="large">Large</Label>
3940
</Stack>

packages/react/src/Label/Label.features.stories.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,13 @@ export default {
99
component: Label,
1010
} as Meta<typeof Label>
1111

12-
export const Large = () => <Label size="large">Large</Label>
12+
export const Sizes = () => (
13+
<Stack direction="horizontal" flexWrap="wrap">
14+
<Label size="small">Small</Label>
15+
<Label size="medium">Medium</Label>
16+
<Label size="large">Large</Label>
17+
</Stack>
18+
)
1319

1420
export const Color = () => (
1521
<Stack alignItems="flex-start" direction="horizontal" flexWrap="wrap">

packages/react/src/Label/Label.module.css

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@
2828
color: var(--brand-Label-color-start, var(--brand-Label-color, currentColor));
2929
position: relative;
3030
height: min-content;
31-
padding-inline: var(--base-size-16);
32-
padding-block: var(--base-size-4);
3331
background: none;
3432
text-align: center;
3533
}
@@ -54,12 +52,26 @@
5452
mask-composite: exclude;
5553
}
5654

55+
.Label--size-small {
56+
min-height: var(--base-size-20);
57+
padding-inline: var(--base-size-8);
58+
padding-block: var(--base-size-2);
59+
}
60+
61+
.Label--size-small .Label__label {
62+
font-size: var(--base-size-12) !important; /* Font size not available in the typographic scale */
63+
}
64+
5765
.Label--size-medium {
5866
min-height: var(--base-size-28);
67+
padding-inline: var(--base-size-16);
68+
padding-block: var(--base-size-4);
5969
}
6070

6171
.Label--size-large {
6272
min-height: var(--base-size-32);
73+
padding-inline: var(--base-size-16);
74+
padding-block: var(--base-size-4);
6375
}
6476

6577
.Label--color-default {

packages/react/src/Label/Label.module.css.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ declare const styles: {
2323
readonly "Label--gradient": string;
2424
readonly "Label--size-large": string;
2525
readonly "Label--size-medium": string;
26+
readonly "Label--size-small": string;
2627
readonly "Label__icon-visual": string;
2728
readonly "Label__label": string;
2829
readonly "Label__leading-visual": string;

packages/react/src/Label/Label.test.tsx

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, {render, cleanup} from '@testing-library/react'
22
import '@testing-library/jest-dom'
33

4-
import {Label} from './Label'
4+
import {Label, LabelSizes} from './Label'
55
import {axe, toHaveNoViolations} from 'jest-axe'
66
import {CopilotIcon} from '@primer/octicons-react'
77

@@ -32,14 +32,11 @@ describe('Label', () => {
3232
expect(labelEl.classList).toContain(expectedShapeClass)
3333
})
3434

35-
it('renders the correct size', () => {
36-
const expectedSize = `large`
37-
const expectedSizeClass = `Label--size-${expectedSize}`
38-
39-
const {getByTestId} = render(<Label size={expectedSize}>{mockText}</Label>)
40-
35+
it.each(LabelSizes)('renders the correct size: %s', size => {
36+
const {getByTestId} = render(<Label size={size}>{mockText}</Label>)
4137
const labelEl = getByTestId(Label.testIds.root)
42-
expect(labelEl.classList).toContain(expectedSizeClass)
38+
39+
expect(labelEl.classList).toContain(`Label--size-${size}`)
4340
})
4441

4542
it('renders the correct default color', () => {

packages/react/src/Label/Label.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ import {Icon} from '@primer/octicons-react'
1919
const Gradients = [...BiColorGradients, ...TriColorGradients] as const
2020

2121
export const LabelColors = [...Colors, ...Gradients] as const
22-
export const LabelSizes = ['medium', 'large'] as const
22+
export const LabelSizes = ['small', 'medium', 'large'] as const
2323

2424
export const defaultLabelColor = LabelColors[0]
25-
export const defaultLabelSize = LabelSizes[0]
25+
export const defaultLabelSize = LabelSizes[1]
2626

2727
export type LabelProps = BaseProps<HTMLSpanElement> & {
2828
/**
@@ -95,7 +95,7 @@ const _Label = forwardRef<HTMLSpanElement, LabelProps>(
9595
</span>
9696
)}
9797
<span className={clsx(styles['Label__text'])}>
98-
<Text as="span" size={size === 'medium' ? '100' : '200'} className={clsx(styles['Label__label'])}>
98+
<Text as="span" size={size === 'large' ? '200' : '100'} className={clsx(styles['Label__label'])}>
9999
{children}
100100
</Text>
101101
</span>

packages/react/src/Label/Label.visual.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ test.describe('Visual Comparison: Label', () => {
2121
expect(await page.screenshot({fullPage: true})).toMatchSnapshot()
2222
})
2323

24-
test('Label / Large', async ({page}) => {
25-
await page.goto('http://localhost:6006/iframe.html?args=&id=components-label-features--large&viewMode=story')
24+
test('Label / Sizes', async ({page}) => {
25+
await page.goto('http://localhost:6006/iframe.html?args=&id=components-label-features--sizes&viewMode=story')
2626

2727
await page.waitForTimeout(500)
2828
expect(await page.screenshot({fullPage: true})).toMatchSnapshot()
11.3 KB
Loading

0 commit comments

Comments
 (0)