archivo del paquete→ .shtukbase/packages/design-components/test/fixture.ts
test/fixture.ts
115 líneas, 4.0 KB.
El archivo tal como está en el paquete: el código y sus comentarios no se traducen.
- // A scratch project with a small component library of three components (a primitive, a composite that uses it, a block that
- // uses the composite), an HTML library and a React file for the primitive. Used by the tests only.
- import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs';
- import { tmpdir } from 'node:os';
- import { dirname, join } from 'node:path';
- export const CHIP_HTML = `<!---
- id: chip
- title: Chip
- level: primitive
- description: A small label.
- parts: [chip-label]
- states: [default, hover]
- status: [empty]
- controls:
- tone: {kind: select, options: [neutral, accent], default: neutral, label: Tone}
- soft: {kind: bool, default: false}
- cssProperties: [--sb-hue-1]
- --->
- <template data-state="default">
- <span data-slot="chip" class="chip"><span data-slot="chip-label">Label</span></span>
- </template>
- <template data-state="hover">
- <span data-slot="chip" class="chip" data-hover>Label</span>
- </template>
- <template data-status="empty">
- <span data-slot="chip" class="chip"> </span>
- </template>
- `;
- export const CHIP_CSS = `.chip { color: var(--foreground); background: var(--muted, #eee); border: 1px solid var(--border); }
- .chip[data-tone="accent"] { background: var(--primary); color: var(--primary-foreground); }
- `;
- export const CHIP_TSX = `/*---
- id: chip
- title: Chip
- level: primitive
- description: A small label.
- states: [default, hover]
- status: [empty]
- controls:
- tone: {kind: select, options: [neutral, accent], default: neutral, label: Tone}
- soft: {kind: bool, default: false}
- ---*/
- export function Chip() { return null; }
- `;
- export const CARD_HTML = `<!---
- id: card
- title: Card
- level: composite
- description: A card with a chip.
- uses: [chip]
- parts: [card-header, card-title]
- states: [default, selected]
- controls:
- preset: {kind: select, options: [base, compact, cover], default: base, section: Look}
- gap: {kind: range, min: 0, max: 32, step: 4, unit: px, default: 8}
- --->
- <template data-state="default"><div data-slot="card" class="card"><h3 data-slot="card-title">Title</h3></div></template>
- <template data-state="selected"><div data-slot="card" class="card" aria-selected="true"></div></template>
- `;
- export const CARD_CSS = `.card { background: var(--card); color: var(--card-foreground); border-radius: var(--radius); box-shadow: var(--sb-edge, 0 0 0 1px #ddd); }
- `;
- export const GRID_HTML = `<!---
- id: card-grid
- title: Card grid
- level: block
- description: A grid of cards.
- uses: [card]
- states: [default]
- --->
- <template data-state="default"><div data-slot="card-grid" class="card-grid"></div></template>
- `;
- export const GRID_CSS = `.card-grid { display: grid; gap: 8px; }\n`;
- export const DESIGN = `---
- type: Page
- title: Design
- style: fixstyle
- libraries: [fix-ui-html, fix-ui-react]
- ---
- `;
- export const COLLECTION = `---
- type: Collection
- title: Components
- itemType: Component
- items: {mode: path, path: /design/components, recursive: false}
- writeTo: /design/components
- sources: []
- ---
- `;
- export function put(root: string, rel: string, text: string): void {
- mkdirSync(dirname(join(root, rel)), { recursive: true });
- writeFileSync(join(root, rel), text);
- }
- /** A new scratch project holding the fixture library. */
- export function project(): string {
- const root = mkdtempSync(join(tmpdir(), 'dsc-'));
- const html = 'design/fix-ui-html/components';
- put(root, 'design/design.md', DESIGN);
- put(root, 'design/components.md', COLLECTION);
- put(root, 'design/fixstyle/tokens.css', ':root { --primary: oklch(0.5 0.2 20); }\n');
- put(root, 'design/fix-ui-html/ui.css', `${CHIP_CSS}${CARD_CSS}${GRID_CSS}`);
- put(root, `${html}/primitive/chip/chip.html`, CHIP_HTML);
- put(root, `${html}/primitive/chip/chip.css`, CHIP_CSS);
- put(root, `${html}/composite/card/card.html`, CARD_HTML);
- put(root, `${html}/composite/card/card.css`, CARD_CSS);
- put(root, `${html}/block/card-grid/card-grid.html`, GRID_HTML);
- put(root, `${html}/block/card-grid/card-grid.css`, GRID_CSS);
- put(root, 'design/fix-ui-react/components/ui/chip.tsx', CHIP_TSX);
- return root;
- }
- export const drop = (root: string) => rmSync(root, { recursive: true, force: true });