Skip to content

Commit 4bac386

Browse files
authored
Added variant support to Hero.Description (#867)
1 parent 2502f65 commit 4bac386

File tree

8 files changed

+48
-11
lines changed

8 files changed

+48
-11
lines changed

.changeset/perfect-needles-guess.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@primer/react-brand': patch
3+
---
4+
5+
`Hero.Description` updated to support `variant="muted"`

apps/docs/content/components/Hero/index.mdx

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ export default ComponentLayout
2121

2222
Use the hero component to provide a title, description and action that introduces the main content of a page. The hero component is designed to be positioned at the top of a page and spans the full width of the viewport. Consider using the [CTA banner](/components/CTABanner) to replicate the content and actions in other parts of the page.
2323

24-
Both heading and description of the hero should be short and descriptive. Heading should be not be longer than 2 lines, and description should be no longer than 3-4 lines.
24+
Both the heading and description of the hero should be concise and descriptive. The heading should not exceed two lines, and the description should be limited to 3–4 lines.
25+
26+
The description must maintain a minimum contrast ratio of 4.5:1 at all times. Since it may appear in either the `default` or `muted` text colors, ensure the `muted` variant is used only when contrast is sufficient and no background imagery is present.
2527

2628
The hero component is not designed to provide a lot of information to the user. Consider using other components, such as the [section intro](/components/SectionIntro) or the [river](/components/River) component instead.
2729

@@ -47,8 +49,6 @@ The hero can optionally include primary and secondary actions. These actions are
4749

4850
## Options
4951

50-
51-
5252
### Alignment
5353

5454
Hero elements can be aligned to the start or center of the page. By default, the hero is aligned to the start of the page to allow for an image or a visual asset to be positioned on the right of the hero. Use the center alignment if the asset is centered or not present, or the scenario calls for it.

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

+6-3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import {
1616
HeadingStretch,
1717
defaultHeadingTag,
1818
HeadingLetterSpacing,
19+
TextVariants,
20+
defaultTextVariant,
1921
} from '@primer/react-brand'
2022
import {Label} from '@primer/react'
2123
import {PropTableValues} from '../../../src/components'
@@ -121,9 +123,10 @@ Forwards all props from the [Heading component](/components/Heading), including
121123

122124
### Hero.Description
123125

124-
| name | type | default | description |
125-
| ----------- | -------- | ------- | ----------------------- |
126-
| `className` | `string` | | Sets a custom CSS class |
126+
| name | type | default | description |
127+
| ----------- | ------------------------------------------------------- | ------------------------------------------------- | ----------------------------------- |
128+
| `className` | `string` | | Sets a custom CSS class |
129+
| `variant` | <PropTableValues values={TextVariants} addLineBreaks /> | <PropTableValues values={[defaultTextVariant]} /> | Specify alternative text appearance |
127130

128131
Forwards `size` and `weight` props from the [Text component](/components/Text).
129132

apps/docs/scripts/components-with-animation.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ export const supportedComponents = [
99
'Image',
1010
'Label',
1111
'Pillar',
12-
'Stack',
1312
'SectionIntro',
13+
'Stack',
1414
'Statistic',
1515
'Testimonial',
1616
'Text',

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

+12
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,18 @@ export const Centered: StoryFn<typeof Hero> = _args => (
3232
</Hero>
3333
)
3434

35+
export const WithMutedDescriptions: StoryFn<typeof Hero> = _args => (
36+
<Hero align="center">
37+
<Hero.Label>Label</Hero.Label>
38+
<Hero.Heading>This is my super sweet hero heading</Hero.Heading>
39+
<Hero.Description variant="muted">
40+
Lorem ipsum dolor sit amet, consectetur adipiscing elit. In sapien sit ullamcorper id. Aliquam luctus sed turpis
41+
felis nam pulvinar risus elementum.
42+
</Hero.Description>
43+
<Hero.PrimaryAction href="#">Primary action</Hero.PrimaryAction>
44+
</Hero>
45+
)
46+
3547
export const WithImageBlockEndDefault: StoryFn<typeof Hero> = _args => (
3648
<Grid>
3749
<Grid.Column>

packages/react/src/Hero/Hero.tsx

+12-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import clsx from 'clsx'
33
import styles from './Hero.module.css'
44
import {Button, ButtonBaseProps} from '../Button'
55
import {Heading, HeadingProps} from '../Heading'
6-
import {Text, TextSizes, TextWeightVariants, ResponsiveWeightMap} from '../Text'
6+
import {Text, TextSizes, TextWeightVariants, ResponsiveWeightMap, TextProps} from '../Text'
77
import {Label, LabelProps} from '../Label'
88
import {Image, ImageProps} from '../Image'
99
import {Grid} from '../Grid'
@@ -133,12 +133,20 @@ const HeroHeading = forwardRef<HTMLHeadingElement, HeroHeadingProps>(({children,
133133
type HeroDescriptionProps = {
134134
size?: (typeof TextSizes)[number]
135135
weight?: TextWeightVariants | ResponsiveWeightMap
136-
} & BaseProps<HTMLParagraphElement>
136+
} & BaseProps<HTMLParagraphElement> &
137+
TextProps
137138

138139
const HeroDescription = forwardRef<HTMLParagraphElement, PropsWithChildren<HeroDescriptionProps>>(
139-
({size = '200', weight, children, className}: PropsWithChildren<HeroDescriptionProps>, ref) => {
140+
({size = '200', weight, children, variant = 'default', className}: PropsWithChildren<HeroDescriptionProps>, ref) => {
140141
return (
141-
<Text ref={ref} className={clsx(styles['Hero-description'], className)} as="p" size={size} weight={weight}>
142+
<Text
143+
ref={ref}
144+
className={clsx(styles['Hero-description'], className)}
145+
as="p"
146+
size={size}
147+
weight={weight}
148+
variant={variant}
149+
>
142150
{children}
143151
</Text>
144152
)

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

+9
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,15 @@ test.describe('Visual Comparison: Hero', () => {
2121
expect(await page.screenshot({fullPage: true})).toMatchSnapshot()
2222
})
2323

24+
test('Hero / With Muted Descriptions', async ({page}) => {
25+
await page.goto(
26+
'http://localhost:6006/iframe.html?args=&id=components-hero-features--with-muted-descriptions&viewMode=story',
27+
)
28+
29+
await page.waitForTimeout(500)
30+
expect(await page.screenshot({fullPage: true})).toMatchSnapshot()
31+
})
32+
2433
test('Hero / With an image (left + bottom)', async ({page}) => {
2534
await page.goto(
2635
'http://localhost:6006/iframe.html?args=&id=components-hero-features--with-image-block-end-default&viewMode=story',

0 commit comments

Comments
 (0)