@kujoforall/paper-ui 0.2.0 → 0.2.2
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/CHANGELOG.md +12 -0
- package/dist/components/ui/button.d.ts.map +1 -1
- package/dist/components/ui/button.js +5 -3
- package/dist/components/ui/button.js.map +1 -1
- package/dist/components/ui/theme-toggle.d.ts.map +1 -1
- package/dist/components/ui/theme-toggle.js +17 -5
- package/dist/components/ui/theme-toggle.js.map +1 -1
- package/package.json +1 -1
- package/src/components/ui/button.tsx +5 -3
- package/src/components/ui/theme-toggle.tsx +17 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @kujoforall/paper-ui
|
|
2
2
|
|
|
3
|
+
## 0.2.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- f8b1818: `Button asChild` passes its child straight to Radix's `Slot`. It called `Children.only` first, which throws on the lazy reference a Next server component passes for a client component such as `Link`, so the server render failed and Next fell back to rendering in the browser.
|
|
8
|
+
|
|
9
|
+
## 0.2.1
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- e8f8b36: `ThemeProvider` no longer reads storage during its first render, so a server-rendered page (Next) hydrates without a mismatch on `ThemeToggle`. The stored theme is read straight after, before paint; the dark class set by `themeInitScript` is left alone until then, so there is no flash.
|
|
14
|
+
|
|
3
15
|
## 0.2.0
|
|
4
16
|
|
|
5
17
|
### Minor Changes
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"button.d.ts","sourceRoot":"","sources":["../../../src/components/ui/button.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAO,KAAK,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,
|
|
1
|
+
{"version":3,"file":"button.d.ts","sourceRoot":"","sources":["../../../src/components/ui/button.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAO,KAAK,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,EAAY,KAAK,cAAc,EAAkB,MAAM,OAAO,CAAC;AAatE,QAAA,MAAM,cAAc;;;8EAkDnB,CAAC;AASF,MAAM,WAAW,WAAY,SAAQ,cAAc,CAAC,QAAQ,CAAC,EAAE,YAAY,CAAC,OAAO,cAAc,CAAC;IAC9F,kFAAkF;IAClF,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,iFAAiF;IACjF,OAAO,CAAC,EAAE,OAAO,CAAC;CACrB;AA2BD,wBAAgB,MAAM,CAAC,EAAE,SAAS,EAAE,OAAO,EAAE,IAAI,EAAE,OAAe,EAAE,OAAe,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,KAAK,EAAE,EAAE,WAAW,+BAsCpI;AAED,OAAO,EAAE,cAAc,EAAE,CAAC"}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { Slot } from "@radix-ui/react-slot";
|
|
4
4
|
import { cva } from "class-variance-authority";
|
|
5
|
-
import { Children
|
|
5
|
+
import { Children } from "react";
|
|
6
6
|
import { cn } from "../../lib/utils.js";
|
|
7
7
|
import { Spinner } from "./spinner.js";
|
|
8
8
|
/* Buttons are small (28–40px), lightly weighted and 4px-rounded. The loudest thing a
|
|
@@ -97,9 +97,11 @@ export function Button({ className, variant, size, asChild = false, loading = fa
|
|
|
97
97
|
console.warn("paper-ui: an icon-only Button needs an aria-label (or aria-labelledby, or title) so a screen reader can name it.");
|
|
98
98
|
}
|
|
99
99
|
const classes = cn(buttonVariants({ variant, size }), loading && "text-transparent! [&>svg]:invisible", className);
|
|
100
|
+
// The child goes to Slot as it is. A Next server component that passes a client
|
|
101
|
+
// component (a Link) hands it over as a lazy reference, not an element, and Slot
|
|
102
|
+
// unwraps that; a Children.only here threw on it and failed the server render.
|
|
100
103
|
if (asChild) {
|
|
101
|
-
|
|
102
|
-
return (_jsx(Slot, { className: classes, "aria-busy": loading || undefined, onClick: onClick, ...props, children: isValidElement(child) ? child : children }));
|
|
104
|
+
return (_jsx(Slot, { className: classes, "aria-busy": loading || undefined, onClick: onClick, ...props, children: children }));
|
|
103
105
|
}
|
|
104
106
|
return (_jsxs("button", { type: type ?? "button", className: classes, "aria-busy": loading || undefined, "data-loading": loading || undefined,
|
|
105
107
|
// Not `disabled` while loading: that would drop focus from the button the
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"button.js","sourceRoot":"","sources":["../../../src/components/ui/button.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,OAAO,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAC5C,OAAO,EAAE,GAAG,EAAqB,MAAM,0BAA0B,CAAC;AAClE,OAAO,EAAE,QAAQ,
|
|
1
|
+
{"version":3,"file":"button.js","sourceRoot":"","sources":["../../../src/components/ui/button.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,OAAO,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAC5C,OAAO,EAAE,GAAG,EAAqB,MAAM,0BAA0B,CAAC;AAClE,OAAO,EAAE,QAAQ,EAAuC,MAAM,OAAO,CAAC;AACtE,OAAO,EAAE,EAAE,EAAE,MAAM,oBAAoB,CAAC;AACxC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAe,CAAC;AAExC;;;;;;;sDAOsD;AAEtD,MAAM,cAAc,GAAG,GAAG,CACtB;IACI,sFAAsF;IACtF,2DAA2D;IAC3D,2FAA2F;IAC3F,+CAA+C;IAC/C,2HAA2H;IAC3H,8CAA8C;CACjD,EACD;IACI,QAAQ,EAAE;QACN,OAAO,EAAE;YACL,iDAAiD;YACjD,OAAO,EAAE;gBACL,2FAA2F;gBAC3F,sDAAsD;aACzD;YACD,6EAA6E;YAC7E,SAAS,EAAE,yEAAyE;YACpF,0DAA0D;YAC1D,KAAK,EAAE,oDAAoD;YAC3D,6DAA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QAC1E,gEAAgE;QAChE,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,cAAc,EAAE,CAAC,CAAC,CAAC,OAAO,KAClD,KAAK,aAER,QAAQ,CAAC,QAAQ,CAAC,EAClB,OAAO,IAAI,CACR,eAAM,SAAS,EAAC,mDAAmD,YAC/D,KAAC,OAAO,IAAC,SAAS,EAAE,EAAE,CAAC,QAAQ,EAAE,WAAW,CAAC,OAAO,IAAI,WAAW,CAAC,IAAI,UAAU,CAAC,GAAI,GACpF,CACV,IACI,CACZ,CAAC;AACN,CAAC;AAED,OAAO,EAAE,cAAc,EAAE,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"theme-toggle.d.ts","sourceRoot":"","sources":["../../../src/components/ui/theme-toggle.tsx"],"names":[],"mappings":"AAGA,OAAO,
|
|
1
|
+
{"version":3,"file":"theme-toggle.d.ts","sourceRoot":"","sources":["../../../src/components/ui/theme-toggle.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAmE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AACxG,OAAO,EAAsB,KAAK,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAIpE,KAAK,iBAAiB,GAAG;IAAE,KAAK,EAAE,KAAK,CAAC;IAAC,QAAQ,EAAE,OAAO,GAAG,MAAM,CAAC;IAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAA;CAAE,CAAC;AA2BxG,wBAAgB,aAAa,CAAC,EAAE,QAAQ,EAAE,UAAsB,EAAE,EAAE;IAAE,QAAQ,EAAE,SAAS,CAAC;IAAC,UAAU,CAAC,EAAE,MAAM,CAAA;CAAE,+BAkC/G;AAED,6FAA6F;AAC7F,wBAAgB,QAAQ,IAAI,iBAAiB,CAI5C;AAKD,wBAAgB,WAAW,gCAU1B"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
3
|
import { Moon, Sun } from "lucide-react";
|
|
4
|
-
import { createContext, useContext, useEffect, useState } from "react";
|
|
4
|
+
import { createContext, useContext, useEffect, useLayoutEffect, useState } from "react";
|
|
5
5
|
import { isTheme, THEME_KEY } from "../../lib/theme.js";
|
|
6
6
|
import { Button } from "./button.js";
|
|
7
7
|
import { Tooltip } from "./tooltip.js";
|
|
@@ -21,11 +21,22 @@ function read(storageKey) {
|
|
|
21
21
|
"system" keeps following the OS after load, not just at it. Pair it with
|
|
22
22
|
themeInitScript() in <head> so the first paint is already right.
|
|
23
23
|
|
|
24
|
+
The first render is the same on the server and in the browser (system, light),
|
|
25
|
+
so a server-rendered page hydrates without a mismatch; the stored choice and the
|
|
26
|
+
system's are read straight after, before the browser paints. Until then the
|
|
27
|
+
`dark` class is left as the init script set it, so there is no flash either.
|
|
28
|
+
|
|
24
29
|
From triptrack and medialogue, 2026-12-05; it replaces the kit's animated toggle,
|
|
25
30
|
which had no system mode and could throw where storage is blocked. */
|
|
26
31
|
export function ThemeProvider({ children, storageKey = THEME_KEY }) {
|
|
27
|
-
const [theme, setThemeState] = useState(
|
|
28
|
-
const [systemDark, setSystemDark] = useState(
|
|
32
|
+
const [theme, setThemeState] = useState("system");
|
|
33
|
+
const [systemDark, setSystemDark] = useState(false);
|
|
34
|
+
const [ready, setReady] = useState(false);
|
|
35
|
+
useLayoutEffect(() => {
|
|
36
|
+
setThemeState(read(storageKey));
|
|
37
|
+
setSystemDark(prefersDark());
|
|
38
|
+
setReady(true);
|
|
39
|
+
}, [storageKey]);
|
|
29
40
|
useEffect(() => {
|
|
30
41
|
const query = window.matchMedia("(prefers-color-scheme: dark)");
|
|
31
42
|
const onChange = (event) => setSystemDark(event.matches);
|
|
@@ -34,8 +45,9 @@ export function ThemeProvider({ children, storageKey = THEME_KEY }) {
|
|
|
34
45
|
}, []);
|
|
35
46
|
const resolved = theme === "system" ? (systemDark ? "dark" : "light") : theme;
|
|
36
47
|
useEffect(() => {
|
|
37
|
-
|
|
38
|
-
|
|
48
|
+
if (ready)
|
|
49
|
+
document.documentElement.classList.toggle("dark", resolved === "dark");
|
|
50
|
+
}, [resolved, ready]);
|
|
39
51
|
const setTheme = (next) => {
|
|
40
52
|
setThemeState(next);
|
|
41
53
|
try {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"theme-toggle.js","sourceRoot":"","sources":["../../../src/components/ui/theme-toggle.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,SAAS,EAAE,QAAQ,EAAkB,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"theme-toggle.js","sourceRoot":"","sources":["../../../src/components/ui/theme-toggle.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,SAAS,EAAE,eAAe,EAAE,QAAQ,EAAkB,MAAM,OAAO,CAAC;AACxG,OAAO,EAAE,OAAO,EAAE,SAAS,EAAc,MAAM,oBAAoB,CAAC;AACpE,OAAO,EAAE,MAAM,EAAE,MAAM,aAAc,CAAC;AACtC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAe,CAAC;AAIxC,MAAM,YAAY,GAAG,aAAa,CAA2B,IAAI,CAAC,CAAC;AAEnE,MAAM,WAAW,GAAG,GAAY,EAAE,CAAC,OAAO,MAAM,KAAK,WAAW,IAAI,MAAM,CAAC,UAAU,CAAC,8BAA8B,CAAC,CAAC,OAAO,CAAC;AAE9H,SAAS,IAAI,CAAC,UAAkB;IAC5B,IAAI,CAAC;QACD,MAAM,MAAM,GAAG,YAAY,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;QAChD,OAAO,OAAO,CAA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,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,YACrG,QAAQ,KAAK,MAAM,CAAC,CAAC,CAAC,KAAC,IAAI,KAAG,CAAC,CAAC,CAAC,KAAC,GAAG,KAAG,GACpC,GACH,CACb,CAAC;AACN,CAAC"}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import { Slot } from "@radix-ui/react-slot";
|
|
4
4
|
import { cva, type VariantProps } from "class-variance-authority";
|
|
5
|
-
import { Children,
|
|
5
|
+
import { Children, type ComponentProps, type ReactNode } from "react";
|
|
6
6
|
import { cn } from "../../lib/utils.ts";
|
|
7
7
|
import { Spinner } from "./spinner.tsx";
|
|
8
8
|
|
|
@@ -114,11 +114,13 @@ export function Button({ className, variant, size, asChild = false, loading = fa
|
|
|
114
114
|
|
|
115
115
|
const classes = cn(buttonVariants({ variant, size }), loading && "text-transparent! [&>svg]:invisible", className);
|
|
116
116
|
|
|
117
|
+
// The child goes to Slot as it is. A Next server component that passes a client
|
|
118
|
+
// component (a Link) hands it over as a lazy reference, not an element, and Slot
|
|
119
|
+
// unwraps that; a Children.only here threw on it and failed the server render.
|
|
117
120
|
if (asChild) {
|
|
118
|
-
const child = Children.only(children);
|
|
119
121
|
return (
|
|
120
122
|
<Slot className={classes} aria-busy={loading || undefined} onClick={onClick} {...props}>
|
|
121
|
-
{
|
|
123
|
+
{children}
|
|
122
124
|
</Slot>
|
|
123
125
|
);
|
|
124
126
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
3
|
import { Moon, Sun } from "lucide-react";
|
|
4
|
-
import { createContext, useContext, useEffect, useState, type ReactNode } from "react";
|
|
4
|
+
import { createContext, useContext, useEffect, useLayoutEffect, useState, type ReactNode } from "react";
|
|
5
5
|
import { isTheme, THEME_KEY, type Theme } from "../../lib/theme.ts";
|
|
6
6
|
import { Button } from "./button.tsx";
|
|
7
7
|
import { Tooltip } from "./tooltip.tsx";
|
|
@@ -26,11 +26,23 @@ function read(storageKey: string): Theme {
|
|
|
26
26
|
"system" keeps following the OS after load, not just at it. Pair it with
|
|
27
27
|
themeInitScript() in <head> so the first paint is already right.
|
|
28
28
|
|
|
29
|
+
The first render is the same on the server and in the browser (system, light),
|
|
30
|
+
so a server-rendered page hydrates without a mismatch; the stored choice and the
|
|
31
|
+
system's are read straight after, before the browser paints. Until then the
|
|
32
|
+
`dark` class is left as the init script set it, so there is no flash either.
|
|
33
|
+
|
|
29
34
|
From triptrack and medialogue, 2026-12-05; it replaces the kit's animated toggle,
|
|
30
35
|
which had no system mode and could throw where storage is blocked. */
|
|
31
36
|
export function ThemeProvider({ children, storageKey = THEME_KEY }: { children: ReactNode; storageKey?: string }) {
|
|
32
|
-
const [theme, setThemeState] = useState<Theme>(
|
|
33
|
-
const [systemDark, setSystemDark] = useState(
|
|
37
|
+
const [theme, setThemeState] = useState<Theme>("system");
|
|
38
|
+
const [systemDark, setSystemDark] = useState(false);
|
|
39
|
+
const [ready, setReady] = useState(false);
|
|
40
|
+
|
|
41
|
+
useLayoutEffect(() => {
|
|
42
|
+
setThemeState(read(storageKey));
|
|
43
|
+
setSystemDark(prefersDark());
|
|
44
|
+
setReady(true);
|
|
45
|
+
}, [storageKey]);
|
|
34
46
|
|
|
35
47
|
useEffect(() => {
|
|
36
48
|
const query = window.matchMedia("(prefers-color-scheme: dark)");
|
|
@@ -42,8 +54,8 @@ export function ThemeProvider({ children, storageKey = THEME_KEY }: { children:
|
|
|
42
54
|
const resolved = theme === "system" ? (systemDark ? "dark" : "light") : theme;
|
|
43
55
|
|
|
44
56
|
useEffect(() => {
|
|
45
|
-
document.documentElement.classList.toggle("dark", resolved === "dark");
|
|
46
|
-
}, [resolved]);
|
|
57
|
+
if (ready) document.documentElement.classList.toggle("dark", resolved === "dark");
|
|
58
|
+
}, [resolved, ready]);
|
|
47
59
|
|
|
48
60
|
const setTheme = (next: Theme) => {
|
|
49
61
|
setThemeState(next);
|