-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/develop'
- Loading branch information
Showing
18 changed files
with
330 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,6 +48,7 @@ export { | |
Selector, | ||
Grid, | ||
Item, | ||
Heading, | ||
} from '@westpac/ui'; | ||
|
||
export { | ||
|
9 changes: 1 addition & 8 deletions
9
apps/site/src/content/design-system/components/heading/code/accessibility-api/content.mdoc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1 @@ | ||
Render the heading in uppercase. Line height is adjusted as necessary. | ||
|
||
```jsx | ||
<Fragment> | ||
<h1 className="typography-body-3 uppercase">Heading</h1> | ||
<h1 className="typography-brand-3 uppercase">BrandHeading</h2> | ||
</Fragment> | ||
``` | ||
No specific accessibility attributes required. |
8 changes: 4 additions & 4 deletions
8
apps/site/src/content/design-system/components/heading/code/heading-types/content.mdoc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
There are two heading component options: Heading and BrandHeading. Heading renders in body font and BrandHeading in brand font. | ||
|
||
```jsx | ||
<Fragment> | ||
<h1 className="typography-body-1">Heading</h1> | ||
<h1 className="typography-brand-1">BrandHeading</h1> | ||
</Fragment> | ||
<> | ||
<Heading tag="h1" size={1}>Heading</Heading> | ||
<Heading tag="h1" size={1} brandHeading>BrandHeading</Heading> | ||
</> | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 4 additions & 4 deletions
8
apps/site/src/content/design-system/components/heading/code/tag/content.mdoc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
Define the heading element tag (<h1> - <h6>). This will be determined by the size if a tag is not provided. | ||
|
||
```jsx | ||
<Fragment> | ||
<h1 className="typography-body-3">Heading tag h1 size 3</h1> | ||
<h2 className="typography-body-5">Heading tag h2 size 5</h2> | ||
</Fragment> | ||
<> | ||
<Heading tag="h1" size={3}>Heading tag h1 size 3</Heading> | ||
<Heading tag="h2" size={5}>Heading tag h2 size 5</Heading> | ||
</> | ||
``` |
8 changes: 4 additions & 4 deletions
8
apps/site/src/content/design-system/components/heading/code/uppercase/content.mdoc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
Render the heading in uppercase. Line height is adjusted as necessary. | ||
|
||
```jsx | ||
<Fragment> | ||
<h1 className="typography-body-3 uppercase">Heading</h1> | ||
<h1 className="typography-brand-3 uppercase">BrandHeading</h2> | ||
</Fragment> | ||
<> | ||
<Heading size={1} uppercase>Heading</Heading> | ||
<Heading size={1} brandHeading uppercase>BrandHeading</Heading> | ||
</> | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import React from 'react'; | ||
|
||
import { styles } from './heading.styles.js'; | ||
import { type HeadingProps } from './heading.types.js'; | ||
|
||
export function Heading({ className, tag, brandHeading, size, children, uppercase, ...props }: HeadingProps) { | ||
const sizeToTag = { | ||
1: 'h1', | ||
2: 'h2', | ||
3: 'h3', | ||
4: 'h4', | ||
5: 'h5', | ||
6: 'h6', | ||
7: 'h6', | ||
8: 'h6', | ||
9: 'h6', | ||
10: 'h6', | ||
}; | ||
const Tag = typeof size === 'number' && !tag ? (sizeToTag[size] as keyof HeadingProps['tag']) : tag ? tag : 'h6'; | ||
|
||
return ( | ||
<Tag className={styles({ className, brandHeading, size, uppercase })} {...props}> | ||
{children} | ||
</Tag> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { render } from '@testing-library/react'; | ||
|
||
import { Heading } from './heading.component.js'; | ||
import { styles } from './heading.styles.js'; | ||
import { HeadingProps } from './heading.types.js'; | ||
|
||
describe('Heading', () => { | ||
it('renders the component', () => { | ||
const { container } = render(<Heading size={1}>Heading</Heading>); | ||
expect(container).toBeInTheDocument(); | ||
}); | ||
|
||
it('should have the correct size', () => { | ||
const sizes = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; | ||
sizes.forEach((size: any) => { | ||
const { getByTestId } = render( | ||
<Heading data-testid={size} size={size}> | ||
Heading | ||
</Heading>, | ||
); | ||
expect(getByTestId(size)).toHaveClass(`typography-body-${size}`); | ||
}); | ||
}); | ||
|
||
it('should have the heading tag', () => { | ||
const headingLevels = [1, 2, 3, 4, 5, 6]; | ||
headingLevels.forEach((level: any) => { | ||
const { getByRole } = render( | ||
<Heading tag={`h${level}` as keyof HeadingProps['tag']} size={1}> | ||
Heading | ||
</Heading>, | ||
); | ||
expect(getByRole('heading', { level: level })).toBeInTheDocument(); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
import { type Meta, StoryFn, type StoryObj } from '@storybook/react'; | ||
|
||
import { Heading } from './heading.component.js'; | ||
import { HeadingProps } from './heading.types.js'; | ||
|
||
const meta: Meta<typeof Heading> = { | ||
title: 'Components/Heading', | ||
component: Heading, | ||
tags: ['autodocs'], | ||
decorators: [(Story: StoryFn) => <Story />], | ||
parameters: { | ||
layout: 'centered', | ||
}, | ||
}; | ||
|
||
export default meta; | ||
type Story = StoryObj<typeof meta>; | ||
|
||
const sizes = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; | ||
|
||
/** | ||
* > Default usage example | ||
*/ | ||
export const Default = () => { | ||
return sizes.map((size: any) => <Heading size={size}>Heading size: {size}</Heading>); | ||
}; | ||
|
||
/** | ||
* > With tag prop | ||
*/ | ||
export const WithTag = () => { | ||
return sizes.map((size: any) => ( | ||
<Heading tag={size > 1 ? 'h1' : 'h2'} size={size}> | ||
Heading tag:{size > 1 ? ' h1' : ' h2'} size: {size} | ||
</Heading> | ||
)); | ||
}; | ||
|
||
/** | ||
* > Brand usage example | ||
*/ | ||
export const Brand = () => { | ||
return sizes.map((size: any) => ( | ||
<Heading size={size} brandHeading> | ||
Heading size: {size} | ||
</Heading> | ||
)); | ||
}; | ||
|
||
/** | ||
* > With tag and brand prop | ||
*/ | ||
export const WithTagAndBrand = () => { | ||
return sizes.map((size: any) => ( | ||
<Heading tag={size > 1 ? 'h1' : 'h2'} size={size} brandHeading> | ||
Heading tag:{size > 1 ? ' h1' : ' h2'} size: {size} | ||
</Heading> | ||
)); | ||
}; | ||
|
||
/** | ||
* > Uppercase usage example | ||
*/ | ||
export const Uppercase = () => { | ||
return sizes.map((size: any) => ( | ||
<Heading size={size} uppercase> | ||
Heading size: {size} | ||
</Heading> | ||
)); | ||
}; | ||
|
||
/** | ||
* > Responsive usage example | ||
*/ | ||
export const Responsive = () => { | ||
return ( | ||
<> | ||
<Heading size={{ xsl: 10, sm: 8, md: 6, lg: 4, xl: 2 }}> | ||
Heading size: [xsl: 10, sm: 8, md: 6, lg: 4, xl: 2 ] | ||
</Heading> | ||
<Heading size={{ xsl: 10, xl: 2 }}>Heading size: [xsl: 10, xl: 2]</Heading> | ||
</> | ||
); | ||
}; | ||
|
||
/** | ||
* > Responsive with tag usage example | ||
*/ | ||
export const ResponsiveWithTag = () => { | ||
return ( | ||
<> | ||
<Heading tag="h2" size={{ xsl: 10, sm: 8, md: 6, lg: 4, xl: 2 }}> | ||
Heading tag: h2 size: [xsl: 10, sm: 8, md: 6, lg: 4, xl: 2 ] | ||
</Heading> | ||
<Heading tag="h2" size={{ xsl: 10, xl: 2 }}> | ||
Heading tag: h2 size: [xsl: 10, xl: 2] | ||
</Heading> | ||
</> | ||
); | ||
}; |
Oops, something went wrong.
c00ac0c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
gel-next-site – ./apps/site
gel-next-site.vercel.app
gel-next-site-git-main-westpacgel.vercel.app
gel-next-site-westpacgel.vercel.app