shru-design-system 0.1.6 → 0.1.9

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,184 +1,114 @@
1
1
  # shru-design-system
2
2
 
3
- A React component library with atoms and molecules built on Radix UI and Tailwind CSS.
3
+ A React component library with atoms and molecules built on Radix UI and Tailwind CSS, featuring a dynamic theme system.
4
+
5
+ ## Project Structure
6
+
7
+ ### Root Files
8
+
9
+ - **`package.json`** - Package configuration, dependencies, and scripts
10
+ - **`tsconfig.json`** - TypeScript configuration
11
+ - **`tsup.config.ts`** - Build configuration for bundling (ESM/CJS)
12
+ - **`tailwind.config.js`** - Tailwind CSS configuration (for library development)
13
+ - **`postcss.config.js`** - PostCSS configuration (for library development)
14
+ - **`.gitignore`** - Git ignore rules
15
+
16
+ ### Source Code (`src/`)
17
+
18
+ - **`src/index.ts`** - Main entry point, exports all components and utilities
19
+ - **`src/utils.ts`** - Utility functions (cn helper for class merging)
20
+
21
+ #### Atoms (`src/atoms/`)
22
+ Basic UI building blocks:
23
+ - **`Button.tsx`** - Button component with variants and sizes
24
+ - **`Badge.tsx`** - Badge component for labels and tags
25
+ - **`TextInput.tsx`** - Text input field component
26
+ - **`Label.tsx`** - Form label component
27
+ - **`Textarea.tsx`** - Multi-line text input component
28
+ - **`Separator.tsx`** - Horizontal/vertical divider component
29
+ - **`Checkbox.tsx`** - Checkbox input component
30
+
31
+ #### Molecules (`src/molecules/`)
32
+ Composite components:
33
+ - **`Modal.tsx`** - Modal dialog component
34
+ - **`Select.tsx`** - Dropdown select component
35
+ - **`Tooltip.tsx`** - Tooltip component
36
+
37
+ #### Theme System (`src/themes/`)
38
+ - **`themeConfig.ts`** - Theme configuration and category definitions
39
+ - **`themeUtils.ts`** - Theme utility functions (loading, merging, flattening)
40
+ - **`applyThemeSync.ts`** - Synchronous theme application (prevents FOUC)
41
+ - **`useTheme.tsx`** - React hook for theme management
42
+ - **`ui/ThemeToggle/`** - Theme toggle UI component and related files
43
+ - **`ThemeToggle.tsx`** - Main theme toggle component
44
+ - **`useThemeToggle.ts`** - Hook for theme toggle UI state
45
+ - **`themeToggleConfig.ts`** - Theme toggle configuration
46
+ - **`themeToggleUtils.ts`** - Theme toggle utility functions
47
+ - **`index.ts`** - Theme toggle exports
48
+
49
+ ### Build Output (`dist/`)
50
+
51
+ - **`index.js`** - CommonJS bundle
52
+ - **`index.mjs`** - ESM bundle
53
+ - **`index.d.ts`** - TypeScript declarations (CJS)
54
+ - **`index.d.mts`** - TypeScript declarations (ESM)
55
+
56
+ ### Scripts (`scripts/`)
57
+
58
+ Setup and runtime scripts:
59
+ - **`init.js`** - Postinstall script that sets up Tailwind, PostCSS, and token files in consuming apps
60
+ - **`apply-theme-sync.js`** - Standalone synchronous theme script (injected into HTML)
61
+ - **`applyThemeSync.js`** - Synchronous theme application module
62
+ - **`themeConfig.js`** - Theme configuration (JavaScript version)
63
+ - **`themeUtils.js`** - Theme utilities (JavaScript version)
64
+ - **`tokens/`** - Default token files (copied to consuming apps)
65
+ - **`base.json`** - Base design tokens
66
+ - **`palettes.json`** - Color palette definitions
67
+ - **`themes/`** - Theme category files
68
+ - **`color/`** - Color theme variants (white, dark)
69
+ - **`typography/`** - Typography themes (sans, serif)
70
+ - **`shape/`** - Shape themes (smooth, sharp)
71
+ - **`density/`** - Density themes (comfortable, compact)
72
+ - **`animation/`** - Animation themes (gentle, brisk)
73
+ - **`custom/`** - Custom theme examples (brand, minimal)
74
+
75
+ ### Test Application (`test/`)
76
+
77
+ Local test environment for developing and testing the library:
78
+ - **`package.json`** - Test app dependencies
79
+ - **`vite.config.ts`** - Vite configuration for test app
80
+ - **`index.html`** - Test app HTML entry point
81
+ - **`src/App.tsx`** - Test app component showcasing all library components
82
+ - **`src/main.tsx`** - Test app entry point
83
+ - **`src/index.css`** - Test app global styles
84
+ - **`tailwind.config.js`** - Tailwind config for test app
85
+ - **`postcss.config.js`** - PostCSS config for test app
86
+ - **`public/tokens/`** - Token files for testing (generated by init script)
87
+ - **`dist/`** - Vite build output (ignored in git)
4
88
 
5
- ## Installation
89
+ ## Usage
6
90
 
91
+ Install the package:
7
92
  ```bash
8
93
  npm install shru-design-system
9
94
  ```
10
95
 
11
- ## Quick Setup
12
-
13
- After installation, run the setup script to configure Tailwind CSS:
14
-
15
- ```bash
16
- npx shru-design-system-init
17
- ```
18
-
19
- Or it will run automatically after `npm install` (you can skip this step if it already ran).
20
-
21
- ## Manual Setup
22
-
23
- If you prefer to set up manually or the automatic setup didn't work:
24
-
25
- ### 1. Install Tailwind CSS
26
-
27
- ```bash
28
- npm install -D tailwindcss postcss autoprefixer
29
- npx tailwindcss init -p
30
- ```
31
-
32
- ### 2. Configure Tailwind
33
-
34
- Update `tailwind.config.js`:
35
-
36
- ```js
37
- export default {
38
- content: [
39
- "./index.html",
40
- "./src/**/*.{js,ts,jsx,tsx}",
41
- "./node_modules/shru-design-system/dist/**/*.{js,mjs}",
42
- ],
43
- theme: {
44
- extend: {
45
- colors: {
46
- background: "hsl(var(--background))",
47
- foreground: "hsl(var(--foreground))",
48
- primary: {
49
- DEFAULT: "hsl(var(--primary))",
50
- foreground: "hsl(var(--primary-foreground))",
51
- },
52
- secondary: {
53
- DEFAULT: "hsl(var(--secondary))",
54
- foreground: "hsl(var(--secondary-foreground))",
55
- },
56
- destructive: {
57
- DEFAULT: "hsl(var(--destructive))",
58
- foreground: "hsl(var(--destructive-foreground))",
59
- },
60
- muted: {
61
- DEFAULT: "hsl(var(--muted))",
62
- foreground: "hsl(var(--muted-foreground))",
63
- },
64
- accent: {
65
- DEFAULT: "hsl(var(--accent))",
66
- foreground: "hsl(var(--accent-foreground))",
67
- },
68
- popover: {
69
- DEFAULT: "hsl(var(--popover))",
70
- foreground: "hsl(var(--popover-foreground))",
71
- },
72
- border: "hsl(var(--border))",
73
- input: "hsl(var(--input))",
74
- ring: "hsl(var(--ring))",
75
- },
76
- borderRadius: {
77
- lg: "var(--radius)",
78
- md: "calc(var(--radius) - 2px)",
79
- sm: "calc(var(--radius) - 4px)",
80
- },
81
- },
82
- },
83
- plugins: [],
84
- }
85
- ```
86
-
87
- ### 3. Add CSS Variables
88
-
89
- Create or update `src/index.css`:
90
-
91
- ```css
92
- @tailwind base;
93
- @tailwind components;
94
- @tailwind utilities;
95
-
96
- @layer base {
97
- :root {
98
- --background: 0 0% 100%;
99
- --foreground: 222.2 84% 4.9%;
100
- --primary: 222.2 47.4% 11.2%;
101
- --primary-foreground: 210 40% 98%;
102
- --secondary: 210 40% 96.1%;
103
- --secondary-foreground: 222.2 47.4% 11.2%;
104
- --destructive: 0 84.2% 60.2%;
105
- --destructive-foreground: 210 40% 98%;
106
- --muted: 210 40% 96.1%;
107
- --muted-foreground: 215.4 16.3% 46.9%;
108
- --accent: 210 40% 96.1%;
109
- --accent-foreground: 222.2 47.4% 11.2%;
110
- --popover: 0 0% 100%;
111
- --popover-foreground: 222.2 84% 4.9%;
112
- --border: 214.3 31.8% 91.4%;
113
- --input: 214.3 31.8% 91.4%;
114
- --ring: 222.2 84% 4.9%;
115
- --radius: 0.5rem;
116
- }
117
-
118
- * {
119
- border-color: hsl(var(--border));
120
- }
121
-
122
- body {
123
- background-color: hsl(var(--background));
124
- color: hsl(var(--foreground));
125
- }
126
- }
127
- ```
128
-
129
- ### 4. Import CSS
130
-
131
- Import the CSS file in your entry point (e.g., `src/main.tsx`):
96
+ The `postinstall` script automatically sets up Tailwind CSS, PostCSS, and token files in your project.
132
97
 
98
+ Import components:
133
99
  ```tsx
134
- import './index.css'
100
+ import { Button, Modal, ThemeToggle } from 'shru-design-system'
135
101
  ```
136
102
 
137
- ## Usage
103
+ ## Development
138
104
 
139
- ```tsx
140
- import { Button, Badge, Modal, Select } from 'shru-design-system'
141
-
142
- function App() {
143
- return (
144
- <div>
145
- <Button variant="default">Click me</Button>
146
- <Badge>New</Badge>
147
-
148
- <Modal>
149
- <ModalTrigger asChild>
150
- <Button>Open Modal</Button>
151
- </ModalTrigger>
152
- <ModalContent>
153
- <ModalHeader>
154
- <ModalTitle>Hello</ModalTitle>
155
- <ModalDescription>This is a modal</ModalDescription>
156
- </ModalHeader>
157
- </ModalContent>
158
- </Modal>
159
- </div>
160
- )
161
- }
105
+ Build the library:
106
+ ```bash
107
+ npm run build
162
108
  ```
163
109
 
164
- ## Components
165
-
166
- ### Atoms
167
- - **Button** - Versatile button with multiple variants and sizes
168
- - **Badge** - Small status indicators
169
-
170
- ### Molecules
171
- - **Modal** - Dialog component with overlay
172
- - **Select** - Dropdown select component
173
-
174
- ## Peer Dependencies
175
-
176
- Make sure to install these peer dependencies:
177
-
110
+ Test locally:
178
111
  ```bash
179
- npm install @radix-ui/react-slot @radix-ui/react-dialog @radix-ui/react-select class-variance-authority clsx tailwind-merge lucide-react
112
+ cd test && npm run dev
180
113
  ```
181
114
 
182
- ## License
183
-
184
- MIT
package/dist/index.d.mts CHANGED
@@ -1,6 +1,9 @@
1
1
  import * as class_variance_authority_types from 'class-variance-authority/types';
2
2
  import * as React from 'react';
3
3
  import { VariantProps } from 'class-variance-authority';
4
+ import * as LabelPrimitive from '@radix-ui/react-label';
5
+ import * as SeparatorPrimitive from '@radix-ui/react-separator';
6
+ import * as CheckboxPrimitive from '@radix-ui/react-checkbox';
4
7
  import * as react_jsx_runtime from 'react/jsx-runtime';
5
8
  import * as DialogPrimitive from '@radix-ui/react-dialog';
6
9
  import * as SelectPrimitive from '@radix-ui/react-select';
@@ -26,6 +29,30 @@ declare const Badge: React.ForwardRefExoticComponent<Omit<React.ClassAttributes<
26
29
  asChild?: boolean;
27
30
  }, "ref"> & React.RefAttributes<HTMLSpanElement>>;
28
31
 
32
+ declare const textInputTypes: readonly ["text", "email", "password", "number", "tel", "url", "search"];
33
+ interface TextInputProps extends React.ComponentProps<"input"> {
34
+ type?: typeof textInputTypes[number];
35
+ }
36
+ declare const TextInput: React.ForwardRefExoticComponent<Omit<TextInputProps, "ref"> & React.RefAttributes<HTMLInputElement>>;
37
+
38
+ interface LabelProps extends React.ComponentProps<typeof LabelPrimitive.Root> {
39
+ }
40
+ declare const Label: React.ForwardRefExoticComponent<Omit<LabelProps, "ref"> & React.RefAttributes<HTMLLabelElement>>;
41
+
42
+ interface TextareaProps extends React.ComponentProps<"textarea"> {
43
+ }
44
+ declare const Textarea: React.ForwardRefExoticComponent<Omit<TextareaProps, "ref"> & React.RefAttributes<HTMLTextAreaElement>>;
45
+
46
+ declare const separatorOrientations: readonly ["horizontal", "vertical"];
47
+ interface SeparatorProps extends React.ComponentProps<typeof SeparatorPrimitive.Root> {
48
+ orientation?: typeof separatorOrientations[number];
49
+ }
50
+ declare const Separator: React.ForwardRefExoticComponent<Omit<SeparatorProps, "ref"> & React.RefAttributes<HTMLDivElement>>;
51
+
52
+ interface CheckboxProps extends React.ComponentProps<typeof CheckboxPrimitive.Root> {
53
+ }
54
+ declare const Checkbox: React.ForwardRefExoticComponent<Omit<CheckboxProps, "ref"> & React.RefAttributes<HTMLButtonElement>>;
55
+
29
56
  declare function Modal({ ...props }: React.ComponentProps<typeof DialogPrimitive.Root>): react_jsx_runtime.JSX.Element;
30
57
  declare function ModalTrigger({ ...props }: React.ComponentProps<typeof DialogPrimitive.Trigger>): react_jsx_runtime.JSX.Element;
31
58
  declare function ModalPortal({ ...props }: React.ComponentProps<typeof DialogPrimitive.Portal>): react_jsx_runtime.JSX.Element;
@@ -130,11 +157,32 @@ type ThemeCategory = {
130
157
  order: number;
131
158
  themes: Record<string, ThemeMetadata>;
132
159
  };
160
+ /**
161
+ * Centralized theme category order
162
+ * Used everywhere to ensure consistency
163
+ * Custom category is included but handled specially (optional, user-created files)
164
+ *
165
+ * ⚠️ IF YOU UPDATE THIS, ALSO UPDATE:
166
+ * 1. scripts/themeConfig.js - THEME_CATEGORY_ORDER (JavaScript version)
167
+ * 2. scripts/apply-theme-sync.js - THEME_CATEGORY_ORDER constant (standalone script, can't import)
168
+ */
169
+ declare const THEME_CATEGORY_ORDER: readonly ["color", "typography", "shape", "density", "animation", "custom"];
133
170
  /**
134
171
  * Register a custom theme dynamically
135
172
  * Allows users to add themes without modifying the base config
173
+ * Can be used for any category including custom
136
174
  */
137
175
  declare function registerTheme(category: string, themeId: string, metadata: ThemeMetadata): Record<string, ThemeCategory>;
176
+ /**
177
+ * Register a theme from a token file
178
+ * Helper function to automatically register a theme by loading its file
179
+ * Users can call this after creating a theme file
180
+ */
181
+ declare function registerThemeFromFile(category: string, themeId: string, filePath?: string): Promise<{
182
+ success: boolean;
183
+ themeId: string;
184
+ category: string;
185
+ }>;
138
186
  /**
139
187
  * Get merged theme categories (base + discovered)
140
188
  */
@@ -178,4 +226,4 @@ declare function getCurrentCSSVariables(): Record<string, string>;
178
226
  */
179
227
  declare function applyThemeSync(): void;
180
228
 
181
- export { Badge, Button, Modal, ModalClose, ModalContent, ModalDescription, ModalFooter, ModalHeader, ModalOverlay, ModalPortal, ModalTitle, ModalTrigger, Select, SelectContent, SelectGroup, SelectItem, SelectLabel, SelectScrollDownButton, SelectScrollUpButton, SelectSeparator, SelectTrigger, SelectValue, type ThemeMetadata$1 as ThemeMetadata, type ThemeSelection, ThemeToggle, type ThemeToggleProps, Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, applyThemeSync, badgeVariants, buttonVariants, enableDebugMode, getCurrentCSSVariables, getTheme, getThemeCategories, getThemeFilePath, getThemesForCategory, registerTheme, useTheme, useThemeToggle };
229
+ export { Badge, Button, Checkbox, Label, Modal, ModalClose, ModalContent, ModalDescription, ModalFooter, ModalHeader, ModalOverlay, ModalPortal, ModalTitle, ModalTrigger, Select, SelectContent, SelectGroup, SelectItem, SelectLabel, SelectScrollDownButton, SelectScrollUpButton, SelectSeparator, SelectTrigger, SelectValue, Separator, THEME_CATEGORY_ORDER, TextInput, Textarea, type ThemeMetadata$1 as ThemeMetadata, type ThemeSelection, ThemeToggle, type ThemeToggleProps, Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, applyThemeSync, badgeVariants, buttonVariants, enableDebugMode, getCurrentCSSVariables, getTheme, getThemeCategories, getThemeFilePath, getThemesForCategory, registerTheme, registerThemeFromFile, useTheme, useThemeToggle };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,9 @@
1
1
  import * as class_variance_authority_types from 'class-variance-authority/types';
2
2
  import * as React from 'react';
3
3
  import { VariantProps } from 'class-variance-authority';
4
+ import * as LabelPrimitive from '@radix-ui/react-label';
5
+ import * as SeparatorPrimitive from '@radix-ui/react-separator';
6
+ import * as CheckboxPrimitive from '@radix-ui/react-checkbox';
4
7
  import * as react_jsx_runtime from 'react/jsx-runtime';
5
8
  import * as DialogPrimitive from '@radix-ui/react-dialog';
6
9
  import * as SelectPrimitive from '@radix-ui/react-select';
@@ -26,6 +29,30 @@ declare const Badge: React.ForwardRefExoticComponent<Omit<React.ClassAttributes<
26
29
  asChild?: boolean;
27
30
  }, "ref"> & React.RefAttributes<HTMLSpanElement>>;
28
31
 
32
+ declare const textInputTypes: readonly ["text", "email", "password", "number", "tel", "url", "search"];
33
+ interface TextInputProps extends React.ComponentProps<"input"> {
34
+ type?: typeof textInputTypes[number];
35
+ }
36
+ declare const TextInput: React.ForwardRefExoticComponent<Omit<TextInputProps, "ref"> & React.RefAttributes<HTMLInputElement>>;
37
+
38
+ interface LabelProps extends React.ComponentProps<typeof LabelPrimitive.Root> {
39
+ }
40
+ declare const Label: React.ForwardRefExoticComponent<Omit<LabelProps, "ref"> & React.RefAttributes<HTMLLabelElement>>;
41
+
42
+ interface TextareaProps extends React.ComponentProps<"textarea"> {
43
+ }
44
+ declare const Textarea: React.ForwardRefExoticComponent<Omit<TextareaProps, "ref"> & React.RefAttributes<HTMLTextAreaElement>>;
45
+
46
+ declare const separatorOrientations: readonly ["horizontal", "vertical"];
47
+ interface SeparatorProps extends React.ComponentProps<typeof SeparatorPrimitive.Root> {
48
+ orientation?: typeof separatorOrientations[number];
49
+ }
50
+ declare const Separator: React.ForwardRefExoticComponent<Omit<SeparatorProps, "ref"> & React.RefAttributes<HTMLDivElement>>;
51
+
52
+ interface CheckboxProps extends React.ComponentProps<typeof CheckboxPrimitive.Root> {
53
+ }
54
+ declare const Checkbox: React.ForwardRefExoticComponent<Omit<CheckboxProps, "ref"> & React.RefAttributes<HTMLButtonElement>>;
55
+
29
56
  declare function Modal({ ...props }: React.ComponentProps<typeof DialogPrimitive.Root>): react_jsx_runtime.JSX.Element;
30
57
  declare function ModalTrigger({ ...props }: React.ComponentProps<typeof DialogPrimitive.Trigger>): react_jsx_runtime.JSX.Element;
31
58
  declare function ModalPortal({ ...props }: React.ComponentProps<typeof DialogPrimitive.Portal>): react_jsx_runtime.JSX.Element;
@@ -130,11 +157,32 @@ type ThemeCategory = {
130
157
  order: number;
131
158
  themes: Record<string, ThemeMetadata>;
132
159
  };
160
+ /**
161
+ * Centralized theme category order
162
+ * Used everywhere to ensure consistency
163
+ * Custom category is included but handled specially (optional, user-created files)
164
+ *
165
+ * ⚠️ IF YOU UPDATE THIS, ALSO UPDATE:
166
+ * 1. scripts/themeConfig.js - THEME_CATEGORY_ORDER (JavaScript version)
167
+ * 2. scripts/apply-theme-sync.js - THEME_CATEGORY_ORDER constant (standalone script, can't import)
168
+ */
169
+ declare const THEME_CATEGORY_ORDER: readonly ["color", "typography", "shape", "density", "animation", "custom"];
133
170
  /**
134
171
  * Register a custom theme dynamically
135
172
  * Allows users to add themes without modifying the base config
173
+ * Can be used for any category including custom
136
174
  */
137
175
  declare function registerTheme(category: string, themeId: string, metadata: ThemeMetadata): Record<string, ThemeCategory>;
176
+ /**
177
+ * Register a theme from a token file
178
+ * Helper function to automatically register a theme by loading its file
179
+ * Users can call this after creating a theme file
180
+ */
181
+ declare function registerThemeFromFile(category: string, themeId: string, filePath?: string): Promise<{
182
+ success: boolean;
183
+ themeId: string;
184
+ category: string;
185
+ }>;
138
186
  /**
139
187
  * Get merged theme categories (base + discovered)
140
188
  */
@@ -178,4 +226,4 @@ declare function getCurrentCSSVariables(): Record<string, string>;
178
226
  */
179
227
  declare function applyThemeSync(): void;
180
228
 
181
- export { Badge, Button, Modal, ModalClose, ModalContent, ModalDescription, ModalFooter, ModalHeader, ModalOverlay, ModalPortal, ModalTitle, ModalTrigger, Select, SelectContent, SelectGroup, SelectItem, SelectLabel, SelectScrollDownButton, SelectScrollUpButton, SelectSeparator, SelectTrigger, SelectValue, type ThemeMetadata$1 as ThemeMetadata, type ThemeSelection, ThemeToggle, type ThemeToggleProps, Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, applyThemeSync, badgeVariants, buttonVariants, enableDebugMode, getCurrentCSSVariables, getTheme, getThemeCategories, getThemeFilePath, getThemesForCategory, registerTheme, useTheme, useThemeToggle };
229
+ export { Badge, Button, Checkbox, Label, Modal, ModalClose, ModalContent, ModalDescription, ModalFooter, ModalHeader, ModalOverlay, ModalPortal, ModalTitle, ModalTrigger, Select, SelectContent, SelectGroup, SelectItem, SelectLabel, SelectScrollDownButton, SelectScrollUpButton, SelectSeparator, SelectTrigger, SelectValue, Separator, THEME_CATEGORY_ORDER, TextInput, Textarea, type ThemeMetadata$1 as ThemeMetadata, type ThemeSelection, ThemeToggle, type ThemeToggleProps, Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, applyThemeSync, badgeVariants, buttonVariants, enableDebugMode, getCurrentCSSVariables, getTheme, getThemeCategories, getThemeFilePath, getThemesForCategory, registerTheme, registerThemeFromFile, useTheme, useThemeToggle };