@ttt-productions/theme-core 0.2.15 → 0.3.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/dist/react/index.d.ts +3 -1
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js +2 -1
- package/dist/react/index.js.map +1 -1
- package/dist/react/theme-switcher.d.ts +38 -0
- package/dist/react/theme-switcher.d.ts.map +1 -0
- package/dist/react/theme-switcher.js +27 -0
- package/dist/react/theme-switcher.js.map +1 -0
- package/package.json +1 -1
package/dist/react/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"AAEA,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,YAAY,EAAE,kBAAkB,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC"}
|
package/dist/react/index.js
CHANGED
package/dist/react/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
export interface ThemeOption {
|
|
3
|
+
/** Theme value passed to next-themes' setTheme. */
|
|
4
|
+
value: string;
|
|
5
|
+
/** Human-readable label rendered in the menu. */
|
|
6
|
+
label: string;
|
|
7
|
+
/** Icon rendered next to the label and in the trigger when this theme is active. */
|
|
8
|
+
icon?: React.ReactNode;
|
|
9
|
+
}
|
|
10
|
+
export interface ThemeSwitcherProps {
|
|
11
|
+
/** Ordered list of selectable themes. */
|
|
12
|
+
themes: ThemeOption[];
|
|
13
|
+
/** Render prop for the trigger button. Receives the icon for the active theme. */
|
|
14
|
+
renderTrigger: (args: {
|
|
15
|
+
activeIcon: React.ReactNode;
|
|
16
|
+
srLabel: string;
|
|
17
|
+
disabled: boolean;
|
|
18
|
+
}) => React.ReactNode;
|
|
19
|
+
/** Render prop for the menu container. */
|
|
20
|
+
renderMenu: (args: {
|
|
21
|
+
children: React.ReactNode;
|
|
22
|
+
}) => React.ReactNode;
|
|
23
|
+
/** Render prop for each menu item. */
|
|
24
|
+
renderItem: (args: {
|
|
25
|
+
option: ThemeOption;
|
|
26
|
+
isActive: boolean;
|
|
27
|
+
onSelect: () => void;
|
|
28
|
+
}) => React.ReactNode;
|
|
29
|
+
/** Accessible label for the trigger. Defaults to "Toggle theme". */
|
|
30
|
+
srLabel?: string;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Headless, fully-render-prop-driven theme switcher.
|
|
34
|
+
* theme-core owns the next-themes integration and the "available themes" data shape.
|
|
35
|
+
* Consumers own all visual styling — wrap their own DropdownMenu / Button / Icon set.
|
|
36
|
+
*/
|
|
37
|
+
export declare function ThemeSwitcher({ themes, renderTrigger, renderMenu, renderItem, srLabel, }: ThemeSwitcherProps): import("react/jsx-runtime").JSX.Element;
|
|
38
|
+
//# sourceMappingURL=theme-switcher.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"theme-switcher.d.ts","sourceRoot":"","sources":["../../src/react/theme-switcher.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAG/B,MAAM,WAAW,WAAW;IAC1B,mDAAmD;IACnD,KAAK,EAAE,MAAM,CAAC;IACd,iDAAiD;IACjD,KAAK,EAAE,MAAM,CAAC;IACd,oFAAoF;IACpF,IAAI,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;CACxB;AAED,MAAM,WAAW,kBAAkB;IACjC,yCAAyC;IACzC,MAAM,EAAE,WAAW,EAAE,CAAC;IACtB,kFAAkF;IAClF,aAAa,EAAE,CAAC,IAAI,EAAE;QACpB,UAAU,EAAE,KAAK,CAAC,SAAS,CAAC;QAC5B,OAAO,EAAE,MAAM,CAAC;QAChB,QAAQ,EAAE,OAAO,CAAC;KACnB,KAAK,KAAK,CAAC,SAAS,CAAC;IACtB,0CAA0C;IAC1C,UAAU,EAAE,CAAC,IAAI,EAAE;QAAE,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;KAAE,KAAK,KAAK,CAAC,SAAS,CAAC;IACrE,sCAAsC;IACtC,UAAU,EAAE,CAAC,IAAI,EAAE;QACjB,MAAM,EAAE,WAAW,CAAC;QACpB,QAAQ,EAAE,OAAO,CAAC;QAClB,QAAQ,EAAE,MAAM,IAAI,CAAC;KACtB,KAAK,KAAK,CAAC,SAAS,CAAC;IACtB,oEAAoE;IACpE,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,EAC5B,MAAM,EACN,aAAa,EACb,UAAU,EACV,UAAU,EACV,OAAwB,GACzB,EAAE,kBAAkB,2CAyBpB"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import { useTheme } from "next-themes";
|
|
5
|
+
/**
|
|
6
|
+
* Headless, fully-render-prop-driven theme switcher.
|
|
7
|
+
* theme-core owns the next-themes integration and the "available themes" data shape.
|
|
8
|
+
* Consumers own all visual styling — wrap their own DropdownMenu / Button / Icon set.
|
|
9
|
+
*/
|
|
10
|
+
export function ThemeSwitcher({ themes, renderTrigger, renderMenu, renderItem, srLabel = "Toggle theme", }) {
|
|
11
|
+
const { theme, setTheme } = useTheme();
|
|
12
|
+
const [mounted, setMounted] = React.useState(false);
|
|
13
|
+
React.useEffect(() => setMounted(true), []);
|
|
14
|
+
const active = themes.find((t) => t.value === theme);
|
|
15
|
+
const activeIcon = active?.icon ?? null;
|
|
16
|
+
const trigger = renderTrigger({ activeIcon, srLabel, disabled: !mounted });
|
|
17
|
+
if (!mounted)
|
|
18
|
+
return _jsx(_Fragment, { children: trigger });
|
|
19
|
+
return (_jsx(_Fragment, { children: renderMenu({
|
|
20
|
+
children: themes.map((option) => renderItem({
|
|
21
|
+
option,
|
|
22
|
+
isActive: option.value === theme,
|
|
23
|
+
onSelect: () => setTheme(option.value),
|
|
24
|
+
})),
|
|
25
|
+
}) }));
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=theme-switcher.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"theme-switcher.js","sourceRoot":"","sources":["../../src/react/theme-switcher.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAgCvC;;;;GAIG;AACH,MAAM,UAAU,aAAa,CAAC,EAC5B,MAAM,EACN,aAAa,EACb,UAAU,EACV,UAAU,EACV,OAAO,GAAG,cAAc,GACL;IACnB,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,GAAG,QAAQ,EAAE,CAAC;IACvC,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IACpD,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC,CAAC;IAE5C,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EA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