/** * The off-canvas drawer, drawn as a drawer. * * On the tablet/mobile canvases the panel the Menu Toggle opens sits beside * the header rows, on the side it slides in from: a narrow card topped with * the toggle's own icon and a close ×, its elements stacked the way the real * panel stacks them. The Toggle chip and this card light up together, so the * button and what it opens read as one thing. On desktop — where the panel * never shows — it shrinks to a tab that jumps to the mobile canvas. * * Contents are the template's `mobile` list. Drawer items use `oc:`-prefixed * sortable ids, since the same element may also sit in a header row. */ import { __, sprintf, _n } from '@wordpress/i18n'; import { Button } from '@wordpress/components'; import { useDroppable, SortableContext, verticalListSortingStrategy, } from '../../dnd'; import { PanelRight, Plus, Settings, X } from '../../icons'; import { SortableDockChip } from './dock-row'; import AddElementMenu from './add-element-menu'; import ToggleIconPicker from './toggle-icon-picker'; import Segmented from './segmented'; import { toggleIconFor } from './toggle-icons'; import ColorField from '../../controls/color-field'; import RangeField from '../../controls/range-field'; import type { ElementDef } from './element-groups'; export const DRAWER = '__drawer__'; export const DRAWER_PREFIX = 'oc:'; export const toDrawerId = ( id: string ): string => DRAWER_PREFIX + id; export const isDrawerId = ( id: string ): boolean => id === DRAWER || id.startsWith( DRAWER_PREFIX ); export const fromDrawerId = ( id: string ): string => id.startsWith( DRAWER_PREFIX ) ? id.slice( DRAWER_PREFIX.length ) : id; /** Drawer options, stored on the Toggle element (`header.elements.toggle`). */ export interface DrawerSettings { icon?: string; style?: 'slide' | 'fullscreen'; side?: 'left' | 'right'; width?: number; align?: 'left' | 'center' | 'right'; background?: string; overlay?: string; } const DEFAULT_WIDTH = 320; interface DrawerCardProps { items: string[]; available: ElementDef[]; settings: DrawerSettings; labelFor: ( id: string ) => string; onAdd: ( id: string ) => void; onRemove: ( id: string ) => void; onEdit: ( id: string ) => void; onOpenSettings: () => void; hot: boolean; onHover: ( hot: boolean ) => void; } export default function DrawerCard( { items, available, settings, labelFor, onAdd, onRemove, onEdit, onOpenSettings, hot, onHover, }: DrawerCardProps ) { const { setNodeRef, isOver } = useDroppable( { id: DRAWER } ); const ToggleIcon = toggleIconFor( settings.icon ?? '' ); const fullscreen = 'fullscreen' === settings.style; return (
{ __( 'An empty panel shows the Off-Canvas Menu.', 'aureon' ) }
) }