@tokiforge/styled-components 2.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/LICENSE +17 -0
- package/README.md +76 -0
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +24 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/package.json +67 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
GNU AFFERO GENERAL PUBLIC LICENSE
|
|
2
|
+
Version 3, 19 November 2007
|
|
3
|
+
|
|
4
|
+
Copyright (C) 2026 TokiForge Community
|
|
5
|
+
|
|
6
|
+
This program is free software: you can redistribute it and/or modify
|
|
7
|
+
it under the terms of the GNU Affero General Public License as published by
|
|
8
|
+
the Free Software Foundation, either version 3 of the License, or
|
|
9
|
+
(at your option) any later version.
|
|
10
|
+
|
|
11
|
+
This program is distributed in the hope that it will be useful,
|
|
12
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14
|
+
GNU Affero General Public License for more details.
|
|
15
|
+
|
|
16
|
+
You should have received a copy of the GNU Affero General Public License
|
|
17
|
+
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
package/README.md
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
# @tokiforge/styled-components
|
|
2
|
+
|
|
3
|
+
styled-components CSS-in-JS adapter for TokiForge theming system.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @tokiforge/styled-components @tokiforge/core styled-components
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```tsx
|
|
14
|
+
import { ThemeProvider, useTheme, styled } from "@tokiforge/styled-components";
|
|
15
|
+
|
|
16
|
+
const StyledButton = styled.button`
|
|
17
|
+
background-color: var(--hf-color-primary);
|
|
18
|
+
color: white;
|
|
19
|
+
padding: 12px 24px;
|
|
20
|
+
border: none;
|
|
21
|
+
border-radius: 4px;
|
|
22
|
+
`;
|
|
23
|
+
|
|
24
|
+
function App() {
|
|
25
|
+
return (
|
|
26
|
+
<ThemeProvider config={config}>
|
|
27
|
+
<ThemeSwitcher />
|
|
28
|
+
<StyledButton>Click me</StyledButton>
|
|
29
|
+
</ThemeProvider>
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function ThemeSwitcher() {
|
|
34
|
+
const { theme, setTheme, availableThemes } = useTheme();
|
|
35
|
+
|
|
36
|
+
return (
|
|
37
|
+
<select value={theme} onChange={(e) => setTheme(e.target.value)}>
|
|
38
|
+
{availableThemes.map((t) => (
|
|
39
|
+
<option key={t} value={t}>{t}</option>
|
|
40
|
+
))}
|
|
41
|
+
</select>
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## API
|
|
47
|
+
|
|
48
|
+
### `ThemeProvider`
|
|
49
|
+
|
|
50
|
+
styled-components compatible theme provider.
|
|
51
|
+
|
|
52
|
+
**Props:**
|
|
53
|
+
- `config`: Theme configuration
|
|
54
|
+
- `prefix?`: CSS variable prefix (default: `hf`)
|
|
55
|
+
- `children`: React children
|
|
56
|
+
|
|
57
|
+
### `useTheme()`
|
|
58
|
+
|
|
59
|
+
Hook to access theme context.
|
|
60
|
+
|
|
61
|
+
**Returns:** `{ runtime, currentTheme, tokens, setTheme, nextTheme, availableThemes }`
|
|
62
|
+
|
|
63
|
+
### `styled`
|
|
64
|
+
|
|
65
|
+
Re-exported from `styled-components` for convenience.
|
|
66
|
+
|
|
67
|
+
## Features
|
|
68
|
+
|
|
69
|
+
- styled-components v5+ support
|
|
70
|
+
- Runtime theme switching
|
|
71
|
+
- CSS variable injection
|
|
72
|
+
- TypeScript support
|
|
73
|
+
|
|
74
|
+
## License
|
|
75
|
+
|
|
76
|
+
AGPL-3.0
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
'use strict';var react=require('react'),core=require('@tokiforge/core'),styledComponents=require('styled-components'),jsxRuntime=require('react/jsx-runtime');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var styledComponents__default=/*#__PURE__*/_interopDefault(styledComponents);var h=react.createContext(null);function E({config:n,children:T,prefix:m="hf"}){let[e]=react.useState(()=>new core.ThemeRuntime(n)),[s,a]=react.useState(()=>e.getCurrentTheme()),[c,l]=react.useState(()=>e.getThemeTokens(s??e.getAvailableThemes()[0]));react.useEffect(()=>{e.init(":root",m);let t=()=>{let i=e.getCurrentTheme(),v=e.getThemeTokens(i??e.getAvailableThemes()[0]);a(i),l(v);};return window.addEventListener("tokiforge:theme-change",t),()=>{window.removeEventListener("tokiforge:theme-change",t);}},[e,m]);let u=react.useCallback(t=>{e.nextTheme();},[e]),g=react.useCallback(async t=>{e.applyTheme(t);},[e]),d=react.useCallback(async()=>{let t=e.nextTheme();e.applyTheme(t);},[e]),f={runtime:e,currentTheme:s,tokens:c,switchTheme:u,setTheme:g,nextTheme:d,availableThemes:e.getAvailableThemes()};return jsxRuntime.jsx(h.Provider,{value:f,children:T})}function N(){let n=react.useContext(h);if(!n)throw new Error("useTheme must be used within a ThemeProvider");return n}Object.defineProperty(exports,"styled",{enumerable:true,get:function(){return styledComponents__default.default}});exports.ThemeProvider=E;exports.useTheme=N;Object.keys(core).forEach(function(k){if(k!=='default'&&!Object.prototype.hasOwnProperty.call(exports,k))Object.defineProperty(exports,k,{enumerable:true,get:function(){return core[k]}})});//# sourceMappingURL=index.cjs.map
|
|
2
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.tsx"],"names":["ThemeContext","createContext","ThemeProvider","config","children","prefix","runtime","useState","ThemeRuntime","currentTheme","setCurrentTheme","tokens","setTokens","useEffect","handleThemeChange","newTheme","newTokens","switchTheme","useCallback","_themeName","setTheme","themeName","nextTheme","next","contextValue","jsx","useTheme","context","useContext"],"mappings":"4SAgBA,IAAMA,CAAAA,CAAeC,mBAAAA,CAAwC,IAAI,CAAA,CAQ1D,SAASC,CAAAA,CAAc,CAC5B,MAAA,CAAAC,CAAAA,CACA,SAAAC,CAAAA,CACA,MAAA,CAAAC,CAAAA,CAAS,IACX,CAAA,CAAiC,CAC/B,GAAM,CAACC,CAAO,CAAA,CAAIC,cAAAA,CAAS,IAAM,IAAIC,kBAAaL,CAAM,CAAC,CAAA,CACnD,CAACM,CAAAA,CAAcC,CAAe,EAAIH,cAAAA,CAAwB,IAAMD,CAAAA,CAAQ,eAAA,EAAiB,CAAA,CACzF,CAACK,CAAAA,CAAQC,CAAS,CAAA,CAAIL,cAAAA,CAAuB,IAAMD,CAAAA,CAAQ,eAAeG,CAAAA,EAAgBH,CAAAA,CAAQ,kBAAA,EAAmB,CAAE,CAAC,CAAC,CAAC,CAAA,CAEhIO,eAAAA,CAAU,IAAM,CACdP,CAAAA,CAAQ,IAAA,CAAK,QAASD,CAAM,CAAA,CAC5B,IAAMS,CAAAA,CAAoB,IAAM,CAC9B,IAAMC,CAAAA,CAAWT,CAAAA,CAAQ,eAAA,EAAgB,CACnCU,CAAAA,CAAYV,CAAAA,CAAQ,eAAeS,CAAAA,EAAYT,CAAAA,CAAQ,kBAAA,EAAmB,CAAE,CAAC,CAAC,CAAA,CACpFI,CAAAA,CAAgBK,CAAQ,CAAA,CACxBH,CAAAA,CAAUI,CAAS,EACrB,CAAA,CACA,cAAO,gBAAA,CAAiB,wBAAA,CAA0BF,CAAiB,CAAA,CAC5D,IAAM,CACX,OAAO,mBAAA,CAAoB,wBAAA,CAA0BA,CAAiB,EACxE,CACF,CAAA,CAAG,CAACR,CAAAA,CAASD,CAAM,CAAC,CAAA,CAEpB,IAAMY,CAAAA,CAAcC,kBACjBC,CAAAA,EAAuB,CACtBb,CAAAA,CAAQ,SAAA,GACV,CAAA,CACA,CAACA,CAAO,CACV,CAAA,CAEMc,CAAAA,CAAWF,iBAAAA,CACf,MAAOG,GAAsB,CAC3Bf,CAAAA,CAAQ,UAAA,CAAWe,CAAS,EAC9B,CAAA,CACA,CAACf,CAAO,CACV,CAAA,CAEMgB,CAAAA,CAAYJ,iBAAAA,CAAY,SAAY,CACxC,IAAMK,CAAAA,CAAOjB,CAAAA,CAAQ,SAAA,EAAU,CAC/BA,CAAAA,CAAQ,WAAWiB,CAAI,EACzB,CAAA,CAAG,CAACjB,CAAO,CAAC,EAENkB,CAAAA,CAAkC,CACtC,OAAA,CAAAlB,CAAAA,CACA,YAAA,CAAAG,CAAAA,CACA,OAAAE,CAAAA,CACA,WAAA,CAAAM,CAAAA,CACA,QAAA,CAAAG,CAAAA,CACA,SAAA,CAAAE,EACA,eAAA,CAAiBhB,CAAAA,CAAQ,kBAAA,EAC3B,CAAA,CAEA,OAAOmB,eAACzB,CAAAA,CAAa,QAAA,CAAb,CAAsB,KAAA,CAAOwB,CAAAA,CAAe,QAAA,CAAApB,EAAS,CAC/D,CAEO,SAASsB,CAAAA,EAA8B,CAC5C,IAAMC,EAAUC,gBAAAA,CAAW5B,CAAY,CAAA,CACvC,GAAI,CAAC2B,CAAAA,CACH,MAAM,IAAI,KAAA,CAAM,8CAA8C,CAAA,CAEhE,OAAOA,CACT","file":"index.cjs","sourcesContent":["import React, { createContext, useContext, useState, useEffect, useCallback } from 'react';\nimport { ThemeRuntime } from '@tokiforge/core';\nimport type { DesignTokens, ThemeConfig } from '@tokiforge/core';\nimport styled from 'styled-components';\nexport * from '@tokiforge/core';\n\ninterface ThemeContextValue {\n runtime: ThemeRuntime;\n currentTheme: string | null;\n tokens: DesignTokens;\n switchTheme: (themeName: string) => void;\n setTheme: (themeName: string) => Promise<void>;\n nextTheme: () => Promise<void>;\n availableThemes: string[];\n}\n\nconst ThemeContext = createContext<ThemeContextValue | null>(null);\n\ninterface ThemeProviderProps {\n config: ThemeConfig;\n children: React.ReactNode;\n prefix?: string;\n}\n\nexport function ThemeProvider({\n config,\n children,\n prefix = 'hf',\n}: Readonly<ThemeProviderProps>) {\n const [runtime] = useState(() => new ThemeRuntime(config));\n const [currentTheme, setCurrentTheme] = useState<string | null>(() => runtime.getCurrentTheme());\n const [tokens, setTokens] = useState<DesignTokens>(() => runtime.getThemeTokens(currentTheme ?? runtime.getAvailableThemes()[0]));\n\n useEffect(() => {\n runtime.init(':root', prefix);\n const handleThemeChange = () => {\n const newTheme = runtime.getCurrentTheme();\n const newTokens = runtime.getThemeTokens(newTheme ?? runtime.getAvailableThemes()[0]);\n setCurrentTheme(newTheme);\n setTokens(newTokens);\n };\n window.addEventListener('tokiforge:theme-change', handleThemeChange);\n return () => {\n window.removeEventListener('tokiforge:theme-change', handleThemeChange);\n };\n }, [runtime, prefix]);\n\n const switchTheme = useCallback(\n (_themeName: string) => {\n runtime.nextTheme();\n },\n [runtime]\n );\n\n const setTheme = useCallback(\n async (themeName: string) => {\n runtime.applyTheme(themeName);\n },\n [runtime]\n );\n\n const nextTheme = useCallback(async () => {\n const next = runtime.nextTheme();\n runtime.applyTheme(next);\n }, [runtime]);\n\n const contextValue: ThemeContextValue = {\n runtime,\n currentTheme,\n tokens,\n switchTheme,\n setTheme,\n nextTheme,\n availableThemes: runtime.getAvailableThemes(),\n };\n\n return <ThemeContext.Provider value={contextValue}>{children}</ThemeContext.Provider>;\n}\n\nexport function useTheme(): ThemeContextValue {\n const context = useContext(ThemeContext);\n if (!context) {\n throw new Error('useTheme must be used within a ThemeProvider');\n }\n return context;\n}\n\nexport { styled };\n"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { ThemeConfig, ThemeRuntime, DesignTokens } from '@tokiforge/core';
|
|
4
|
+
export * from '@tokiforge/core';
|
|
5
|
+
export { default as styled } from 'styled-components';
|
|
6
|
+
|
|
7
|
+
interface ThemeContextValue {
|
|
8
|
+
runtime: ThemeRuntime;
|
|
9
|
+
currentTheme: string | null;
|
|
10
|
+
tokens: DesignTokens;
|
|
11
|
+
switchTheme: (themeName: string) => void;
|
|
12
|
+
setTheme: (themeName: string) => Promise<void>;
|
|
13
|
+
nextTheme: () => Promise<void>;
|
|
14
|
+
availableThemes: string[];
|
|
15
|
+
}
|
|
16
|
+
interface ThemeProviderProps {
|
|
17
|
+
config: ThemeConfig;
|
|
18
|
+
children: React.ReactNode;
|
|
19
|
+
prefix?: string;
|
|
20
|
+
}
|
|
21
|
+
declare function ThemeProvider({ config, children, prefix, }: Readonly<ThemeProviderProps>): react_jsx_runtime.JSX.Element;
|
|
22
|
+
declare function useTheme(): ThemeContextValue;
|
|
23
|
+
|
|
24
|
+
export { ThemeProvider, useTheme };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { ThemeConfig, ThemeRuntime, DesignTokens } from '@tokiforge/core';
|
|
4
|
+
export * from '@tokiforge/core';
|
|
5
|
+
export { default as styled } from 'styled-components';
|
|
6
|
+
|
|
7
|
+
interface ThemeContextValue {
|
|
8
|
+
runtime: ThemeRuntime;
|
|
9
|
+
currentTheme: string | null;
|
|
10
|
+
tokens: DesignTokens;
|
|
11
|
+
switchTheme: (themeName: string) => void;
|
|
12
|
+
setTheme: (themeName: string) => Promise<void>;
|
|
13
|
+
nextTheme: () => Promise<void>;
|
|
14
|
+
availableThemes: string[];
|
|
15
|
+
}
|
|
16
|
+
interface ThemeProviderProps {
|
|
17
|
+
config: ThemeConfig;
|
|
18
|
+
children: React.ReactNode;
|
|
19
|
+
prefix?: string;
|
|
20
|
+
}
|
|
21
|
+
declare function ThemeProvider({ config, children, prefix, }: Readonly<ThemeProviderProps>): react_jsx_runtime.JSX.Element;
|
|
22
|
+
declare function useTheme(): ThemeContextValue;
|
|
23
|
+
|
|
24
|
+
export { ThemeProvider, useTheme };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import {createContext,useState,useEffect,useCallback,useContext}from'react';import {ThemeRuntime}from'@tokiforge/core';export*from'@tokiforge/core';export{default as styled}from'styled-components';import {jsx}from'react/jsx-runtime';var h=createContext(null);function E({config:n,children:T,prefix:m="hf"}){let[e]=useState(()=>new ThemeRuntime(n)),[s,a]=useState(()=>e.getCurrentTheme()),[c,l]=useState(()=>e.getThemeTokens(s??e.getAvailableThemes()[0]));useEffect(()=>{e.init(":root",m);let t=()=>{let i=e.getCurrentTheme(),v=e.getThemeTokens(i??e.getAvailableThemes()[0]);a(i),l(v);};return window.addEventListener("tokiforge:theme-change",t),()=>{window.removeEventListener("tokiforge:theme-change",t);}},[e,m]);let u=useCallback(t=>{e.nextTheme();},[e]),g=useCallback(async t=>{e.applyTheme(t);},[e]),d=useCallback(async()=>{let t=e.nextTheme();e.applyTheme(t);},[e]),f={runtime:e,currentTheme:s,tokens:c,switchTheme:u,setTheme:g,nextTheme:d,availableThemes:e.getAvailableThemes()};return jsx(h.Provider,{value:f,children:T})}function N(){let n=useContext(h);if(!n)throw new Error("useTheme must be used within a ThemeProvider");return n}export{E as ThemeProvider,N as useTheme};//# sourceMappingURL=index.js.map
|
|
2
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.tsx"],"names":["ThemeContext","createContext","ThemeProvider","config","children","prefix","runtime","useState","ThemeRuntime","currentTheme","setCurrentTheme","tokens","setTokens","useEffect","handleThemeChange","newTheme","newTokens","switchTheme","useCallback","_themeName","setTheme","themeName","nextTheme","next","contextValue","jsx","useTheme","context","useContext"],"mappings":"yOAgBA,IAAMA,CAAAA,CAAeC,aAAAA,CAAwC,IAAI,CAAA,CAQ1D,SAASC,CAAAA,CAAc,CAC5B,MAAA,CAAAC,CAAAA,CACA,SAAAC,CAAAA,CACA,MAAA,CAAAC,CAAAA,CAAS,IACX,CAAA,CAAiC,CAC/B,GAAM,CAACC,CAAO,CAAA,CAAIC,QAAAA,CAAS,IAAM,IAAIC,aAAaL,CAAM,CAAC,CAAA,CACnD,CAACM,CAAAA,CAAcC,CAAe,EAAIH,QAAAA,CAAwB,IAAMD,CAAAA,CAAQ,eAAA,EAAiB,CAAA,CACzF,CAACK,CAAAA,CAAQC,CAAS,CAAA,CAAIL,QAAAA,CAAuB,IAAMD,CAAAA,CAAQ,eAAeG,CAAAA,EAAgBH,CAAAA,CAAQ,kBAAA,EAAmB,CAAE,CAAC,CAAC,CAAC,CAAA,CAEhIO,SAAAA,CAAU,IAAM,CACdP,CAAAA,CAAQ,IAAA,CAAK,QAASD,CAAM,CAAA,CAC5B,IAAMS,CAAAA,CAAoB,IAAM,CAC9B,IAAMC,CAAAA,CAAWT,CAAAA,CAAQ,eAAA,EAAgB,CACnCU,CAAAA,CAAYV,CAAAA,CAAQ,eAAeS,CAAAA,EAAYT,CAAAA,CAAQ,kBAAA,EAAmB,CAAE,CAAC,CAAC,CAAA,CACpFI,CAAAA,CAAgBK,CAAQ,CAAA,CACxBH,CAAAA,CAAUI,CAAS,EACrB,CAAA,CACA,cAAO,gBAAA,CAAiB,wBAAA,CAA0BF,CAAiB,CAAA,CAC5D,IAAM,CACX,OAAO,mBAAA,CAAoB,wBAAA,CAA0BA,CAAiB,EACxE,CACF,CAAA,CAAG,CAACR,CAAAA,CAASD,CAAM,CAAC,CAAA,CAEpB,IAAMY,CAAAA,CAAcC,YACjBC,CAAAA,EAAuB,CACtBb,CAAAA,CAAQ,SAAA,GACV,CAAA,CACA,CAACA,CAAO,CACV,CAAA,CAEMc,CAAAA,CAAWF,WAAAA,CACf,MAAOG,GAAsB,CAC3Bf,CAAAA,CAAQ,UAAA,CAAWe,CAAS,EAC9B,CAAA,CACA,CAACf,CAAO,CACV,CAAA,CAEMgB,CAAAA,CAAYJ,WAAAA,CAAY,SAAY,CACxC,IAAMK,CAAAA,CAAOjB,CAAAA,CAAQ,SAAA,EAAU,CAC/BA,CAAAA,CAAQ,WAAWiB,CAAI,EACzB,CAAA,CAAG,CAACjB,CAAO,CAAC,EAENkB,CAAAA,CAAkC,CACtC,OAAA,CAAAlB,CAAAA,CACA,YAAA,CAAAG,CAAAA,CACA,OAAAE,CAAAA,CACA,WAAA,CAAAM,CAAAA,CACA,QAAA,CAAAG,CAAAA,CACA,SAAA,CAAAE,EACA,eAAA,CAAiBhB,CAAAA,CAAQ,kBAAA,EAC3B,CAAA,CAEA,OAAOmB,IAACzB,CAAAA,CAAa,QAAA,CAAb,CAAsB,KAAA,CAAOwB,CAAAA,CAAe,QAAA,CAAApB,EAAS,CAC/D,CAEO,SAASsB,CAAAA,EAA8B,CAC5C,IAAMC,EAAUC,UAAAA,CAAW5B,CAAY,CAAA,CACvC,GAAI,CAAC2B,CAAAA,CACH,MAAM,IAAI,KAAA,CAAM,8CAA8C,CAAA,CAEhE,OAAOA,CACT","file":"index.js","sourcesContent":["import React, { createContext, useContext, useState, useEffect, useCallback } from 'react';\nimport { ThemeRuntime } from '@tokiforge/core';\nimport type { DesignTokens, ThemeConfig } from '@tokiforge/core';\nimport styled from 'styled-components';\nexport * from '@tokiforge/core';\n\ninterface ThemeContextValue {\n runtime: ThemeRuntime;\n currentTheme: string | null;\n tokens: DesignTokens;\n switchTheme: (themeName: string) => void;\n setTheme: (themeName: string) => Promise<void>;\n nextTheme: () => Promise<void>;\n availableThemes: string[];\n}\n\nconst ThemeContext = createContext<ThemeContextValue | null>(null);\n\ninterface ThemeProviderProps {\n config: ThemeConfig;\n children: React.ReactNode;\n prefix?: string;\n}\n\nexport function ThemeProvider({\n config,\n children,\n prefix = 'hf',\n}: Readonly<ThemeProviderProps>) {\n const [runtime] = useState(() => new ThemeRuntime(config));\n const [currentTheme, setCurrentTheme] = useState<string | null>(() => runtime.getCurrentTheme());\n const [tokens, setTokens] = useState<DesignTokens>(() => runtime.getThemeTokens(currentTheme ?? runtime.getAvailableThemes()[0]));\n\n useEffect(() => {\n runtime.init(':root', prefix);\n const handleThemeChange = () => {\n const newTheme = runtime.getCurrentTheme();\n const newTokens = runtime.getThemeTokens(newTheme ?? runtime.getAvailableThemes()[0]);\n setCurrentTheme(newTheme);\n setTokens(newTokens);\n };\n window.addEventListener('tokiforge:theme-change', handleThemeChange);\n return () => {\n window.removeEventListener('tokiforge:theme-change', handleThemeChange);\n };\n }, [runtime, prefix]);\n\n const switchTheme = useCallback(\n (_themeName: string) => {\n runtime.nextTheme();\n },\n [runtime]\n );\n\n const setTheme = useCallback(\n async (themeName: string) => {\n runtime.applyTheme(themeName);\n },\n [runtime]\n );\n\n const nextTheme = useCallback(async () => {\n const next = runtime.nextTheme();\n runtime.applyTheme(next);\n }, [runtime]);\n\n const contextValue: ThemeContextValue = {\n runtime,\n currentTheme,\n tokens,\n switchTheme,\n setTheme,\n nextTheme,\n availableThemes: runtime.getAvailableThemes(),\n };\n\n return <ThemeContext.Provider value={contextValue}>{children}</ThemeContext.Provider>;\n}\n\nexport function useTheme(): ThemeContextValue {\n const context = useContext(ThemeContext);\n if (!context) {\n throw new Error('useTheme must be used within a ThemeProvider');\n }\n return context;\n}\n\nexport { styled };\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tokiforge/styled-components",
|
|
3
|
+
"version": "2.3.0",
|
|
4
|
+
"description": "styled-components adapter for TokiForge theming",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.cjs",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js",
|
|
13
|
+
"require": "./dist/index.cjs"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist",
|
|
18
|
+
"README.md"
|
|
19
|
+
],
|
|
20
|
+
"sideEffects": false,
|
|
21
|
+
"peerDependencies": {
|
|
22
|
+
"@tokiforge/core": "^2.3.0",
|
|
23
|
+
"react": ">=16.8.0",
|
|
24
|
+
"styled-components": ">=5.3.0"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@testing-library/react": "^16.3.2",
|
|
28
|
+
"@types/react": "^19.2.14",
|
|
29
|
+
"@types/styled-components": "^5.1.34",
|
|
30
|
+
"jsdom": "^29.1.1",
|
|
31
|
+
"react": "^19.2.0",
|
|
32
|
+
"styled-components": "^6.1.17",
|
|
33
|
+
"tsup": "^8.0.0",
|
|
34
|
+
"typescript": "^6.0.3",
|
|
35
|
+
"vitest": "^4.1.5"
|
|
36
|
+
},
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"@tokiforge/core": "^2.3.0"
|
|
39
|
+
},
|
|
40
|
+
"keywords": [
|
|
41
|
+
"styled-components",
|
|
42
|
+
"theming",
|
|
43
|
+
"design-tokens"
|
|
44
|
+
],
|
|
45
|
+
"author": "TokiForge Community",
|
|
46
|
+
"license": "AGPL-3.0",
|
|
47
|
+
"repository": {
|
|
48
|
+
"type": "git",
|
|
49
|
+
"url": "https://github.com/TokiForge/tokiforge.git"
|
|
50
|
+
},
|
|
51
|
+
"homepage": "https://github.com/TokiForge/tokiforge#readme",
|
|
52
|
+
"bugs": {
|
|
53
|
+
"url": "https://github.com/TokiForge/tokiforge/issues"
|
|
54
|
+
},
|
|
55
|
+
"publishConfig": {
|
|
56
|
+
"access": "public"
|
|
57
|
+
},
|
|
58
|
+
"scripts": {
|
|
59
|
+
"build": "tsup",
|
|
60
|
+
"build:all": "npm run build",
|
|
61
|
+
"dev": "tsup --watch",
|
|
62
|
+
"lint": "eslint src --ext .ts,.tsx",
|
|
63
|
+
"clean": "rm -rf dist",
|
|
64
|
+
"test": "vitest run",
|
|
65
|
+
"test:watch": "vitest"
|
|
66
|
+
}
|
|
67
|
+
}
|