Skip to content

Commit a0c8744

Browse files
committed
refactor: use preset components in block library
1 parent 5ac2457 commit a0c8744

File tree

3 files changed

+41
-62
lines changed

3 files changed

+41
-62
lines changed
Lines changed: 10 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,24 @@
1-
.BlockGroup {
2-
display: flex;
3-
flex-direction: column;
4-
}
5-
6-
.BlockGroup-Category {
7-
margin: 0;
8-
padding: 0.5rem 0.75rem;
9-
font-size: 0.75rem;
10-
font-weight: 500;
11-
border-top: 1px solid var(--composify-palette-outline);
12-
border-bottom: 1px solid var(--composify-palette-outline);
13-
background-color: var(--composify-palette-surface-container);
14-
color: var(--composify-palette-on-surface);
15-
}
16-
17-
.BlockGroup-BlockList {
18-
display: grid;
19-
grid-template-columns: repeat(2, 1fr);
20-
gap: 0.25rem;
21-
padding: 0.5rem;
22-
}
23-
24-
.BlockGroup-BlockItem {
25-
display: flex;
26-
flex-direction: column;
27-
align-items: center;
28-
gap: 0.375rem;
29-
border-radius: 0.25rem;
30-
padding: 0.25rem;
1+
.item {
2+
gap: 6px;
3+
border-radius: 4px;
4+
padding: 4px;
315
overflow: hidden;
326
}
337

34-
.BlockGroup-BlockItemPreview {
35-
display: flex;
36-
justify-content: center;
37-
align-items: center;
8+
.preview {
9+
overflow: hidden;
3810
border-radius: 0.25rem;
3911
border: 1px solid var(--composify-palette-outline);
40-
background-color: var(--composify-palette-surface-container-low);
41-
overflow: hidden;
42-
width: 7.75rem;
43-
height: 7.75rem;
12+
transition: border 0.15s;
4413
}
4514

46-
.BlockGroup-BlockItemPreview:hover {
15+
.preview:hover {
4716
border: 1px solid var(--composify-palette-primary);
4817
}
4918

50-
.BlockGroup-BlockName {
19+
.name {
5120
align-self: stretch;
52-
margin: 0 0.1875rem;
53-
font-size: 0.75rem;
54-
color: var(--composify-palette-on-surface);
21+
margin: 0 3px;
5522
overflow: hidden;
5623
text-overflow: ellipsis;
5724
}

packages/react/src/editor/BlockGroup/BlockGroup.tsx

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,29 @@
11
import type { FC, ReactNode } from 'react';
22
import toJsxString from 'react-element-to-jsx-string';
3+
import { Grid, Separator, Text, VStack } from '../../preset';
34
import { type Block, type Node, Parser, Renderer } from '../../renderer';
4-
import { getClassNameFactory } from '../../utils';
5+
import { createVariants } from '../../utils';
56
import { TargetType } from '../Constants';
67
import { ContentScaler } from '../ContentScaler';
78
import { Draggable } from '../Draggable';
89
import styles from './BlockGroup.module.css';
910

10-
const getClassName = getClassNameFactory('BlockGroup', styles);
11+
const variants = createVariants(styles);
1112

1213
type Props = {
1314
category: string;
1415
blocks: Block[];
1516
};
1617

1718
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 }}>
2127
{blocks.map((block) => {
2228
const propertySpecs = block.props ?? {};
2329

@@ -51,24 +57,28 @@ export const BlockGroup: FC<Props> = ({ category, blocks }) => (
5157
.join(' ');
5258

5359
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+
>
6370
<ContentScaler width={1024} height={1024}>
6471
<Renderer source={`<${block.name} ${jsxProps} />`} />
6572
</ContentScaler>
66-
</div>
73+
</VStack>
6774
</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>
7079
);
7180
})}
72-
</div>
73-
</div>
81+
</Grid>
82+
<Separator orientation="horizontal" />
83+
</VStack>
7484
);

packages/react/src/editor/BlockLibrary/BlockLibrary.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { FC } from 'react';
2+
import { Separator } from '../../preset';
23
import { Catalog } from '../../renderer';
34
import { BlockGroup } from '../BlockGroup';
45
import { ComposifyEditorProvider } from '../ComposifyEditorContext';
@@ -9,6 +10,7 @@ type Props = {
910

1011
export const BlockLibrary: FC<Props> = ({ query }) => (
1112
<ComposifyEditorProvider isLibrary={true} isVisualEditor={false}>
13+
<Separator orientation="horizontal" />
1214
{Catalog.getAll(query).map(({ category, blocks }) => (
1315
<BlockGroup key={category} category={category} blocks={blocks} />
1416
))}

0 commit comments

Comments
 (0)