Skip to content

Commit 64e141b

Browse files
committed
fix: add orientation to the PropertyControl and set horizontal as default
1 parent e6cfe8c commit 64e141b

File tree

14 files changed

+151
-82
lines changed

14 files changed

+151
-82
lines changed
Lines changed: 60 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,79 @@
1-
.PropertyControl {
1+
.frame {
22
display: flex;
3+
grid-column: 1 / -1;
4+
}
5+
6+
.frame--orientation-horizontal {
7+
gap: 8px;
8+
align-items: center;
9+
}
10+
11+
.frame--orientation-vertical {
12+
gap: 4px;
313
flex-direction: column;
14+
align-items: stretch;
415
}
516

6-
.PropertyControl-Header {
17+
.header {
718
display: flex;
819
align-items: center;
920
justify-content: space-between;
10-
height: 1.75rem;
21+
height: 26px;
1122
}
1223

13-
.PropertyControl-Label {
14-
color: var(--composify-palette-on-surface);
24+
.header--orientation-horizontal {
25+
flex: 1;
26+
}
27+
28+
.header--compact {
29+
display: none;
30+
}
31+
32+
.label {
33+
color: var(--composify-palette-on-surface-variant);
1534
font-size: 0.75rem;
16-
font-weight: 600;
35+
font-weight: 500;
1736
}
1837

19-
.PropertyControl-OptionalButton {
38+
.input {
2039
display: flex;
40+
flex: 2;
41+
gap: 4px;
42+
}
43+
44+
.input > :not([data-slot="remove-button"]) {
45+
flex: 1;
46+
}
47+
48+
.addButton {
49+
display: inline-flex;
50+
align-items: center;
51+
height: 36px;
52+
padding: 0 8px;
53+
font-size: 12px;
54+
outline: none;
55+
border-radius: 4px;
56+
border: 1px solid var(--composify-palette-outline);
57+
color: var(--composify-palette-on-surface-variant);
58+
background-color: var(--composify-palette-surface-container-low);
59+
}
60+
61+
.removeButton {
62+
display: inline-flex;
63+
align-self: center;
2164
align-items: center;
2265
justify-content: center;
23-
cursor: pointer;
24-
padding: 0.375rem;
25-
margin-right: -0.375rem;
66+
width: 26px;
67+
height: 26px;
2668
outline: none;
2769
border: none;
28-
border-radius: 0.25rem;
70+
border-radius: 4px;
2971
background-color: transparent;
30-
fill: var(--composify-palette-secondary);
72+
transition: background-color 0.15s;
73+
cursor: pointer;
74+
color: var(--composify-palette-on-surface-variant);
75+
}
76+
77+
.removeButton:hover {
78+
background-color: var(--composify-palette-surface-container);
3179
}
Lines changed: 40 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
import { MinusIcon } from 'lucide-react';
12
import { type ReactNode, useCallback } from 'react';
23
import type { PropertySpec } from '../../renderer';
3-
import { getClassNameFactory } from '../../utils';
4+
import { createVariants } from '../../utils';
45
import { useEditing } from '../EditingContext';
56
import styles from './PropertyControl.module.css';
67

@@ -9,18 +10,20 @@ type Props<SpecValue, Value = SpecValue> = {
910
spec: PropertySpec<SpecValue>;
1011
defaultValue: Value;
1112
value?: Value;
13+
orientation?: 'horizontal' | 'vertical';
1214
compact?: boolean;
1315
onChange?: (name: string, value?: Value) => void;
1416
renderInput: (value: Value, onChange: (value?: Value) => void) => ReactNode;
1517
};
1618

17-
const getClassName = getClassNameFactory('PropertyControl', styles);
19+
const variants = createVariants(styles);
1820

1921
export const PropertyControl = <SpecValue, Value = SpecValue>({
2022
name,
2123
spec,
2224
defaultValue,
2325
value,
26+
orientation = 'horizontal',
2427
compact,
2528
onChange,
2629
renderInput,
@@ -55,40 +58,41 @@ export const PropertyControl = <SpecValue, Value = SpecValue>({
5558
);
5659

5760
return (
58-
<div className={getClassName()}>
59-
{compact ? null : (
60-
<div className={getClassName('Header')}>
61-
<span className={getClassName('Label')}>{spec.label}</span>
62-
{spec.optional && (
63-
<button
64-
type="button"
65-
className={getClassName('OptionalButton')}
66-
onClick={handleClickOptional}
67-
>
68-
{isEffectiveValueDefined ? (
69-
<svg
70-
xmlns="http://www.w3.org/2000/svg"
71-
width={16}
72-
height={16}
73-
viewBox="0 0 640 640"
74-
>
75-
<path d="M96 320C96 302.3 110.3 288 128 288L512 288C529.7 288 544 302.3 544 320C544 337.7 529.7 352 512 352L128 352C110.3 352 96 337.7 96 320z" />
76-
</svg>
77-
) : (
78-
<svg
79-
xmlns="http://www.w3.org/2000/svg"
80-
width={14}
81-
height={14}
82-
viewBox="0 0 640 640"
83-
>
84-
<path d="M352 128C352 110.3 337.7 96 320 96C302.3 96 288 110.3 288 128L288 288L128 288C110.3 288 96 302.3 96 320C96 337.7 110.3 352 128 352L288 352L288 512C288 529.7 302.3 544 320 544C337.7 544 352 529.7 352 512L352 352L512 352C529.7 352 544 337.7 544 320C544 302.3 529.7 288 512 288L352 288L352 128z" />
85-
</svg>
86-
)}
87-
</button>
88-
)}
89-
</div>
90-
)}
91-
{isEffectiveValueDefined && renderInput(effectiveValue, handleChange)}
61+
<div className={variants('frame', { orientation })}>
62+
<div className={variants('header', { orientation, compact })}>
63+
<span className={variants('label')}>{spec.label}</span>
64+
{spec.optional && orientation === 'vertical' && isEffectiveValueDefined && (
65+
<button
66+
data-slot="remove-button"
67+
type="button"
68+
className={variants('removeButton')}
69+
onClick={handleClickOptional}
70+
>
71+
<MinusIcon />
72+
</button>
73+
)}
74+
</div>
75+
<div className={variants('input')}>
76+
{isEffectiveValueDefined ? (
77+
<>
78+
{renderInput(effectiveValue, handleChange)}
79+
{spec.optional && orientation === 'horizontal' && (
80+
<button
81+
data-slot="remove-button"
82+
type="button"
83+
className={variants('removeButton')}
84+
onClick={handleClickOptional}
85+
>
86+
<MinusIcon />
87+
</button>
88+
)}
89+
</>
90+
) : (
91+
<button type="button" className={variants('addButton')} onClick={handleClickOptional}>
92+
Add..
93+
</button>
94+
)}
95+
</div>
9296
</div>
9397
);
9498
};

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ export const WithObjectItems = () => {
7878
{ name: 'Alice', age: 30 },
7979
{ name: 'Bob', age: 25 },
8080
],
81+
optional: true,
8182
}}
8283
value={value}
8384
onChange={(_, next) => setValue(next)}

packages/react/src/editor/PropertyControlArray/PropertyControlArray.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ const getClassName = getClassNameFactory('PropertyControlArray', styles);
2626
export const PropertyControlArray = ({ name, spec, ...props }: Props) => (
2727
<PropertyControl<any[]>
2828
{...props}
29+
orientation="vertical"
2930
name={name}
3031
spec={spec}
3132
defaultValue={spec.default ?? []}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
.PropertyControlNumber {
22
flex: 1;
3+
field-sizing: content;
34
padding: 0.5rem;
45
font-size: 0.875rem;
56
line-height: 1.4;

packages/react/src/editor/PropertyControlNumber/PropertyControlNumber.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export const PropertyControlNumber = ({ spec, ...props }: Props) => (
2121
renderInput={(value, onChange) => (
2222
<input
2323
type="number"
24+
size={undefined}
2425
value={value}
2526
onChange={(event) => onChange(Number(event.target.value))}
2627
className={getClassName()}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
.PropertyControlObject {
22
display: flex;
33
flex-direction: column;
4-
gap: 1rem;
5-
padding: 0.5rem 0.75rem 0.75rem 0.75rem;
6-
border-radius: 0.25rem;
4+
gap: 10px;
5+
padding: 12px;
6+
border-radius: 4px;
77
border: 1px solid var(--composify-palette-outline);
88
}

packages/react/src/editor/PropertyControlObject/PropertyControlObject.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const getClassName = getClassNameFactory('PropertyControlObject', styles);
2525
export const PropertyControlObject = ({ spec, ...props }: Props) => (
2626
<PropertyControl<Record<string, any>>
2727
{...props}
28+
orientation="vertical"
2829
spec={spec}
2930
defaultValue={spec.default ?? {}}
3031
renderInput={(value, onChange) => {
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
.PropertyLibrary {
2-
display: flex;
3-
flex-direction: column;
4-
gap: 0.5rem;
5-
padding: 0.5rem 0.75rem 1rem 0.75rem;
2+
display: grid;
3+
grid-template-columns: 1fr 1fr;
4+
grid-gap: 10px;
5+
padding: 12px;
66
border-bottom: 1px solid var(--composify-palette-outline);
77
}

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.container {
1+
.button {
22
display: inline-flex;
33
flex-shrink: 0;
44
align-items: center;
@@ -14,54 +14,54 @@
1414
transition-duration: 0.15s;
1515
}
1616

17-
.container:disabled {
17+
.button:disabled {
1818
pointer-events: none;
1919
opacity: 0.7;
2020
}
2121

22-
.container--variant-primary {
22+
.button--variant-primary {
2323
background-color: var(--composify-palette-primary);
2424
color: var(--composify-palette-on-primary);
2525
}
2626

27-
.container--variant-primary:hover {
27+
.button--variant-primary:hover {
2828
opacity: 0.9;
2929
}
3030

31-
.container--variant-secondary {
31+
.button--variant-secondary {
3232
background-color: var(--composify-palette-secondary);
3333
color: var(--composify-palette-on-secondary);
3434
}
3535

36-
.container--variant-secondary:hover {
36+
.button--variant-secondary:hover {
3737
opacity: 0.9;
3838
}
3939

40-
.container--variant-outline {
40+
.button--variant-outline {
4141
border: 1px solid var(--composify-palette-outline);
4242
background-color: var(--composify-palette-surface);
4343
color: var(--composify-palette-on-surface);
4444
}
4545

46-
.container--variant-outline:hover {
47-
background-color: var(--composify-palette-surface-container);
46+
.button--variant-outline:hover {
47+
background-color: var(--composify-palette-surface-button);
4848
}
4949

50-
.container--size-xs {
50+
.button--size-sm {
5151
height: 32px;
5252
padding: 0 12px;
5353
gap: 4px;
5454
font-size: 12px;
5555
}
5656

57-
.container--size-sm {
57+
.button--size-md {
5858
height: 36px;
5959
padding: 0 12px;
6060
gap: 6px;
6161
font-size: 14px;
6262
}
6363

64-
.container--size-md {
64+
.button--size-lg {
6565
height: 42px;
6666
padding: 0 16px;
6767
gap: 8px;

0 commit comments

Comments
 (0)