diff --git a/spec/__snapshots__/Storyshots.test.js.snap b/spec/__snapshots__/Storyshots.test.js.snap
index 47193930..f253dcef 100644
--- a/spec/__snapshots__/Storyshots.test.js.snap
+++ b/spec/__snapshots__/Storyshots.test.js.snap
@@ -9054,8 +9054,8 @@ Array [
`;
exports[`Storyshots Components/Heading Default 1`] = `
-
The fastest way to recruit research participants
-
+
`;
exports[`Storyshots Components/Heading Levels 1`] = `
@@ -9128,7 +9128,72 @@ Array [
>
The fastest way to recruit research participants
,
-
+ This is a heading level 2 with size="xxxl"
+ ,
+
+ This is a heading level 2 with size="xxl"
+
,
+
+ This is a heading level 2 with size="xl"
+
,
+
+ This is a heading level 2 with size="lg"
+
,
+
+ This is a heading level 2 with size="md"
+
,
+
+ This is a heading level 2 with size="sm"
+
,
+
- The fastest way to recruit research participants
-
,
+ This is a heading level 2 with size="xs"
+ ,
]
`;
@@ -10428,8 +10493,8 @@ exports[`Storyshots Components/MoneyInput Default 1`] = `
value="$ 1,250.99"
/>
-
Value:
1250.99
-
+
`;
@@ -10472,8 +10537,8 @@ exports[`Storyshots Components/MoneyInput Prefix 1`] = `
value="USD$ 500"
/>
-
Value:
500
-
+
`;
@@ -10516,8 +10581,8 @@ exports[`Storyshots Components/MoneyInput Step 1`] = `
value="$ 200"
/>
-
Value:
200
-
+
`;
diff --git a/src/Heading/Heading.stories.tsx b/src/Heading/Heading.stories.tsx
index 7be127c0..80bd34bd 100644
--- a/src/Heading/Heading.stories.tsx
+++ b/src/Heading/Heading.stories.tsx
@@ -24,6 +24,7 @@ type Story = StoryObj;
export const Default: Story = {
args: {
children: 'The fastest way to recruit research participants',
+ level: 1,
},
};
@@ -61,13 +62,30 @@ export const Default: Story = {
export const Levels: Story = {
render: () => (
<>
- The fastest way to recruit research participants
- The fastest way to recruit research participants
- The fastest way to recruit research participants
- The fastest way to recruit research participants
- The fastest way to recruit research participants
- The fastest way to recruit research participants
- The fastest way to recruit research participants
+ The fastest way to recruit research participants
+ The fastest way to recruit research participants
+ The fastest way to recruit research participants
+ The fastest way to recruit research participants
+ The fastest way to recruit research participants
+ The fastest way to recruit research participants
+ >
+ ),
+};
+
+/**
+ Headings come with default sizes based on their level, but you are able to
+ adjust its size based on visual hierarchy needs.
+*/
+export const Sizes: Story = {
+ render: () => (
+ <>
+ This is a heading level 2 with size="xxxl"
+ This is a heading level 2 with size="xxl"
+ This is a heading level 2 with size="xl"
+ This is a heading level 2 with size="lg"
+ This is a heading level 2 with size="md"
+ This is a heading level 2 with size="sm"
+ This is a heading level 2 with size="xs"
>
),
};
diff --git a/src/Heading/Heading.tsx b/src/Heading/Heading.tsx
index bb219af8..8c2e41ac 100644
--- a/src/Heading/Heading.tsx
+++ b/src/Heading/Heading.tsx
@@ -8,16 +8,27 @@ export interface HeadingProps {
children?: ReactNode;
className?: string;
level: 1 | 2 | 3 | 4 | 5 | 6;
- size: 'xs' | 'sm' | 'md' | 'lg' | 'xl' | 'xxl' | 'xxxl';
+ size?: 'xs' | 'sm' | 'md' | 'lg' | 'xl' | 'xxl' | 'xxxl';
textAlign?: 'left' | 'center' | 'right';
- weight: 'regular' | 'medium' | 'bold';
+ weight?: 'regular' | 'medium' | 'bold';
}
+const LevelToSizeMap = {
+ 1: 'xxxl',
+ 2: 'xxl',
+ 3: 'xl',
+ 4: 'lg',
+ 5: 'md',
+ 6: 'sm',
+};
+
+const getHeadingSizeClassFromLevel = (level: number) => `Heading--${LevelToSizeMap[level]}`;
+
const Heading = ({
children,
className,
- level = 2,
- size = 'xxl',
+ level = 1,
+ size,
textAlign,
weight = 'bold',
...props
@@ -28,6 +39,7 @@ const Heading = ({
className: classNames(
className,
'Heading',
+ !size && getHeadingSizeClassFromLevel(level),
{
[`Heading--${size}`]: !!size,
[`Heading--${weight}`]: !!weight,