Skip to content

Commit b86bef4

Browse files
authored
Merge pull request #12853 from TylerAPfledderer/refactor/typography-DS-update
refactor(theme/typography): update typography with DS
2 parents 55d531a + a29b281 commit b86bef4

File tree

8 files changed

+89
-53
lines changed

8 files changed

+89
-53
lines changed

.storybook/preview.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ import "../src/styles/global.css"
99

1010
const extendedTheme = extendBaseTheme(theme)
1111

12-
const chakraBreakpointArray = Object.entries(extendedTheme.breakpoints)
12+
const chakraBreakpointArray = Object.entries(extendedTheme.breakpoints) as [
13+
string,
14+
string
15+
][]
1316

1417
const preview: Preview = {
1518
globals: {
@@ -42,6 +45,9 @@ const preview: Preview = {
4245
viewports: chakraBreakpointArray.reduce((prevVal, currVal) => {
4346
const [token, key] = currVal
4447

48+
// `key` value is in em. Need to convert to px for Chromatic Story mode snapshots
49+
const emToPx = (Number(key.replace("em", "")) * 16).toString() + "px"
50+
4551
// Replace base value
4652
if (token === "base")
4753
return {
@@ -60,7 +66,7 @@ const preview: Preview = {
6066
[token]: {
6167
name: token,
6268
styles: {
63-
width: key,
69+
width: emToPx,
6470
height: "600px",
6571
},
6672
},

src/@chakra-ui/components/Heading.ts

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,42 @@
1-
import { defineStyle, defineStyleConfig } from "@chakra-ui/react"
1+
import { defineStyleConfig } from "@chakra-ui/react"
22

33
import { headingDefaultTheme } from "./components.utils"
44

5-
const { sizes: defaultSizes } = headingDefaultTheme
5+
const HEADING_SIZES = ["2xl", "xl", "lg", "md", "sm", "xs"] as const
66

7-
const lineHeightScale = {
8-
"4xl": "6xs",
9-
"3xl": ["6xs", null, "5xs"],
10-
"2xl": ["4xs", null, "5xs"],
11-
xl: ["2xs", null, "4xs"],
12-
lg: ["2xs", null, "3xs"],
13-
md: "xs",
14-
sm: "base",
7+
type SCALE_VALUE = string | [string, null, null, string]
8+
9+
type SIZE_SCALE = { [key in (typeof HEADING_SIZES)[number]]: SCALE_VALUE }
10+
11+
const lineHeightScale: SIZE_SCALE = {
12+
"2xl": "4xs",
13+
xl: ["2xs", null, null, "4xs"],
14+
lg: "2xs",
15+
md: ["xs", null, null, "2xs"],
16+
sm: ["base", null, null, "xs"],
1517
xs: "base",
1618
}
1719

18-
/*
19-
* Instead of rewriting the entire sizes object, take the existing value from the
20-
* default theme and replace the lineHeight values.
21-
*/
22-
const sizes = Object.entries(defaultSizes || {}).reduceRight(
23-
(acc, [key, value]) => {
24-
return {
25-
...acc,
26-
[key]: defineStyle({
27-
...value,
28-
lineHeight: lineHeightScale[key],
29-
}),
30-
}
31-
},
32-
{
33-
...defaultSizes,
20+
const fontSizeScale: SIZE_SCALE = {
21+
"2xl": ["4xl", null, null, "5xl"],
22+
xl: ["3xl", null, null, "4xl"],
23+
lg: ["2xl", null, null, "3xl"],
24+
md: ["xl", null, null, "2xl"],
25+
sm: ["md", null, null, "xl"],
26+
xs: ["sm", null, null, "md"],
27+
}
28+
29+
const sizes = HEADING_SIZES.reduce<{
30+
[key: string]: { fontSize: SCALE_VALUE; lineHeight: SCALE_VALUE }
31+
}>((obj, key) => {
32+
return {
33+
...obj,
34+
[key]: {
35+
fontSize: fontSizeScale[key],
36+
lineHeight: lineHeightScale[key],
37+
},
3438
}
35-
)
39+
}, {})
3640

3741
export const Heading = defineStyleConfig({
3842
...headingDefaultTheme,

src/@chakra-ui/components/Text.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,19 @@ const sizes = {
1111
}),
1212
"4xl": defineStyle({
1313
fontSize: "4xl",
14-
lineHeight: "sm",
14+
lineHeight: "4xs",
1515
}),
1616
"3xl": defineStyle({
1717
fontSize: "3xl",
18-
lineHeight: "sm",
18+
lineHeight: "2xs",
1919
}),
2020
"2xl": defineStyle({
2121
fontSize: "2xl",
22-
lineHeight: "sm",
22+
lineHeight: "2xs",
2323
}),
2424
xl: defineStyle({
2525
fontSize: "xl",
26-
lineHeight: "sm",
26+
lineHeight: "xs",
2727
}),
2828
lg: defineStyle({
2929
fontSize: "lg",

src/@chakra-ui/foundations/typography.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const typography = {
1010
"5xs": 1.15,
1111
"4xs": 1.2,
1212
"3xs": 1.25,
13-
"2xs": 1.35,
13+
"2xs": 1.3,
1414
xs: 1.4,
1515
sm: 1.5,
1616
base: 1.6,

src/@chakra-ui/styles.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const styles = {
1212
body: {
1313
bg: "background.base",
1414
lineHeight: "base",
15-
fontSize: "md",
15+
fontSize: ["sm", null, null, "md"],
1616
},
1717
a: {
1818
color: "primary.base",

src/components/BaseStories/Heading.stories.tsx

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
Stack,
88
VStack,
99
} from "@chakra-ui/react"
10+
import { objectKeys } from "@chakra-ui/utils"
1011
import { Meta, StoryObj } from "@storybook/react"
1112

1213
import Translation from "../Translation"
@@ -16,6 +17,16 @@ const meta = {
1617
component: HeadingComponent,
1718
parameters: {
1819
layout: null,
20+
chromatic: {
21+
modes: {
22+
md: {
23+
viewport: "md",
24+
},
25+
"2xl": {
26+
viewport: "2xl",
27+
},
28+
},
29+
},
1930
},
2031
decorators: [
2132
(Story) => (
@@ -31,20 +42,14 @@ export default meta
3142
type Story = StoryObj<typeof meta>
3243

3344
const headingScale: Array<HeadingProps> = [
34-
{
35-
as: "h1",
36-
size: "4xl",
37-
},
38-
{
39-
as: "h1",
40-
size: "3xl",
41-
},
4245
{
4346
as: "h1",
4447
size: "2xl",
4548
},
4649
{
47-
// No props as the default is `h2` with size `xl
50+
// Note that `h2` is the default render
51+
as: "h2",
52+
size: "xl",
4853
},
4954
{
5055
as: "h3",
@@ -65,16 +70,13 @@ const headingScale: Array<HeadingProps> = [
6570
]
6671

6772
export const Heading: Story = {
68-
args: {
69-
children: <Translation id="page-index:page-index-title" />,
70-
},
71-
render: (args) => (
73+
render: () => (
7274
<VStack w="full">
7375
<Box>
7476
Adjust the viewport to below &quot;md&quot; to see the font size and
7577
line height change
7678
</Box>
77-
<Stack>
79+
<Stack width="full" maxW="4xl">
7880
{headingScale.map((obj, idx) => (
7981
<Flex key={idx} gap="6">
8082
<HeadingComponent
@@ -86,7 +88,7 @@ export const Heading: Story = {
8688
{(obj.size as string) || "xl"}
8789
</HeadingComponent>
8890
<HeadingComponent flex="3" {...obj}>
89-
{args.children}
91+
{`${obj.as} base component`}
9092
</HeadingComponent>
9193
</Flex>
9294
))}

src/components/BaseStories/Text.stories.tsx

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,18 @@ const meta = {
2222
parameters: {
2323
layout: "none",
2424
},
25+
argTypes: {
26+
children: {
27+
table: {
28+
disable: true,
29+
},
30+
},
31+
fontWeight: {
32+
table: {
33+
disable: true,
34+
},
35+
},
36+
},
2537
decorators: [
2638
(Story) => (
2739
<Center minH="100vh">
@@ -145,6 +157,18 @@ export const Link: StoryObj<typeof ChakraLink> = {
145157
}
146158

147159
export const BodyCopy: Story = {
160+
parameters: {
161+
chromatic: {
162+
modes: {
163+
md: {
164+
viewport: "md",
165+
},
166+
"2xl": {
167+
viewport: "2xl",
168+
},
169+
},
170+
},
171+
},
148172
render: () => (
149173
<Box maxW="prose" px="4">
150174
<Text>

src/components/Hero/HubHero/index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,15 @@ const HubHero = ({
5050
wordBreak="break-word"
5151
>
5252
{title ? (
53-
<Heading
53+
<Text
5454
as="h1"
55-
size="sm"
55+
size="md"
5656
color="body.medium"
5757
fontWeight="normal"
5858
textTransform="uppercase"
5959
>
6060
{title}
61-
</Heading>
61+
</Text>
6262
) : null}
6363
<Stack
6464
alignSelf="center"

0 commit comments

Comments
 (0)