@dreamtree-org/twreact-ui 2.0.9 → 2.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/DESIGN.md +3 -0
  2. package/README.md +9 -4
  3. package/ai-skills/dreamtree-ui.md +12 -8
  4. package/dist/ai-schema.json +314 -70
  5. package/dist/components/blocks/AppShell.d.ts.map +1 -1
  6. package/dist/components/blocks/ProductCard.d.ts +4 -0
  7. package/dist/components/blocks/ProductCard.d.ts.map +1 -0
  8. package/dist/components/blocks/ProductCardParts.d.ts +19 -0
  9. package/dist/components/blocks/ProductCardParts.d.ts.map +1 -0
  10. package/dist/components/blocks/StatCard.d.ts.map +1 -1
  11. package/dist/components/core/Accordion.d.ts.map +1 -1
  12. package/dist/components/core/Button.d.ts.map +1 -1
  13. package/dist/components/core/OptionCard.d.ts +14 -0
  14. package/dist/components/core/OptionCard.d.ts.map +1 -0
  15. package/dist/components/core/OptionCardGroup.d.ts +2 -0
  16. package/dist/components/core/OptionCardGroup.d.ts.map +1 -0
  17. package/dist/components/core/QuantityStepper.d.ts +8 -0
  18. package/dist/components/core/QuantityStepper.d.ts.map +1 -0
  19. package/dist/components/core/menu/MenuPopover.d.ts.map +1 -1
  20. package/dist/components/utility/ImageGallery.d.ts +4 -0
  21. package/dist/components/utility/ImageGallery.d.ts.map +1 -0
  22. package/dist/components/utility/imageGalleryParts.d.ts +55 -0
  23. package/dist/components/utility/imageGalleryParts.d.ts.map +1 -0
  24. package/dist/esm/components/blocks/AppShell.js +17 -6
  25. package/dist/esm/components/blocks/ProductCard.js +122 -0
  26. package/dist/esm/components/blocks/ProductCardParts.js +128 -0
  27. package/dist/esm/components/blocks/StatCard.js +20 -5
  28. package/dist/esm/components/core/Accordion.js +3 -1
  29. package/dist/esm/components/core/Button.js +17 -2
  30. package/dist/esm/components/core/OptionCard.js +340 -0
  31. package/dist/esm/components/core/QuantityStepper.js +194 -0
  32. package/dist/esm/components/core/menu/MenuPopover.js +4 -2
  33. package/dist/esm/components/navigation/Navbar.js +1 -1
  34. package/dist/esm/components/utility/ImageGallery.js +150 -0
  35. package/dist/esm/components/utility/imageGalleryParts.js +380 -0
  36. package/dist/esm/index.js +4 -0
  37. package/dist/index.css +1 -1
  38. package/dist/index.d.ts +6 -1
  39. package/dist/index.esm.css +1 -1
  40. package/dist/index.esm.js +1850 -505
  41. package/dist/index.js +1854 -504
  42. package/dist/tokens/tailwind3-preset.cjs +4 -1
  43. package/dist/tokens/theme.css +3 -0
  44. package/dist/tokens/tokens.json +7 -0
  45. package/dist/tokens/vars.css +2 -0
  46. package/dist/types/blocks.d.ts +61 -1
  47. package/dist/types/blocks.d.ts.map +1 -1
  48. package/dist/types/index.d.ts +102 -1
  49. package/dist/types/index.d.ts.map +1 -1
  50. package/doc/README.md +5 -1
  51. package/mcp/catalog.snapshot.json +480 -9
  52. package/package.json +3 -2
  53. package/tokens/brand.schema.json +22 -0
  54. package/tokens/lib.cjs +26 -0
  55. package/tokens/tokens.json +2 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dreamtree-org/twreact-ui",
3
- "version": "2.0.9",
3
+ "version": "2.1.1",
4
4
  "description": "A comprehensive React + Tailwind components library for building modern web apps",
5
5
  "author": {
6
6
  "name": "Partha Preetham Krishna",
@@ -166,8 +166,9 @@
166
166
  "@storybook/blocks": "8.6.15",
167
167
  "@storybook/react": "8.6.15",
168
168
  "@storybook/react-vite": "8.6.15",
169
+ "@testing-library/dom": "^10.4.2",
169
170
  "@testing-library/jest-dom": "^6.9.1",
170
- "@testing-library/react": "^13.4.0",
171
+ "@testing-library/react": "^16.3.3",
171
172
  "@tiptap/core": "^3.32.0",
172
173
  "@tiptap/pm": "^3.32.0",
173
174
  "@tiptap/react": "^3.32.0",
@@ -573,6 +573,28 @@
573
573
  }
574
574
  }
575
575
  ]
576
+ },
577
+ "primary-foreground": {
578
+ "oneOf": [
579
+ {
580
+ "type": "string",
581
+ "pattern": "^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6})$"
582
+ },
583
+ {
584
+ "type": "object",
585
+ "additionalProperties": false,
586
+ "properties": {
587
+ "light": {
588
+ "type": "string",
589
+ "pattern": "^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6})$"
590
+ },
591
+ "dark": {
592
+ "type": "string",
593
+ "pattern": "^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6})$"
594
+ }
595
+ }
596
+ }
597
+ ]
576
598
  }
577
599
  }
578
600
  },
package/tokens/lib.cjs CHANGED
@@ -122,6 +122,26 @@ function roles(tokens) {
122
122
  return out;
123
123
  }
124
124
 
125
+ // WCAG relative luminance and contrast ratio of two hex colours.
126
+ function luminance(hex) {
127
+ const [r, g, b] = hexToChannels(hex).split(' ').map((c) => {
128
+ const v = Number(c) / 255;
129
+ return v <= 0.03928 ? v / 12.92 : ((v + 0.055) / 1.055) ** 2.4;
130
+ });
131
+ return 0.2126 * r + 0.7152 * g + 0.0722 * b;
132
+ }
133
+ const contrast = (a, b) => {
134
+ const [hi, lo] = [luminance(a), luminance(b)].sort((x, y) => y - x);
135
+ return (hi + 0.05) / (lo + 0.05);
136
+ };
137
+
138
+ /** The colour for text on a primary fill: white or role.foreground, whichever contrasts more with primary-700. */
139
+ function onPrimary(tokens) {
140
+ const fill = tokens.color.primary['700'].$value;
141
+ const dark = tokens.role.foreground.$value;
142
+ return contrast('#ffffff', fill) >= contrast(dark, fill) ? '#ffffff' : dark;
143
+ }
144
+
125
145
  /** Merge a brand file over the tokens: brand.color.<scale>.<step> and brand.role.<name> (string or {light,dark}). */
126
146
  function applyBrand(tokens, brand) {
127
147
  if (!brand) return tokens;
@@ -133,6 +153,11 @@ function applyBrand(tokens, brand) {
133
153
  next.color[scale][step] = { $value: hex };
134
154
  }
135
155
  }
156
+ // #189: a light primary needs dark text on it; the brand can still set the role itself.
157
+ if (brand.color && brand.color.primary && next.role['primary-foreground']) {
158
+ const on = onPrimary(next);
159
+ next.role['primary-foreground'] = { ...next.role['primary-foreground'], $value: on, $extensions: { [DARK_KEY]: on } };
160
+ }
136
161
  for (const [name, value] of Object.entries(brand.role || {})) {
137
162
  if (!next.role[name]) throw new Error(`Brand "${brandId(brand)}" sets unknown role "${name}". Known: ${Object.keys(roles(tokens)).join(', ')}.`);
138
163
  // A plain string overrides light only; dark keeps the shared value unless {light, dark} is given.
@@ -278,6 +303,7 @@ module.exports = {
278
303
  brandCss,
279
304
  applyBrand,
280
305
  hexToChannels,
306
+ contrast,
281
307
  scales,
282
308
  roles,
283
309
  tailwindColors,
@@ -111,7 +111,8 @@
111
111
  "line": { "$value": "#e2e8f0", "$description": "Card and divider borders.", "$extensions": { "org.dreamtree.dark": "#1f2937" } },
112
112
  "shell": { "$value": "#0f172a", "$description": "App shell sidebar background.", "$extensions": { "org.dreamtree.dark": "#020617" } },
113
113
  "shell-foreground": { "$value": "#cbd5e1", "$description": "Sidebar text.", "$extensions": { "org.dreamtree.dark": "#cbd5e1" } },
114
- "shell-active": { "$value": "#1e293b", "$description": "Active sidebar item fill.", "$extensions": { "org.dreamtree.dark": "#1e293b" } }
114
+ "shell-active": { "$value": "#1e293b", "$description": "Active sidebar item fill.", "$extensions": { "org.dreamtree.dark": "#1e293b" } },
115
+ "primary-foreground": { "$value": "#ffffff", "$description": "Text, icons, tiles (primary-foreground/12) and focus rings on a primary-600 to primary-900 fill, such as a brand band. A brand that changes color.primary gets white or role.foreground, whichever contrasts more with its primary-700.", "$extensions": { "org.dreamtree.dark": "#ffffff" } }
115
116
  },
116
117
  "font": {
117
118
  "family": {