Skip to content

Commit a2b1917

Browse files
committed
feat: add text preset
1 parent 34cafb4 commit a2b1917

File tree

7 files changed

+349
-293
lines changed

7 files changed

+349
-293
lines changed

packages/react/src/editor/Editor/Editor.stories.tsx

Lines changed: 39 additions & 293 deletions
Original file line numberDiff line numberDiff line change
@@ -1,309 +1,55 @@
1-
import { type FC, type PropsWithChildren, useMemo } from 'react';
2-
import { Catalog } from '../../renderer';
31
import { Editor } from './Editor';
42
import '../../preset';
53

6-
type StackProps = PropsWithChildren<{
7-
flexDirection?: 'row' | 'column';
8-
alignItems?: 'flex-start' | 'flex-end' | 'center' | 'stretch';
9-
justifyContent?:
10-
| 'flex-start'
11-
| 'flex-end'
12-
| 'center'
13-
| 'space-between'
14-
| 'space-around'
15-
| 'space-evenly';
16-
gap?: number;
17-
size?: {
18-
width?: number | string;
19-
minWidth?: number | string;
20-
maxWidth?: number | string;
21-
height?: number | string;
22-
minHeight?: number | string;
23-
maxHeight?: number | string;
24-
};
25-
padding?: { top: number; right: number; bottom: number; left: number };
26-
margin?: { top: number; right: number; bottom: number; left: number };
27-
backgroundColor?: string;
28-
}>;
29-
30-
const Stack: FC<StackProps> = ({
31-
flexDirection,
32-
alignItems,
33-
justifyContent,
34-
gap,
35-
size,
36-
padding,
37-
margin,
38-
backgroundColor,
39-
...props
40-
}) => {
41-
const style = useMemo(
42-
() => ({
43-
display: 'flex',
44-
flexDirection,
45-
alignItems,
46-
justifyContent,
47-
gap,
48-
width: size?.width,
49-
minWidth: size?.minWidth,
50-
maxWidth: size?.maxWidth,
51-
height: size?.height,
52-
minHeight: size?.minHeight,
53-
maxHeight: size?.maxHeight,
54-
paddingLeft: padding?.left,
55-
paddingRight: padding?.right,
56-
paddingTop: padding?.top,
57-
paddingBottom: padding?.bottom,
58-
marginLeft: margin?.left,
59-
marginRight: margin?.right,
60-
marginTop: margin?.top,
61-
marginBottom: margin?.bottom,
62-
backgroundColor,
63-
}),
64-
[flexDirection, alignItems, justifyContent, gap, size, padding, margin, backgroundColor],
65-
);
66-
67-
return <div style={style} {...props} />;
68-
};
69-
70-
type TextProps = {
71-
children: string;
72-
textAlign: 'left' | 'center' | 'right';
73-
};
74-
75-
const Text: FC<TextProps> = ({ children, textAlign }) => (
76-
<span style={{ textAlign }}>{children}</span>
77-
);
78-
79-
Catalog.register('Stack', {
80-
component: Stack,
81-
props: {
82-
flexDirection: {
83-
label: 'Flex Direction',
84-
type: 'radio',
85-
options: [
86-
{ label: 'Row', value: 'row' },
87-
{ label: 'Column', value: 'column' },
88-
],
89-
default: 'row',
90-
},
91-
justifyContent: {
92-
label: 'Justify Content',
93-
type: 'select',
94-
options: [
95-
{ label: 'Start', value: 'flex-start' },
96-
{ label: 'End', value: 'flex-end' },
97-
{ label: 'Center', value: 'center' },
98-
{ label: 'Space Between', value: 'space-between' },
99-
{ label: 'Space Around', value: 'space-around' },
100-
{ label: 'Space Evenly', value: 'space-evenly' },
101-
],
102-
default: 'flex-start',
103-
optional: true,
104-
},
105-
alignItems: {
106-
label: 'Align Items',
107-
type: 'select',
108-
options: [
109-
{ label: 'Start', value: 'flex-start' },
110-
{ label: 'End', value: 'flex-end' },
111-
{ label: 'Center', value: 'center' },
112-
{ label: 'Stretch', value: 'stretch' },
113-
],
114-
default: 'stretch',
115-
optional: true,
116-
},
117-
gap: {
118-
label: 'Gap',
119-
type: 'number',
120-
default: 0,
121-
optional: true,
122-
},
123-
size: {
124-
label: 'Size',
125-
type: 'object',
126-
fields: {
127-
width: {
128-
label: 'Width',
129-
type: 'number',
130-
default: 100,
131-
optional: true,
132-
},
133-
minWidth: {
134-
label: 'Min Width',
135-
type: 'number',
136-
default: 0,
137-
optional: true,
138-
},
139-
maxWidth: {
140-
label: 'Max Width',
141-
type: 'number',
142-
default: 1000,
143-
optional: true,
144-
},
145-
height: {
146-
label: 'Height',
147-
type: 'number',
148-
default: 100,
149-
optional: true,
150-
},
151-
minHeight: {
152-
label: 'Min Height',
153-
type: 'number',
154-
default: 0,
155-
optional: true,
156-
},
157-
maxHeight: {
158-
label: 'Max Height',
159-
type: 'number',
160-
default: 1000,
161-
optional: true,
162-
},
163-
},
164-
optional: true,
165-
},
166-
padding: {
167-
label: 'Padding',
168-
type: 'object',
169-
fields: {
170-
top: {
171-
label: 'Top',
172-
type: 'number',
173-
default: 0,
174-
},
175-
right: {
176-
label: 'Right',
177-
type: 'number',
178-
default: 0,
179-
},
180-
bottom: {
181-
label: 'Bottom',
182-
type: 'number',
183-
default: 0,
184-
},
185-
left: {
186-
label: 'Left',
187-
type: 'number',
188-
default: 0,
189-
},
190-
},
191-
optional: true,
192-
},
193-
margin: {
194-
label: 'Margin',
195-
type: 'object',
196-
fields: {
197-
top: {
198-
label: 'Top',
199-
type: 'number',
200-
default: 0,
201-
},
202-
right: {
203-
label: 'Right',
204-
type: 'number',
205-
default: 0,
206-
},
207-
bottom: {
208-
label: 'Bottom',
209-
type: 'number',
210-
default: 0,
211-
},
212-
left: {
213-
label: 'Left',
214-
type: 'number',
215-
default: 0,
216-
},
217-
},
218-
optional: true,
219-
},
220-
backgroundColor: {
221-
label: 'Background Color',
222-
type: 'text',
223-
default: '#ffffff',
224-
optional: true,
225-
},
226-
children: {
227-
label: 'Children',
228-
type: 'node',
229-
},
230-
},
231-
});
232-
233-
Catalog.register('Text', {
234-
component: Text,
235-
props: {
236-
children: {
237-
label: 'Content',
238-
type: 'text',
239-
default: 'Lorem ipsum',
240-
},
241-
textAlign: {
242-
label: 'Text Align',
243-
type: 'radio',
244-
options: [
245-
{ label: 'Left', value: 'left' },
246-
{ label: 'Center', value: 'center' },
247-
{ label: 'Right', value: 'right' },
248-
],
249-
default: 'left',
250-
},
251-
},
252-
});
253-
2544
export const BasicUsage = () => {
2555
const source = `
256-
<Stack
257-
flexDirection="column"
258-
justifyContent="flex-start"
259-
alignItems="stretch"
6+
<VStack
7+
alignHorizontal="stretch"
8+
alignVertical="start"
2609
gap={8}
261-
backgroundColor="#ffffff"
10+
background="#ffffff"
26211
>
263-
<Text textAlign="left">Welcome to Composify! 👋</Text>
264-
<Stack
265-
flexDirection="row"
266-
justifyContent="flex-start"
267-
alignItems="stretch"
268-
backgroundColor="#f8fafc"
12+
<Text color="#1E1E1E" size="md" weight="normal" align="left">Welcome to Composify! 👋</Text>
13+
<HStack
14+
alignHorizontal="start"
15+
alignVertical="stretch"
16+
background="#f8fafc"
26917
>
270-
<Stack
271-
flexDirection="row"
272-
justifyContent="flex-start"
273-
alignItems="stretch"
274-
size={{ width: 100, height: 100 }}
275-
backgroundColor="#f1f5f9"
18+
<HStack
19+
alignHorizontal="start"
20+
alignVertical="stretch"
21+
width={100}
22+
height={100}
23+
background="#f1f5f9"
27624
/>
277-
<Stack
278-
flexDirection="row"
279-
justifyContent="flex-start"
280-
alignItems="stretch"
281-
size={{ width: 125, height: 100 }}
282-
backgroundColor="#e2e8f0"
25+
<HStack
26+
alignHorizontal="start"
27+
alignVertical="stretch"
28+
width={125}
29+
height={100}
30+
background="#e2e8f0"
28331
/>
284-
<Stack
285-
flexDirection="row"
286-
justifyContent="flex-start"
287-
alignItems="stretch"
288-
size={{ width: 150, height: 100 }}
289-
backgroundColor="#cbd5e1"
32+
<HStack
33+
alignHorizontal="start"
34+
alignVertical="stretch"
35+
width={150}
36+
height={100}
37+
background="#cbd5e1"
29038
/>
291-
</Stack>
292-
<Stack
293-
flexDirection="row"
294-
justifyContent="flex-start"
295-
alignItems="stretch"
296-
size={{ height: 100 }}
297-
backgroundColor="#f1f5f9"
39+
</HStack>
40+
<HStack
41+
alignHorizontal="start"
42+
alignVertical="stretch"
43+
height={100}
44+
background="#f1f5f9"
29845
/>
299-
<Stack
300-
flexDirection="row"
301-
justifyContent="flex-start"
302-
alignItems="stretch"
303-
size={{ height: 100 }}
304-
backgroundColor="#cbd5e1"
46+
<HStack
47+
alignHorizontal="start"
48+
alignVertical="stretch"
49+
height={100}
50+
background="#cbd5e1"
30551
/>
306-
</Stack>
52+
</VStack>
30753
`;
30854

30955
return <Editor title="Lorem Ipsum" source={source} onSubmit={console.log} />;

packages/react/src/preset/Button/ButtonCatalog.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Button } from './Button';
33

44
Catalog.register('Button', {
55
component: Button,
6+
category: 'Content',
67
props: {
78
variant: {
89
label: 'Variant',

0 commit comments

Comments
 (0)