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

100% Statements 11/11
100% Branches 2/2
100% Functions 5/5
100% Lines 10/10

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 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278                                      1x       1x                             1x                 1x             3x     9x                             2x 1x                                                                   3x                                                                                                                                                                                                   4x                                                                                                                                                
import type { Metadata } from 'next';
import { notFound } from 'next/navigation';
import { ChevronRight, Monitor, Moon, Sun } from 'lucide-react';
import { Breadcrumbs } from '@/components/Breadcrumbs';
import { ArrowRightIcon, SearchIcon } from '@/components/icons';
import { Pager } from '@/components/Pager';
import { TabBar } from '@/components/TabBar';
import { Badge } from '@/components/ui/Badge';
import { Button } from '@/components/ui/Button';
import { Combobox } from '@/components/ui/Combobox';
import { DropdownItem, DropdownMenu } from '@/components/ui/DropdownMenu';
import { Input, Textarea } from '@/components/ui/Input';
import { Tag } from '@/components/ui/Tag';
import { Tooltip } from '@/components/ui/Tooltip';
import { STYLE_PREVIEW_ENABLED } from '@/lib/dev-tools';
import { PreviewLabel, PreviewLayout, PreviewSection, type PreviewTocItem } from '../preview-ui';
import { SearchBarDemo } from '../SearchBarDemo';
import { ToastDemo } from '../ToastDemo';
 
export const metadata: Metadata = {
  title: 'Style Preview — Components',
};
 
const TOC: PreviewTocItem[] = [
  { id: 'badges', text: 'Badges' },
  { id: 'breadcrumbs', text: 'Breadcrumbs' },
  { id: 'buttons', text: 'Buttons' },
  { id: 'combobox', text: 'Combobox' },
  { id: 'dropdown-menu', text: 'Dropdown menu' },
  { id: 'pager', text: 'Pager' },
  { id: 'tags', text: 'Tags' },
  { id: 'search-bar', text: 'Search bar' },
  { id: 'tabs', text: 'Tabs' },
  { id: 'text-inputs', text: 'Text inputs' },
  { id: 'toast', text: 'Toast' },
  { id: 'tooltip', text: 'Tooltip' },
];
 
const COMBOBOX_OPTIONS = [
  { value: 'account', label: 'Account' },
  { value: 'contact', label: 'Contact' },
  { value: 'lead', label: 'Lead' },
  { value: 'opportunity', label: 'Opportunity' },
  { value: 'case', label: 'Case' },
  { value: 'campaign', label: 'Campaign' },
];
 
const BUTTON_VARIANTS = [
  { variant: 'ghost', label: 'Ghost' },
  { variant: 'brand', label: 'Brand' },
  { variant: 'outline', label: 'Outline' },
] as const;
 
function ButtonRows({ variant }: { variant: (typeof BUTTON_VARIANTS)[number]['variant'] }) {
  return (
    <div className="style-preview__stack">
      {(['sm', 'md', 'lg'] as const).map((size) => (
        <div key={size} className="style-preview__row style-preview__row--wide">
          <code className="style-preview__size">size=&quot;{size}&quot;</code>
          <Button variant={variant} size={size} iconRight={<ArrowRightIcon />}>
            Button
          </Button>
          <Button variant={variant} size={size} iconOnly aria-label="Example icon button">
            <ArrowRightIcon />
          </Button>
        </div>
      ))}
    </div>
  );
}
 
export default function ComponentsPage() {
  if (!STYLE_PREVIEW_ENABLED) notFound();
  return (
    <PreviewLayout
      heading="Components"
      lead="Interactive, React-built UI components used to construct the site — chrome, forms, and navigation. Content elements you add from markdown live on the Page Layouts tab."
      current="/style-preview/components"
      toc={TOC}
    >
      <PreviewSection id="badges" title="Badges" tag="<Badge> — count / status labels">
        <div className="style-preview__row">
          <Badge tone="brand">New</Badge>
          <Badge tone="success">Stable</Badge>
          <Badge tone="warning">Beta</Badge>
          <Badge tone="neutral">Deprecated</Badge>
        </div>
      </PreviewSection>
 
      <PreviewSection id="breadcrumbs" title="Breadcrumbs" tag=".breadcrumbs">
        <Breadcrumbs
          items={[
            { name: 'Foundations', url: '#' },
            { name: 'Color', url: '#' },
            { name: 'Overview', url: '#' },
          ]}
        />
      </PreviewSection>
 
      <PreviewSection
        id="buttons"
        title="Buttons"
        tag=".site-button — variants: ghost / brand / outline; sizes: sm / md / lg"
        note="Interactive here — hover, click, and tab to see hover/active/focus states."
      >
        <div className="style-preview__stack style-preview__stack--loose">
          {BUTTON_VARIANTS.map(({ variant, label }) => (
            <div key={variant}>
              <PreviewLabel>{label}</PreviewLabel>
              <ButtonRows variant={variant} />
            </div>
          ))}
        </div>
      </PreviewSection>
 
      <PreviewSection
        id="combobox"
        title="Combobox"
        tag="<Combobox> — text field + option menu; states: default / filled / error"
        note="Click or type to open the menu; typing filters. Same chrome as Text inputs. Use editable={false} for a select-only field."
      >
        <div className="style-preview__fields">
          <Combobox
            label="Object"
            placeholder="Select an object…"
            supportingText="Type to filter the list."
            options={COMBOBOX_OPTIONS}
          />
          <Combobox label="Object (preselected)" defaultValue="account" options={COMBOBOX_OPTIONS} />
          <Combobox
            label="Select only"
            placeholder="Choose one…"
            editable={false}
            options={COMBOBOX_OPTIONS}
          />
          <Combobox
            label="Error state"
            placeholder="Select an object…"
            error="Select a valid object."
            options={COMBOBOX_OPTIONS}
          />
          <Combobox label="Disabled" placeholder="Select an object…" disabled options={COMBOBOX_OPTIONS} />
        </div>
      </PreviewSection>
 
      <PreviewSection
        id="dropdown-menu"
        title="Dropdown menu"
        tag=".dropdown-menu / .dropdown-menu__item"
        note="No icons / leading icons / leading + trailing caret."
      >
        <div className="style-preview__row style-preview__row--loose">
          <DropdownMenu>
            <DropdownItem role="menuitemradio" aria-checked="true">
              Light
            </DropdownItem>
            <DropdownItem role="menuitemradio" aria-checked="false">
              Dark
            </DropdownItem>
            <DropdownItem role="menuitemradio" aria-checked="false">
              System
            </DropdownItem>
          </DropdownMenu>
 
          <DropdownMenu>
            <DropdownItem role="menuitemradio" aria-checked="true" icon={<Sun size={18} />}>
              Light
            </DropdownItem>
            <DropdownItem role="menuitemradio" aria-checked="false" icon={<Moon size={18} />}>
              Dark
            </DropdownItem>
            <DropdownItem role="menuitemradio" aria-checked="false" icon={<Monitor size={18} />}>
              System
            </DropdownItem>
          </DropdownMenu>
 
          <DropdownMenu>
            <DropdownItem role="menuitem" icon={<Sun size={18} />} trailing={<ChevronRight size={20} />}>
              Appearance
            </DropdownItem>
            <DropdownItem role="menuitem" icon={<Monitor size={18} />} trailing={<ChevronRight size={20} />}>
              Display
            </DropdownItem>
          </DropdownMenu>
        </div>
      </PreviewSection>
 
      <PreviewSection
        id="pager"
        title="Pager"
        tag=".pager — prev / next"
        note="Hover a button: text + arrow go brand and the arrow slides."
      >
        <Pager prev={{ name: 'Design Tokens', url: '#' }} next={{ name: 'Color System', url: '#' }} />
      </PreviewSection>
 
      <PreviewSection
        id="tags"
        title="Tags"
        tag="<Tag> — filter tags; default / hover / selected"
        note="Bordered chips: default is subtle, hover intensifies the border + text, selected (active) is brand-tinted."
      >
        <div className="style-preview__row style-preview__row--tight">
          <Tag active>All (128)</Tag>
          {['Color (42)', 'Spacing (18)', 'Typography (12)', 'Shadow (6)'].map((t) => (
            <Tag key={t}>{t}</Tag>
          ))}
        </div>
      </PreviewSection>
 
      <PreviewSection
        id="search-bar"
        title="Search bar"
        tag="<SearchBar> — text input with a leading search icon"
        note="A standard text field (same chrome as Text inputs) with a search adornment — no results dropdown."
      >
        <SearchBarDemo />
      </PreviewSection>
 
      <PreviewSection id="tabs" title="Tabs" tag=".site-tabs — active + inactive">
        <TabBar
          tabs={[
            { name: 'Overview', url: '#overview', active: true },
            { name: 'Guidelines', url: '#guidelines', active: false },
            { name: 'Code', url: '#code', active: false },
            { name: 'Accessibility', url: '#accessibility', active: false },
          ]}
        />
      </PreviewSection>
 
      <PreviewSection
        id="text-inputs"
        title="Text inputs"
        tag=".field / .field__box"
        note="Rest/hover/focus are live; error + disabled are frozen in those states."
      >
        <div className="style-preview__fields">
          <Input label="Field Label" placeholder="Placeholder text…" />
          <Input label="With leading icon" iconLeft={<SearchIcon />} placeholder="Search…" />
          <Input
            label="Required + supporting text"
            required
            defaultValue="Filled Text"
            supportingText="Supporting text"
          />
          <Input label="Error state" defaultValue="Error Text" error="Error help text" />
          <Input label="Disabled" defaultValue="Filled Text" disabled />
          <Textarea
            label="Text area"
            placeholder="Placeholder text…"
            supportingText="Multi-line; drag the corner to resize."
          />
        </div>
      </PreviewSection>
 
      <PreviewSection
        id="toast"
        title="Toast"
        tag=".toast — lower-left alert; timed or dismissible, with an optional link/action"
        note="Trigger a toast to see it stack in the lower-left corner. Info/success/warning auto-dismiss after 5s; error stays until dismissed. Hover the link or close X for the intense color."
      >
        <ToastDemo />
      </PreviewSection>
 
      <PreviewSection id="tooltip" title="Tooltip" tag="<Tooltip> — copy confirmation; sizes: small / large">
        <div className="style-preview__row style-preview__row--wide">
          <Tooltip inline size="large">
            Copied
          </Tooltip>
          <Tooltip inline size="small">
            Copied
          </Tooltip>
        </div>
      </PreviewSection>
    </PreviewLayout>
  );
}