import { drawerInputClass, Field, ImagePickerField, MarkdownBodyField, Section, Segmented, Toggle, useScopedFormContext } from '@components/common/page-builder/index.js'; import { LinkPicker } from '@components/common/page-builder/pickers/LinkPicker.js'; import { _ } from '@evershop/evershop/lib/locale/translate/_'; import React from 'react'; import type { BrandStoryLayout } from './BrandStory.js'; interface BrandStorySettingProps { brandStoryWidget?: { layout?: BrandStoryLayout; image?: string | null; imageAlt?: string; imageWidth?: number | null; imageHeight?: number | null; eyebrow?: string | null; heading?: string; body?: string; bodySecondary?: string | null; link?: { label: string; url: string; newTab: boolean } | null; pullQuote?: string | null; imageSize?: 40 | 50 | 60; }; } const LAYOUT_OPTIONS: ReadonlyArray<{ value: BrandStoryLayout; label: string; }> = [ { value: 'image-left', label: _('Image left') }, { value: 'image-right', label: _('Image right') }, { value: 'centered', label: _('Centered') }, { value: 'pull-quote', label: _('Pull quote') } ]; const IMAGE_SIZE_OPTIONS: ReadonlyArray<{ value: 40 | 50 | 60; label: string }> = [ { value: 40, label: '40%' }, { value: 50, label: '50%' }, { value: 60, label: '60%' } ]; export default function BrandStorySetting({ brandStoryWidget }: BrandStorySettingProps) { const { layout, image, imageAlt, imageWidth, imageHeight, eyebrow, heading, body, bodySecondary, link, pullQuote, imageSize } = brandStoryWidget ?? {}; const { register, setValue, watch } = useScopedFormContext(); const layoutV = ((watch('settings.layout') as string) ?? layout ?? 'image-left') as BrandStoryLayout; const imageV = (watch('settings.image') as string) ?? image ?? ''; const imageAltV = (watch('settings.imageAlt') as string) ?? imageAlt ?? ''; const eyebrowV = (watch('settings.eyebrow') as string) ?? eyebrow ?? ''; const headingV = (watch('settings.heading') as string) ?? heading ?? ''; const bodyV = (watch('settings.body') as string) ?? body ?? ''; const bodySecondaryV = (watch('settings.bodySecondary') as string) ?? bodySecondary ?? ''; const linkV = (watch('settings.link') as | { label: string; url: string; newTab: boolean } | null) ?? link ?? null; const pullQuoteV = (watch('settings.pullQuote') as string) ?? pullQuote ?? ''; const imageSizeV = ((watch('settings.imageSize') as number) ?? imageSize ?? 50) as 40 | 50 | 60; const showImageField = layoutV !== 'pull-quote'; const showImageSizeField = layoutV === 'image-left' || layoutV === 'image-right'; const showPullQuoteField = layoutV === 'pull-quote'; return (
value={layoutV} options={LAYOUT_OPTIONS} onChange={(v) => setValue('settings.layout', v, { shouldDirty: true }) } /> {showImageSizeField && ( value={imageSizeV} options={IMAGE_SIZE_OPTIONS} onChange={(v) => setValue('settings.imageSize', v, { shouldDirty: true }) } /> )}
{showImageField && (
{ setValue('settings.image', v || null, { shouldDirty: true }); if (!v) { setValue('settings.imageWidth', null, { shouldDirty: true }); setValue('settings.imageHeight', null, { shouldDirty: true }); } }} onLoadDimensions={({ width: w, height: h }) => { setValue('settings.imageWidth', w, { shouldDirty: true }); setValue('settings.imageHeight', h, { shouldDirty: true }); }} /> setValue('settings.imageAlt', e.target.value, { shouldDirty: true }) } placeholder={_('Describe the image')} className={drawerInputClass} />
)}
setValue('settings.eyebrow', e.target.value, { shouldDirty: true }) } placeholder={_('Our story')} className={drawerInputClass} /> setValue('settings.heading', e.target.value, { shouldDirty: true }) } placeholder={_('Made by hand, in small batches')} className={drawerInputClass} /> {showPullQuoteField && (