/** * WooCommerce workspace — small pieces of markup shared across more than one * view's `fields.tsx` (the sidebar control on both Shop's and Single * Product's Layout tab; the plugin-extras renderer on Shop/Single * Product/Cart/Checkout). */ import { __ } from '@wordpress/i18n'; import type { LucideIcon } from '../../icons'; import SegmentedControl from '../../controls/segmented-control'; import InfoNote from '../../controls/info-note'; import { PanelFieldsList } from '../panel-section'; import type { SectionExtra, SetPath } from '../../types'; import type { Option } from './types'; import { INHERIT, SIDEBAR_ICONS } from './constants'; export const toOptions = ( list?: Option[] ) => ( list ?? [] ).map( ( item ) => ( { value: item.value, label: item.label, } ) ); interface SidebarFieldProps { ctx: string; layoutContexts?: Record< string, Record< string, unknown > >; sidebarOptions: Array< { value: string; label: string; icon?: LucideIcon; } >; setPath: SetPath; } // Sidebar position for the Product Catalog / Single Product views. Writes to // the same sparse per-context layout tree the Content Templates workspace // uses (layout.contexts..sidebar), so the cascade — global default → // context override → per-page meta — stays in one place. export function SidebarField( { ctx, layoutContexts, sidebarOptions, setPath, }: SidebarFieldProps ) { return ( <> setPath( `layout.contexts.${ ctx }.sidebar`, INHERIT === next ? '' : next ) } /> { /* The note carries a step the reader has to act on (populate the widget area), so it's an InfoNote rather than the control's own muted `help` line. */ } { __( '“Inherit” follows the site-wide Layout default. The column shows default shop widgets until you add your own to the Shop Sidebar widget area (Appearance → Widgets).', 'aureon' ) } ); } export function sidebarOptionsFor( layoutSchema?: { sidebars?: Option[]; } ): Array< { value: string; label: string; icon: LucideIcon } > { return [ { value: INHERIT, label: __( 'Inherit', 'aureon' ), icon: SIDEBAR_ICONS[ INHERIT ], }, ...( layoutSchema?.sidebars ?? [] ).map( ( item ) => ( { value: item.value, label: item.label, icon: SIDEBAR_ICONS[ item.value ], } ) ), ]; } // Renders whichever plugin surfaces targeted a given view (see the `extras` // prop on the hub/hooks), or nothing. export function ExtrasFields( { list }: { list?: SectionExtra[] } ) { if ( ! list || 0 === list.length ) { return null; } return (
{ list.map( ( extra ) => ( ) ) }
); }