import { router } from '@inertiajs/react'; import { ChevronDown, Check, Palette } from 'lucide-react'; import type { CSSProperties } from 'react'; import { useState } from 'react'; import StoreStyleController from '@/actions/App/Http/Controllers/StoreStyleController'; import { cn } from '@/lib/utils'; import type { Store, StoreStyleInfo, StylePreset } from '@/types'; const fieldClass = 'h-9 w-full min-w-0 rounded-md border border-input bg-transparent px-3 py-1 text-base shadow-xs outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:opacity-50 md:text-sm'; /** The fine-tune choices, in plain words. Keys and values match PlanSchema::STYLE_OPTIONS. */ const fineTune: { key: string; label: string; choices: Record; }[] = [ { key: 'buttons', label: 'Buttons', choices: { solid: 'Solid', outline: 'Outline', shadow: 'Bold shadow' }, }, { key: 'cards', label: 'Cards and photos', choices: { border: 'Thin line', shadow: 'Soft shadow', plain: 'No edge', hard: 'Bold line and shadow', }, }, { key: 'spacing', label: 'Spacing', choices: { compact: 'Compact', normal: 'Normal', airy: 'Airy' }, }, { key: 'headings', label: 'Headings', choices: { normal: 'Normal', uppercase: 'Spaced capitals', heavy: 'Extra bold', }, }, { key: 'backgrounds', label: 'Backgrounds', choices: { plain: 'Plain', alternate: 'Alternating bands' }, }, { key: 'motion', label: 'Motion', choices: { none: 'None', gentle: 'Gentle fade-in' }, }, ]; const radiusPx: Record = { none: '0px', small: '4px', medium: '10px', large: '16px', full: '9999px', }; /** * The Design tab's Style box: pick a ready-made look, or fine-tune one option at a time. * Colours are kept as they are. */ export default function StylePicker({ store, current, presets, busy, }: { store: Store; current: StoreStyleInfo | null; presets: StylePreset[]; busy: boolean; }) { const [saving, setSaving] = useState(false); if (!current) { return null; } function send(data: { preset?: string; style?: Record }) { router.put(StoreStyleController.update.url(store.slug), data, { preserveScroll: true, onStart: () => setSaving(true), onFinish: () => setSaving(false), }); } const active = presets.find( (preset) => preset.radius === current.radius && preset.fonts.heading === current.fonts?.heading && preset.fonts.body === current.fonts?.body && Object.entries(preset.style).every( ([key, value]) => current.options[key] === value, ), ); const disabled = busy || saving; return (

Style

The feel of your whole store: buttons, cards, fonts, spacing and motion. Your colours stay the same.

    {presets.map((preset) => { const selected = active?.key === preset.key; return (
  • ); })}
Fine-tune
{fineTune.map((option) => (
))}
); } /** A tiny button in the preset's shape, in neutral colours. */ function sample(preset: StylePreset): CSSProperties { const radius = radiusPx[preset.radius] ?? '10px'; if (preset.style.buttons === 'outline') { return { borderRadius: radius, boxShadow: 'inset 0 0 0 1.5px currentColor', }; } if (preset.style.buttons === 'shadow') { return { borderRadius: radius, background: '#facc15', color: '#111', border: '2px solid #111', boxShadow: '2px 2px 0 #111', }; } return { borderRadius: radius, background: '#111', color: '#fff' }; }