import { ColorSwatchField, Field, ImagePickerField, Section, Segmented, Slider, useScopedFormContext } from '@components/common/page-builder/index.js'; import { _ } from '@evershop/evershop/lib/locale/translate/_'; import React from 'react'; import type { SectionPadding, SectionTint, SectionWidth } from './Section.js'; interface SectionSettingProps { sectionWidget?: { width?: SectionWidth | null; padding?: SectionPadding | null; background?: string | null; backgroundImage?: string | null; backgroundImageWidth?: number | null; backgroundImageHeight?: number | null; overlayTint?: SectionTint | null; overlayOpacity?: number | null; }; } const WIDTH_OPTIONS: ReadonlyArray<{ value: SectionWidth; label: string }> = [ { value: 'boxed', label: _('Boxed') }, { value: 'wide', label: _('Wide (full bleed)') } ]; const PADDING_OPTIONS: ReadonlyArray<{ value: SectionPadding; label: string; }> = [ { value: 'none', label: _('None') }, { value: 'sm', label: _('S') }, { value: 'md', label: _('M') }, { value: 'lg', label: _('L') }, { value: 'xl', label: _('XL') } ]; const TINT_OPTIONS: ReadonlyArray<{ value: SectionTint; label: string }> = [ { value: 'none', label: _('None') }, { value: 'dark', label: _('Dark') }, { value: 'light', label: _('Light') }, { value: 'gradient', label: _('Gradient') } ]; export default function SectionSetting({ sectionWidget }: SectionSettingProps) { const { width = 'boxed', padding = 'md', background = null, backgroundImage = null, backgroundImageWidth = null, backgroundImageHeight = null, overlayTint = 'none', overlayOpacity = 0.3 } = sectionWidget ?? {}; const { register, setValue, watch } = useScopedFormContext(); const widthV = ((watch('settings.width') as string) ?? width ?? 'boxed') as SectionWidth; const paddingV = ((watch('settings.padding') as string) ?? padding ?? 'md') as SectionPadding; const backgroundV = (watch('settings.background') as string) ?? background ?? ''; const backgroundImageV = (watch('settings.backgroundImage') as string) ?? backgroundImage ?? ''; const tintV = ((watch('settings.overlayTint') as string) ?? overlayTint ?? 'none') as SectionTint; const opacityV = (watch('settings.overlayOpacity') as number) ?? overlayOpacity ?? 0.3; return (
value={widthV} options={WIDTH_OPTIONS} onChange={(v) => setValue('settings.width', v, { shouldDirty: true }) } /> value={paddingV} options={PADDING_OPTIONS} onChange={(v) => setValue('settings.padding', v, { shouldDirty: true }) } />
setValue('settings.background', v || null, { shouldDirty: true }) } /> { setValue('settings.backgroundImage', v || null, { shouldDirty: true }); if (!v) { setValue('settings.backgroundImageWidth', null, { shouldDirty: true }); setValue('settings.backgroundImageHeight', null, { shouldDirty: true }); } }} onLoadDimensions={({ width: w, height: h }) => { setValue('settings.backgroundImageWidth', w, { shouldDirty: true }); setValue('settings.backgroundImageHeight', h, { shouldDirty: true }); }} /> {backgroundImageV && ( <> value={tintV} options={TINT_OPTIONS} onChange={(v) => setValue('settings.overlayTint', v, { shouldDirty: true }) } /> {tintV !== 'none' && ( setValue('settings.overlayOpacity', v / 100, { shouldDirty: true }) } /> )} )}
{/* Hidden mirrors so the standalone widgetEdit form posts these on Save. The drawer's auto-save reads from form state directly. */}
); } export const query = ` query Query( $width: String $padding: String $background: String $backgroundImage: String $backgroundImageWidth: Float $backgroundImageHeight: Float $overlayTint: String $overlayOpacity: Float ) { sectionWidget( width: $width padding: $padding background: $background backgroundImage: $backgroundImage backgroundImageWidth: $backgroundImageWidth backgroundImageHeight: $backgroundImageHeight overlayTint: $overlayTint overlayOpacity: $overlayOpacity ) { width padding background backgroundImage backgroundImageWidth backgroundImageHeight overlayTint overlayOpacity } } `; export const variables = `{ width: getWidgetSetting("width", "boxed"), padding: getWidgetSetting("padding", "md"), background: getWidgetSetting("background"), backgroundImage: getWidgetSetting("backgroundImage"), backgroundImageWidth: getWidgetSetting("backgroundImageWidth"), backgroundImageHeight: getWidgetSetting("backgroundImageHeight"), overlayTint: getWidgetSetting("overlayTint", "none"), overlayOpacity: getWidgetSetting("overlayOpacity", 0.3) }`;