-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathtypography.tsx
More file actions
213 lines (192 loc) · 4.66 KB
/
typography.tsx
File metadata and controls
213 lines (192 loc) · 4.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
import * as React from 'react'
import { Slot } from '@radix-ui/react-slot'
import { cn } from '@/lib/utils'
export interface HeadingProps extends React.HTMLAttributes<HTMLHeadingElement> {
as?: 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6'
size?: 'xs' | 'sm' | 'md' | 'lg' | 'xl' | '2xl' | '3xl' | '4xl'
weight?: 'normal' | 'medium' | 'semibold' | 'bold'
asChild?: boolean
}
const headingSizes = {
xs: 'text-xs',
sm: 'text-sm',
md: 'text-base',
lg: 'text-lg',
xl: 'text-xl',
'2xl': 'text-2xl',
'3xl': 'text-3xl',
'4xl': 'text-4xl sm:text-5xl',
}
const headingWeights = {
normal: 'font-normal',
medium: 'font-medium',
semibold: 'font-semibold',
bold: 'font-bold',
}
const defaultSizes: Record<string, keyof typeof headingSizes> = {
h1: '4xl',
h2: '3xl',
h3: '2xl',
h4: 'xl',
h5: 'lg',
h6: 'md',
}
export function Heading({
as: Tag = 'h2',
size,
weight = 'bold',
asChild,
className,
children,
...props
}: HeadingProps) {
const Comp: any = asChild ? Slot : Tag
const resolvedSize = size || defaultSizes[Tag]
return (
<Comp
className={cn(
'tracking-tight text-foreground',
headingSizes[resolvedSize],
headingWeights[weight],
className
)}
{...props}
>
{children}
</Comp>
)
}
export interface TextProps extends React.HTMLAttributes<HTMLParagraphElement> {
as?: 'p' | 'span' | 'div' | 'label'
size?: 'xs' | 'sm' | 'md' | 'lg' | 'xl'
weight?: 'normal' | 'medium' | 'semibold' | 'bold'
color?: 'default' | 'muted' | 'primary' | 'destructive'
leading?: 'none' | 'tight' | 'snug' | 'normal' | 'relaxed' | 'loose'
asChild?: boolean
}
const textSizes = {
xs: 'text-xs',
sm: 'text-sm',
md: 'text-base',
lg: 'text-lg',
xl: 'text-xl',
}
const textWeights = {
normal: 'font-normal',
medium: 'font-medium',
semibold: 'font-semibold',
bold: 'font-bold',
}
const textColors = {
default: 'text-foreground',
muted: 'text-muted-foreground',
primary: 'text-primary',
destructive: 'text-destructive',
}
const textLeading = {
none: 'leading-none',
tight: 'leading-tight',
snug: 'leading-snug',
normal: 'leading-normal',
relaxed: 'leading-relaxed',
loose: 'leading-loose',
}
export function Text({
as: Tag = 'p',
size = 'md',
weight = 'normal',
color = 'default',
leading = 'normal',
asChild,
className,
children,
...props
}: TextProps) {
const Comp: any = asChild ? Slot : Tag
return (
<Comp
className={cn(
textSizes[size],
textWeights[weight],
textColors[color],
textLeading[leading],
className
)}
{...props}
>
{children}
</Comp>
)
}
export interface ProseProps extends React.HTMLAttributes<HTMLDivElement> {
size?: 'sm' | 'md' | 'lg'
}
const proseSizes = {
sm: 'prose-sm',
md: 'prose',
lg: 'prose-lg',
}
export function Prose({
size = 'md',
className,
children,
...props
}: ProseProps) {
return (
<div
className={cn(
'prose dark:prose-invert max-w-none',
proseSizes[size],
className
)}
{...props}
>
{children}
</div>
)
}
export interface CodeProps extends React.HTMLAttributes<HTMLElement> {
inline?: boolean
}
export function Code({
inline = true,
className,
children,
...props
}: CodeProps) {
if (inline) {
return (
<code
className={cn(
'relative rounded bg-muted px-[0.3rem] py-[0.2rem] font-mono text-sm',
className
)}
{...props}
>
{children}
</code>
)
}
return (
<pre
className={cn('overflow-x-auto rounded-lg bg-muted p-4', className)}
{...props}
>
<code className="font-mono text-sm">{children}</code>
</pre>
)
}
export interface KbdProps extends React.HTMLAttributes<HTMLElement> {}
export function Kbd({ className, children, ...props }: KbdProps) {
return (
<kbd
className={cn(
'pointer-events-none inline-flex h-5 select-none items-center gap-1 rounded border bg-muted px-1.5 font-mono text-[10px] font-medium text-muted-foreground',
className
)}
{...props}
>
{children}
</kbd>
)
}