@nicolassancho/storybook-core 3.0.13 → 3.2.0

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.
package/README.md CHANGED
@@ -24,6 +24,8 @@ documented in Storybook. It is published to npm as `@nicolassancho/storybook-cor
24
24
  plug in your framework.
25
25
  - **Design tokens, not compiled CSS.** Colors, font sizes and breakpoints ship as a Tailwind v4
26
26
  `@theme` file, and your app's Tailwind generates the classes.
27
+ - **Light and dark themes.** The dark theme follows the operating system, a `data-theme` attribute
28
+ on `<html>` overrides it, and every story is checked with axe and its `play` test in both themes.
27
29
  - **Typed and documented.** TypeScript strict, every prop documented in JSDoc, and interaction
28
30
  tests written as Storybook `play` functions.
29
31
 
@@ -41,6 +43,8 @@ Storybook.
41
43
 
42
44
  ![The color palette, with the text contrast of each step](https://raw.githubusercontent.com/NicolasSancho/Storybook-core/main/docs/colors.png)
43
45
 
46
+ ![The same palette in the dark theme](https://raw.githubusercontent.com/NicolasSancho/Storybook-core/main/docs/colors-dark.png)
47
+
44
48
  ## Using the library
45
49
 
46
50
  Install the package, then add the design tokens and the source scan to your Tailwind v4 stylesheet:
@@ -74,7 +78,7 @@ The full guide (install, links and images, the Next.js App Router) is the **Cons
74
78
  ```bash
75
79
  npm install # also builds the library (the `prepare` script)
76
80
  npm run storybook # dev server on http://localhost:6006
77
- npm test # runs every story in headless Chromium, with axe and the play tests
81
+ npm test # runs every story in headless Chromium, in both themes, with axe and the play tests
78
82
  npm run build # compiles the library to dist/
79
83
  ```
80
84
 
@@ -12,11 +12,11 @@ var __rest = (this && this.__rest) || function (s, e) {
12
12
  import { jsx as _jsx } from "react/jsx-runtime";
13
13
  import { tv } from "tailwind-variants";
14
14
  const buttonStyles = tv({
15
- base: "font-bold text-white inline-flex items-center focus:outline-hidden focus-visible:ring-2 focus-visible:ring-primary focus-visible:ring-offset-2",
15
+ base: "font-bold inline-flex items-center focus:outline-hidden focus-visible:ring-2 focus-visible:ring-primary focus-visible:ring-offset-2 focus-visible:ring-offset-surface",
16
16
  variants: {
17
17
  variant: {
18
- primary: "rounded-sm bg-primary text-white enabled:hover:bg-primary-darker",
19
- secondary: "rounded-sm bg-secondary text-white enabled:hover:bg-secondary-darker focus-visible:ring-secondary",
18
+ primary: "rounded-sm bg-primary text-on-primary enabled:hover:bg-primary-darker",
19
+ secondary: "rounded-sm bg-secondary text-on-secondary enabled:hover:bg-secondary-darker focus-visible:ring-secondary",
20
20
  text: "rounded-sm text-primary enabled:hover:underline",
21
21
  },
22
22
  size: {
@@ -12,7 +12,7 @@ var __rest = (this && this.__rest) || function (s, e) {
12
12
  import { jsx as _jsx } from "react/jsx-runtime";
13
13
  import { tv } from "tailwind-variants";
14
14
  const searchInputStyles = tv({
15
- base: "w-full rounded-sm bg-white px-3 py-2 text-sm placeholder:text-neutral-500 focus:outline-hidden focus:ring-2 transition-colors",
15
+ base: "w-full rounded-sm bg-surface px-3 py-2 text-sm text-neutral-900 placeholder:text-neutral-500 focus:outline-hidden focus:ring-2 transition-colors",
16
16
  variants: {
17
17
  variantSize: {
18
18
  small: "text-xs py-1 px-2",
@@ -5,8 +5,17 @@ export interface TextProps {
5
5
  * Text color. Every option reaches the 4.5:1 text contrast on white.
6
6
  */
7
7
  color?: "base" | "dark" | "darker" | "primary" | "secondary";
8
- size?: "small" | "medium" | "large";
9
- weight?: "normal" | "bold" | "semibold";
8
+ /**
9
+ * Text size: 14px, 16px and 20px for body copy, 32px for headings and a fluid 36 to 64px for
10
+ * hero text. Each size sets its own line-height, and `display` also tightens the tracking.
11
+ */
12
+ size?: "small" | "medium" | "large" | "heading" | "display";
13
+ /**
14
+ * Font family: `body` is `font-sans`, `display` is `font-display` (the heading font the
15
+ * consumer sets with `--font-display`, the body font when none is set).
16
+ */
17
+ font?: "body" | "display";
18
+ weight?: "normal" | "medium" | "semibold" | "bold";
10
19
  underline?: boolean;
11
20
  children: React.ReactNode;
12
21
  className?: string;
@@ -1,8 +1,11 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { tv } from "tailwind-variants";
3
3
  const textStyles = tv({
4
- base: "font-sans",
5
4
  variants: {
5
+ font: {
6
+ body: "font-sans",
7
+ display: "font-display",
8
+ },
6
9
  color: {
7
10
  base: "text-neutral-500",
8
11
  dark: "text-neutral-700",
@@ -14,11 +17,14 @@ const textStyles = tv({
14
17
  small: "text-sm",
15
18
  medium: "text-base",
16
19
  large: "text-lg",
20
+ heading: "text-2xl",
21
+ display: "text-4xl",
17
22
  },
18
23
  weight: {
19
24
  normal: "font-normal",
20
- bold: "font-bold",
25
+ medium: "font-medium",
21
26
  semibold: "font-semibold",
27
+ bold: "font-bold",
22
28
  },
23
29
  underline: {
24
30
  true: "underline",
@@ -26,12 +32,13 @@ const textStyles = tv({
26
32
  },
27
33
  },
28
34
  defaultVariants: {
35
+ font: "body",
29
36
  color: "dark",
30
37
  size: "medium",
31
38
  weight: "normal",
32
39
  underline: false,
33
40
  },
34
41
  });
35
- export const Text = ({ as: Component = "div", color = "dark", size = "medium", weight = "normal", underline = false, children, className = "", }) => {
36
- return (_jsx(Component, { className: textStyles({ color, size, weight, underline, className }), children: children }));
42
+ export const Text = ({ as: Component = "div", font = "body", color = "dark", size = "medium", weight = "normal", underline = false, children, className = "", }) => {
43
+ return (_jsx(Component, { className: textStyles({ font, color, size, weight, underline, className }), children: children }));
37
44
  };
@@ -6,11 +6,11 @@ const cartIconStyles = tv({
6
6
  base: "relative inline-flex items-center",
7
7
  variants: {
8
8
  interactive: {
9
- true: "cursor-pointer rounded-sm focus:outline-hidden focus-visible:ring-2 focus-visible:ring-primary focus-visible:ring-offset-2",
9
+ true: "cursor-pointer rounded-sm focus:outline-hidden focus-visible:ring-2 focus-visible:ring-primary focus-visible:ring-offset-2 focus-visible:ring-offset-surface",
10
10
  },
11
11
  },
12
12
  slots: {
13
- badge: "absolute -top-1 -right-1 bg-danger text-white text-xs rounded-full px-1",
13
+ badge: "absolute -top-1 -right-1 bg-danger text-on-danger text-xs rounded-full px-1",
14
14
  },
15
15
  });
16
16
  export const CartIcon = ({ count = 0, onClick, color = "black", size = "medium", className, ariaLabel, }) => {
@@ -8,7 +8,7 @@ const productCardStyles = tv({
8
8
  slots: {
9
9
  imageWrapper: "relative aspect-3/4",
10
10
  image: "w-full h-full object-cover",
11
- tag: "absolute top-2 left-2 bg-neutral-950 text-white text-xs px-2 py-1 rounded-sm",
11
+ tag: "absolute top-2 left-2 bg-neutral-950 text-neutral-25 text-xs px-2 py-1 rounded-sm",
12
12
  body: "p-2 flex flex-col",
13
13
  productInfo: "flex flex-col",
14
14
  title: "text-sm font-medium",
@@ -1,7 +1,7 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { tv } from "tailwind-variants";
3
3
  const headerStyles = tv({
4
- base: "w-full flex items-center justify-between px-4 h-16 bg-white shadow-sm",
4
+ base: "w-full flex items-center justify-between px-4 h-16 bg-surface shadow-sm",
5
5
  });
6
6
  const slotStyles = tv({
7
7
  base: "flex items-center gap-2 flex-row h-full",
@@ -1,75 +1,116 @@
1
1
  /*
2
2
  Design tokens. Shipped as dist/styles/theme.css: consumers import it after
3
- `@import "tailwindcss"`. Keep the Colors story in sync with the values here.
3
+ `@import "tailwindcss"`. The Colors story reads these values, so it needs no edit when they change.
4
4
  */
5
5
  @theme {
6
- /* Closed type scale: these are the only text sizes that exist. */
6
+ /*
7
+ Closed type scale: these are the only text sizes that exist. Sizes are in rem, so they follow
8
+ the browser's font-size setting, and each size carries its line-height (`text-sm` sets both).
9
+ 4xl is the fluid display size (36px on phones, 64px from about 1200px wide). The names are
10
+ Tailwind's t-shirt sizes on purpose: tailwind-merge reads `text-display` as a color and
11
+ would drop one of `text-display` and `text-neutral-900` when they meet in a tv() call.
12
+ */
7
13
  --text-*: initial;
8
- --text-xs: 12px;
9
- --text-sm: 14px;
10
- --text-base: 16px;
11
- --text-lg: 20px;
12
- --text-xl: 24px;
13
- --text-2xl: 32px;
14
+ --text-xs: 0.75rem;
15
+ --text-xs--line-height: 1rem;
16
+ --text-sm: 0.875rem;
17
+ --text-sm--line-height: 1.25rem;
18
+ --text-base: 1rem;
19
+ --text-base--line-height: 1.5rem;
20
+ --text-lg: 1.25rem;
21
+ --text-lg--line-height: 1.75rem;
22
+ --text-xl: 1.5rem;
23
+ --text-xl--line-height: 2rem;
24
+ --text-2xl: 2rem;
25
+ --text-2xl--line-height: 2.5rem;
26
+ --text-3xl: 2.5rem;
27
+ --text-3xl--line-height: 3rem;
28
+ --text-4xl: clamp(2.25rem, 5.4vw, 4rem);
29
+ --text-4xl--line-height: 1.04;
30
+ --text-4xl--letter-spacing: -0.03em;
31
+
32
+ /*
33
+ Font families. The library loads no fonts: a consumer sets --font-sans (body) and optionally
34
+ --font-display (headings). Without one, headings use the body font.
35
+ */
36
+ --font-display: var(--font-sans);
14
37
 
15
- --color-primary-50: #f9fbfc;
16
- --color-primary-100: #f1f7fa;
17
- --color-primary-200: #d9e7ef;
18
- --color-primary-300: #b8d3e4;
19
- --color-primary-400: #90b5d2;
20
- --color-primary-500: #6b98c1;
21
- --color-primary-600: #457ab0; /* 4.5:1 with white: lightest step usable for text */
22
- --color-primary-700: #0060ab;
23
- --color-primary-800: #00548a; /* same as DEFAULT */
24
- --color-primary-900: #00426c;
25
- --color-primary-950: #003054;
26
- --color-primary: #00548a;
27
- --color-primary-lighter: #0077cc;
28
- --color-primary-darker: #003366;
38
+ --color-primary-50: light-dark(#f9fbfc, #12191d);
39
+ --color-primary-100: light-dark(#f1f7fa, #121e23);
40
+ --color-primary-200: light-dark(#d9e7ef, #192b35);
41
+ --color-primary-300: light-dark(#b8d3e4, #223a49);
42
+ --color-primary-400: light-dark(#90b5d2, #404e5a);
43
+ --color-primary-500: light-dark(#6b98c1, #4d657c);
44
+ --color-primary-600: light-dark(
45
+ #457ab0,
46
+ #5281b1
47
+ ); /* 4.5:1 with white: lightest step usable for text */
48
+ --color-primary-700: light-dark(#0060ab, #589de4);
49
+ --color-primary-800: light-dark(#00548a, #73b0e6); /* same as DEFAULT */
50
+ --color-primary-900: light-dark(#00426c, #96c9f6);
51
+ --color-primary-950: light-dark(#003054, #c2e0fe);
52
+ --color-primary: light-dark(#00548a, #73b0e6);
53
+ --color-primary-lighter: light-dark(#0077cc, #4d94dc);
54
+ --color-primary-darker: light-dark(#003366, #96c9f6);
29
55
 
30
- --color-secondary-50: #fff7ed;
31
- --color-secondary-100: #ffedd5;
32
- --color-secondary-200: #fed7aa;
33
- --color-secondary-300: #fdba74;
34
- --color-secondary-400: #fb923c;
35
- --color-secondary-500: #f97316;
36
- --color-secondary-600: #ea580c;
37
- --color-secondary-700: #c2410c; /* same as DEFAULT; 5.2:1 with white, lightest step usable for text */
38
- --color-secondary-800: #9a3412; /* same as darker */
39
- --color-secondary-900: #7c2d12;
40
- --color-secondary-950: #431407;
41
- --color-secondary: #c2410c; /* 5.2:1 with white (WCAG AA) */
56
+ --color-secondary-50: light-dark(#fff7ed, #1e1a14);
57
+ --color-secondary-100: light-dark(#ffedd5, #272117);
58
+ --color-secondary-200: light-dark(#fed7aa, #382b1d);
59
+ --color-secondary-300: light-dark(#fdba74, #4e3922);
60
+ --color-secondary-400: light-dark(#fb923c, #6f4627);
61
+ --color-secondary-500: light-dark(#f97316, #924920);
62
+ --color-secondary-600: light-dark(#ea580c, #bf4401);
63
+ --color-secondary-700: light-dark(
64
+ #c2410c,
65
+ #d9653e
66
+ ); /* same as DEFAULT; 5.2:1 with white, lightest step usable for text */
67
+ --color-secondary-800: light-dark(#9a3412, #ec886b); /* same as darker */
68
+ --color-secondary-900: light-dark(#7c2d12, #f7a58b);
69
+ --color-secondary-950: light-dark(#431407, #fee7e1);
70
+ --color-secondary: light-dark(#c2410c, #d9653e); /* 5.2:1 with white (WCAG AA) */
42
71
  --color-secondary-lighter: #f28b2d; /* original brand orange: decorative use only, fails AA with white */
43
- --color-secondary-darker: #9a3412; /* 7.3:1 with white */
72
+ --color-secondary-darker: light-dark(#9a3412, #ec886b); /* 7.3:1 with white */
44
73
 
45
74
  /*
46
75
  Semantic colors: the plain name is for text and icons on white or on `subtle` (all 4.5:1 or
47
76
  better), `subtle` is for backgrounds. Always pair with text or an icon, never color alone.
48
77
  */
49
- --color-danger: #b91c1c; /* 6.5:1 with white */
50
- --color-danger-subtle: #fef2f2;
51
- --color-success: #15803d; /* 5.0:1 with white */
52
- --color-success-subtle: #f0fdf4;
53
- --color-warning: #92400e; /* 7.1:1 with white */
54
- --color-warning-subtle: #fef3c7;
78
+ --color-danger: light-dark(#b91c1c, #f47a70); /* 6.5:1 with white */
79
+ --color-danger-subtle: light-dark(#fef2f2, #2a1a1a);
80
+ --color-success: light-dark(#15803d, #4cb06b); /* 5.0:1 with white */
81
+ --color-success-subtle: light-dark(#f0fdf4, #16221a);
82
+ --color-warning: light-dark(#92400e, #e0a23a); /* 7.1:1 with white */
83
+ --color-warning-subtle: light-dark(#fef3c7, #2a2210);
84
+
85
+ /*
86
+ Surface: the default background of the page and of controls (inputs, header). It is white in
87
+ light mode and the darkest tone in dark mode, so use it instead of `bg-white`.
88
+ `on-*`: the text and icon color for a filled brand or danger background (`bg-primary`,
89
+ `bg-secondary`, `bg-danger`). It is white in light mode and dark in dark mode, so use it
90
+ instead of `text-white`. Both are 4.5:1 or better on the fill, in both themes.
91
+ */
92
+ --color-surface: light-dark(#ffffff, #141414);
93
+ --color-on-primary: light-dark(#ffffff, #141414);
94
+ --color-on-secondary: light-dark(#ffffff, #141414);
95
+ --color-on-danger: light-dark(#ffffff, #141414);
55
96
 
56
97
  /*
57
98
  Gray scale. Jobs: 900 body text, 600 secondary text, 500 placeholder, 400 input borders
58
99
  (3:1), 200 dividers, 50 page background. 100 to 300 are never for text.
59
100
  */
60
101
  --color-neutral-*: initial;
61
- --color-neutral-25: rgb(250 250 250);
62
- --color-neutral-50: rgb(246 246 246);
63
- --color-neutral-100: rgb(231 231 231);
64
- --color-neutral-200: rgb(209 209 209);
65
- --color-neutral-300: rgb(176 176 176);
66
- --color-neutral-400: rgb(136 136 136);
67
- --color-neutral-500: rgb(109 109 109);
68
- --color-neutral-600: rgb(93 93 93);
69
- --color-neutral-700: rgb(79 79 79);
70
- --color-neutral-800: rgb(69 69 69);
71
- --color-neutral-900: rgb(61 61 61);
72
- --color-neutral-950: rgb(48 48 48);
102
+ --color-neutral-25: light-dark(rgb(250 250 250), rgb(24 24 24));
103
+ --color-neutral-50: light-dark(rgb(246 246 246), rgb(27 27 27));
104
+ --color-neutral-100: light-dark(rgb(231 231 231), rgb(39 39 39));
105
+ --color-neutral-200: light-dark(rgb(209 209 209), rgb(54 54 54));
106
+ --color-neutral-300: light-dark(rgb(176 176 176), rgb(76 76 76));
107
+ --color-neutral-400: light-dark(rgb(136 136 136), rgb(108 108 108));
108
+ --color-neutral-500: light-dark(rgb(109 109 109), rgb(135 135 135));
109
+ --color-neutral-600: light-dark(rgb(93 93 93), rgb(155 155 155));
110
+ --color-neutral-700: light-dark(rgb(79 79 79), rgb(176 176 176));
111
+ --color-neutral-800: light-dark(rgb(69 69 69), rgb(194 194 194));
112
+ --color-neutral-900: light-dark(rgb(61 61 61), rgb(212 212 212));
113
+ --color-neutral-950: light-dark(rgb(48 48 48), rgb(232 232 232));
73
114
 
74
115
  --breakpoint-xs: 0px;
75
116
  --breakpoint-sm: 640px;
@@ -77,3 +118,35 @@
77
118
  --breakpoint-lg: 1024px;
78
119
  --breakpoint-xl: 1280px;
79
120
  }
121
+
122
+ /*
123
+ Light and dark. Every color above is `light-dark(light, dark)`, so one declaration holds both
124
+ themes. Which one applies is the root's `color-scheme`: it follows the operating system by
125
+ default, and `data-theme="light"` or `data-theme="dark"` on <html> overrides it. `color-scheme`
126
+ also themes native controls and scrollbars. Set the attribute on <html> only: Tailwind compiles
127
+ `light-dark()` to custom-property toggles that are resolved at the root, so a nested element
128
+ with its own `data-theme` would not change.
129
+
130
+ The color names keep their jobs in both themes: the `neutral`, `primary` and `secondary` ramps
131
+ are inverted, so 900 is still body text, 200 still a divider and 50 the page background.
132
+ `-darker` is the hover step, so it is lighter in dark. `secondary-lighter` is decorative and the
133
+ same in both themes.
134
+
135
+ How the dark values were chosen: each step keeps the contrast ratio its light value has against
136
+ white, measured against the dark surface (#141414), with the same hue. Tints (50 to 400) have
137
+ less chroma so large areas stay calm, and the neutral text steps (700 to 950) are a little
138
+ brighter than a strict match because light text on a dark ground reads thinner. Text colors are
139
+ 4.5:1 or better on `surface`, and semantic colors are too on their `subtle` background. The
140
+ Colors story lists every pairing for both themes and `npm test` asserts them.
141
+ */
142
+ :root {
143
+ color-scheme: light dark;
144
+ }
145
+
146
+ :root[data-theme="light"] {
147
+ color-scheme: light;
148
+ }
149
+
150
+ :root[data-theme="dark"] {
151
+ color-scheme: dark;
152
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nicolassancho/storybook-core",
3
- "version": "3.0.13",
3
+ "version": "3.2.0",
4
4
  "description": "Accessible React + Tailwind component library built with tailwind-variants and documented in Storybook.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",