All files / packages/design-system-2-site/src/app/(frontend)/style-preview page.tsx

100% Statements 18/18
100% Branches 2/2
100% Functions 7/7
100% Lines 15/15

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182                                          1x       1x                 1x                                               92x 1x   1x                                             3x                     1x 1x   1x                             2x 1x                 21x                               8x                                                               11x                    
import type { ComponentType, SVGProps } from 'react';
import type { Metadata } from 'next';
import { notFound } from 'next/navigation';
import {
  ArrowLeftIcon,
  ArrowRightIcon,
  BulletedListIcon,
  CanvasContentIcon,
  CaretDownIcon,
  CaretRightIcon,
  CloseIcon,
  MoonIcon,
  SearchIcon,
  ThumbsDownIcon,
  ThumbsUpIcon,
} from '@/components/icons';
import { STYLE_PREVIEW_ENABLED } from '@/lib/dev-tools';
import { PreviewLayout, PreviewSection, type PreviewTocItem } from './preview-ui';
import { ShadowSwatches } from './ShadowSwatches';
import { TokenSwatches } from './TokenSwatches';
 
export const metadata: Metadata = {
  title: 'Style Preview — Global Values',
};
 
const TOC: PreviewTocItem[] = [
  { id: 'type-styles', text: 'Type styles' },
  { id: 'colors', text: 'Colors' },
  { id: 'spacing', text: 'Spacing' },
  { id: 'border-radius', text: 'Border radius' },
  { id: 'shadows', text: 'Shadows' },
  { id: 'icons', text: 'Icons' },
];
 
const TYPE_CLASSES = [
  'text-display',
  'text-heading-xl',
  'text-heading-lg',
  'text-heading-md',
  'text-heading-sm',
  'text-heading-xs',
  'text-subtitle',
  'text-body-lg',
  'text-body-lg-medium',
  'text-body-lg-semibold',
  'text-body-lg-bold',
  'text-body-md',
  'text-body-md-medium',
  'text-body-md-semibold',
  'text-body-md-bold',
  'text-body-sm',
  'text-body-sm-medium',
  'text-body-sm-semibold',
  'text-body-sm-bold',
  'text-mono-sm',
  'text-mono-md',
];
 
const scale = (prefix: string, steps: (number | string)[]) => steps.map((s) => `${prefix}-${s}`);
const PALETTE_STEPS = [5, 10, 20, 30, 35, 40, 50, 60, 65, 70, 80, 90, 95];
 
const COLOR_GROUPS: { label: string; tokens: string[] }[] = [
  { label: 'Background', tokens: scale('--color-background', ['subtle', 'default', 'intense']) },
  {
    label: 'Brand background',
    tokens: scale('--color-background-brand', ['subtle', 'default', 'vivid', 'intense']),
  },
  {
    label: 'Foreground',
    tokens: [
      ...scale('--color-foreground', ['faint', 'subtle', 'default', 'intense']),
      ...scale('--color-foreground-brand', ['subtle', 'default', 'intense']),
    ],
  },
  {
    label: 'Border',
    tokens: [
      ...scale('--color-border', ['subtle', 'default', 'intense']),
      ...scale('--color-border-brand', ['subtle', 'default', 'intense']),
    ],
  },
  {
    label: 'Feedback',
    tokens: ['background', 'foreground', 'border'].flatMap((role) =>
      scale(`--color-${role}`, ['success', 'warning', 'error', 'info']),
    ),
  },
  { label: 'Palette — Indigo', tokens: scale('--color-palette-indigo', PALETTE_STEPS) },
  {
    label: 'Palette — Neutral',
    tokens: scale('--color-palette-neutral', [0, 5, 10, 15, 20, 30, 40, 50, 60, 70, 80, 85, 90, 95, 100]),
  },
  { label: 'Palette — Neutral Indigo', tokens: scale('--color-palette-neutral-indigo', PALETTE_STEPS) },
];
 
const SPACING_TOKENS = scale('--spacing', [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]);
const RADIUS_TOKENS = scale('--border-radius', ['xs', 'sm', 'md', 'lg', 'xl', '2xl', 'full']);
 
const ICONS: { name: string; Icon: ComponentType<SVGProps<SVGSVGElement>> }[] = [
  { name: 'SearchIcon', Icon: SearchIcon },
  { name: 'CloseIcon', Icon: CloseIcon },
  { name: 'CaretDownIcon', Icon: CaretDownIcon },
  { name: 'CaretRightIcon', Icon: CaretRightIcon },
  { name: 'BulletedListIcon', Icon: BulletedListIcon },
  { name: 'ArrowRightIcon', Icon: ArrowRightIcon },
  { name: 'ArrowLeftIcon', Icon: ArrowLeftIcon },
  { name: 'MoonIcon', Icon: MoonIcon },
  { name: 'CanvasContentIcon', Icon: CanvasContentIcon },
  { name: 'ThumbsUpIcon', Icon: ThumbsUpIcon },
  { name: 'ThumbsDownIcon', Icon: ThumbsDownIcon },
];
 
export default function GlobalValuesPage() {
  if (!STYLE_PREVIEW_ENABLED) notFound();
  return (
    <PreviewLayout
      heading="Global Values"
      lead="Global design tokens — type styles, color, spacing, border radius, shadows, and the icon set."
      current="/style-preview"
      toc={TOC}
    >
      <PreviewSection id="type-styles" title="Type styles" tag="text-* utility classes">
        {TYPE_CLASSES.map((cls) => (
          <div key={cls} className="style-preview__type-row">
            <code className="style-preview__type-name">.{cls}</code>
            <div className={`${cls} style-preview__type-sample`}>
              The quick brown fox jumps over the lazy dog
            </div>
          </div>
        ))}
      </PreviewSection>
 
      <PreviewSection
        id="colors"
        title="Colors"
        tag="--color-* tokens"
        note="Swatches with live computed values — they update with the active theme."
      >
        {COLOR_GROUPS.map((group) => (
          <div key={group.label}>
            <div className="style-preview__subhead">{group.label}</div>
            <TokenSwatches tokens={group.tokens} kind="color" />
          </div>
        ))}
      </PreviewSection>
 
      <PreviewSection id="spacing" title="Spacing" tag="--spacing-* tokens">
        <TokenSwatches tokens={SPACING_TOKENS} kind="spacing" />
      </PreviewSection>
 
      <PreviewSection id="border-radius" title="Border radius" tag="--border-radius-* tokens">
        <TokenSwatches tokens={RADIUS_TOKENS} kind="radius" />
      </PreviewSection>
 
      <PreviewSection
        id="shadows"
        title="Shadows"
        tag="--shadow-1 … --shadow-4 tokens"
        note="Live values that reflect the current theme."
      >
        <ShadowSwatches />
      </PreviewSection>
 
      <PreviewSection
        id="icons"
        title="Icons"
        tag="src/components/icons.tsx"
        note="Chrome icons used across the site UI. Link-tile icons live on the Page Layouts tab, next to the link tiles."
      >
        <div className="style-preview__icons">
          {ICONS.map(({ name, Icon }) => (
            <div key={name} className="style-preview__icon">
              <Icon width={24} height={24} />
              <code className="style-preview__icon-name">{name}</code>
            </div>
          ))}
        </div>
      </PreviewSection>
    </PreviewLayout>
  );
}