@codeplex-sac/theme 0.0.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.
package/index.cjs ADDED
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const m=require("react/jsx-runtime"),t=require("react"),s=t.createContext(void 0),l="codeplex-theme",h=({children:o,defaultTheme:i="light"})=>{const[r,n]=t.useState(()=>{if(typeof window<"u"){const e=localStorage.getItem(l);if(e==="light"||e==="dark")return e;if(window.matchMedia("(prefers-color-scheme: dark)").matches)return"dark"}return i}),c=t.useCallback(e=>{const a=document.documentElement;a.classList.remove("light","dark"),a.classList.add(e),localStorage.setItem(l,e)},[]);t.useEffect(()=>{c(r)},[r,c]);const d=t.useCallback(e=>{n(e)},[]),u=t.useCallback(()=>{n(e=>e==="light"?"dark":"light")},[]);return m.jsx(s.Provider,{value:{theme:r,toggleTheme:u,setTheme:d},children:o})},T=()=>{const o=t.useContext(s);if(!o)throw new Error("useTheme must be used within a CodeplexThemeProvider");return o};exports.CodeplexThemeProvider=h;exports.ThemeContext=s;exports.useTheme=T;
package/index.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ export * from './lib/types';
2
+ export * from './lib/provider';
3
+ export * from './lib/hooks';
package/index.js ADDED
@@ -0,0 +1,39 @@
1
+ import { jsx as h } from "react/jsx-runtime";
2
+ import { createContext as u, useState as f, useCallback as r, useEffect as g, useContext as p } from "react";
3
+ const m = u(void 0), a = "codeplex-theme", v = ({
4
+ children: t,
5
+ defaultTheme: d = "light"
6
+ }) => {
7
+ const [o, s] = f(() => {
8
+ if (typeof window < "u") {
9
+ const e = localStorage.getItem(a);
10
+ if (e === "light" || e === "dark")
11
+ return e;
12
+ if (window.matchMedia("(prefers-color-scheme: dark)").matches)
13
+ return "dark";
14
+ }
15
+ return d;
16
+ }), n = r((e) => {
17
+ const c = document.documentElement;
18
+ c.classList.remove("light", "dark"), c.classList.add(e), localStorage.setItem(a, e);
19
+ }, []);
20
+ g(() => {
21
+ n(o);
22
+ }, [o, n]);
23
+ const i = r((e) => {
24
+ s(e);
25
+ }, []), l = r(() => {
26
+ s((e) => e === "light" ? "dark" : "light");
27
+ }, []);
28
+ return /* @__PURE__ */ h(m.Provider, { value: { theme: o, toggleTheme: l, setTheme: i }, children: t });
29
+ }, E = () => {
30
+ const t = p(m);
31
+ if (!t)
32
+ throw new Error("useTheme must be used within a CodeplexThemeProvider");
33
+ return t;
34
+ };
35
+ export {
36
+ v as CodeplexThemeProvider,
37
+ m as ThemeContext,
38
+ E as useTheme
39
+ };
package/lib/hooks.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ import { ThemeContextType } from './types';
2
+ export declare const useTheme: () => ThemeContextType;
@@ -0,0 +1,8 @@
1
+ import { default as React, ReactNode } from 'react';
2
+ import { CodeplexTheme, ThemeContextType } from './types';
3
+ export declare const ThemeContext: React.Context<ThemeContextType | undefined>;
4
+ export interface CodeplexThemeProviderProps {
5
+ children: ReactNode;
6
+ defaultTheme?: CodeplexTheme;
7
+ }
8
+ export declare const CodeplexThemeProvider: React.FC<CodeplexThemeProviderProps>;
package/lib/theme.d.ts ADDED
@@ -0,0 +1 @@
1
+ export declare function theme(): string;
package/lib/types.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ export type CodeplexTheme = 'light' | 'dark';
2
+ export interface ThemeContextType {
3
+ theme: CodeplexTheme;
4
+ toggleTheme: () => void;
5
+ setTheme: (theme: CodeplexTheme) => void;
6
+ }
package/package.json ADDED
@@ -0,0 +1,23 @@
1
+ {
2
+ "name": "@codeplex-sac/theme",
3
+ "version": "0.0.1",
4
+ "type": "module",
5
+ "main": "./index.js",
6
+ "types": "./index.d.ts",
7
+ "dependencies": {},
8
+ "publishConfig": {
9
+ "access": "public"
10
+ },
11
+ "exports": {
12
+ ".": {
13
+ "types": "./index.d.ts",
14
+ "import": "./index.js",
15
+ "require": "./index.cjs"
16
+ }
17
+ },
18
+ "peerDependencies": {
19
+ "react": "^19.0.0",
20
+ "react-dom": "^19.0.0"
21
+ },
22
+ "module": "./index.js"
23
+ }