import { ColorSwatchField, Field, Section, Segmented, Toggle, useScopedFormContext } from '@components/common/page-builder/index.js'; import { _ } from '@evershop/evershop/lib/locale/translate/_'; import React from 'react'; import type { SeparatorSize } from './Separator.js'; interface SeparatorSettingProps { separatorWidget?: { size?: SeparatorSize | null; showLine?: boolean | null; lineColor?: string | null; }; } const SIZE_OPTIONS: ReadonlyArray<{ value: SeparatorSize; label: string }> = [ { value: 'xs', label: _('XS') }, { value: 'sm', label: _('S') }, { value: 'md', label: _('M') }, { value: 'lg', label: _('L') }, { value: 'xl', label: _('XL') } ]; export default function SeparatorSetting({ separatorWidget }: SeparatorSettingProps) { const { size = 'md', showLine = false, lineColor = null } = separatorWidget ?? {}; const { register, setValue, watch } = useScopedFormContext(); const sizeV = ((watch('settings.size') as string) ?? size ?? 'md') as SeparatorSize; const showLineV = (watch('settings.showLine') as boolean | null) ?? showLine ?? false; const lineColorV = (watch('settings.lineColor') as string) ?? lineColor ?? ''; return (
value={sizeV} options={SIZE_OPTIONS} onChange={(v) => setValue('settings.size', v, { shouldDirty: true }) } />
setValue('settings.showLine', v, { shouldDirty: true }) } /> {showLineV && ( setValue('settings.lineColor', v || null, { shouldDirty: true }) } /> )}
{/* Hidden mirrors so the standalone widgetEdit form posts these on Save. Drawer auto-save reads from form state directly. */}
); } export const query = ` query Query($size: String, $showLine: Boolean, $lineColor: String) { separatorWidget(size: $size, showLine: $showLine, lineColor: $lineColor) { size showLine lineColor } } `; export const variables = `{ size: getWidgetSetting("size", "md"), showLine: getWidgetSetting("showLine", false), lineColor: getWidgetSetting("lineColor") }`;