|
1 | 1 | import type { FC, ReactNode } from 'react'; |
2 | 2 | import toJsxString from 'react-element-to-jsx-string'; |
| 3 | +import { Grid, Separator, Text, VStack } from '../../preset'; |
3 | 4 | import { type Block, type Node, Parser, Renderer } from '../../renderer'; |
4 | | -import { getClassNameFactory } from '../../utils'; |
| 5 | +import { createVariants } from '../../utils'; |
5 | 6 | import { TargetType } from '../Constants'; |
6 | 7 | import { ContentScaler } from '../ContentScaler'; |
7 | 8 | import { Draggable } from '../Draggable'; |
8 | 9 | import styles from './BlockGroup.module.css'; |
9 | 10 |
|
10 | | -const getClassName = getClassNameFactory('BlockGroup', styles); |
| 11 | +const variants = createVariants(styles); |
11 | 12 |
|
12 | 13 | type Props = { |
13 | 14 | category: string; |
14 | 15 | blocks: Block[]; |
15 | 16 | }; |
16 | 17 |
|
17 | 18 | export const BlockGroup: FC<Props> = ({ category, blocks }) => ( |
18 | | - <div className={getClassName()}> |
19 | | - <h4 className={getClassName('Category')}>{category}</h4> |
20 | | - <div className={getClassName('BlockList')}> |
| 19 | + <VStack> |
| 20 | + <VStack padding={{ top: 8, bottom: 8, left: 12, right: 12 }} background="surface-container"> |
| 21 | + <Text size="xs" weight="medium" color="on-surface"> |
| 22 | + {category} |
| 23 | + </Text> |
| 24 | + </VStack> |
| 25 | + <Separator orientation="horizontal" /> |
| 26 | + <Grid columns={2} gap={4} padding={{ top: 8, bottom: 8, left: 8, right: 8 }}> |
21 | 27 | {blocks.map((block) => { |
22 | 28 | const propertySpecs = block.props ?? {}; |
23 | 29 |
|
@@ -51,24 +57,28 @@ export const BlockGroup: FC<Props> = ({ category, blocks }) => ( |
51 | 57 | .join(' '); |
52 | 58 |
|
53 | 59 | return ( |
54 | | - <div key={block.name} className={getClassName('BlockItem')}> |
55 | | - <Draggable |
56 | | - type={TargetType.Library} |
57 | | - item={{ |
58 | | - ...node, |
59 | | - props: defaultProps, |
60 | | - }} |
61 | | - > |
62 | | - <div className={getClassName('BlockItemPreview')}> |
| 60 | + <VStack key={block.name} className={variants('item')}> |
| 61 | + <Draggable type={TargetType.Library} item={node}> |
| 62 | + <VStack |
| 63 | + width={124} |
| 64 | + height={124} |
| 65 | + alignHorizontal="center" |
| 66 | + alignVertical="center" |
| 67 | + background="surface-container-low" |
| 68 | + className={variants('preview')} |
| 69 | + > |
63 | 70 | <ContentScaler width={1024} height={1024}> |
64 | 71 | <Renderer source={`<${block.name} ${jsxProps} />`} /> |
65 | 72 | </ContentScaler> |
66 | | - </div> |
| 73 | + </VStack> |
67 | 74 | </Draggable> |
68 | | - <p className={getClassName('BlockName')}>{block.name}</p> |
69 | | - </div> |
| 75 | + <Text size="xs" color="on-surface" className={variants('name')}> |
| 76 | + {block.name} |
| 77 | + </Text> |
| 78 | + </VStack> |
70 | 79 | ); |
71 | 80 | })} |
72 | | - </div> |
73 | | - </div> |
| 81 | + </Grid> |
| 82 | + <Separator orientation="horizontal" /> |
| 83 | + </VStack> |
74 | 84 | ); |
0 commit comments