Skip to content

Commit 47c3667

Browse files
feat: create generic SelectSizeV2 component that manages both icon and file tree shapes, add selectSizeV2 to properties pod
1 parent 13ae182 commit 47c3667

6 files changed

Lines changed: 99 additions & 1 deletion

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
export * from './select-size.component';
2+
export * from './select-size-v2';
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './select-size-v2.component';
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
.container {
2+
display: flex;
3+
gap: 0.5em;
4+
align-items: center;
5+
padding: var(--space-xs) var(--space-md);
6+
border-bottom: 1px solid var(--primary-300);
7+
}
8+
9+
.container :first-child {
10+
flex: 1;
11+
}
12+
13+
.range {
14+
cursor: pointer;
15+
width: 60px;
16+
height: var(--space-lg);
17+
}
18+
19+
.size {
20+
width: 10px;
21+
padding: 0 var(--space-md) 0 var(--space-s);
22+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { ElementSize, ShapeType } from '@/core/model';
2+
import classes from './select-size-v2.component.module.css';
3+
import { sizeToStep, stepToSize } from './select-size.utils';
4+
import { getSizeConfigForShape } from '@/pods/canvas/model/shape-other-props.utils';
5+
6+
interface Props {
7+
label: string;
8+
shapeType?: ShapeType;
9+
value: string;
10+
onChange: (value: ElementSize) => void;
11+
}
12+
13+
export const SelectSizeV2: React.FC<Props> = ({
14+
label,
15+
shapeType,
16+
value,
17+
onChange,
18+
}) => {
19+
if (!shapeType) return null;
20+
21+
const config = getSizeConfigForShape(shapeType);
22+
23+
if (!config) return null;
24+
25+
return (
26+
<div className={classes.container}>
27+
<p>{label}</p>
28+
<input
29+
type="range"
30+
min={1}
31+
max={config.availableSizes.length}
32+
step={1}
33+
value={sizeToStep(config, value)}
34+
onChange={e => onChange(stepToSize(config, e.target.value))}
35+
className={classes.range}
36+
/>
37+
<p className={classes.size}>{value}</p>
38+
</div>
39+
);
40+
};
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { ElementSize, SizeConfig } from '@/core/model';
2+
3+
export const sizeToStep = (config: SizeConfig, size: string): string => {
4+
const index = config.availableSizes.indexOf(size as ElementSize);
5+
return index >= 0 ? (index + 1).toString() : '1';
6+
};
7+
8+
export const stepToSize = (config: SizeConfig, step: string): ElementSize => {
9+
const index = parseInt(step) - 1;
10+
return config.availableSizes[index] || config.availableSizes[0];
11+
};

src/pods/properties/properties.pod.tsx

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@ import classes from './properties.pod.module.css';
33
import { ZIndexOptions } from './components/zindex/zindex-option.component';
44
import { ColorPicker } from './components/color-picker/color-picker.component';
55
import { Checked } from './components/checked/checked.component';
6-
import { SelectSize, SelectIcon, BorderRadius, Disabled } from './components';
6+
import {
7+
SelectSize,
8+
SelectIcon,
9+
BorderRadius,
10+
Disabled,
11+
SelectSizeV2,
12+
} from './components';
713
import { StrokeStyle } from './components/stroke-style/stroke.style.component';
814
import { ImageSrc } from './components/image-src/image-selector.component';
915
import { ImageBlackAndWhite } from './components/image-black-and-white/image-black-and-white-selector.component';
@@ -145,6 +151,23 @@ export const PropertiesPod = () => {
145151
}
146152
/>
147153
</ShowProp>
154+
155+
<ShowProp
156+
singleSelection={isSingleSelection}
157+
multipleSelectionPropsInCommon={multipleSelectionPropsInCommon}
158+
propKey="size"
159+
propValue={selectedShapeData?.otherProps?.size}
160+
>
161+
<SelectSizeV2
162+
label="Size"
163+
shapeType={selectedShapeData?.type}
164+
value={selectedShapeData?.otherProps?.size ?? ''}
165+
onChange={size =>
166+
updateOtherPropsOnSelected('size', size, isMultipleSelection)
167+
}
168+
/>
169+
</ShowProp>
170+
148171
<ShowProp
149172
singleSelection={isSingleSelection}
150173
multipleSelectionPropsInCommon={multipleSelectionPropsInCommon}

0 commit comments

Comments
 (0)