Skip to content

Commit 1905d91

Browse files
fix(app): allow zero padding
1 parent d3bcdac commit 1905d91

File tree

3 files changed

+39
-11
lines changed

3 files changed

+39
-11
lines changed

apps/codeimage/src/components/PropertyEditor/FrameStyleForm.tsx

+28-8
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,24 @@ import {CustomColorPicker} from './controls/ColorPicker/CustomColorPicker';
1212
import {PanelHeader} from './PanelHeader';
1313
import {PanelRow, TwoColumnPanelRow} from './PanelRow';
1414
import {SuspenseEditorItem} from './SuspenseEditorItem';
15+
import {Select, createSelectOptions} from '@codeui/kit';
1516

1617
export const FrameStyleForm: ParentComponent = () => {
1718
const [t] = useI18n<AppLocaleEntries>();
1819
const {editorPadding, editorRadius} = appEnvironment;
1920
const frame = getFrameState();
2021

22+
const paddingOptions = createSelectOptions(
23+
editorPadding.map(padding => ({
24+
label: padding.label,
25+
value: padding.value,
26+
})),
27+
{
28+
key: 'label',
29+
valueKey: 'value',
30+
},
31+
);
32+
2133
return (
2234
<>
2335
<PanelHeader label={t('frame.frame')} />
@@ -27,16 +39,24 @@ export const FrameStyleForm: ParentComponent = () => {
2739
<SuspenseEditorItem
2840
fallback={<SkeletonLine width={'100%'} height={'26px'} />}
2941
>
30-
<SegmentedField
31-
adapt
42+
<Select
43+
{...paddingOptions.props()}
44+
{...paddingOptions.controlled(
45+
() => String(frame.store.padding),
46+
padding => {
47+
if (typeof padding !== 'undefined') {
48+
frame.setPadding(Number(padding));
49+
// when padding is 0, we would like to set radius to bigger number to hide any background issues
50+
if (Number(padding) === 0) {
51+
frame.setRadius(16);
52+
}
53+
}
54+
},
55+
)}
56+
options={paddingOptions.options()}
57+
aria-label={'Padding'}
3258
id={'paddingField'}
3359
size={'xs'}
34-
value={frame.store.padding}
35-
onChange={frame.setPadding}
36-
items={editorPadding.map(padding => ({
37-
label: padding.toString(),
38-
value: padding,
39-
}))}
4060
/>
4161
</SuspenseEditorItem>
4262
</TwoColumnPanelRow>

apps/codeimage/src/core/configuration.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,13 @@ export const [appEnvironment] = createConfiguration({
77
locales: SUPPORTED_LOCALES,
88
themes: [],
99
languages: [],
10-
editorPadding: [16, 32, 64, 128],
10+
editorPadding: [
11+
{label: '0', value: "0"},
12+
{label: '16', value: "16"},
13+
{label: '32', value: "32"},
14+
{label: '64', value: "64"},
15+
{label: '128', value: "128"},
16+
],
1117
editorRadius: [
1218
{label: '0', value: 0},
1319
{label: '8', value: 8},

apps/codeimage/src/state/editor/frame.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,11 @@ const frameState = defineStore(() => getInitialFrameState())
8686
.hold(store.commands.setNextPadding, (_, {state}) => {
8787
const availablePadding = appEnvironment.editorPadding;
8888
const padding = state.padding;
89-
const currentIndex = appEnvironment.editorPadding.indexOf(padding);
89+
const currentIndex = appEnvironment.editorPadding.findIndex(
90+
item => Number(item.value) === padding,
91+
);
9092
const next = (currentIndex + 1) % availablePadding.length;
91-
return {...state, padding: availablePadding[next]};
93+
return {...state, padding: Number(availablePadding[next].value)};
9294
})
9395
.hold(store.commands.setFromPreset, presetData => {
9496
store.set(state => ({...state, ...presetData}));

0 commit comments

Comments
 (0)