Skip to content

Commit fb85f54

Browse files
refactor(Text.stories): update stories for tailwind
1 parent 37ce2d4 commit fb85f54

File tree

3 files changed

+182
-182
lines changed

3 files changed

+182
-182
lines changed

src/components/BaseStories/Text.stories.tsx

Lines changed: 0 additions & 174 deletions
This file was deleted.
Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
import * as React from "react"
2+
import { Meta, StoryObj } from "@storybook/react"
3+
4+
import { cn } from "@/lib/utils/cn"
5+
6+
import LinkComponent from "../../Link"
7+
import Translation from "../../Translation"
8+
import { Center, Flex, Stack, VStack } from "../flex"
9+
10+
const meta = {
11+
title: "Atoms / Typography / Text",
12+
parameters: {
13+
layout: "none",
14+
},
15+
decorators: [
16+
(Story) => (
17+
<Center className="min-h-[100vh]">
18+
<Story />
19+
</Center>
20+
),
21+
],
22+
} satisfies Meta
23+
24+
export default meta
25+
26+
type Story = StoryObj<typeof meta>
27+
28+
const textSizes = [
29+
"text-6xl",
30+
"text-5xl",
31+
"text-4xl",
32+
"text-3xl",
33+
"text-2xl",
34+
"text-xl",
35+
"text-lg",
36+
"text-sm",
37+
"text-xs",
38+
]
39+
40+
const SINGLE_TEXT_CHILD = <Translation id="page-index:page-index-title" />
41+
42+
export const Normal = {
43+
decorators: [
44+
(Story) => (
45+
<VStack className="w-full">
46+
<div>
47+
Adjust the viewport to below &quot;md&quot; to see the font size and
48+
line height change
49+
</div>
50+
<Stack>
51+
<Story />
52+
</Stack>
53+
</VStack>
54+
),
55+
],
56+
render: () => {
57+
return (
58+
<>
59+
{textSizes.map((size) => (
60+
<Flex key={size} className="gap-6">
61+
<p className={cn(size, "flex-1 text-end")}>
62+
{size.replace("text-", "")}
63+
</p>
64+
<p className={cn(size, "flex-[9]")}>{SINGLE_TEXT_CHILD}</p>
65+
</Flex>
66+
))}
67+
</>
68+
)
69+
},
70+
} satisfies Story
71+
72+
export const Bold: Story = {
73+
decorators: Normal.decorators,
74+
render: () => {
75+
return (
76+
<>
77+
{textSizes.map((size) => (
78+
<Flex key={size} className="gap-6">
79+
<p className={cn(size, "flex-1 text-end")}>
80+
{size.replace("text-", "")}
81+
</p>
82+
<p className={cn(size, "flex-[9] font-bold")}>
83+
{SINGLE_TEXT_CHILD}
84+
</p>
85+
</Flex>
86+
))}
87+
</>
88+
)
89+
},
90+
}
91+
export const Italic: Story = {
92+
decorators: Normal.decorators,
93+
render: () => {
94+
return (
95+
<>
96+
{textSizes.map((size) => (
97+
<Flex key={size} className="gap-6">
98+
<p className={cn(size, "flex-1 text-end")}>
99+
{size.replace("text-", "")}
100+
</p>
101+
<p className={cn(size, "flex-[9] italic")}>{SINGLE_TEXT_CHILD}</p>
102+
</Flex>
103+
))}
104+
</>
105+
)
106+
},
107+
}
108+
109+
export const Link: Story = {
110+
decorators: Normal.decorators,
111+
render: () => {
112+
return (
113+
<>
114+
{textSizes.map((size) => (
115+
<Flex key={size} className="gap-6">
116+
<p className={cn(size, "flex-1 text-end")}>
117+
{size.replace("text-", "")}
118+
</p>
119+
<LinkComponent href="#" className={cn(size, "flex-[9]")}>
120+
{SINGLE_TEXT_CHILD}
121+
</LinkComponent>
122+
</Flex>
123+
))}
124+
</>
125+
)
126+
},
127+
}
128+
129+
export const BodyCopy: Story = {
130+
parameters: {
131+
chromatic: {
132+
modes: {
133+
md: {
134+
viewport: "md",
135+
},
136+
"2xl": {
137+
viewport: "2xl",
138+
},
139+
},
140+
},
141+
},
142+
render: () => (
143+
<div className="max-w-prose px-4">
144+
<p>
145+
Text body normal. Ethereum is open access to digital money and
146+
data-friendly services for everyone - no matter your background or
147+
location. It&apos;s a community-built technology behind the
148+
cryptocurrency ether (ETH) and thousands of applications you can use
149+
today!
150+
</p>
151+
</div>
152+
),
153+
}

src/components/ui/flex.tsx

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,41 +11,62 @@ const Flex = forwardRef<FlexElement, FlexProps>(
1111
({ asChild, className, ...props }, ref) => {
1212
const Comp = asChild ? Slot : "div"
1313

14+
return <Comp ref={ref} className={cn("flex", className)} {...props} />
15+
}
16+
)
17+
18+
Flex.displayName = "Flex"
19+
20+
const Center = forwardRef<FlexElement, FlexProps>(
21+
({ className, ...props }, ref) => {
1422
return (
15-
<Comp
23+
<Flex
1624
ref={ref}
17-
className={cn("flex", className)}
25+
className={cn("items-center justify-center", className)}
1826
{...props}
1927
/>
2028
)
2129
}
22-
2330
)
2431

25-
Flex.displayName = "Flex"
32+
Center.displayName = "Center"
2633

2734
const Stack = forwardRef<FlexElement, FlexProps>(
2835
({ className, ...props }, ref) => {
29-
return <Flex ref={ref} className={cn("flex-col gap-2", className)} {...props} />
36+
return (
37+
<Flex ref={ref} className={cn("flex-col gap-2", className)} {...props} />
38+
)
3039
}
3140
)
3241

3342
Stack.displayName = "Stack"
3443

3544
const HStack = forwardRef<FlexElement, FlexProps>(
3645
({ className, ...props }, ref) => {
37-
return <Stack ref={ref} className={cn("flex-row items-center", className)} {...props} />
46+
return (
47+
<Stack
48+
ref={ref}
49+
className={cn("flex-row items-center", className)}
50+
{...props}
51+
/>
52+
)
3853
}
3954
)
4055

4156
HStack.displayName = "HStack"
4257

4358
const VStack = forwardRef<FlexElement, FlexProps>(
4459
({ className, ...props }, ref) => {
45-
return <Stack ref={ref} className={cn("flex-col items-center", className)} {...props} />
60+
return (
61+
<Stack
62+
ref={ref}
63+
className={cn("flex-col items-center", className)}
64+
{...props}
65+
/>
66+
)
4667
}
4768
)
4869

4970
VStack.displayName = "VStack"
5071

51-
export { Flex, HStack, Stack, VStack }
72+
export { Center, Flex, HStack, Stack, VStack }

0 commit comments

Comments
 (0)