@epicbagel/saas-kit 1.3.0 → 1.4.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.
@@ -0,0 +1,78 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { ReactNode } from 'react';
3
+ import { ThemePalette, ThemeMode } from '../lib/neutral-theme.js';
4
+
5
+ /** Light, dark, or whatever the device prefers. */
6
+ type ThemeSelectorMode = ThemeMode | "system";
7
+ interface PalettePreviewProps {
8
+ /** The palette to paint. */
9
+ palette: ThemePalette;
10
+ /**
11
+ * Pin one mode. When the palette has that mode's tokens, they paint the
12
+ * preview directly, whatever palette or mode the page is in. Without
13
+ * them, or without a mode, the preview carries `data-theme` (and
14
+ * `data-mode`) and the page's palette CSS paints it; left off, it follows
15
+ * the page's mode.
16
+ */
17
+ mode?: ThemeMode;
18
+ className?: string;
19
+ }
20
+ /**
21
+ * A miniature app in one palette: a sidebar, a header with a primary
22
+ * action, and a card holding the first three chart colours. Built from the
23
+ * same token utilities the app uses (`bg-sidebar`, `bg-primary`,
24
+ * `rounded-lg`, ...), so the corners follow the palette's radius too.
25
+ * Decorative: hidden from assistive technology.
26
+ */
27
+ declare function PalettePreview({ palette, mode, className }: PalettePreviewProps): react_jsx_runtime.JSX.Element;
28
+ interface ThemeSelectorProps {
29
+ /**
30
+ * The palettes to offer, in display order. Defaults to the kit's neutral
31
+ * palette alone. A palette with tokens previews from them; one without
32
+ * relies on the page's palette CSS (see `ThemePalette`).
33
+ */
34
+ palettes?: readonly ThemePalette[];
35
+ /**
36
+ * The chosen palette's id. Defaults to the neutral palette's. Pass `null`
37
+ * while it isn't known yet (before the stored pick is read), so no card
38
+ * is marked rather than the wrong one.
39
+ */
40
+ palette?: string | null;
41
+ /** Called with a palette's id when someone picks it. */
42
+ onPaletteChange?: (palette: string) => void;
43
+ /** The chosen mode. Defaults to `system`; `null` marks none. */
44
+ mode?: ThemeSelectorMode | null;
45
+ /** Called when someone picks a mode. */
46
+ onModeChange?: (mode: ThemeSelectorMode) => void;
47
+ /** The palette group's legend. Defaults to "Theme". */
48
+ paletteLabel?: ReactNode;
49
+ /** A line under the palette group's legend. */
50
+ paletteDescription?: ReactNode;
51
+ /** The mode group's legend. Defaults to "Mode". */
52
+ modeLabel?: ReactNode;
53
+ /** A line under the mode group's legend. */
54
+ modeDescription?: ReactNode;
55
+ lightLabel?: string;
56
+ darkLabel?: string;
57
+ systemLabel?: string;
58
+ className?: string;
59
+ }
60
+ /**
61
+ * Appearance settings: light, dark or system, then a grid of palettes.
62
+ *
63
+ * The two are independent axes (every palette ships both modes), and the
64
+ * selector owns neither: it shows the values it is given and reports picks
65
+ * through `onModeChange` and `onPaletteChange`. Wire it to whatever applies
66
+ * them, typically next-themes for the mode and a `data-theme` attribute on
67
+ * `<html>` for the palette.
68
+ *
69
+ * It knows no palette but the kit's neutral one, its default: pass the
70
+ * palettes a host offers. Each palette is a radio card (arrow keys move
71
+ * between them) previewing both modes. The grid is one column on a phone
72
+ * (below `sm`), and otherwise sizes to the selector rather than the
73
+ * viewport, so it fits a dialog as well as a settings page: one column while
74
+ * the selector is narrower than 24rem, two from there, three from 42rem.
75
+ */
76
+ declare function ThemeSelector({ palettes, palette, onPaletteChange, mode, onModeChange, paletteLabel, paletteDescription, modeLabel, modeDescription, lightLabel, darkLabel, systemLabel, className, }: ThemeSelectorProps): react_jsx_runtime.JSX.Element;
77
+
78
+ export { PalettePreview, type PalettePreviewProps, ThemeSelector, type ThemeSelectorMode, type ThemeSelectorProps };
@@ -0,0 +1,188 @@
1
+ "use client";
2
+ "use client";
3
+ import {
4
+ ToggleGroup,
5
+ ToggleGroupItem
6
+ } from "../chunk-X3PRMR5G.js";
7
+ import "../chunk-FJLINIC6.js";
8
+ import {
9
+ RadioGroup,
10
+ RadioGroupItem
11
+ } from "../chunk-HAQOT2CD.js";
12
+ import {
13
+ Field,
14
+ FieldContent,
15
+ FieldDescription,
16
+ FieldGroup,
17
+ FieldLabel,
18
+ FieldLegend,
19
+ FieldSet,
20
+ FieldTitle
21
+ } from "../chunk-TWCJMFST.js";
22
+ import "../chunk-HYTILYE5.js";
23
+ import {
24
+ Icon
25
+ } from "../chunk-KN4RPX35.js";
26
+ import "../chunk-E2TQMDO7.js";
27
+ import {
28
+ NEUTRAL_PALETTE,
29
+ NEUTRAL_THEME_ID,
30
+ paletteStyle
31
+ } from "../chunk-F3DAFAMD.js";
32
+ import {
33
+ cn
34
+ } from "../chunk-G6SRSWXB.js";
35
+
36
+ // src/primitives/theme-selector.tsx
37
+ import { useId, useMemo } from "react";
38
+ import { Monitor, Moon, Sun } from "lucide-react";
39
+ import { jsx, jsxs } from "react/jsx-runtime";
40
+ var MODES = ["light", "dark", "system"];
41
+ var DEFAULT_PALETTES = [NEUTRAL_PALETTE];
42
+ function isMode(value) {
43
+ return MODES.includes(value);
44
+ }
45
+ function PalettePreview({ palette, mode, className }) {
46
+ const tokens = mode ? palette[mode] : void 0;
47
+ const style = useMemo(
48
+ () => tokens ? paletteStyle(tokens, palette.radius) : void 0,
49
+ [tokens, palette.radius]
50
+ );
51
+ return /* @__PURE__ */ jsxs(
52
+ "span",
53
+ {
54
+ "data-slot": "palette-preview",
55
+ "data-theme": palette.id,
56
+ "data-mode": mode,
57
+ "aria-hidden": "true",
58
+ style,
59
+ className: cn(
60
+ "pointer-events-none flex h-24 w-full select-none overflow-hidden rounded-md border border-border bg-background",
61
+ className
62
+ ),
63
+ children: [
64
+ /* @__PURE__ */ jsxs("span", { className: "flex w-1/4 flex-col gap-1.5 bg-sidebar p-2", children: [
65
+ /* @__PURE__ */ jsx("span", { className: "h-1.5 w-3/4 rounded-full bg-sidebar-primary" }),
66
+ /* @__PURE__ */ jsx("span", { className: "h-1.5 w-full rounded-full bg-sidebar-accent" }),
67
+ /* @__PURE__ */ jsx("span", { className: "h-1.5 w-2/3 rounded-full bg-sidebar-accent" }),
68
+ /* @__PURE__ */ jsx("span", { className: "h-1.5 w-5/6 rounded-full bg-sidebar-accent" })
69
+ ] }),
70
+ /* @__PURE__ */ jsxs("span", { className: "flex min-w-0 flex-1 flex-col gap-2 p-2", children: [
71
+ /* @__PURE__ */ jsxs("span", { className: "flex items-center gap-1.5", children: [
72
+ /* @__PURE__ */ jsx("span", { className: "h-2 w-1/3 rounded-full bg-foreground/70" }),
73
+ /* @__PURE__ */ jsx("span", { className: "ml-auto h-3 w-8 rounded-sm bg-primary" })
74
+ ] }),
75
+ /* @__PURE__ */ jsxs("span", { className: "flex flex-1 flex-col gap-1.5 rounded-lg border border-border bg-card p-2", children: [
76
+ /* @__PURE__ */ jsx("span", { className: "h-1.5 w-full rounded-full bg-muted-foreground/40" }),
77
+ /* @__PURE__ */ jsx("span", { className: "h-1.5 w-4/5 rounded-full bg-muted-foreground/40" }),
78
+ /* @__PURE__ */ jsxs("span", { className: "flex gap-1 pt-0.5", children: [
79
+ /* @__PURE__ */ jsx("span", { className: "h-1.5 w-4 rounded-full bg-[hsl(var(--chart-1))]" }),
80
+ /* @__PURE__ */ jsx("span", { className: "h-1.5 w-4 rounded-full bg-[hsl(var(--chart-2))]" }),
81
+ /* @__PURE__ */ jsx("span", { className: "h-1.5 w-4 rounded-full bg-[hsl(var(--chart-3))]" })
82
+ ] })
83
+ ] })
84
+ ] })
85
+ ]
86
+ }
87
+ );
88
+ }
89
+ function PaletteOption({ palette, id }) {
90
+ const titleId = `${id}-title`;
91
+ const descriptionId = `${id}-description`;
92
+ return /* @__PURE__ */ jsx(
93
+ FieldLabel,
94
+ {
95
+ htmlFor: id,
96
+ className: "cursor-pointer transition-colors not-has-data-[state=checked]:hover:border-foreground/30",
97
+ children: /* @__PURE__ */ jsxs(Field, { children: [
98
+ /* @__PURE__ */ jsxs("span", { className: "flex overflow-hidden rounded-md border border-border", children: [
99
+ /* @__PURE__ */ jsx(
100
+ PalettePreview,
101
+ {
102
+ palette,
103
+ mode: "light",
104
+ className: "w-1/2 rounded-none border-0 border-r border-border"
105
+ }
106
+ ),
107
+ /* @__PURE__ */ jsx(PalettePreview, { palette, mode: "dark", className: "w-1/2 rounded-none border-0" })
108
+ ] }),
109
+ /* @__PURE__ */ jsxs(Field, { orientation: "horizontal", children: [
110
+ /* @__PURE__ */ jsxs(FieldContent, { children: [
111
+ /* @__PURE__ */ jsx(FieldTitle, { id: titleId, children: palette.label }),
112
+ palette.description ? /* @__PURE__ */ jsx(FieldDescription, { id: descriptionId, children: palette.description }) : null
113
+ ] }),
114
+ /* @__PURE__ */ jsx(
115
+ RadioGroupItem,
116
+ {
117
+ value: palette.id,
118
+ id,
119
+ "aria-labelledby": titleId,
120
+ "aria-describedby": palette.description ? descriptionId : void 0
121
+ }
122
+ )
123
+ ] })
124
+ ] })
125
+ }
126
+ );
127
+ }
128
+ function ThemeSelector({
129
+ palettes = DEFAULT_PALETTES,
130
+ palette = NEUTRAL_THEME_ID,
131
+ onPaletteChange,
132
+ mode = "system",
133
+ onModeChange,
134
+ paletteLabel = "Theme",
135
+ paletteDescription,
136
+ modeLabel = "Mode",
137
+ modeDescription,
138
+ lightLabel = "Light",
139
+ darkLabel = "Dark",
140
+ systemLabel = "System",
141
+ className
142
+ }) {
143
+ const id = useId();
144
+ const modeOptions = [
145
+ { value: "light", label: lightLabel, icon: Sun },
146
+ { value: "dark", label: darkLabel, icon: Moon },
147
+ { value: "system", label: systemLabel, icon: Monitor }
148
+ ];
149
+ return /* @__PURE__ */ jsxs(FieldGroup, { "data-slot": "theme-selector", className: cn("gap-6", className), children: [
150
+ /* @__PURE__ */ jsxs(FieldSet, { className: "gap-3", children: [
151
+ /* @__PURE__ */ jsx(FieldLegend, { variant: "label", children: modeLabel }),
152
+ modeDescription ? /* @__PURE__ */ jsx(FieldDescription, { children: modeDescription }) : null,
153
+ /* @__PURE__ */ jsx(
154
+ ToggleGroup,
155
+ {
156
+ type: "single",
157
+ variant: "outline",
158
+ value: mode ?? "",
159
+ onValueChange: (next) => {
160
+ if (isMode(next)) onModeChange?.(next);
161
+ },
162
+ className: "grid w-full grid-cols-3",
163
+ children: modeOptions.map((option) => /* @__PURE__ */ jsxs(ToggleGroupItem, { value: option.value, className: "min-w-0", children: [
164
+ /* @__PURE__ */ jsx(Icon, { icon: option.icon }),
165
+ option.label
166
+ ] }, option.value))
167
+ }
168
+ )
169
+ ] }),
170
+ /* @__PURE__ */ jsxs(FieldSet, { className: "gap-3", children: [
171
+ /* @__PURE__ */ jsx(FieldLegend, { variant: "label", children: paletteLabel }),
172
+ paletteDescription ? /* @__PURE__ */ jsx(FieldDescription, { children: paletteDescription }) : null,
173
+ /* @__PURE__ */ jsx(
174
+ RadioGroup,
175
+ {
176
+ value: palette ?? "",
177
+ onValueChange: (next) => onPaletteChange?.(next),
178
+ className: "grid-cols-1 sm:@sm/field-group:grid-cols-2 @2xl/field-group:grid-cols-3",
179
+ children: palettes.map((option) => /* @__PURE__ */ jsx(PaletteOption, { palette: option, id: `${id}-palette-${option.id}` }, option.id))
180
+ }
181
+ )
182
+ ] })
183
+ ] });
184
+ }
185
+ export {
186
+ PalettePreview,
187
+ ThemeSelector
188
+ };
@@ -1,51 +1,11 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } }"use client";
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});"use client";
2
2
 
3
3
 
4
- var _chunkGXHGMI3Zcjs = require('../chunk-GXHGMI3Z.cjs');
5
4
 
5
+ var _chunkD5EHW3O2cjs = require('../chunk-D5EHW3O2.cjs');
6
+ require('../chunk-GXHGMI3Z.cjs');
7
+ require('../chunk-KWLSBTB2.cjs');
6
8
 
7
- var _chunkKWLSBTB2cjs = require('../chunk-KWLSBTB2.cjs');
8
9
 
9
- // src/primitives/toggle-group.tsx
10
- var _react = require('react'); var React = _interopRequireWildcard(_react);
11
- var _reacttogglegroup = require('@radix-ui/react-toggle-group'); var ToggleGroupPrimitive = _interopRequireWildcard(_reacttogglegroup);
12
- var _jsxruntime = require('react/jsx-runtime');
13
- var ToggleGroupContext = React.createContext({
14
- size: "default",
15
- variant: "default"
16
- });
17
- var ToggleGroup = React.forwardRef(({ className, variant, size, children, ...props }, ref) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
18
- ToggleGroupPrimitive.Root,
19
- {
20
- ref,
21
- className: _chunkKWLSBTB2cjs.cn.call(void 0, "flex items-center justify-center gap-1", className),
22
- ...props,
23
- children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, ToggleGroupContext.Provider, { value: { variant, size }, children })
24
- }
25
- ));
26
- ToggleGroup.displayName = ToggleGroupPrimitive.Root.displayName;
27
- var ToggleGroupItem = React.forwardRef(({ className, children, variant, size, grow = false, textSize = "inherit", ...props }, ref) => {
28
- const context = React.useContext(ToggleGroupContext);
29
- return /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
30
- ToggleGroupPrimitive.Item,
31
- {
32
- ref,
33
- className: _chunkKWLSBTB2cjs.cn.call(void 0,
34
- _chunkGXHGMI3Zcjs.toggleVariants.call(void 0, {
35
- variant: context.variant || variant,
36
- size: context.size || size
37
- }),
38
- grow && "flex-1",
39
- textSize === "xs" && "text-xs",
40
- className
41
- ),
42
- ...props,
43
- children
44
- }
45
- );
46
- });
47
- ToggleGroupItem.displayName = ToggleGroupPrimitive.Item.displayName;
48
10
 
49
-
50
-
51
- exports.ToggleGroup = ToggleGroup; exports.ToggleGroupItem = ToggleGroupItem;
11
+ exports.ToggleGroup = _chunkD5EHW3O2cjs.ToggleGroup; exports.ToggleGroupItem = _chunkD5EHW3O2cjs.ToggleGroupItem;
@@ -1,50 +1,10 @@
1
1
  "use client";
2
2
  import {
3
- toggleVariants
4
- } from "../chunk-FJLINIC6.js";
5
- import {
6
- cn
7
- } from "../chunk-G6SRSWXB.js";
8
-
9
- // src/primitives/toggle-group.tsx
10
- import * as React from "react";
11
- import * as ToggleGroupPrimitive from "@radix-ui/react-toggle-group";
12
- import { jsx } from "react/jsx-runtime";
13
- var ToggleGroupContext = React.createContext({
14
- size: "default",
15
- variant: "default"
16
- });
17
- var ToggleGroup = React.forwardRef(({ className, variant, size, children, ...props }, ref) => /* @__PURE__ */ jsx(
18
- ToggleGroupPrimitive.Root,
19
- {
20
- ref,
21
- className: cn("flex items-center justify-center gap-1", className),
22
- ...props,
23
- children: /* @__PURE__ */ jsx(ToggleGroupContext.Provider, { value: { variant, size }, children })
24
- }
25
- ));
26
- ToggleGroup.displayName = ToggleGroupPrimitive.Root.displayName;
27
- var ToggleGroupItem = React.forwardRef(({ className, children, variant, size, grow = false, textSize = "inherit", ...props }, ref) => {
28
- const context = React.useContext(ToggleGroupContext);
29
- return /* @__PURE__ */ jsx(
30
- ToggleGroupPrimitive.Item,
31
- {
32
- ref,
33
- className: cn(
34
- toggleVariants({
35
- variant: context.variant || variant,
36
- size: context.size || size
37
- }),
38
- grow && "flex-1",
39
- textSize === "xs" && "text-xs",
40
- className
41
- ),
42
- ...props,
43
- children
44
- }
45
- );
46
- });
47
- ToggleGroupItem.displayName = ToggleGroupPrimitive.Item.displayName;
3
+ ToggleGroup,
4
+ ToggleGroupItem
5
+ } from "../chunk-X3PRMR5G.js";
6
+ import "../chunk-FJLINIC6.js";
7
+ import "../chunk-G6SRSWXB.js";
48
8
  export {
49
9
  ToggleGroup,
50
10
  ToggleGroupItem
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@epicbagel/saas-kit",
3
- "version": "1.3.0",
3
+ "version": "1.4.0",
4
4
  "description": "Accessible React primitives, layout components and design tokens for SaaS apps, built on Radix UI and Tailwind CSS v4.",
5
5
  "license": "MIT",
6
6
  "keywords": [
@@ -1150,6 +1150,16 @@
1150
1150
  "default": "./dist/primitives/textarea.cjs"
1151
1151
  }
1152
1152
  },
1153
+ "./primitives/theme-selector": {
1154
+ "import": {
1155
+ "types": "./dist/primitives/theme-selector.d.ts",
1156
+ "default": "./dist/primitives/theme-selector.js"
1157
+ },
1158
+ "require": {
1159
+ "types": "./dist/primitives/theme-selector.d.cts",
1160
+ "default": "./dist/primitives/theme-selector.cjs"
1161
+ }
1162
+ },
1153
1163
  "./primitives/thinking-screen": {
1154
1164
  "import": {
1155
1165
  "types": "./dist/primitives/thinking-screen.d.ts",