import { drawerInputClass, Field, ImagePickerField, MarkdownBodyField, Section, Segmented, useScopedFormContext } from '@components/common/page-builder/index.js'; import { ProductPicker } from '@components/common/page-builder/pickers/ProductPicker.js'; import { _ } from '@evershop/evershop/lib/locale/translate/_'; import React from 'react'; interface ProductHeroSettingProps { productHeroWidget?: { productUuid?: string | null; image?: string | null; imageAlt?: string; imageWidth?: number | null; imageHeight?: number | null; eyebrow?: string | null; copy?: string | null; imagePosition?: 'left' | 'right'; product?: { name?: string | null; url?: string | null } | null; }; } export default function ProductHeroSetting({ productHeroWidget }: ProductHeroSettingProps) { const { productUuid, image, imageAlt, imageWidth, imageHeight, eyebrow, copy, imagePosition, product } = productHeroWidget ?? {}; const { register, setValue, watch } = useScopedFormContext(); const productUuidV = (watch('settings.productUuid') as string) ?? productUuid ?? ''; 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 copyV = (watch('settings.copy') as string) ?? copy ?? ''; const imagePositionV = ((watch('settings.imagePosition') as string) ?? imagePosition ?? 'left') as 'left' | 'right'; const pickedName = (watch('_pickedProductName') as string) ?? product?.name ?? ''; return (
{ setValue('settings.productUuid', uuid, { shouldDirty: true }); setValue('_pickedProductName', name); }} /> {pickedName && (
{_('Selected:')}{' '} {pickedName}
)}
{ 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 || null, { shouldDirty: true }) } placeholder={_('FEATURED')} className={drawerInputClass} /> setValue('settings.copy', v || null, { shouldDirty: true }) } placeholder={_( 'Two lines of copy explaining why this product is being spotlighted right now.' )} rows={3} softLimit={240} />
value={imagePositionV} options={[ { value: 'left', label: _('Image left') }, { value: 'right', label: _('Image right') } ]} onChange={(v) => setValue('settings.imagePosition', v, { shouldDirty: true }) } />
); } export const query = ` query Query( $productUuid: String $image: String $imageAlt: String $imageWidth: Float $imageHeight: Float $eyebrow: String $copy: String $imagePosition: String ) { productHeroWidget( productUuid: $productUuid image: $image imageAlt: $imageAlt imageWidth: $imageWidth imageHeight: $imageHeight eyebrow: $eyebrow copy: $copy imagePosition: $imagePosition ) { productUuid image imageAlt imageWidth imageHeight eyebrow copy imagePosition product { name url } } } `; export const variables = `{ productUuid: getWidgetSetting("productUuid"), image: getWidgetSetting("image"), imageAlt: getWidgetSetting("imageAlt"), imageWidth: getWidgetSetting("imageWidth"), imageHeight: getWidgetSetting("imageHeight"), eyebrow: getWidgetSetting("eyebrow"), copy: getWidgetSetting("copy"), imagePosition: getWidgetSetting("imagePosition", "left") }`;