|
| 1 | +// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license. |
| 2 | + |
| 3 | +import { definePage } from '@objectstack/spec/ui'; |
| 4 | + |
| 5 | +/** |
| 6 | + * Styling Gallery (ADR-0065) — the canonical example of the SDUI scoped-styling |
| 7 | + * model. A pricing page composed from generic blocks (`flex` / `element:text` / |
| 8 | + * `element:button`) that each carry a `responsiveStyles` object (per-breakpoint |
| 9 | + * CSS-property maps) with **design-token values** (`var(--space-*)`, |
| 10 | + * `var(--surface)`, `var(--brand)`, `hsl(var(--primary))`, …) — NO `className`. |
| 11 | + * |
| 12 | + * objectui's `SchemaRenderer` compiles each node's `responsiveStyles` to |
| 13 | + * **id-scoped CSS** injected as an unlayered `<style>` at render: build-independent |
| 14 | + * (arbitrary values + tokens pass through verbatim), collision-free (per-node |
| 15 | + * scope beats base utilities without `@layer` games), responsive-correct |
| 16 | + * (breakpoint maps → generated `@media`, never `md:` classes). This is the |
| 17 | + * preferred way to style a metadata-authored page; see the objectstack-ui skill |
| 18 | + * "Styling (ADR-0065)" section. |
| 19 | + * |
| 20 | + * Note: child nodes go in `properties.children` (the renderer hoists `properties` |
| 21 | + * to schema level at render); `responsiveStyles`/`id` are top-level envelope fields. |
| 22 | + */ |
| 23 | + |
| 24 | +/** One checklist line: an accent-coloured check + the label. */ |
| 25 | +function feature(label: string): any { |
| 26 | + return { |
| 27 | + id: `feat_${label}`, |
| 28 | + type: 'flex', |
| 29 | + responsiveStyles: { large: { display: 'flex', alignItems: 'flex-start', gap: 'var(--space-2)' } }, |
| 30 | + properties: { |
| 31 | + children: [ |
| 32 | + { id: `feat_${label}_chk`, type: 'element:text', responsiveStyles: { large: { color: 'hsl(var(--primary))', fontWeight: '700', lineHeight: '1.5' } }, properties: { content: '✓' } }, |
| 33 | + { id: `feat_${label}_lbl`, type: 'element:text', responsiveStyles: { large: { fontSize: '14px', color: 'var(--text-strong)', lineHeight: '1.5' } }, properties: { content: label } }, |
| 34 | + ], |
| 35 | + }, |
| 36 | + }; |
| 37 | +} |
| 38 | + |
| 39 | +/** A plan column — a styled `flex` box (no opinionated page:card). */ |
| 40 | +function planCard(o: { name: string; price: string; period: string; tagline: string; features: string[]; cta: string; popular?: boolean }): any { |
| 41 | + return { |
| 42 | + id: `plan_${o.name}`, |
| 43 | + type: 'flex', |
| 44 | + responsiveStyles: { |
| 45 | + large: { |
| 46 | + display: 'flex', flexDirection: 'column', gap: 'var(--space-4)', |
| 47 | + padding: 'var(--space-6)', borderRadius: 'var(--radius-xl)', |
| 48 | + backgroundColor: 'var(--surface)', |
| 49 | + border: o.popular ? '1px solid hsl(var(--primary))' : '1px solid var(--hairline)', |
| 50 | + boxShadow: o.popular ? '0 0 0 3px hsl(var(--primary) / 0.25), var(--shadow-lg)' : 'var(--shadow-sm)', |
| 51 | + }, |
| 52 | + small: { padding: 'var(--space-4)', gap: 'var(--space-3)' }, |
| 53 | + }, |
| 54 | + properties: { |
| 55 | + children: [ |
| 56 | + ...(o.popular |
| 57 | + ? [{ id: `plan_${o.name}_badge`, type: 'element:text', responsiveStyles: { large: { alignSelf: 'flex-start', fontSize: '12px', fontWeight: '600', color: 'var(--brand-foreground)', backgroundColor: 'var(--brand)', padding: '2px 10px', borderRadius: '999px' } }, properties: { content: 'Most popular' } }] |
| 58 | + : []), |
| 59 | + { id: `plan_${o.name}_name`, type: 'element:text', responsiveStyles: { large: { fontSize: '13px', fontWeight: '600', color: 'var(--text-muted)', textTransform: 'uppercase', letterSpacing: '0.06em' } }, properties: { content: o.name } }, |
| 60 | + { |
| 61 | + id: `plan_${o.name}_price_row`, type: 'flex', |
| 62 | + responsiveStyles: { large: { display: 'flex', alignItems: 'baseline', gap: 'var(--space-2)' } }, |
| 63 | + properties: { |
| 64 | + children: [ |
| 65 | + { id: `plan_${o.name}_price`, type: 'element:text', responsiveStyles: { large: { fontSize: '40px', fontWeight: '700', color: 'var(--text-strong)', fontVariantNumeric: 'tabular-nums' }, small: { fontSize: '32px' } }, properties: { content: o.price } }, |
| 66 | + { id: `plan_${o.name}_period`, type: 'element:text', responsiveStyles: { large: { fontSize: '13px', color: 'var(--text-muted)' } }, properties: { content: o.period } }, |
| 67 | + ], |
| 68 | + }, |
| 69 | + }, |
| 70 | + { id: `plan_${o.name}_tagline`, type: 'element:text', responsiveStyles: { large: { fontSize: '13px', color: 'var(--text-muted)', minHeight: '34px' } }, properties: { content: o.tagline } }, |
| 71 | + { id: `plan_${o.name}_divider`, type: 'flex', responsiveStyles: { large: { height: '1px', backgroundColor: 'var(--hairline)', margin: 'var(--space-1) 0' } }, properties: { children: [] } }, |
| 72 | + ...o.features.map(feature), |
| 73 | + { id: `cta_${o.name}`, type: 'element:button', responsiveStyles: { large: { marginTop: 'auto', width: '100%' } }, properties: { label: o.cta, variant: o.popular ? 'primary' : 'secondary', size: 'large' } }, |
| 74 | + ], |
| 75 | + }, |
| 76 | + }; |
| 77 | +} |
| 78 | + |
| 79 | +export const StylingGalleryPage = definePage({ |
| 80 | + name: 'showcase_styling_gallery', |
| 81 | + label: 'Styling (ADR-0065)', |
| 82 | + type: 'app', |
| 83 | + template: 'default', |
| 84 | + kind: 'full', |
| 85 | + isDefault: false, |
| 86 | + regions: [ |
| 87 | + { |
| 88 | + name: 'main', |
| 89 | + width: 'full', |
| 90 | + components: [ |
| 91 | + { |
| 92 | + id: 'styling_root', |
| 93 | + type: 'flex', |
| 94 | + responsiveStyles: { |
| 95 | + large: { minHeight: '100%', display: 'flex', flexDirection: 'column', alignItems: 'center', gap: 'var(--space-8)', padding: 'var(--space-12) var(--space-6)' }, |
| 96 | + small: { padding: 'var(--space-8) var(--space-4)' }, |
| 97 | + }, |
| 98 | + properties: { |
| 99 | + children: [ |
| 100 | + { |
| 101 | + id: 'styling_header', type: 'flex', |
| 102 | + responsiveStyles: { large: { display: 'flex', flexDirection: 'column', gap: 'var(--space-3)', textAlign: 'center', maxWidth: '42rem' } }, |
| 103 | + properties: { |
| 104 | + children: [ |
| 105 | + { id: 'styling_title', type: 'element:text', responsiveStyles: { large: { fontSize: '40px', fontWeight: '700', letterSpacing: '-0.02em', color: 'var(--text-strong)' }, small: { fontSize: '30px' } }, properties: { content: 'Plans & Pricing' } }, |
| 106 | + { id: 'styling_subtitle', type: 'element:text', responsiveStyles: { large: { fontSize: '16px', color: 'var(--text-muted)' } }, properties: { content: 'Styled entirely with responsiveStyles + design tokens — zero Tailwind class strings (ADR-0065).' } }, |
| 107 | + ], |
| 108 | + }, |
| 109 | + }, |
| 110 | + { |
| 111 | + id: 'plan_grid', type: 'flex', |
| 112 | + responsiveStyles: { |
| 113 | + large: { display: 'grid', gridTemplateColumns: 'repeat(4, minmax(0,1fr))', gap: 'var(--space-6)', width: '100%', maxWidth: '80rem', alignItems: 'stretch', marginTop: 'var(--space-4)' }, |
| 114 | + medium: { gridTemplateColumns: 'repeat(2, minmax(0,1fr))' }, |
| 115 | + small: { gridTemplateColumns: '1fr' }, |
| 116 | + }, |
| 117 | + properties: { |
| 118 | + children: [ |
| 119 | + planCard({ name: 'Free', price: '$0', period: 'forever', tagline: 'For evaluating and small personal projects.', features: ['1 environment', '3 users', 'AI online development', '7-day audit retention'], cta: 'Get started' }), |
| 120 | + planCard({ name: 'Solo', price: '$29', period: 'per month', tagline: 'For solo builders and indie makers.', features: ['2 environments', '10 users', 'Custom domains', 'Stronger AI model', '30-day audit retention'], cta: 'Upgrade to Solo', popular: true }), |
| 121 | + planCard({ name: 'Team', price: '$99', period: 'per month', tagline: 'For teams shipping real apps.', features: ['2 environments', '100 users', 'Custom domains', '30-day audit retention'], cta: 'Upgrade to Team' }), |
| 122 | + planCard({ name: 'Business', price: '$299', period: 'per month', tagline: 'For organizations that need SSO and scale.', features: ['4 environments', '500 users', 'SSO / SAML', '1-year audit retention'], cta: 'Upgrade to Business' }), |
| 123 | + ], |
| 124 | + }, |
| 125 | + }, |
| 126 | + ], |
| 127 | + }, |
| 128 | + }, |
| 129 | + ], |
| 130 | + }, |
| 131 | + ], |
| 132 | +}); |
0 commit comments