forked from Weaverse/pilot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
paragraph.tsx
171 lines (166 loc) · 4.59 KB
/
paragraph.tsx
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
import type {
HydrogenComponentProps,
HydrogenComponentSchema,
} from "@weaverse/hydrogen";
import type { VariantProps } from "class-variance-authority";
import { cva } from "class-variance-authority";
import { clsx } from "clsx";
import { forwardRef } from "react";
export interface ParagraphProps
extends VariantProps<typeof variants>,
Partial<HydrogenComponentProps> {
as?: "p" | "div";
content: string;
color?: string;
}
let variants = cva("paragraph", {
variants: {
textSize: {
xs: "text-xs",
sm: "text-sm",
base: "",
lg: "text-lg",
xl: "text-xl",
"2xl": "text-2xl",
"3xl": "text-3xl",
"4xl": "text-4xl",
"5xl": "text-5xl",
"6xl": "text-6xl",
"7xl": "text-7xl",
"8xl": "text-8xl",
"9xl": "text-9xl",
},
width: {
full: "w-full mx-auto",
narrow: "w-full md:w-1/2 lg:w-3/4 max-w-4xl mx-auto",
},
alignment: {
left: "text-left",
center: "text-center",
right: "text-right",
},
},
defaultVariants: {
width: "full",
textSize: "base",
},
});
let Paragraph = forwardRef<
HTMLParagraphElement | HTMLDivElement,
ParagraphProps
>((props, ref) => {
let {
as: Tag = "p",
width,
content,
textSize,
color,
alignment,
className,
...rest
} = props;
return (
<Tag
ref={ref}
{...rest}
style={{ color }}
className={clsx(variants({ textSize, width, alignment, className }))}
suppressHydrationWarning
dangerouslySetInnerHTML={{ __html: content }}
/>
);
});
export default Paragraph;
export let schema: HydrogenComponentSchema = {
type: "paragraph",
title: "Paragraph",
inspector: [
{
group: "Paragraph",
inputs: [
{
type: "richtext",
name: "content",
label: "Content",
defaultValue:
"Pair large text with an image or full-width video to showcase your brand's lifestyle to describe and showcase an important detail of your products that you can tag on your image.",
placeholder:
"Pair large text with an image or full-width video to showcase your brand's lifestyle to describe and showcase an important detail of your products that you can tag on your image.",
},
{
type: "select",
name: "as",
label: "HTML tag",
configs: {
options: [
{ value: "p", label: "<p> (Paragraph)" },
{ value: "div", label: "<div> (Div)" },
],
},
defaultValue: "p",
},
{
type: "color",
name: "color",
label: "Text color",
},
{
type: "select",
name: "textSize",
label: "Text size",
configs: {
options: [
{ value: "xs", label: "Extra small (text-xs)" },
{ value: "sm", label: "Small (text-sm)" },
{ value: "base", label: "Base (text-base)" },
{ value: "lg", label: "Large (text-lg)" },
{ value: "xl", label: "Extra large (text-xl)" },
{ value: "2xl", label: "2x large (text-2xl)" },
{ value: "3xl", label: "3x large (text-3xl)" },
{ value: "4xl", label: "4x large (text-4xl)" },
{ value: "5xl", label: "5x large (text-5xl)" },
{ value: "6xl", label: "6x large (text-6xl)" },
{ value: "7xl", label: "7x large (text-7xl)" },
{ value: "8xl", label: "8x large (text-8xl)" },
{ value: "9xl", label: "9x large (text-9xl)" },
],
},
defaultValue: "base",
},
{
type: "toggle-group",
name: "width",
label: "Width",
configs: {
options: [
{ value: "full", label: "Full", icon: "move-horizontal" },
{
value: "narrow",
label: "Narrow",
icon: "fold-horizontal",
},
],
},
defaultValue: "narrow",
},
{
type: "toggle-group",
name: "alignment",
label: "Alignment",
configs: {
options: [
{ value: "left", label: "Left", icon: "align-start-vertical" },
{
value: "center",
label: "Center",
icon: "align-center-vertical",
},
{ value: "right", label: "Right", icon: "align-end-vertical" },
],
},
defaultValue: "center",
},
],
},
],
};