Skip to content

Commit 9451ca7

Browse files
committed
feat: add select preset
1 parent a3e8586 commit 9451ca7

File tree

11 files changed

+60
-31
lines changed

11 files changed

+60
-31
lines changed
Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1+
import { Select } from '../../preset';
12
import type { SelectPropertySpec } from '../../renderer';
2-
import { getClassNameFactory } from '../../utils';
33
import { PropertyControl } from '../PropertyControl';
4-
import styles from './PropertyControlSelect.module.css';
54

65
type Props<Value> = {
76
name: string;
@@ -11,30 +10,22 @@ type Props<Value> = {
1110
onChange?: (name: string, value?: Value) => void;
1211
};
1312

14-
const getClassName = getClassNameFactory('PropertyControlSelect', styles);
15-
1613
export const PropertyControlSelect = <Value,>({ name, spec, ...props }: Props<Value>) => (
1714
<PropertyControl<Value>
1815
{...props}
1916
name={name}
2017
spec={spec}
2118
defaultValue={spec.default ?? spec.options[0].value}
2219
renderInput={(value, onChange) => (
23-
<select
24-
className={getClassName()}
20+
<Select
21+
options={spec.options.map((option, index) => ({ label: option.label, value: index }))}
2522
value={String(spec.options.findIndex((option) => option.value === value))}
2623
onChange={(event) => {
2724
const index = Number(event.target.value);
2825

2926
onChange(spec.options[index].value);
3027
}}
31-
>
32-
{spec.options.map((option, index) => (
33-
<option key={option.label} value={index}>
34-
{option.label}
35-
</option>
36-
))}
37-
</select>
28+
/>
3829
)}
3930
/>
4031
);

packages/react/src/preset/HStack/HStack.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import type { FC, PropsWithChildren } from 'react';
22
import { createVariants } from '../../utils';
33
import styles from './HStack.module.css';
44

5+
const variants = createVariants(styles);
6+
57
type Props = PropsWithChildren<{
68
className?: string;
79
alignHorizontal?: 'start' | 'end' | 'center' | 'between' | 'around';
@@ -21,8 +23,6 @@ type Props = PropsWithChildren<{
2123
background?: string;
2224
}>;
2325

24-
const variants = createVariants(styles);
25-
2626
export const HStack: FC<Props> = ({
2727
className,
2828
alignHorizontal,

packages/react/src/preset/HStack/HStackCatalog.tsx

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

1515
Catalog.register('HStack', {
1616
component: HStack,
17+
category: 'Layout',
1718
props: {
1819
alignHorizontal: {
1920
group: 'Layout',

packages/react/src/preset/Input/Input.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import type { ComponentProps, FC } from 'react';
22
import { createVariants } from '../../utils';
33
import styles from './Input.module.css';
44

5-
type Props = ComponentProps<'input'>;
6-
75
const variants = createVariants(styles);
86

7+
type Props = ComponentProps<'input'>;
8+
99
export const Input: FC<Props> = ({ className, ...props }) => (
1010
<input className={variants('input', { className })} {...props} />
1111
);

packages/react/src/preset/Segment/Segment.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import type { ReactNode } from 'react';
22
import { createVariants } from '../../utils';
33
import styles from './Segment.module.css';
44

5+
const variants = createVariants(styles);
6+
57
type Props<Value> = {
68
className?: string;
79
size: 'sm' | 'md';
@@ -13,8 +15,6 @@ type Props<Value> = {
1315
onChange: (value: Value) => void;
1416
};
1517

16-
const variants = createVariants(styles);
17-
1818
export const Segment = <Value,>({
1919
className,
2020
size,

packages/react/src/editor/PropertyControlSelect/PropertyControlSelect.module.css renamed to packages/react/src/preset/Select/Select.module.css

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,30 @@
1-
.PropertyControlSelect {
2-
flex: 1;
3-
padding: 0.5rem;
4-
font-size: 0.875rem;
5-
line-height: 1.4;
6-
appearance: none;
7-
outline: none;
8-
border: 1px solid var(--composify-palette-outline);
9-
border-radius: 0.25rem;
1+
.select {
2+
width: 100%;
3+
min-width: 0;
4+
height: 32px;
5+
padding: 0 8px;
6+
font-size: 13px;
107
color: var(--composify-palette-on-surface);
8+
border-radius: 4px;
9+
border: 1px solid var(--composify-palette-outline);
1110
background: url("data:image/svg+xml;utf8,<svg fill='gray' width='16' height='16' viewBox='0 0 20 20' xmlns='http://www.w3.org/2000/svg'><path d='M5.25 7.25L10 12l4.75-4.75z'/></svg>")
1211
no-repeat right 0.5rem center;
1312
background-color: var(--composify-palette-surface-container-low);
13+
transition: border-color 0.15s;
14+
appearance: none;
15+
outline: none;
1416
}
1517

16-
.PropertyControlSelect:focus {
18+
.select:focus-visible {
1719
border-color: var(--composify-palette-primary);
1820
}
21+
22+
.select:disabled {
23+
opacity: 0.7;
24+
cursor: not-allowed;
25+
pointer-events: none;
26+
}
27+
28+
.select::placeholder {
29+
color: var(--composify-palette-on-surface-variant);
30+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import type { ComponentProps, FC } from 'react';
2+
import { createVariants } from '../../utils';
3+
import styles from './Select.module.css';
4+
5+
const variants = createVariants(styles);
6+
7+
type Props = ComponentProps<'select'> & {
8+
options: {
9+
label: string;
10+
value: number | string;
11+
}[];
12+
};
13+
14+
export const Select: FC<Props> = ({ className, options, ...props }) => (
15+
<select className={variants('select', { className })} {...props}>
16+
{options.map((option) => (
17+
<option key={option.value} value={option.value}>
18+
{option.label}
19+
</option>
20+
))}
21+
</select>
22+
);
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { Select } from './Select';

packages/react/src/preset/VStack/VStack.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import type { FC, PropsWithChildren } from 'react';
22
import { createVariants } from '../../utils';
33
import styles from './VStack.module.css';
44

5+
const variants = createVariants(styles);
6+
57
type Props = PropsWithChildren<{
68
className?: string;
79
alignHorizontal?: 'stretch' | 'start' | 'end' | 'center';
@@ -21,8 +23,6 @@ type Props = PropsWithChildren<{
2123
background?: string;
2224
}>;
2325

24-
const variants = createVariants(styles);
25-
2626
export const VStack: FC<Props> = ({
2727
className,
2828
alignHorizontal,

packages/react/src/preset/VStack/VStackCatalog.tsx

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

1515
Catalog.register('VStack', {
1616
component: VStack,
17+
category: 'Layout',
1718
props: {
1819
alignHorizontal: {
1920
group: 'Layout',

0 commit comments

Comments
 (0)