@mbao01/common 0.0.36 → 0.0.38
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/types/components/FileUploader/FileUploader.d.ts +1 -1
- package/dist/types/components/FileUploader/types.d.ts +8 -1
- package/dist/types/typography/TypographyDemo.d.ts +1 -0
- package/dist/types/typography/TypographyScale.d.ts +1 -0
- package/package.json +3 -2
- package/plugin.js +5 -1
- package/src/components/FileUploader/FileUploader.tsx +88 -78
- package/src/components/FileUploader/types.ts +11 -2
- package/src/typography/TypographyDemo.tsx +476 -0
- package/src/typography/TypographyScale.tsx +34 -0
|
@@ -5,7 +5,7 @@ export declare const FileUploader: {
|
|
|
5
5
|
displayName: string;
|
|
6
6
|
Content: import("react").ForwardRefExoticComponent<import("react").HTMLAttributes<HTMLDivElement> & import("react").RefAttributes<HTMLDivElement>>;
|
|
7
7
|
Input: {
|
|
8
|
-
({
|
|
8
|
+
({ classes, children, ...props }: FileUploaderInputProps): import("react/jsx-runtime").JSX.Element;
|
|
9
9
|
displayName: string;
|
|
10
10
|
};
|
|
11
11
|
Item: import("react").ForwardRefExoticComponent<{
|
|
@@ -7,7 +7,14 @@ export type FileUploaderProps = {
|
|
|
7
7
|
dropzoneOptions: DropzoneOptions;
|
|
8
8
|
orientation?: "horizontal" | "vertical";
|
|
9
9
|
} & React.HTMLAttributes<HTMLDivElement>;
|
|
10
|
-
export type FileUploaderInputProps = React.InputHTMLAttributes<HTMLInputElement
|
|
10
|
+
export type FileUploaderInputProps = Omit<React.InputHTMLAttributes<HTMLInputElement>, "className"> & {
|
|
11
|
+
classes?: Partial<{
|
|
12
|
+
all: string;
|
|
13
|
+
accepted: string;
|
|
14
|
+
rejected: string;
|
|
15
|
+
default: string;
|
|
16
|
+
}>;
|
|
17
|
+
};
|
|
11
18
|
export type DirectionOptions = "rtl" | "ltr" | undefined;
|
|
12
19
|
export type FileUploaderContextType = {
|
|
13
20
|
dropzoneState: DropzoneState;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const TypographyDemo: () => import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const TypographyScale: () => import("react/jsx-runtime").JSX.Element;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mbao01/common",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.38",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"author": "Ayomide Bakare",
|
|
7
7
|
"license": "MIT",
|
|
@@ -84,6 +84,7 @@
|
|
|
84
84
|
"@radix-ui/react-toggle": "^1.0.3",
|
|
85
85
|
"@radix-ui/react-toggle-group": "^1.0.4",
|
|
86
86
|
"@radix-ui/react-tooltip": "^1.0.7",
|
|
87
|
+
"@tailwindcss/typography": "^0.5.14",
|
|
87
88
|
"class-variance-authority": "^0.7.0",
|
|
88
89
|
"clsx": "^2.1.0",
|
|
89
90
|
"cmdk": "^1.0.0",
|
|
@@ -145,5 +146,5 @@
|
|
|
145
146
|
"react-dom": "^18.2.0",
|
|
146
147
|
"typescript": "^5.2.2"
|
|
147
148
|
},
|
|
148
|
-
"gitHead": "
|
|
149
|
+
"gitHead": "5f3422b1162cdb852a5f5b1148bc7df241d52e66"
|
|
149
150
|
}
|
package/plugin.js
CHANGED
|
@@ -55,54 +55,67 @@ export const FileUploader = ({
|
|
|
55
55
|
|
|
56
56
|
const handleKeyDown = useCallback(
|
|
57
57
|
(e: React.KeyboardEvent<HTMLDivElement>) => {
|
|
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
|
-
|
|
58
|
+
const files = value ?? [];
|
|
59
|
+
const KEY_LIST = [
|
|
60
|
+
"ArrowLeft",
|
|
61
|
+
"ArrowRight",
|
|
62
|
+
"ArrowUp",
|
|
63
|
+
"ArrowDown",
|
|
64
|
+
"Enter",
|
|
65
|
+
"Space",
|
|
66
|
+
"Delete",
|
|
67
|
+
"Backspace",
|
|
68
|
+
"Escape",
|
|
69
|
+
];
|
|
70
|
+
|
|
71
|
+
if (KEY_LIST.includes(e.key)) {
|
|
72
|
+
e.preventDefault();
|
|
73
|
+
e.stopPropagation();
|
|
74
|
+
|
|
75
|
+
const moveNext = () => {
|
|
76
|
+
const nextIndex = activeIndex + 1;
|
|
77
|
+
setActiveIndex(nextIndex > files.length - 1 ? 0 : nextIndex);
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
const movePrev = () => {
|
|
81
|
+
const nextIndex = activeIndex - 1;
|
|
82
|
+
setActiveIndex(nextIndex < 0 ? files.length - 1 : nextIndex);
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
const prevKey =
|
|
86
|
+
orientation === "horizontal"
|
|
87
|
+
? direction === "ltr"
|
|
88
|
+
? "ArrowLeft"
|
|
89
|
+
: "ArrowRight"
|
|
90
|
+
: "ArrowUp";
|
|
91
|
+
|
|
92
|
+
const nextKey =
|
|
93
|
+
orientation === "horizontal"
|
|
94
|
+
? direction === "ltr"
|
|
95
|
+
? "ArrowRight"
|
|
96
|
+
: "ArrowLeft"
|
|
97
|
+
: "ArrowDown";
|
|
98
|
+
|
|
99
|
+
if (e.key === nextKey) {
|
|
100
|
+
moveNext();
|
|
101
|
+
} else if (e.key === prevKey) {
|
|
102
102
|
movePrev();
|
|
103
|
+
} else if (e.key === "Enter" || e.key === "Space") {
|
|
104
|
+
if (activeIndex === -1) {
|
|
105
|
+
dropzoneState.inputRef.current?.click();
|
|
106
|
+
}
|
|
107
|
+
} else if (e.key === "Delete" || e.key === "Backspace") {
|
|
108
|
+
if (activeIndex !== -1) {
|
|
109
|
+
removeFileFromSet(activeIndex);
|
|
110
|
+
if (files.length - 1 === 0) {
|
|
111
|
+
setActiveIndex(-1);
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
movePrev();
|
|
115
|
+
}
|
|
116
|
+
} else if (e.key === "Escape") {
|
|
117
|
+
setActiveIndex(-1);
|
|
103
118
|
}
|
|
104
|
-
} else if (e.key === "Escape") {
|
|
105
|
-
setActiveIndex(-1);
|
|
106
119
|
}
|
|
107
120
|
},
|
|
108
121
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
@@ -197,17 +210,13 @@ export const FileUploader = ({
|
|
|
197
210
|
}}
|
|
198
211
|
>
|
|
199
212
|
<div
|
|
200
|
-
tabIndex={0}
|
|
201
213
|
onKeyDownCapture={handleKeyDown}
|
|
202
|
-
className={cn(
|
|
203
|
-
"
|
|
204
|
-
|
|
205
|
-
{
|
|
206
|
-
"gap-2": value && value.length > 0,
|
|
207
|
-
}
|
|
208
|
-
)}
|
|
214
|
+
className={cn("grid w-full overflow-hidden", className, {
|
|
215
|
+
"gap-2": value && value.length > 0,
|
|
216
|
+
})}
|
|
209
217
|
dir={dir}
|
|
210
218
|
{...props}
|
|
219
|
+
tabIndex={-1}
|
|
211
220
|
>
|
|
212
221
|
{children}
|
|
213
222
|
</div>
|
|
@@ -257,9 +266,9 @@ const FileUploaderItem = forwardRef<
|
|
|
257
266
|
<div
|
|
258
267
|
ref={ref}
|
|
259
268
|
className={cn(
|
|
260
|
-
"h-6 p-1 justify-between cursor-pointer relative",
|
|
261
|
-
|
|
262
|
-
|
|
269
|
+
"h-6 p-1 justify-between cursor-pointer relative rounded",
|
|
270
|
+
{ "bg-base-300": isSelected },
|
|
271
|
+
className
|
|
263
272
|
)}
|
|
264
273
|
{...props}
|
|
265
274
|
>
|
|
@@ -275,7 +284,12 @@ const FileUploaderItem = forwardRef<
|
|
|
275
284
|
onClick={() => removeFileFromSet(index)}
|
|
276
285
|
>
|
|
277
286
|
<span className="sr-only">remove item {index}</span>
|
|
278
|
-
<TrashIcon
|
|
287
|
+
<TrashIcon
|
|
288
|
+
className={cn(
|
|
289
|
+
"w-4 h-4 shrink-0 hover:stroke-destructive duration-200 ease-in-out",
|
|
290
|
+
{ "text-error": isSelected }
|
|
291
|
+
)}
|
|
292
|
+
/>
|
|
279
293
|
</button>
|
|
280
294
|
</div>
|
|
281
295
|
);
|
|
@@ -284,7 +298,7 @@ const FileUploaderItem = forwardRef<
|
|
|
284
298
|
FileUploaderItem.displayName = "FileUploaderItem";
|
|
285
299
|
|
|
286
300
|
const FileUploaderInput = ({
|
|
287
|
-
|
|
301
|
+
classes,
|
|
288
302
|
children,
|
|
289
303
|
...props
|
|
290
304
|
}: FileUploaderInputProps) => {
|
|
@@ -292,39 +306,35 @@ const FileUploaderInput = ({
|
|
|
292
306
|
useFileUpload();
|
|
293
307
|
const rootProps = isLOF ? {} : dropzoneState.getRootProps();
|
|
294
308
|
return (
|
|
295
|
-
<div
|
|
296
|
-
{...props}
|
|
297
|
-
className={`relative w-full ${
|
|
298
|
-
isLOF ? "opacity-50 cursor-not-allowed " : "cursor-pointer "
|
|
299
|
-
}`}
|
|
300
|
-
>
|
|
309
|
+
<div {...props} className="relative w-full">
|
|
301
310
|
<div
|
|
302
311
|
className={cn(
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
className
|
|
312
|
+
classes?.all,
|
|
313
|
+
"w-full rounded-lg duration-300 ease-in-out",
|
|
314
|
+
isLOF ? "opacity-50 cursor-not-allowed" : "cursor-pointer",
|
|
315
|
+
dropzoneState.isDragAccept
|
|
316
|
+
? classes?.accepted
|
|
317
|
+
: dropzoneState.isDragReject || isFileTooBig
|
|
318
|
+
? classes?.rejected
|
|
319
|
+
: classes?.default
|
|
312
320
|
)}
|
|
313
321
|
{...rootProps}
|
|
314
322
|
>
|
|
315
323
|
{children}
|
|
316
324
|
</div>
|
|
317
325
|
<input
|
|
318
|
-
{...props}
|
|
319
326
|
ref={hiddenInputRef}
|
|
327
|
+
{...props}
|
|
320
328
|
type="file"
|
|
321
|
-
|
|
329
|
+
tabIndex={-1}
|
|
330
|
+
className="hidden opacity-0"
|
|
322
331
|
/>
|
|
323
332
|
<input
|
|
324
|
-
disabled={isLOF}
|
|
325
333
|
ref={dropzoneState.inputRef}
|
|
334
|
+
disabled={isLOF}
|
|
326
335
|
{...dropzoneState.getInputProps()}
|
|
327
|
-
|
|
336
|
+
tabIndex={-1}
|
|
337
|
+
className={cn({ "cursor-not-allowed": isLOF })}
|
|
328
338
|
/>
|
|
329
339
|
</div>
|
|
330
340
|
);
|
|
@@ -9,8 +9,17 @@ export type FileUploaderProps = {
|
|
|
9
9
|
orientation?: "horizontal" | "vertical";
|
|
10
10
|
} & React.HTMLAttributes<HTMLDivElement>;
|
|
11
11
|
|
|
12
|
-
export type FileUploaderInputProps =
|
|
13
|
-
React.InputHTMLAttributes<HTMLInputElement
|
|
12
|
+
export type FileUploaderInputProps = Omit<
|
|
13
|
+
React.InputHTMLAttributes<HTMLInputElement>,
|
|
14
|
+
"className"
|
|
15
|
+
> & {
|
|
16
|
+
classes?: Partial<{
|
|
17
|
+
all: string;
|
|
18
|
+
accepted: string;
|
|
19
|
+
rejected: string;
|
|
20
|
+
default: string;
|
|
21
|
+
}>;
|
|
22
|
+
};
|
|
14
23
|
|
|
15
24
|
export type DirectionOptions = "rtl" | "ltr" | undefined;
|
|
16
25
|
|
|
@@ -0,0 +1,476 @@
|
|
|
1
|
+
export const TypographyDemo = () => {
|
|
2
|
+
return (
|
|
3
|
+
<div className="min-h-screen py-8 flex flex-col justify-center relative overflow-hidden lg:py-12">
|
|
4
|
+
<img
|
|
5
|
+
src="/img/beams.jpg"
|
|
6
|
+
alt=""
|
|
7
|
+
className="fixed top-48 left-1/2 -translate-x-2/3 -translate-y-1/2 max-w-none"
|
|
8
|
+
width="1308"
|
|
9
|
+
/>
|
|
10
|
+
<div className="absolute inset-0 bg-[url(/img/grid.svg)] bg-top [mask-image:linear-gradient(180deg,white,rgba(255,255,255,0))]"></div>
|
|
11
|
+
<div className="relative w-full px-6 py-12 shadow-xl shadow-slate-700/10 ring-1 ring-gray-900/5 md:max-w-3xl md:mx-auto lg:max-w-4xl lg:pt-16 lg:pb-28">
|
|
12
|
+
<div className="max-w-prose mx-auto lg:text-lg">
|
|
13
|
+
<svg className="h-6" fill="none" viewBox="0 0 297 24">
|
|
14
|
+
<path
|
|
15
|
+
className="fill-sky-400"
|
|
16
|
+
fillRule="evenodd"
|
|
17
|
+
d="M19.418.523c-5.178 0-8.415 2.589-9.71 7.767 1.943-2.59 4.208-3.56 6.797-2.913 1.477.37 2.533 1.44 3.702 2.627 1.903 1.933 4.107 4.17 8.92 4.17 5.178 0 8.414-2.59 9.708-7.768-1.941 2.59-4.207 3.56-6.796 2.913-1.477-.37-2.533-1.441-3.702-2.628C26.434 2.76 24.23.523 19.417.523zm-9.71 11.65c-5.177 0-8.413 2.59-9.708 7.767 1.942-2.589 4.207-3.56 6.796-2.913 1.477.37 2.533 1.441 3.702 2.628 1.904 1.932 4.107 4.169 8.92 4.169 5.178 0 8.414-2.59 9.709-7.767-1.942 2.589-4.208 3.56-6.797 2.912-1.477-.369-2.533-1.44-3.701-2.627-1.904-1.932-4.108-4.169-8.92-4.169z"
|
|
18
|
+
clipRule="evenodd"
|
|
19
|
+
></path>
|
|
20
|
+
<path
|
|
21
|
+
className="fill-slate-900"
|
|
22
|
+
d="M59.31 8.962v-2.79h-3.328V2.414l-2.898.858v2.898h-2.468v2.79h2.468v6.44c0 3.489 1.771 4.723 6.225 4.186v-2.602c-2.2.107-3.327.134-3.327-1.584v-6.44h3.327zM72.013 6.171v1.905c-1.02-1.395-2.603-2.254-4.696-2.254-3.649 0-6.68 3.06-6.68 7.057 0 3.971 3.031 7.057 6.68 7.057 2.093 0 3.676-.859 4.696-2.28v1.931h2.897V6.171h-2.897zm-4.24 11.001c-2.415 0-4.24-1.797-4.24-4.293 0-2.495 1.825-4.293 4.24-4.293s4.24 1.798 4.24 4.293c0 2.496-1.825 4.293-4.24 4.293zM79.737 4.159c1.02 0 1.852-.859 1.852-1.851 0-1.02-.832-1.852-1.852-1.852s-1.851.832-1.851 1.852c0 .992.832 1.85 1.851 1.85zm-1.449 15.428h2.898V6.171h-2.898v13.416zM84.55 19.587h2.898V0h-2.897v19.587zM106.268 6.171l-2.629 9.257-2.791-9.257h-2.763l-2.818 9.257-2.602-9.257h-3.06l4.213 13.416h2.844l2.818-9.042 2.79 9.042h2.844l4.213-13.416h-3.059zM112.91 4.159c1.019 0 1.851-.859 1.851-1.851 0-1.02-.832-1.852-1.851-1.852-1.02 0-1.852.832-1.852 1.852 0 .992.832 1.85 1.852 1.85zm-1.449 15.428h2.898V6.171h-2.898v13.416zM124.78 5.822c-1.824 0-3.273.671-4.159 2.067V6.17h-2.898v13.416h2.898v-7.19c0-2.738 1.503-3.865 3.408-3.865 1.824 0 3.005 1.074 3.005 3.113v7.942h2.898V11.35c0-3.488-2.147-5.528-5.152-5.528zM143.677.805v7.271c-1.019-1.395-2.602-2.254-4.695-2.254-3.649 0-6.681 3.06-6.681 7.057 0 3.971 3.032 7.057 6.681 7.057 2.093 0 3.676-.859 4.695-2.28v1.931h2.898V.805h-2.898zm-4.239 16.367c-2.415 0-4.239-1.797-4.239-4.293 0-2.495 1.824-4.293 4.239-4.293s4.239 1.798 4.239 4.293c0 2.496-1.824 4.293-4.239 4.293z"
|
|
23
|
+
></path>
|
|
24
|
+
<path
|
|
25
|
+
className="fill-sky-400"
|
|
26
|
+
d="M161.544 5.748h-10.182v2.61h3.717v11.23h2.728V8.357h3.737v-2.61zM175.997 5.748h-3.084l-3.005 5.773-3.006-5.773h-3.084l4.725 8.442v5.397h2.709V14.19l4.745-8.442zM184.461 5.748h-5.16v13.84h2.728V15.04h2.432c2.669 0 4.725-2.056 4.725-4.646s-2.056-4.646-4.725-4.646zm0 6.741h-2.432V8.3h2.432c1.166 0 2.016.889 2.016 2.095 0 1.186-.85 2.095-2.016 2.095zM199.387 19.864c3.994 0 7.196-3.163 7.196-7.197 0-4.053-3.202-7.196-7.196-7.196-3.994 0-7.177 3.143-7.177 7.196 0 4.034 3.183 7.197 7.177 7.197zm0-2.67c-2.511 0-4.468-1.877-4.468-4.527 0-2.669 1.957-4.547 4.468-4.547s4.468 1.878 4.468 4.547c0 2.65-1.957 4.528-4.468 4.528zM224.061 12.153h-6.94v2.412h4.191c-.474 1.582-1.858 2.63-4.033 2.63-2.886 0-4.725-1.938-4.725-4.508 0-2.63 1.898-4.567 4.527-4.567 1.681 0 3.085.81 3.717 1.918l2.333-1.345c-1.166-1.897-3.4-3.222-6.03-3.222-4.132 0-7.256 3.203-7.256 7.216 0 3.954 3.085 7.177 7.414 7.177 3.974 0 6.802-2.65 6.802-6.643v-1.068zM235.57 19.587h2.946l-3.064-5.22c1.581-.73 2.669-2.293 2.669-4.033 0-2.53-2.057-4.586-4.607-4.586h-5.536v13.84h2.729v-4.805h2.076l2.787 4.804zm-4.863-11.289h2.807c1.028 0 1.878.89 1.878 2.037 0 1.146-.85 2.056-1.878 2.056h-2.807V8.298zM250.996 19.587h2.966l-4.864-13.84h-3.38l-4.844 13.84h2.946l.83-2.491h5.516l.83 2.491zm-5.476-5.041l1.898-5.655 1.898 5.655h-3.796zM262.443 5.748h-5.16v13.84h2.728V15.04h2.432c2.669 0 4.725-2.056 4.725-4.646s-2.056-4.646-4.725-4.646zm0 6.741h-2.432V8.3h2.432c1.167 0 2.017.889 2.017 2.095 0 1.186-.85 2.095-2.017 2.095zM278.79 5.748v5.496h-5.14V5.748h-2.728v13.84h2.728v-5.734h5.14v5.733h2.709V5.747h-2.709zM297 5.748h-3.084l-3.005 5.773-3.006-5.773h-3.084l4.725 8.442v5.397h2.709V14.19L297 5.748z"
|
|
27
|
+
></path>
|
|
28
|
+
</svg>
|
|
29
|
+
</div>
|
|
30
|
+
<div className="mt-8 prose prose-slate mx-auto lg:prose-lg">
|
|
31
|
+
<p className="lead">
|
|
32
|
+
Until now, trying to style an article, document, or blog post with
|
|
33
|
+
Tailwind has been a tedious task that required a keen eye for
|
|
34
|
+
typography and a lot of complex custom CSS.
|
|
35
|
+
</p>
|
|
36
|
+
<p>
|
|
37
|
+
By default, Tailwind removes all of the default browser styling from
|
|
38
|
+
paragraphs, headings, lists and more. This ends up being really
|
|
39
|
+
useful for building application UIs because you spend less time
|
|
40
|
+
undoing user-agent styles, but when you <em>really are</em> just
|
|
41
|
+
trying to style some content that came from a rich-text editor in a
|
|
42
|
+
CMS or a markdown file, it can be surprising and unintuitive.
|
|
43
|
+
</p>
|
|
44
|
+
<p>
|
|
45
|
+
We get lots of complaints about it actually, with people regularly
|
|
46
|
+
asking us things like:
|
|
47
|
+
</p>
|
|
48
|
+
<blockquote>
|
|
49
|
+
<p>
|
|
50
|
+
Why is Tailwind removing the default styles on my <code>h1</code>{" "}
|
|
51
|
+
elements? How do I disable this? What do you mean I lose all the
|
|
52
|
+
other base styles too?
|
|
53
|
+
</p>
|
|
54
|
+
</blockquote>
|
|
55
|
+
<p>
|
|
56
|
+
We hear you, but we're not convinced that simply disabling our
|
|
57
|
+
base styles is what you really want. You don't want to have to
|
|
58
|
+
remove annoying margins every time you use a <code>p</code> element
|
|
59
|
+
in a piece of your dashboard UI. And I doubt you really want your
|
|
60
|
+
blog posts to use the user-agent styles either — you want them to
|
|
61
|
+
look <em>awesome</em>, not awful.
|
|
62
|
+
</p>
|
|
63
|
+
<p>
|
|
64
|
+
The <code>@tailwindcss/typography</code> plugin is our attempt to
|
|
65
|
+
give you what you <em>actually</em> want, without any of the
|
|
66
|
+
downsides of doing something stupid like disabling our base styles.
|
|
67
|
+
</p>
|
|
68
|
+
<p>
|
|
69
|
+
It adds a new <code>prose</code> class that you can slap on any
|
|
70
|
+
block of vanilla HTML content and turn it into a beautiful,
|
|
71
|
+
well-formatted document:
|
|
72
|
+
</p>
|
|
73
|
+
<pre>
|
|
74
|
+
<code
|
|
75
|
+
className="language-html"
|
|
76
|
+
dangerouslySetInnerHTML={{
|
|
77
|
+
__html: `<article class="prose">
|
|
78
|
+
<h1>Garlic bread with cheese: What the science tells us</h1>
|
|
79
|
+
<p>
|
|
80
|
+
For years parents have espoused the health benefits of eating garlic bread with cheese to their
|
|
81
|
+
children, with the food earning such an iconic status in our culture that kids will often dress
|
|
82
|
+
up as warm, cheesy loaf for Halloween.
|
|
83
|
+
</p>
|
|
84
|
+
<p>
|
|
85
|
+
But a recent study shows that the celebrated appetizer may be linked to a series of rabies cases
|
|
86
|
+
springing up around the country.
|
|
87
|
+
</p>
|
|
88
|
+
<!-- ... -->
|
|
89
|
+
</article>`,
|
|
90
|
+
}}
|
|
91
|
+
/>
|
|
92
|
+
</pre>
|
|
93
|
+
<p>
|
|
94
|
+
For more information about how to use the plugin and the features it
|
|
95
|
+
includes,{" "}
|
|
96
|
+
<a href="https://github.com/tailwindcss/typography/blob/master/README.md">
|
|
97
|
+
read the documentation
|
|
98
|
+
</a>
|
|
99
|
+
.
|
|
100
|
+
</p>
|
|
101
|
+
<hr />
|
|
102
|
+
<h2>What to expect from here on out</h2>
|
|
103
|
+
<p>
|
|
104
|
+
What follows from here is just a bunch of absolute nonsense
|
|
105
|
+
I've written to dogfood the plugin itself. It includes every
|
|
106
|
+
sensible typographic element I could think of, like{" "}
|
|
107
|
+
<strong>bold text</strong>, unordered lists, ordered lists, code
|
|
108
|
+
blocks, block quotes, <em>and even italics</em>.
|
|
109
|
+
</p>
|
|
110
|
+
<p>
|
|
111
|
+
It's important to cover all of these use cases for a few
|
|
112
|
+
reasons:
|
|
113
|
+
</p>
|
|
114
|
+
<ol>
|
|
115
|
+
<li>We want everything to look good out of the box.</li>
|
|
116
|
+
<li>
|
|
117
|
+
Really just the first reason, that's the whole point of the
|
|
118
|
+
plugin.
|
|
119
|
+
</li>
|
|
120
|
+
<li>
|
|
121
|
+
Here's a third pretend reason though a list with three items
|
|
122
|
+
looks more realistic than a list with two items.
|
|
123
|
+
</li>
|
|
124
|
+
</ol>
|
|
125
|
+
<p>Now we're going to try out another header style.</p>
|
|
126
|
+
<h3>Typography should be easy</h3>
|
|
127
|
+
<p>
|
|
128
|
+
So that's a header for you — with any luck if we've done
|
|
129
|
+
our job correctly that will look pretty reasonable.
|
|
130
|
+
</p>
|
|
131
|
+
<p>Something a wise person once told me about typography is:</p>
|
|
132
|
+
<blockquote>
|
|
133
|
+
<p>
|
|
134
|
+
Typography is pretty important if you don't want your stuff
|
|
135
|
+
to look like trash. Make it good then it won't be bad.
|
|
136
|
+
</p>
|
|
137
|
+
</blockquote>
|
|
138
|
+
<p>
|
|
139
|
+
It's probably important that images look okay here by default
|
|
140
|
+
as well:
|
|
141
|
+
</p>
|
|
142
|
+
<figure>
|
|
143
|
+
<img
|
|
144
|
+
src="https://images.unsplash.com/photo-1556740758-90de374c12ad?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1000&q=80"
|
|
145
|
+
alt=""
|
|
146
|
+
/>
|
|
147
|
+
<figcaption>
|
|
148
|
+
Contrary to popular belief, Lorem Ipsum is not simply random text.
|
|
149
|
+
It has roots in a piece of classical Latin literature from 45 BC,
|
|
150
|
+
making it over 2000 years old.
|
|
151
|
+
</figcaption>
|
|
152
|
+
</figure>
|
|
153
|
+
<p>
|
|
154
|
+
Now I'm going to show you an example of an unordered list to
|
|
155
|
+
make sure that looks good, too:
|
|
156
|
+
</p>
|
|
157
|
+
<ul>
|
|
158
|
+
<li>So here is the first item in this list.</li>
|
|
159
|
+
<li>In this example we're keeping the items short.</li>
|
|
160
|
+
<li>Later, we'll use longer, more complex list items.</li>
|
|
161
|
+
</ul>
|
|
162
|
+
<p>And that's the end of this section.</p>
|
|
163
|
+
<h2>What if we stack headings?</h2>
|
|
164
|
+
<h3>We should make sure that looks good, too.</h3>
|
|
165
|
+
<p>
|
|
166
|
+
Sometimes you have headings directly underneath each other. In those
|
|
167
|
+
cases you often have to undo the top margin on the second heading
|
|
168
|
+
because it usually looks better for the headings to be closer
|
|
169
|
+
together than a paragraph followed by a heading should be.
|
|
170
|
+
</p>
|
|
171
|
+
<h3>When a heading comes after a paragraph …</h3>
|
|
172
|
+
<p>
|
|
173
|
+
When a heading comes after a paragraph, we need a bit more space,
|
|
174
|
+
like I already mentioned above. Now let's see what a more
|
|
175
|
+
complex list would look like.
|
|
176
|
+
</p>
|
|
177
|
+
<ul>
|
|
178
|
+
<li>
|
|
179
|
+
<p>
|
|
180
|
+
<strong>
|
|
181
|
+
I often do this thing where list items have headings.
|
|
182
|
+
</strong>
|
|
183
|
+
</p>
|
|
184
|
+
<p>
|
|
185
|
+
For some reason I think this looks cool which is unfortunate
|
|
186
|
+
because it's pretty annoying to get the styles right.
|
|
187
|
+
</p>
|
|
188
|
+
<p>
|
|
189
|
+
I often have two or three paragraphs in these list items, too,
|
|
190
|
+
so the hard part is getting the spacing between the paragraphs,
|
|
191
|
+
list item heading, and separate list items to all make sense.
|
|
192
|
+
Pretty tough honestly, you could make a strong argument that you
|
|
193
|
+
just shouldn't write this way.
|
|
194
|
+
</p>
|
|
195
|
+
</li>
|
|
196
|
+
<li>
|
|
197
|
+
<p>
|
|
198
|
+
<strong>
|
|
199
|
+
Since this is a list, I need at least two items.
|
|
200
|
+
</strong>
|
|
201
|
+
</p>
|
|
202
|
+
<p>
|
|
203
|
+
I explained what I'm doing already in the previous list
|
|
204
|
+
item, but a list wouldn't be a list if it only had one
|
|
205
|
+
item, and we really want this to look realistic. That's why
|
|
206
|
+
I've added this second list item so I actually have
|
|
207
|
+
something to look at when writing the styles.
|
|
208
|
+
</p>
|
|
209
|
+
</li>
|
|
210
|
+
<li>
|
|
211
|
+
<p>
|
|
212
|
+
<strong>
|
|
213
|
+
It's not a bad idea to add a third item either.
|
|
214
|
+
</strong>
|
|
215
|
+
</p>
|
|
216
|
+
<p>
|
|
217
|
+
I think it probably would've been fine to just use two
|
|
218
|
+
items but three is definitely not worse, and since I seem to be
|
|
219
|
+
having no trouble making up arbitrary things to type, I might as
|
|
220
|
+
well include it.
|
|
221
|
+
</p>
|
|
222
|
+
</li>
|
|
223
|
+
</ul>
|
|
224
|
+
<p>
|
|
225
|
+
After this sort of list I usually have a closing statement or
|
|
226
|
+
paragraph, because it kinda looks weird jumping right to a heading.
|
|
227
|
+
</p>
|
|
228
|
+
<h2>Code should look okay by default.</h2>
|
|
229
|
+
<p>
|
|
230
|
+
I think most people are going to use{" "}
|
|
231
|
+
<a href="https://highlightjs.org/">highlight.js</a> or{" "}
|
|
232
|
+
<a href="https://prismjs.com/">Prism</a> or something if they want
|
|
233
|
+
to style their code blocks but it wouldn't hurt to make them
|
|
234
|
+
look <em>okay</em> out of the box, even with no syntax highlighting.
|
|
235
|
+
</p>
|
|
236
|
+
<p>
|
|
237
|
+
Here's what a default <code>tailwind.config.js</code> file
|
|
238
|
+
looks like at the time of writing:
|
|
239
|
+
</p>
|
|
240
|
+
<pre>
|
|
241
|
+
<code className="language-js">
|
|
242
|
+
{`module.exports = {
|
|
243
|
+
purge: [],
|
|
244
|
+
theme: {
|
|
245
|
+
extend: {},
|
|
246
|
+
},
|
|
247
|
+
variants: {},
|
|
248
|
+
plugins: [],
|
|
249
|
+
}`}
|
|
250
|
+
</code>
|
|
251
|
+
</pre>
|
|
252
|
+
<p>Hopefully that looks good enough to you.</p>
|
|
253
|
+
<h3>What about nested lists?</h3>
|
|
254
|
+
<p>
|
|
255
|
+
Nested lists basically always look bad which is why editors like
|
|
256
|
+
Medium don't even let you do it, but I guess since some of you
|
|
257
|
+
goofballs are going to do it we have to carry the burden of at least
|
|
258
|
+
making it work.
|
|
259
|
+
</p>
|
|
260
|
+
<ol>
|
|
261
|
+
<li>
|
|
262
|
+
<strong>Nested lists are rarely a good idea.</strong>
|
|
263
|
+
<ul>
|
|
264
|
+
<li>
|
|
265
|
+
You might feel like you are being really
|
|
266
|
+
“organized” or something but you are just creating
|
|
267
|
+
a gross shape on the screen that is hard to read.
|
|
268
|
+
</li>
|
|
269
|
+
<li>
|
|
270
|
+
Nested navigation in UIs is a bad idea too, keep things as
|
|
271
|
+
flat as possible.
|
|
272
|
+
</li>
|
|
273
|
+
<li>
|
|
274
|
+
Nesting tons of folders in your source code is also not
|
|
275
|
+
helpful.
|
|
276
|
+
</li>
|
|
277
|
+
</ul>
|
|
278
|
+
</li>
|
|
279
|
+
<li>
|
|
280
|
+
<strong>
|
|
281
|
+
Since we need to have more items, here's another one.
|
|
282
|
+
</strong>
|
|
283
|
+
<ul>
|
|
284
|
+
<li>
|
|
285
|
+
I'm not sure if we'll bother styling more than two
|
|
286
|
+
levels deep.
|
|
287
|
+
</li>
|
|
288
|
+
<li>
|
|
289
|
+
Two is already too much, three is guaranteed to be a bad idea.
|
|
290
|
+
</li>
|
|
291
|
+
<li>If you nest four levels deep you belong in prison.</li>
|
|
292
|
+
</ul>
|
|
293
|
+
</li>
|
|
294
|
+
<li>
|
|
295
|
+
<strong>
|
|
296
|
+
Two items isn't really a list, three is good though.
|
|
297
|
+
</strong>
|
|
298
|
+
<ul>
|
|
299
|
+
<li>
|
|
300
|
+
Again please don't nest lists if you want people to
|
|
301
|
+
actually read your content.
|
|
302
|
+
</li>
|
|
303
|
+
<li>Nobody wants to look at this.</li>
|
|
304
|
+
<li>
|
|
305
|
+
I'm upset that we even have to bother styling this.
|
|
306
|
+
</li>
|
|
307
|
+
</ul>
|
|
308
|
+
</li>
|
|
309
|
+
</ol>
|
|
310
|
+
<p>
|
|
311
|
+
The most annoying thing about lists in Markdown is that{" "}
|
|
312
|
+
<code><li></code> elements aren't given a child{" "}
|
|
313
|
+
<code><p></code> tag unless there are multiple paragraphs in
|
|
314
|
+
the list item. That means I have to worry about styling that
|
|
315
|
+
annoying situation too.
|
|
316
|
+
</p>
|
|
317
|
+
<ul>
|
|
318
|
+
<li>
|
|
319
|
+
<p>
|
|
320
|
+
<strong>For example, here's another nested list.</strong>
|
|
321
|
+
</p>
|
|
322
|
+
<p>But this time with a second paragraph.</p>
|
|
323
|
+
<ul>
|
|
324
|
+
<li>
|
|
325
|
+
These list items won't have <code><p></code> tags
|
|
326
|
+
</li>
|
|
327
|
+
<li>Because they are only one line each</li>
|
|
328
|
+
</ul>
|
|
329
|
+
</li>
|
|
330
|
+
<li>
|
|
331
|
+
<p>
|
|
332
|
+
<strong>
|
|
333
|
+
But in this second top-level list item, they will.
|
|
334
|
+
</strong>
|
|
335
|
+
</p>
|
|
336
|
+
<p>
|
|
337
|
+
This is especially annoying because of the spacing on this
|
|
338
|
+
paragraph.
|
|
339
|
+
</p>
|
|
340
|
+
<ul>
|
|
341
|
+
<li>
|
|
342
|
+
<p>
|
|
343
|
+
As you can see here, because I've added a second line,
|
|
344
|
+
this list item now has a <code><p></code> tag.
|
|
345
|
+
</p>
|
|
346
|
+
<p>
|
|
347
|
+
This is the second line I'm talking about by the way.
|
|
348
|
+
</p>
|
|
349
|
+
</li>
|
|
350
|
+
<li>
|
|
351
|
+
<p>
|
|
352
|
+
Finally here's another list item so it's more like
|
|
353
|
+
a list.
|
|
354
|
+
</p>
|
|
355
|
+
</li>
|
|
356
|
+
</ul>
|
|
357
|
+
</li>
|
|
358
|
+
<li>
|
|
359
|
+
<p>
|
|
360
|
+
A closing list item, but with no nested list, because why not?
|
|
361
|
+
</p>
|
|
362
|
+
</li>
|
|
363
|
+
</ul>
|
|
364
|
+
<p>And finally a sentence to close off this section.</p>
|
|
365
|
+
<h2>There are other elements we need to style</h2>
|
|
366
|
+
<p>
|
|
367
|
+
I almost forgot to mention links, like{" "}
|
|
368
|
+
<a href="https://tailwindcss.com">
|
|
369
|
+
this link to the Tailwind CSS website
|
|
370
|
+
</a>
|
|
371
|
+
. We almost made them blue but that's so yesterday, so we went
|
|
372
|
+
with dark gray, feels edgier.
|
|
373
|
+
</p>
|
|
374
|
+
<p>We even included table styles, check it out:</p>
|
|
375
|
+
<table>
|
|
376
|
+
<thead>
|
|
377
|
+
<tr>
|
|
378
|
+
<th>Wrestler</th>
|
|
379
|
+
<th>Origin</th>
|
|
380
|
+
<th>Finisher</th>
|
|
381
|
+
</tr>
|
|
382
|
+
</thead>
|
|
383
|
+
<tbody>
|
|
384
|
+
<tr>
|
|
385
|
+
<td>Bret “The Hitman” Hart</td>
|
|
386
|
+
<td>Calgary, AB</td>
|
|
387
|
+
<td>Sharpshooter</td>
|
|
388
|
+
</tr>
|
|
389
|
+
<tr>
|
|
390
|
+
<td>Stone Cold Steve Austin</td>
|
|
391
|
+
<td>Austin, TX</td>
|
|
392
|
+
<td>Stone Cold Stunner</td>
|
|
393
|
+
</tr>
|
|
394
|
+
<tr>
|
|
395
|
+
<td>Randy Savage</td>
|
|
396
|
+
<td>Sarasota, FL</td>
|
|
397
|
+
<td>Elbow Drop</td>
|
|
398
|
+
</tr>
|
|
399
|
+
<tr>
|
|
400
|
+
<td>Vader</td>
|
|
401
|
+
<td>Boulder, CO</td>
|
|
402
|
+
<td>Vader Bomb</td>
|
|
403
|
+
</tr>
|
|
404
|
+
<tr>
|
|
405
|
+
<td>Razor Ramon</td>
|
|
406
|
+
<td>Chuluota, FL</td>
|
|
407
|
+
<td>Razor's Edge</td>
|
|
408
|
+
</tr>
|
|
409
|
+
</tbody>
|
|
410
|
+
</table>
|
|
411
|
+
<p>
|
|
412
|
+
We also need to make sure inline code looks good, like if I wanted
|
|
413
|
+
to talk about <code><span></code> elements or tell you the
|
|
414
|
+
good news about <code>@tailwindcss/typography</code>.
|
|
415
|
+
</p>
|
|
416
|
+
<h3>
|
|
417
|
+
Sometimes I even use <code>code</code> in headings
|
|
418
|
+
</h3>
|
|
419
|
+
<p>
|
|
420
|
+
Even though it's probably a bad idea, and historically
|
|
421
|
+
I've had a hard time making it look good. This{" "}
|
|
422
|
+
<em>“wrap the code blocks in backticks”</em> trick works
|
|
423
|
+
pretty well though really.
|
|
424
|
+
</p>
|
|
425
|
+
<p>
|
|
426
|
+
Another thing I've done in the past is put a <code>code</code>{" "}
|
|
427
|
+
tag inside of a link, like if I wanted to tell you about the{" "}
|
|
428
|
+
<a href="https://github.com/tailwindcss/docs">
|
|
429
|
+
<code>tailwindcss/docs</code>
|
|
430
|
+
</a>{" "}
|
|
431
|
+
repository. I don't love that there is an underline below the
|
|
432
|
+
backticks but it is absolutely not worth the madness it would
|
|
433
|
+
require to avoid it.
|
|
434
|
+
</p>
|
|
435
|
+
<h4>
|
|
436
|
+
We haven't used an <code>h4</code> yet
|
|
437
|
+
</h4>
|
|
438
|
+
<p>
|
|
439
|
+
But now we have. Please don't use <code>h5</code> or{" "}
|
|
440
|
+
<code>h6</code> in your content, Medium only supports two heading
|
|
441
|
+
levels for a reason, you animals. I honestly considered using a{" "}
|
|
442
|
+
<code>before</code> pseudo-element to scream at you if you use an{" "}
|
|
443
|
+
<code>h5</code> or <code>h6</code>.
|
|
444
|
+
</p>
|
|
445
|
+
<p>
|
|
446
|
+
We don't style them at all out of the box because{" "}
|
|
447
|
+
<code>h4</code> elements are already so small that they are the same
|
|
448
|
+
size as the body copy. What are we supposed to do with an{" "}
|
|
449
|
+
<code>h5</code>, make it <em>smaller</em> than the body copy? No
|
|
450
|
+
thanks.
|
|
451
|
+
</p>
|
|
452
|
+
<h3>We still need to think about stacked headings though.</h3>
|
|
453
|
+
<h4>
|
|
454
|
+
Let's make sure we don't screw that up with{" "}
|
|
455
|
+
<code>h4</code> elements, either.
|
|
456
|
+
</h4>
|
|
457
|
+
<p>
|
|
458
|
+
Phew, with any luck we have styled the headings above this text and
|
|
459
|
+
they look pretty good.
|
|
460
|
+
</p>
|
|
461
|
+
<p>
|
|
462
|
+
Let's add a closing paragraph here so things end with a
|
|
463
|
+
decently sized block of text. I can't explain why I want things
|
|
464
|
+
to end that way but I have to assume it's because I think
|
|
465
|
+
things will look weird or unbalanced if there is a heading too close
|
|
466
|
+
to the end of the document.
|
|
467
|
+
</p>
|
|
468
|
+
<p>
|
|
469
|
+
What I've written here is probably long enough, but adding this
|
|
470
|
+
final sentence can't hurt.
|
|
471
|
+
</p>
|
|
472
|
+
</div>
|
|
473
|
+
</div>
|
|
474
|
+
</div>
|
|
475
|
+
);
|
|
476
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export const TypographyScale = () => {
|
|
2
|
+
return (
|
|
3
|
+
<div className="prose">
|
|
4
|
+
<h1>h1. Heading</h1>
|
|
5
|
+
<h2>h2. Heading</h2>
|
|
6
|
+
<h3>h3. Heading</h3>
|
|
7
|
+
<h4>h4. Heading</h4>
|
|
8
|
+
|
|
9
|
+
<sup>superscript text</sup>
|
|
10
|
+
<span>Normal text here</span>
|
|
11
|
+
<sub>subscript text</sub>
|
|
12
|
+
|
|
13
|
+
<p>
|
|
14
|
+
Paragraph. Lorem ipsum dolor sit amet, consectetur adipisicing elit.
|
|
15
|
+
Quos blanditiis tenetur unde suscipit, quam beatae rerum inventore
|
|
16
|
+
consectetur, neque doloribus, cupiditate numquam dignissimos laborum
|
|
17
|
+
fugiat deleniti? Eum quasi quidem quibusdam.
|
|
18
|
+
</p>
|
|
19
|
+
|
|
20
|
+
<button type="button">Primary button text</button>
|
|
21
|
+
<blockquote>
|
|
22
|
+
Blockquote: Lorem ipsum dolor sit amet, consectetur adipisicing elit.
|
|
23
|
+
Quos blanditiis tenetur unde suscipit, quam beatae
|
|
24
|
+
</blockquote>
|
|
25
|
+
<dl>
|
|
26
|
+
<dt>Description term</dt>
|
|
27
|
+
<dd>
|
|
28
|
+
Description detail: Lorem ipsum dolor sit amet, consectetur
|
|
29
|
+
adipisicing elit. Quos blanditiis tenetur unde suscipit, quam beatae
|
|
30
|
+
</dd>
|
|
31
|
+
</dl>
|
|
32
|
+
</div>
|
|
33
|
+
);
|
|
34
|
+
};
|