@razzusharma/accent-theme 1.0.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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Tourgasm
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,201 @@
1
+ # @tourgasm/accent-theme
2
+
3
+ A React hook and provider for dynamic accent color theming. Perfect for adding customizable color themes to your React applications.
4
+
5
+ ## Features
6
+
7
+ - 🎨 **8 Built-in Colors** - Teal, Blue, Purple, Rose, Amber, Emerald, Indigo, Cyan
8
+ - đŸŽ¯ **TypeScript Support** - Fully typed with generics
9
+ - 💾 **Persistence** - Automatically saves user preference to localStorage
10
+ - 🌓 **Dark Mode Compatible** - Works seamlessly with dark mode
11
+ - đŸŽ›ī¸ **Customizable** - Add your own custom colors
12
+ - đŸ“Ļ **Zero Dependencies** - Only peer dependencies on React
13
+ - đŸĒļ **Lightweight** - ~3KB gzipped
14
+
15
+ ## Installation
16
+
17
+ ```bash
18
+ npm install @tourgasm/accent-theme
19
+ # or
20
+ yarn add @tourgasm/accent-theme
21
+ # or
22
+ pnpm add @tourgasm/accent-theme
23
+ ```
24
+
25
+ ## Quick Start
26
+
27
+ ### 1. Wrap your app with the provider
28
+
29
+ ```tsx
30
+ import { AccentThemeProvider } from '@tourgasm/accent-theme';
31
+
32
+ function App() {
33
+ return (
34
+ <AccentThemeProvider>
35
+ <YourApp />
36
+ </AccentThemeProvider>
37
+ );
38
+ }
39
+ ```
40
+
41
+ ### 2. Use the hook in your components
42
+
43
+ ```tsx
44
+ import { useAccentTheme, useAccentColor } from '@tourgasm/accent-theme';
45
+
46
+ function MyComponent() {
47
+ const { accentColor, setAccentColor } = useAccentTheme();
48
+ const { primary, light, gradient } = useAccentColor();
49
+
50
+ return (
51
+ <div style={{ color: primary }}>
52
+ <h1>Current theme: {accentColor}</h1>
53
+ <button onClick={() => setAccentColor('blue')}>
54
+ Switch to Blue
55
+ </button>
56
+ </div>
57
+ );
58
+ }
59
+ ```
60
+
61
+ ### 3. Use the built-in color picker
62
+
63
+ ```tsx
64
+ import { AccentColorPicker } from '@tourgasm/accent-theme';
65
+
66
+ function Settings() {
67
+ return (
68
+ <div>
69
+ <h2>Choose your theme</h2>
70
+ <AccentColorPicker variant="inline" columns={4} />
71
+ </div>
72
+ );
73
+ }
74
+ ```
75
+
76
+ ## Configuration
77
+
78
+ ### Provider Props
79
+
80
+ | Prop | Type | Default | Description |
81
+ |------|------|---------|-------------|
82
+ | `defaultColor` | `string` | `'teal'` | Default accent color |
83
+ | `customColors` | `object` | `undefined` | Add custom colors |
84
+ | `storageKey` | `string` | `'accent-color'` | localStorage key |
85
+ | `cssVariablePrefix` | `string` | `''` | Prefix for CSS variables |
86
+
87
+ ### Custom Colors
88
+
89
+ ```tsx
90
+ import { AccentThemeProvider } from '@tourgasm/accent-theme';
91
+
92
+ const customColors = {
93
+ coral: {
94
+ name: "Coral",
95
+ primary: "16 100% 60%",
96
+ primaryForeground: "0 0% 100%",
97
+ light: "16 100% 70%",
98
+ dark: "16 100% 50%",
99
+ gradient: "from-orange-400 to-red-500",
100
+ },
101
+ };
102
+
103
+ function App() {
104
+ return (
105
+ <AccentThemeProvider
106
+ defaultColor="coral"
107
+ customColors={customColors}
108
+ >
109
+ <YourApp />
110
+ </AccentThemeProvider>
111
+ );
112
+ }
113
+ ```
114
+
115
+ ## CSS Variables
116
+
117
+ The library sets these CSS custom properties on the root element:
118
+
119
+ ```css
120
+ :root {
121
+ --primary: 174 72% 35%; /* HSL values */
122
+ --primary-foreground: 210 40% 98%;
123
+ --accent: 174 72% 45%;
124
+ --ring: 174 72% 45%;
125
+ }
126
+ ```
127
+
128
+ Use them in your CSS/Tailwind:
129
+
130
+ ```css
131
+ .my-button {
132
+ background: hsl(var(--primary));
133
+ color: hsl(var(--primary-foreground));
134
+ }
135
+ ```
136
+
137
+ ```html
138
+ <button class="bg-[hsl(var(--primary))] text-white">
139
+ Click me
140
+ </button>
141
+ ```
142
+
143
+ ## API Reference
144
+
145
+ ### `useAccentTheme()`
146
+
147
+ ```ts
148
+ const {
149
+ accentColor, // Current color name
150
+ setAccentColor, // Function to change color
151
+ accentConfig, // Full color config object
152
+ mounted, // Hydration flag
153
+ } = useAccentTheme();
154
+ ```
155
+
156
+ ### `useAccentColor()`
157
+
158
+ ```ts
159
+ const {
160
+ primary, // hsl() string for primary color
161
+ primaryForeground,// hsl() string for text color
162
+ light, // hsl() string for light variant
163
+ dark, // hsl() string for dark variant
164
+ gradient, // Tailwind gradient class
165
+ mounted, // Hydration flag
166
+ } = useAccentColor();
167
+ ```
168
+
169
+ ### `AccentColorPicker`
170
+
171
+ ```tsx
172
+ <AccentColorPicker
173
+ size="md" // 'sm' | 'md' | 'lg'
174
+ variant="dropdown" // 'dropdown' | 'inline'
175
+ columns={4} // Number of columns for inline
176
+ onChange={(color) => console.log(color)}
177
+ />
178
+ ```
179
+
180
+ ## Tailwind CSS Integration
181
+
182
+ Add to your `tailwind.config.js`:
183
+
184
+ ```js
185
+ module.exports = {
186
+ theme: {
187
+ extend: {
188
+ colors: {
189
+ primary: 'hsl(var(--primary))',
190
+ 'primary-foreground': 'hsl(var(--primary-foreground))',
191
+ accent: 'hsl(var(--accent))',
192
+ ring: 'hsl(var(--ring))',
193
+ },
194
+ },
195
+ },
196
+ }
197
+ ```
198
+
199
+ ## License
200
+
201
+ MIT Š Tourgasm
@@ -0,0 +1,83 @@
1
+ import * as React from 'react';
2
+ import { ReactNode } from 'react';
3
+
4
+ type AccentColor = "teal" | "blue" | "purple" | "rose" | "amber" | "emerald" | "indigo" | "cyan" | string;
5
+ interface AccentColorConfig {
6
+ name: string;
7
+ primary: string;
8
+ primaryForeground: string;
9
+ light: string;
10
+ dark: string;
11
+ gradient: string;
12
+ }
13
+ interface AccentThemeContextType {
14
+ accentColor: AccentColor;
15
+ setAccentColor: (color: AccentColor) => void;
16
+ accentConfig: AccentColorConfig;
17
+ mounted: boolean;
18
+ }
19
+ interface AccentThemeProviderProps {
20
+ children: ReactNode;
21
+ defaultColor?: AccentColor;
22
+ customColors?: Record<string, AccentColorConfig>;
23
+ storageKey?: string;
24
+ cssVariablePrefix?: string;
25
+ }
26
+
27
+ declare function AccentThemeProvider({ children, defaultColor, customColors, storageKey, cssVariablePrefix }: AccentThemeProviderProps): React.FunctionComponentElement<React.ProviderProps<AccentThemeContextType>>;
28
+ declare function useAccentTheme(): AccentThemeContextType;
29
+ declare function useAccentColor(): {
30
+ primary: string;
31
+ primaryForeground: string;
32
+ light: string;
33
+ dark: string;
34
+ gradient: string;
35
+ mounted: boolean;
36
+ };
37
+
38
+ interface AccentColorPickerProps {
39
+ size?: "sm" | "md" | "lg";
40
+ variant?: "dropdown" | "inline";
41
+ columns?: number;
42
+ className?: string;
43
+ onChange?: (color: AccentColor) => void;
44
+ }
45
+ declare function AccentColorPicker({ size, variant, columns, className, onChange, }: AccentColorPickerProps): React.DetailedReactHTMLElement<{
46
+ className: string;
47
+ }, HTMLElement>;
48
+ interface AccentColorSwatchProps {
49
+ color: AccentColor;
50
+ isSelected?: boolean;
51
+ onClick?: () => void;
52
+ size?: "sm" | "md" | "lg";
53
+ }
54
+ declare function AccentColorSwatch({ color, isSelected, onClick, size }: AccentColorSwatchProps): React.DetailedReactHTMLElement<{
55
+ onClick: (() => void) | undefined;
56
+ className: string;
57
+ style: {
58
+ [x: string]: string;
59
+ background: string;
60
+ };
61
+ title: string;
62
+ }, HTMLElement> | null;
63
+
64
+ declare const defaultAccentColors: Record<AccentColor, AccentColorConfig>;
65
+
66
+ declare function generateCSSVariables(config: AccentColorConfig, prefix?: string): Record<string, string>;
67
+ declare function applyCSSVariables(element: HTMLElement, variables: Record<string, string>): void;
68
+ declare function createGradient(config: AccentColorConfig, direction?: string): string;
69
+ declare function createShadow(config: AccentColorConfig, intensity?: number, blur?: number): string;
70
+ declare function adjustHSL(hsl: string, adjustments: {
71
+ hue?: number;
72
+ saturation?: number;
73
+ lightness?: number;
74
+ }): string;
75
+ declare function getContrastColor(hsl: string, threshold?: number): "black" | "white";
76
+ declare function isClient(): boolean;
77
+ declare const storage: {
78
+ get: (key: string, defaultValue?: string) => string | undefined;
79
+ set: (key: string, value: string) => void;
80
+ remove: (key: string) => void;
81
+ };
82
+
83
+ export { type AccentColor, type AccentColorConfig, AccentColorPicker, AccentColorSwatch, type AccentThemeContextType, AccentThemeProvider, type AccentThemeProviderProps, adjustHSL, applyCSSVariables, createGradient, createShadow, defaultAccentColors, generateCSSVariables, getContrastColor, isClient, storage, useAccentColor, useAccentTheme };
@@ -0,0 +1,83 @@
1
+ import * as React from 'react';
2
+ import { ReactNode } from 'react';
3
+
4
+ type AccentColor = "teal" | "blue" | "purple" | "rose" | "amber" | "emerald" | "indigo" | "cyan" | string;
5
+ interface AccentColorConfig {
6
+ name: string;
7
+ primary: string;
8
+ primaryForeground: string;
9
+ light: string;
10
+ dark: string;
11
+ gradient: string;
12
+ }
13
+ interface AccentThemeContextType {
14
+ accentColor: AccentColor;
15
+ setAccentColor: (color: AccentColor) => void;
16
+ accentConfig: AccentColorConfig;
17
+ mounted: boolean;
18
+ }
19
+ interface AccentThemeProviderProps {
20
+ children: ReactNode;
21
+ defaultColor?: AccentColor;
22
+ customColors?: Record<string, AccentColorConfig>;
23
+ storageKey?: string;
24
+ cssVariablePrefix?: string;
25
+ }
26
+
27
+ declare function AccentThemeProvider({ children, defaultColor, customColors, storageKey, cssVariablePrefix }: AccentThemeProviderProps): React.FunctionComponentElement<React.ProviderProps<AccentThemeContextType>>;
28
+ declare function useAccentTheme(): AccentThemeContextType;
29
+ declare function useAccentColor(): {
30
+ primary: string;
31
+ primaryForeground: string;
32
+ light: string;
33
+ dark: string;
34
+ gradient: string;
35
+ mounted: boolean;
36
+ };
37
+
38
+ interface AccentColorPickerProps {
39
+ size?: "sm" | "md" | "lg";
40
+ variant?: "dropdown" | "inline";
41
+ columns?: number;
42
+ className?: string;
43
+ onChange?: (color: AccentColor) => void;
44
+ }
45
+ declare function AccentColorPicker({ size, variant, columns, className, onChange, }: AccentColorPickerProps): React.DetailedReactHTMLElement<{
46
+ className: string;
47
+ }, HTMLElement>;
48
+ interface AccentColorSwatchProps {
49
+ color: AccentColor;
50
+ isSelected?: boolean;
51
+ onClick?: () => void;
52
+ size?: "sm" | "md" | "lg";
53
+ }
54
+ declare function AccentColorSwatch({ color, isSelected, onClick, size }: AccentColorSwatchProps): React.DetailedReactHTMLElement<{
55
+ onClick: (() => void) | undefined;
56
+ className: string;
57
+ style: {
58
+ [x: string]: string;
59
+ background: string;
60
+ };
61
+ title: string;
62
+ }, HTMLElement> | null;
63
+
64
+ declare const defaultAccentColors: Record<AccentColor, AccentColorConfig>;
65
+
66
+ declare function generateCSSVariables(config: AccentColorConfig, prefix?: string): Record<string, string>;
67
+ declare function applyCSSVariables(element: HTMLElement, variables: Record<string, string>): void;
68
+ declare function createGradient(config: AccentColorConfig, direction?: string): string;
69
+ declare function createShadow(config: AccentColorConfig, intensity?: number, blur?: number): string;
70
+ declare function adjustHSL(hsl: string, adjustments: {
71
+ hue?: number;
72
+ saturation?: number;
73
+ lightness?: number;
74
+ }): string;
75
+ declare function getContrastColor(hsl: string, threshold?: number): "black" | "white";
76
+ declare function isClient(): boolean;
77
+ declare const storage: {
78
+ get: (key: string, defaultValue?: string) => string | undefined;
79
+ set: (key: string, value: string) => void;
80
+ remove: (key: string) => void;
81
+ };
82
+
83
+ export { type AccentColor, type AccentColorConfig, AccentColorPicker, AccentColorSwatch, type AccentThemeContextType, AccentThemeProvider, type AccentThemeProviderProps, adjustHSL, applyCSSVariables, createGradient, createShadow, defaultAccentColors, generateCSSVariables, getContrastColor, isClient, storage, useAccentColor, useAccentTheme };