ShtukbaseStandard
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.

  1. // A scratch project with a small component library of three components (a primitive, a composite that uses it, a block that
  2. // uses the composite), an HTML library and a React file for the primitive. Used by the tests only.
  3. import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs';
  4. import { tmpdir } from 'node:os';
  5. import { dirname, join } from 'node:path';
  6. export const CHIP_HTML = `<!---
  7. id: chip
  8. title: Chip
  9. level: primitive
  10. description: A small label.
  11. parts: [chip-label]
  12. states: [default, hover]
  13. status: [empty]
  14. controls:
  15. tone: {kind: select, options: [neutral, accent], default: neutral, label: Tone}
  16. soft: {kind: bool, default: false}
  17. cssProperties: [--sb-hue-1]
  18. --->
  19. <template data-state="default">
  20. <span data-slot="chip" class="chip"><span data-slot="chip-label">Label</span></span>
  21. </template>
  22. <template data-state="hover">
  23. <span data-slot="chip" class="chip" data-hover>Label</span>
  24. </template>
  25. <template data-status="empty">
  26. <span data-slot="chip" class="chip">&nbsp;</span>
  27. </template>
  28. `;
  29. export const CHIP_CSS = `.chip { color: var(--foreground); background: var(--muted, #eee); border: 1px solid var(--border); }
  30. .chip[data-tone="accent"] { background: var(--primary); color: var(--primary-foreground); }
  31. `;
  32. export const CHIP_TSX = `/*---
  33. id: chip
  34. title: Chip
  35. level: primitive
  36. description: A small label.
  37. states: [default, hover]
  38. status: [empty]
  39. controls:
  40. tone: {kind: select, options: [neutral, accent], default: neutral, label: Tone}
  41. soft: {kind: bool, default: false}
  42. ---*/
  43. export function Chip() { return null; }
  44. `;
  45. export const CARD_HTML = `<!---
  46. id: card
  47. title: Card
  48. level: composite
  49. description: A card with a chip.
  50. uses: [chip]
  51. parts: [card-header, card-title]
  52. states: [default, selected]
  53. controls:
  54. preset: {kind: select, options: [base, compact, cover], default: base, section: Look}
  55. gap: {kind: range, min: 0, max: 32, step: 4, unit: px, default: 8}
  56. --->
  57. <template data-state="default"><div data-slot="card" class="card"><h3 data-slot="card-title">Title</h3></div></template>
  58. <template data-state="selected"><div data-slot="card" class="card" aria-selected="true"></div></template>
  59. `;
  60. 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); }
  61. `;
  62. export const GRID_HTML = `<!---
  63. id: card-grid
  64. title: Card grid
  65. level: block
  66. description: A grid of cards.
  67. uses: [card]
  68. states: [default]
  69. --->
  70. <template data-state="default"><div data-slot="card-grid" class="card-grid"></div></template>
  71. `;
  72. export const GRID_CSS = `.card-grid { display: grid; gap: 8px; }\n`;
  73. export const DESIGN = `---
  74. type: Page
  75. title: Design
  76. style: fixstyle
  77. libraries: [fix-ui-html, fix-ui-react]
  78. ---
  79. `;
  80. export const COLLECTION = `---
  81. type: Collection
  82. title: Components
  83. itemType: Component
  84. items: {mode: path, path: /design/components, recursive: false}
  85. writeTo: /design/components
  86. sources: []
  87. ---
  88. `;
  89. export function put(root: string, rel: string, text: string): void {
  90. mkdirSync(dirname(join(root, rel)), { recursive: true });
  91. writeFileSync(join(root, rel), text);
  92. }
  93. /** A new scratch project holding the fixture library. */
  94. export function project(): string {
  95. const root = mkdtempSync(join(tmpdir(), 'dsc-'));
  96. const html = 'design/fix-ui-html/components';
  97. put(root, 'design/design.md', DESIGN);
  98. put(root, 'design/components.md', COLLECTION);
  99. put(root, 'design/fixstyle/tokens.css', ':root { --primary: oklch(0.5 0.2 20); }\n');
  100. put(root, 'design/fix-ui-html/ui.css', `${CHIP_CSS}${CARD_CSS}${GRID_CSS}`);
  101. put(root, `${html}/primitive/chip/chip.html`, CHIP_HTML);
  102. put(root, `${html}/primitive/chip/chip.css`, CHIP_CSS);
  103. put(root, `${html}/composite/card/card.html`, CARD_HTML);
  104. put(root, `${html}/composite/card/card.css`, CARD_CSS);
  105. put(root, `${html}/block/card-grid/card-grid.html`, GRID_HTML);
  106. put(root, `${html}/block/card-grid/card-grid.css`, GRID_CSS);
  107. put(root, 'design/fix-ui-react/components/ui/chip.tsx', CHIP_TSX);
  108. return root;
  109. }
  110. export const drop = (root: string) => rmSync(root, { recursive: true, force: true });