Skip to content

Commit

Permalink
Merge 5c41033 into 2ab2b3c
Browse files Browse the repository at this point in the history
  • Loading branch information
langermank authored Aug 1, 2024
2 parents 2ab2b3c + 5c41033 commit 69b2052
Show file tree
Hide file tree
Showing 16 changed files with 154 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/clever-birds-press.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@primer/react": patch
---

Add `variant` prop to Heading for small, medium and large styles
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.
84 changes: 84 additions & 0 deletions e2e/components/Heading.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,88 @@ test.describe('Heading', () => {
})
}
})

test.describe('Small', () => {
for (const theme of themes) {
test.describe(theme, () => {
test('default @vrt', async ({page}) => {
await visit(page, {
id: 'components-heading--small',
globals: {
colorScheme: theme,
},
})

// Default state
expect(await page.screenshot()).toMatchSnapshot(`Heading.Default.${theme}.png`)
})

test('axe @aat', async ({page}) => {
await visit(page, {
id: 'components-heading--small',
globals: {
colorScheme: theme,
},
})
await expect(page).toHaveNoViolations()
})
})
}
})

test.describe('Medium', () => {
for (const theme of themes) {
test.describe(theme, () => {
test('default @vrt', async ({page}) => {
await visit(page, {
id: 'components-heading--medium',
globals: {
colorScheme: theme,
},
})

// Default state
expect(await page.screenshot()).toMatchSnapshot(`Heading.Default.${theme}.png`)
})

test('axe @aat', async ({page}) => {
await visit(page, {
id: 'components-heading--medium',
globals: {
colorScheme: theme,
},
})
await expect(page).toHaveNoViolations()
})
})
}
})

test.describe('Large', () => {
for (const theme of themes) {
test.describe(theme, () => {
test('default @vrt', async ({page}) => {
await visit(page, {
id: 'components-heading--large',
globals: {
colorScheme: theme,
},
})

// Default state
expect(await page.screenshot()).toMatchSnapshot(`Heading.Default.${theme}.png`)
})

test('axe @aat', async ({page}) => {
await visit(page, {
id: 'components-heading--large',
globals: {
colorScheme: theme,
},
})
await expect(page).toHaveNoViolations()
})
})
}
})
})
5 changes: 5 additions & 0 deletions packages/react/src/Heading/Heading.docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
"name": "as",
"type": "React.ElementType",
"defaultValue": "\"h2\""
},
{
"name": "variant",
"type": "'large' | 'medium' | 'small'",
"defaultValue": ""
}
]
}
24 changes: 24 additions & 0 deletions packages/react/src/Heading/Heading.featires.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import React from 'react'
import type {StoryFn} from '@storybook/react'
import Heading from './Heading'

export default {
title: 'Components/Heading',
}

export const TestSx: StoryFn<typeof Heading> = () => (
<Heading
sx={{
fontSize: 2,
fontWeight: 'normal',
}}
>
Heading with sx override
</Heading>
)

export const Small: StoryFn<typeof Heading> = () => <Heading variant="small">Small heading</Heading>

export const Medium: StoryFn<typeof Heading> = () => <Heading variant="medium">Medium heading</Heading>

export const Large: StoryFn<typeof Heading> = () => <Heading variant="large">Large heading</Heading>
11 changes: 9 additions & 2 deletions packages/react/src/Heading/Heading.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export default {
title: 'Components/Heading',
component: Heading,
} as Meta<typeof Heading>

export const Default: StoryFn<typeof Heading> = () => <Heading>Default H2 Heading</Heading>

export const Playground: StoryFn<typeof Heading> = args => <Heading {...args}>Heading</Heading>
Expand All @@ -17,8 +18,14 @@ Playground.args = {
Playground.argTypes = {
as: {
control: {
type: 'select',
options: ['h1', 'h2', 'h3', 'h4', 'h5', 'h6'],
type: 'radio',
},
options: ['h1', 'h2', 'h3', 'h4', 'h5', 'h6'],
},
variant: {
control: {
type: 'radio',
},
options: ['large', 'medium', 'small'],
},
}
16 changes: 15 additions & 1 deletion packages/react/src/Heading/Heading.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,28 @@ import type {ForwardRefComponent as PolymorphicForwardRefComponent} from '../uti

type StyledHeadingProps = {
as?: 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6'
variant?: 'large' | 'medium' | 'small'
} & SxProp

const StyledHeading = styled.h2<StyledHeadingProps>`
font-weight: ${get('fontWeights.bold')};
font-size: ${get('fontSizes.5')};
margin: 0;
&:where([data-variant='large']) {
font: var(--text-title-shorthand-large, 600 32px / 1.5 ${get('fonts.normal')});
}
&:where([data-variant='medium']) {
font: var(--text-title-shorthand-medium, 600 20px / 1.6 ${get('fonts.normal')});
}
&:where([data-variant='small']) {
font: var(--text-title-shorthand-small, 600 16px / 1.5 ${get('fonts.normal')});
}
${sx};
`
const Heading = forwardRef(({as: Component = 'h2', ...props}, forwardedRef) => {
const Heading = forwardRef(({as: Component = 'h2', variant, ...props}, forwardedRef) => {
const innerRef = React.useRef<HTMLHeadingElement>(null)
useRefObjectAsForwardedRef(forwardedRef, innerRef)

Expand All @@ -43,6 +56,7 @@ const Heading = forwardRef(({as: Component = 'h2', ...props}, forwardedRef) => {
{...props}
// @ts-ignore shh
ref={innerRef}
data-variant={variant}
/>
)
}) as PolymorphicForwardRefComponent<'h2', StyledHeadingProps>
Expand Down
12 changes: 12 additions & 0 deletions packages/react/src/NavList/__snapshots__/NavList.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,18 @@ exports[`NavList renders with groups 1`] = `
color: var(--fgColor-muted,var(--color-fg-muted,#656d76));
}
.c3:where([data-variant='large']) {
font: var(--text-title-shorthand-large,600 32px / 1.5 -apple-system,BlinkMacSystemFont,"Segoe UI","Noto Sans",Helvetica,Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji");
}
.c3:where([data-variant='medium']) {
font: var(--text-title-shorthand-medium,600 20px / 1.6 -apple-system,BlinkMacSystemFont,"Segoe UI","Noto Sans",Helvetica,Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji");
}
.c3:where([data-variant='small']) {
font: var(--text-title-shorthand-small,600 16px / 1.5 -apple-system,BlinkMacSystemFont,"Segoe UI","Noto Sans",Helvetica,Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji");
}
.c0 {
margin: 0;
padding-inline-start: 0;
Expand Down

0 comments on commit 69b2052

Please sign in to comment.