@razzusharma/accent-theme 1.0.1 → 2.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/README.md CHANGED
@@ -1,51 +1,35 @@
1
- <<<<<<< HEAD
2
- # @razzu/accent-theme
3
- =======
4
1
  # @razzusharma/accent-theme
5
- >>>>>>> a4f8ab5 (updating readme)
6
2
 
7
- A React hook and provider for dynamic accent color theming. Perfect for adding customizable color themes to your React applications.
3
+ 🎨 **Zero-config accent color theming for React apps.** Just install, wrap, and use. No CSS changes required!
8
4
 
9
5
  ## Features
10
6
 
7
+ - ✅ **Zero Configuration** - CSS variables auto-injected, no globals.css changes needed
11
8
  - 🎨 **8 Built-in Colors** - Teal, Blue, Purple, Rose, Amber, Emerald, Indigo, Cyan
9
+ - 🧩 **Pre-built Components** - Pickers, swatches, menus, buttons - all styled out of the box
10
+ - 🌓 **Dark Mode Ready** - Auto-detects and adapts to next-themes, ThemeProvider, or data-theme
12
11
  - đŸŽ¯ **TypeScript Support** - Fully typed with generics
13
12
  - 💾 **Persistence** - Automatically saves user preference to localStorage
14
- - 🌓 **Dark Mode Compatible** - Works seamlessly with dark mode
15
- - đŸŽ›ī¸ **Customizable** - Add your own custom colors
16
- - đŸ“Ļ **Zero Dependencies** - Only peer dependencies on React
17
- - đŸĒļ **Lightweight** - ~3KB gzipped
13
+ - đŸ“Ļ **Tailwind Plugin** - Optional plugin for extended utilities
14
+ - đŸĒļ **Lightweight** - ~5KB gzipped
18
15
 
19
16
  ## Installation
20
17
 
21
18
  ```bash
22
- <<<<<<< HEAD
23
- npm install @razzu/accent-theme
24
- # or
25
- yarn add @razzu/accent-theme
26
- # or
27
- pnpm add @razzu/accent-theme
28
- =======
29
19
  npm install @razzusharma/accent-theme
30
20
  # or
31
21
  yarn add @razzusharma/accent-theme
32
22
  # or
33
23
  pnpm add @razzusharma/accent-theme
34
-
35
- >>>>>>> a4f8ab5 (updating readme)
36
24
  ```
37
25
 
38
- ## Quick Start
26
+ ## Quick Start (It Just Works!)
39
27
 
40
28
  ### 1. Wrap your app with the provider
41
29
 
42
30
  ```tsx
43
- <<<<<<< HEAD
44
- import { AccentThemeProvider } from '@razzu/accent-theme';
45
-
46
- =======
47
31
  import { AccentThemeProvider } from '@razzusharma/accent-theme';
48
- >>>>>>> a4f8ab5 (updating readme)
32
+
49
33
  function App() {
50
34
  return (
51
35
  <AccentThemeProvider>
@@ -53,21 +37,135 @@ function App() {
53
37
  </AccentThemeProvider>
54
38
  );
55
39
  }
40
+ ```
41
+
42
+ That's it! CSS variables are auto-injected. No globals.css changes needed.
43
+
44
+ ### 2. Drop in a color picker anywhere
45
+
46
+ ```tsx
47
+ import { AccentColorPicker } from '@razzusharma/accent-theme';
48
+
49
+ function Navbar() {
50
+ return (
51
+ <nav>
52
+ <AccentColorPicker variant="dropdown" size="sm" />
53
+ </nav>
54
+ );
55
+ }
56
+ ```
57
+
58
+ ## Pre-built Components
59
+
60
+ ### AccentColorPicker
61
+
62
+ The main color picker component with multiple variants:
63
+
64
+ ```tsx
65
+ import { AccentColorPicker } from '@razzusharma/accent-theme';
66
+
67
+ // Dropdown picker (default)
68
+ <AccentColorPicker variant="dropdown" size="md" />
69
+
70
+ // Inline grid
71
+ <AccentColorPicker variant="inline" columns={4} />
72
+
73
+ // Menu style
74
+ <AccentColorPicker variant="menu" align="end" />
75
+ ```
76
+
77
+ **Props:**
78
+ - `variant`: `"dropdown" | "inline" | "menu"`
79
+ - `size`: `"sm" | "md" | "lg"`
80
+ - `columns`: Number of columns for inline variant
81
+ - `label`: Label text for dropdown trigger
82
+ - `showColorName`: Show color name in dropdown
83
+ - `onChange`: Callback when color changes
84
+ - `className`: Custom classes
85
+
86
+ ### AccentColorSwatches
87
+
88
+ Horizontal row of color dots:
89
+
90
+ ```tsx
91
+ import { AccentColorSwatches } from '@razzusharma/accent-theme';
92
+
93
+ <AccentColorSwatches size="md" gap="md" showCheckmark />
94
+ ```
95
+
96
+ ### AccentColorMenu
97
+
98
+ Dropdown menu with color names:
99
+
100
+ ```tsx
101
+ import { AccentColorMenu } from '@razzusharma/accent-theme';
102
+
103
+ <AccentColorMenu align="end" label="Theme" />
104
+ ```
105
+
106
+ ### AccentColorButton
107
+
108
+ Button showing current accent color:
109
+
110
+ ```tsx
111
+ import { AccentColorButton } from '@razzusharma/accent-theme';
112
+
113
+ <AccentColorButton showLabel buttonVariant="ghost" />
114
+ ```
115
+
116
+ ### AccentColorGrid
117
+
118
+ Configurable grid layout:
119
+
120
+ ```tsx
121
+ import { AccentColorGrid } from '@razzusharma/accent-theme';
122
+
123
+ <AccentColorGrid columns={4} showLabels gap="md" />
124
+ ```
125
+
126
+ ### CurrentAccentIndicator
127
+
128
+ Non-interactive indicator showing current color:
129
+
130
+ ```tsx
131
+ import { CurrentAccentIndicator } from '@razzusharma/accent-theme';
132
+
133
+ <CurrentAccentIndicator showName pulseOnChange />
134
+ ```
135
+
136
+ ### AccentThemeReset
56
137
 
138
+ Reset button to go back to default:
139
+
140
+ ```tsx
141
+ import { AccentThemeReset } from '@razzusharma/accent-theme';
142
+
143
+ <AccentThemeReset variant="button" text="Reset Theme" />
144
+ ```
145
+
146
+ ## Provider Configuration
147
+
148
+ ```tsx
149
+ <AccentThemeProvider
150
+ defaultColor="teal" // Default accent color
151
+ customColors={{...}} // Add custom colors
152
+ storageKey="accent-color" // localStorage key
153
+ cssVariablePrefix="brand" // Prefix CSS variables (--brand-primary)
154
+ injectCSS={true} // Auto-inject base CSS (default: true)
155
+ enableDarkMode={true} // Auto-detect dark mode (default: true)
156
+ >
157
+ {children}
158
+ </AccentThemeProvider>
57
159
  ```
58
160
 
59
- ### 2. Use the hook in your components
161
+ ## Using the Hook
60
162
 
61
163
  ```tsx
62
- <<<<<<< HEAD
63
- import { useAccentTheme, useAccentColor } from '@razzu/accent-theme';
64
- =======
65
164
  import { useAccentTheme, useAccentColor } from '@razzusharma/accent-theme';
66
- >>>>>>> a4f8ab5 (updating readme)
67
165
 
68
166
  function MyComponent() {
69
- const { accentColor, setAccentColor } = useAccentTheme();
70
- const { primary, light, gradient } = useAccentColor();
167
+ const { accentColor, setAccentColor, resetToDefault } = useAccentTheme();
168
+ const { primary, light, dark, gradient } = useAccentColor();
71
169
 
72
170
  return (
73
171
  <div style={{ color: primary }}>
@@ -78,48 +176,49 @@ function MyComponent() {
78
176
  </div>
79
177
  );
80
178
  }
81
-
82
179
  ```
83
180
 
84
- ### 3. Use the built-in color picker
181
+ ## Tailwind CSS Integration (Optional)
85
182
 
86
- ```tsx
87
- <<<<<<< HEAD
88
- import { AccentColorPicker } from '@razzu/accent-theme';
89
- =======
90
- import { AccentColorPicker } from '@razzusharma/accent-theme';
91
- >>>>>>> a4f8ab5 (updating readme)
183
+ For enhanced Tailwind integration, add the plugin:
92
184
 
93
- function Settings() {
94
- return (
95
- <div>
96
- <h2>Choose your theme</h2>
97
- <AccentColorPicker variant="inline" columns={4} />
98
- </div>
99
- );
185
+ ```js
186
+ // tailwind.config.js
187
+ import { accentThemePlugin } from '@razzusharma/accent-theme/tailwind';
188
+
189
+ export default {
190
+ plugins: [accentThemePlugin],
100
191
  }
192
+ ```
101
193
 
194
+ This adds utility classes:
195
+ ```html
196
+ <div class="bg-primary text-primary-foreground ring-accent">
197
+ Content with accent colors
198
+ </div>
102
199
  ```
103
200
 
104
- ## Configuration
201
+ ### Without the Plugin
105
202
 
106
- ### Provider Props
203
+ If you prefer manual setup, CSS variables are available:
204
+
205
+ ```css
206
+ .my-button {
207
+ background: hsl(var(--primary));
208
+ color: hsl(var(--primary-foreground));
209
+ }
210
+ ```
107
211
 
108
- | Prop | Type | Default | Description |
109
- |------|------|---------|-------------|
110
- | `defaultColor` | `string` | `'teal'` | Default accent color |
111
- | `customColors` | `object` | `undefined` | Add custom colors |
112
- | `storageKey` | `string` | `'accent-color'` | localStorage key |
113
- | `cssVariablePrefix` | `string` | `''` | Prefix for CSS variables |
212
+ ```html
213
+ <button class="bg-[hsl(var(--primary))] text-white">
214
+ Click me
215
+ </button>
216
+ ```
114
217
 
115
- ### Custom Colors
218
+ ## Custom Colors
116
219
 
117
220
  ```tsx
118
- <<<<<<< HEAD
119
- import { AccentThemeProvider } from '@razzu/accent-theme';
120
- =======
121
221
  import { AccentThemeProvider } from '@razzusharma/accent-theme';
122
- >>>>>>> a4f8ab5 (updating readme)
123
222
 
124
223
  const customColors = {
125
224
  coral: {
@@ -142,35 +241,57 @@ function App() {
142
241
  </AccentThemeProvider>
143
242
  );
144
243
  }
145
-
146
244
  ```
147
245
 
246
+ ## Dark Mode
247
+
248
+ The package automatically detects dark mode from:
249
+ - `next-themes`
250
+ - `ThemeProvider`
251
+ - `data-theme="dark"` attribute
252
+ - `class="dark"` on html element
253
+ - `prefers-color-scheme: dark` media query
254
+
148
255
  ## CSS Variables
149
256
 
150
- The library sets these CSS custom properties on the root element:
257
+ The following CSS variables are set on the root element:
151
258
 
152
259
  ```css
153
260
  :root {
154
- --primary: 174 72% 35%; /* HSL values */
261
+ --primary: 174 72% 35%; /* HSL values */
155
262
  --primary-foreground: 210 40% 98%;
156
263
  --accent: 174 72% 45%;
157
264
  --ring: 174 72% 45%;
158
265
  }
159
266
  ```
160
267
 
161
- Use them in your CSS/Tailwind:
162
-
268
+ With `cssVariablePrefix="brand"`:
163
269
  ```css
164
- .my-button {
165
- background: hsl(var(--primary));
166
- color: hsl(var(--primary-foreground));
270
+ :root {
271
+ --brand-primary: 174 72% 35%;
272
+ --brand-primary-foreground: 210 40% 98%;
273
+ --brand-accent: 174 72% 45%;
274
+ --brand-ring: 174 72% 45%;
167
275
  }
168
276
  ```
169
277
 
170
- ```html
171
- <button class="bg-[hsl(var(--primary))] text-white">
172
- Click me
173
- </button>
278
+ ## Importing CSS Manually
279
+
280
+ If you prefer to disable auto-injection and import CSS manually:
281
+
282
+ ```tsx
283
+ // Disable auto-injection
284
+ <AccentThemeProvider injectCSS={false}>
285
+ ```
286
+
287
+ ```tsx
288
+ // Import CSS in your app
289
+ import '@razzusharma/accent-theme/styles.css';
290
+ ```
291
+
292
+ Or in CSS:
293
+ ```css
294
+ @import '@razzusharma/accent-theme/styles.css';
174
295
  ```
175
296
 
176
297
  ## API Reference
@@ -183,6 +304,8 @@ const {
183
304
  setAccentColor, // Function to change color
184
305
  accentConfig, // Full color config object
185
306
  mounted, // Hydration flag
307
+ defaultColor, // Default color name
308
+ resetToDefault, // Reset function
186
309
  } = useAccentTheme();
187
310
  ```
188
311
 
@@ -196,43 +319,43 @@ const {
196
319
  dark, // hsl() string for dark variant
197
320
  gradient, // Tailwind gradient class
198
321
  mounted, // Hydration flag
322
+ isDark, // Current dark mode state
199
323
  } = useAccentColor();
200
324
  ```
201
325
 
202
- ### `AccentColorPicker`
326
+ ### Color Config Structure
203
327
 
204
- ```tsx
205
- <AccentColorPicker
206
- size="md" // 'sm' | 'md' | 'lg'
207
- variant="dropdown" // 'dropdown' | 'inline'
208
- columns={4} // Number of columns for inline
209
- onChange={(color) => console.log(color)}
210
- />
328
+ ```ts
329
+ interface AccentColorConfig {
330
+ name: string; // Display name
331
+ primary: string; // HSL value "174 72% 35%"
332
+ primaryForeground: string; // HSL value for text
333
+ light: string; // Lighter variant
334
+ dark: string; // Darker variant
335
+ gradient: string; // Tailwind gradient classes
336
+ }
211
337
  ```
212
338
 
213
- ## Tailwind CSS Integration
339
+ ## Built-in Colors
214
340
 
215
- Add to your `tailwind.config.js`:
341
+ | Color | Name | Primary |
342
+ |-------|------|---------|
343
+ | teal | Teal | `#199c88` |
344
+ | blue | Ocean Blue | `#0b6dc6` |
345
+ | purple | Royal Purple | `#7c3aed` |
346
+ | rose | Rose Pink | `#e11d48` |
347
+ | amber | Sunset Amber | `#d97706` |
348
+ | emerald | Forest Emerald | `#208562` |
349
+ | indigo | Deep Indigo | `#4f46e5` |
350
+ | cyan | Electric Cyan | `#0ba5c9` |
216
351
 
217
- ```js
218
- module.exports = {
219
- theme: {
220
- extend: {
221
- colors: {
222
- primary: 'hsl(var(--primary))',
223
- 'primary-foreground': 'hsl(var(--primary-foreground))',
224
- accent: 'hsl(var(--accent))',
225
- ring: 'hsl(var(--ring))',
226
- },
227
- },
228
- },
229
- }
230
- ```
352
+ ## Browser Support
353
+
354
+ - Chrome/Edge 88+
355
+ - Firefox 78+
356
+ - Safari 14+
357
+ - Supports server-side rendering (Next.js, Remix, etc.)
231
358
 
232
359
  ## License
233
360
 
234
- <<<<<<< HEAD
235
- MIT Š razzu
236
- =======
237
361
  MIT Š razzusharma
238
- >>>>>>> a4f8ab5 (updating readme)
package/dist/index.d.mts CHANGED
@@ -15,6 +15,8 @@ interface AccentThemeContextType {
15
15
  setAccentColor: (color: AccentColor) => void;
16
16
  accentConfig: AccentColorConfig;
17
17
  mounted: boolean;
18
+ defaultColor: AccentColor;
19
+ resetToDefault: () => void;
18
20
  }
19
21
  interface AccentThemeProviderProps {
20
22
  children: ReactNode;
@@ -22,9 +24,61 @@ interface AccentThemeProviderProps {
22
24
  customColors?: Record<string, AccentColorConfig>;
23
25
  storageKey?: string;
24
26
  cssVariablePrefix?: string;
27
+ injectCSS?: boolean;
28
+ enableDarkMode?: boolean;
29
+ }
30
+ type ComponentSize = "sm" | "md" | "lg";
31
+ interface BaseComponentProps {
32
+ className?: string;
33
+ size?: ComponentSize;
34
+ }
35
+ interface AccentColorPickerProps extends BaseComponentProps {
36
+ variant?: "dropdown" | "inline" | "menu";
37
+ columns?: number;
38
+ onChange?: (color: AccentColor) => void;
39
+ label?: string;
40
+ showColorName?: boolean;
41
+ }
42
+ interface AccentColorSwatchesProps extends BaseComponentProps {
43
+ onChange?: (color: AccentColor) => void;
44
+ showCheckmark?: boolean;
45
+ gap?: "sm" | "md" | "lg";
46
+ }
47
+ interface AccentColorMenuProps extends BaseComponentProps {
48
+ onChange?: (color: AccentColor) => void;
49
+ align?: "start" | "center" | "end";
50
+ label?: string;
51
+ }
52
+ interface AccentColorButtonProps extends BaseComponentProps {
53
+ onClick?: () => void;
54
+ showLabel?: boolean;
55
+ buttonVariant?: "default" | "ghost" | "outline";
56
+ }
57
+ interface AccentThemeResetProps extends BaseComponentProps {
58
+ text?: string;
59
+ onReset?: () => void;
60
+ variant?: "button" | "link" | "subtle";
61
+ }
62
+ interface CurrentAccentIndicatorProps extends BaseComponentProps {
63
+ showName?: boolean;
64
+ pulseOnChange?: boolean;
65
+ }
66
+ interface AccentColorGridProps extends BaseComponentProps {
67
+ columns?: 2 | 3 | 4 | 5 | 6 | 8;
68
+ onChange?: (color: AccentColor) => void;
69
+ showLabels?: boolean;
70
+ gap?: "sm" | "md" | "lg";
71
+ }
72
+ interface AccentColorSwatchProps {
73
+ color: AccentColor;
74
+ isSelected?: boolean;
75
+ onClick?: () => void;
76
+ size?: ComponentSize;
77
+ className?: string;
78
+ showCheckmark?: boolean;
25
79
  }
26
80
 
27
- declare function AccentThemeProvider({ children, defaultColor, customColors, storageKey, cssVariablePrefix }: AccentThemeProviderProps): React.FunctionComponentElement<React.ProviderProps<AccentThemeContextType>>;
81
+ declare function AccentThemeProvider({ children, defaultColor, customColors, storageKey, cssVariablePrefix, injectCSS, enableDarkMode, }: AccentThemeProviderProps): React.FunctionComponentElement<React.ProviderProps<AccentThemeContextType>>;
28
82
  declare function useAccentTheme(): AccentThemeContextType;
29
83
  declare function useAccentColor(): {
30
84
  primary: string;
@@ -33,25 +87,11 @@ declare function useAccentColor(): {
33
87
  dark: string;
34
88
  gradient: string;
35
89
  mounted: boolean;
90
+ isDark: boolean;
36
91
  };
92
+ declare function useAccentDarkMode(): boolean;
37
93
 
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<{
94
+ declare function AccentColorSwatch({ color, isSelected, onClick, size, className, showCheckmark, }: AccentColorSwatchProps): React.DetailedReactHTMLElement<{
55
95
  onClick: (() => void) | undefined;
56
96
  className: string;
57
97
  style: {
@@ -59,9 +99,33 @@ declare function AccentColorSwatch({ color, isSelected, onClick, size }: AccentC
59
99
  background: string;
60
100
  };
61
101
  title: string;
102
+ "aria-label": string;
103
+ "aria-pressed": boolean | undefined;
62
104
  }, HTMLElement> | null;
105
+ declare function AccentColorPicker({ size, variant, columns, className, onChange, label, showColorName, }: AccentColorPickerProps): React.DetailedReactHTMLElement<{
106
+ className: string;
107
+ }, HTMLElement> | React.FunctionComponentElement<AccentColorMenuProps>;
108
+ declare function AccentColorSwatches({ className, size, onChange, showCheckmark, gap, }: AccentColorSwatchesProps): React.DetailedReactHTMLElement<{
109
+ className: string;
110
+ }, HTMLElement>;
111
+ declare function AccentColorMenu({ className, size: _size, onChange, align, label, }: AccentColorMenuProps): React.DetailedReactHTMLElement<{
112
+ className: string;
113
+ }, HTMLElement>;
114
+ declare function AccentColorButton({ className, size, onClick, showLabel, buttonVariant, }: AccentColorButtonProps): React.DetailedReactHTMLElement<{
115
+ className: string;
116
+ }, HTMLElement>;
117
+ declare function AccentThemeReset({ className, size, text, onReset, variant, }: AccentThemeResetProps): React.DetailedReactHTMLElement<{
118
+ className: string;
119
+ }, HTMLElement>;
120
+ declare function CurrentAccentIndicator({ className, size, showName, pulseOnChange, }: CurrentAccentIndicatorProps): React.DetailedReactHTMLElement<{
121
+ className: string;
122
+ }, HTMLElement>;
123
+ declare function AccentColorGrid({ className, size, columns, onChange, showLabels, gap, }: AccentColorGridProps): React.DetailedReactHTMLElement<{
124
+ className: string;
125
+ }, HTMLElement>;
63
126
 
64
127
  declare const defaultAccentColors: Record<AccentColor, AccentColorConfig>;
128
+ declare function mergeColors(defaultColors: Record<string, AccentColorConfig>, customColors?: Record<string, AccentColorConfig>): Record<string, AccentColorConfig>;
65
129
 
66
130
  declare function generateCSSVariables(config: AccentColorConfig, prefix?: string): Record<string, string>;
67
131
  declare function applyCSSVariables(element: HTMLElement, variables: Record<string, string>): void;
@@ -80,4 +144,6 @@ declare const storage: {
80
144
  remove: (key: string) => void;
81
145
  };
82
146
 
83
- export { type AccentColor, type AccentColorConfig, AccentColorPicker, AccentColorSwatch, type AccentThemeContextType, AccentThemeProvider, type AccentThemeProviderProps, adjustHSL, applyCSSVariables, createGradient, createShadow, defaultAccentColors, generateCSSVariables, getContrastColor, isClient, storage, useAccentColor, useAccentTheme };
147
+ declare const VERSION = "2.0.0";
148
+
149
+ export { type AccentColor, AccentColorButton, type AccentColorButtonProps, type AccentColorConfig, AccentColorGrid, type AccentColorGridProps, AccentColorMenu, type AccentColorMenuProps, AccentColorPicker, type AccentColorPickerProps, AccentColorSwatch, type AccentColorSwatchProps, AccentColorSwatches, type AccentColorSwatchesProps, type AccentThemeContextType, AccentThemeProvider, type AccentThemeProviderProps, AccentThemeReset, type AccentThemeResetProps, type BaseComponentProps, type ComponentSize, CurrentAccentIndicator, type CurrentAccentIndicatorProps, VERSION, adjustHSL, applyCSSVariables, createGradient, createShadow, defaultAccentColors, generateCSSVariables, getContrastColor, isClient, mergeColors, storage, useAccentColor, useAccentDarkMode, useAccentTheme };