Skip to content

Commit 20b4fc8

Browse files
committed
feat: add icon button preset
1 parent d5ab506 commit 20b4fc8

File tree

9 files changed

+102
-55
lines changed

9 files changed

+102
-55
lines changed

packages/react/src/editor/ActiveBlockControl/ActiveBlockControl.module.css

Lines changed: 0 additions & 35 deletions
This file was deleted.
Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
import { getClassNameFactory } from '../../utils';
1+
import { CopyIcon, TrashIcon } from 'lucide-react';
2+
import { HStack, IconButton, Text } from '../../preset';
23
import { useEditing } from '../EditingContext';
3-
import styles from './ActiveBlockControl.module.css';
4-
5-
const getClassName = getClassNameFactory('ActiveBlockControl', styles);
64

75
export const ActiveBlockControl = () => {
86
const { activeBlock, duplicateActiveBlock, removeActiveBlock } = useEditing();
@@ -12,20 +10,22 @@ export const ActiveBlockControl = () => {
1210
}
1311

1412
return (
15-
<div className={getClassName()}>
16-
<h2 className={getClassName('Title')}>{activeBlock?.type}</h2>
17-
<div className={getClassName('Actions')}>
18-
<button type="button" className={getClassName('ActionItem')} onClick={duplicateActiveBlock}>
19-
<svg xmlns="http://www.w3.org/2000/svg" width={16} height={16} viewBox="0 0 640 640">
20-
<path d="M288 64C252.7 64 224 92.7 224 128L224 384C224 419.3 252.7 448 288 448L480 448C515.3 448 544 419.3 544 384L544 183.4C544 166 536.9 149.3 524.3 137.2L466.6 81.8C454.7 70.4 438.8 64 422.3 64L288 64zM160 192C124.7 192 96 220.7 96 256L96 512C96 547.3 124.7 576 160 576L352 576C387.3 576 416 547.3 416 512L416 496L352 496L352 512L160 512L160 256L176 256L176 192L160 192z" />
21-
</svg>
22-
</button>
23-
<button type="button" className={getClassName('ActionItem')} onClick={removeActiveBlock}>
24-
<svg xmlns="http://www.w3.org/2000/svg" width={16} height={16} viewBox="0 0 640 640">
25-
<path d="M232.7 69.9L224 96L128 96C110.3 96 96 110.3 96 128C96 145.7 110.3 160 128 160L512 160C529.7 160 544 145.7 544 128C544 110.3 529.7 96 512 96L416 96L407.3 69.9C402.9 56.8 390.7 48 376.9 48L263.1 48C249.3 48 237.1 56.8 232.7 69.9zM512 208L128 208L149.1 531.1C150.7 556.4 171.7 576 197 576L443 576C468.3 576 489.3 556.4 490.9 531.1L512 208z" />
26-
</svg>
27-
</button>
28-
</div>
29-
</div>
13+
<HStack
14+
alignHorizontal="between"
15+
alignVertical="center"
16+
padding={{ top: 10, bottom: 10, left: 12, right: 10 }}
17+
>
18+
<Text size="md" weight="semibold" color="on-surface">
19+
{activeBlock.type}
20+
</Text>
21+
<HStack>
22+
<IconButton size="sm" onClick={duplicateActiveBlock}>
23+
<CopyIcon />
24+
</IconButton>
25+
<IconButton size="sm" onClick={removeActiveBlock}>
26+
<TrashIcon />
27+
</IconButton>
28+
</HStack>
29+
</HStack>
3030
);
3131
};

packages/react/src/preset/Button/Button.module.css

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
font-weight: 500;
1111
line-height: 1;
1212
white-space: nowrap;
13+
cursor: pointer;
1314
transition:
1415
background-color 0.15s,
1516
opacity 0.15s;
@@ -48,6 +49,15 @@
4849
background-color: var(--composify-palette-surface-button);
4950
}
5051

52+
.button--variant-ghost {
53+
background-color: transparent;
54+
color: var(--composify-palette-on-surface);
55+
}
56+
57+
.button--variant-ghost:hover {
58+
opacity: 0.7;
59+
}
60+
5161
.button--size-sm {
5262
height: 32px;
5363
padding: 0 12px;

packages/react/src/preset/Button/Button.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { createVariants } from '../../utils';
33
import styles from './Button.module.css';
44

55
type Props = ComponentProps<'button'> & {
6-
variant: 'primary' | 'secondary' | 'outline';
6+
variant: 'primary' | 'secondary' | 'outline' | 'ghost';
77
size: 'sm' | 'md' | 'lg';
88
};
99

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ Catalog.register('Button', {
2121
label: 'Outline',
2222
value: 'outline',
2323
},
24+
{
25+
label: 'Ghost',
26+
value: 'ghost',
27+
},
2428
],
2529
default: 'primary',
2630
},
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
.iconButton {
2+
display: inline-flex;
3+
flex-shrink: 0;
4+
align-items: center;
5+
justify-content: center;
6+
outline: none;
7+
border: none;
8+
background-color: transparent;
9+
font-family: inherit;
10+
line-height: 1;
11+
white-space: nowrap;
12+
cursor: pointer;
13+
transition: opacity 0.15s;
14+
}
15+
16+
.iconButton:disabled {
17+
pointer-events: none;
18+
opacity: 0.7;
19+
}
20+
21+
.iconButton:hover {
22+
opacity: 0.7;
23+
}
24+
25+
.iconButton--size-sm {
26+
width: 32px;
27+
height: 32px;
28+
}
29+
30+
.iconButton--size-sm > svg {
31+
width: 16px;
32+
height: 16px;
33+
}
34+
35+
.iconButton--size-md {
36+
width: 36px;
37+
height: 36px;
38+
}
39+
40+
.iconButton--size-md > svg {
41+
width: 18px;
42+
height: 18px;
43+
}
44+
45+
.iconButton--size-lg {
46+
width: 42px;
47+
height: 42px;
48+
}
49+
50+
.iconButton--size-lg > svg {
51+
width: 20px;
52+
height: 20px;
53+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import type { ComponentProps, FC } from 'react';
2+
import { createVariants } from '../../utils';
3+
import styles from './IconButton.module.css';
4+
5+
type Props = ComponentProps<'button'> & {
6+
size: 'sm' | 'md' | 'lg';
7+
};
8+
9+
const variants = createVariants(styles);
10+
11+
export const IconButton: FC<Props> = ({ className, size, ...props }) => (
12+
<button className={variants('iconButton', { className, size })} {...props} />
13+
);
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { IconButton } from './IconButton';

packages/react/src/preset/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
export { Button } from './Button';
22
export { HStack } from './HStack';
3+
export { IconButton } from './IconButton';
34
export { Input } from './Input';
45
export { Segment } from './Segment';
56
export { Select } from './Select';

0 commit comments

Comments
 (0)