@abhir9/pd-design-system 0.1.22 → 0.1.23

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
@@ -2,6 +2,43 @@
2
2
 
3
3
  Production-grade design system with adapter layer support. Built for teams who need a flexible, type-safe component library that can work with different UI engines without changing application code.
4
4
 
5
+ ## 🎯 What People Love About PD Design System
6
+
7
+ - ✅ **3 Lines to Get Started** - No complex setup, just works
8
+ - ✅ **System Mode Built-In** - Automatically follows OS dark/light preference
9
+ - ✅ **Zero-Config Persistence** - Pass `storageKey` prop, localStorage sync is automatic
10
+ - ✅ **Cross-Tab Sync** - Theme changes sync across browser tabs instantly
11
+ - ✅ **Type-Safe** - Full TypeScript with autocomplete for all props
12
+ - ✅ **Accessible** - WCAG 2.1 AA compliant, built on Radix UI
13
+ - ✅ **Style Isolation** - Works with Tailwind, MUI, AntD, Bootstrap, or plain CSS
14
+ - ✅ **50+ Components** - Buttons, Inputs, Modals, Dropdowns, and more
15
+ - ✅ **1000+ Icons** - All Lucide icons with TypeScript autocomplete
16
+
17
+ ## Why PD Design System?
18
+
19
+ ### 🚀 **Incredibly Easy to Use**
20
+
21
+ ```tsx
22
+ // That's it! Just 3 lines of code
23
+ <ThemeProvider storageKey="my-theme">
24
+ <Button>Click me</Button>
25
+ </ThemeProvider>
26
+ ```
27
+
28
+ No complex setup. No manual theme management. No localStorage code. Everything works automatically.
29
+
30
+ ### ✨ **Key Features**
31
+
32
+ - **🎯 Zero-Config Theme System** - Pass `storageKey` and everything works
33
+ - **🌓 System Mode Support** - Automatically follows OS dark/light preference
34
+ - **💾 Automatic Persistence** - localStorage sync with one prop
35
+ - **🔄 Cross-Tab Sync** - Theme changes sync across browser tabs
36
+ - **🎨 Semantic Tokens** - Design tokens that adapt to themes automatically
37
+ - **📦 Type-Safe** - Full TypeScript with autocomplete
38
+ - **♿ Accessible** - WCAG 2.1 AA compliant out of the box
39
+ - **🔌 Adapter Layer** - Switch UI engines without changing app code
40
+ - **🎭 Style Isolation** - Works with any CSS framework (Tailwind, MUI, AntD, etc.)
41
+
5
42
  ## Philosophy
6
43
 
7
44
  This design system follows a **headless-first, adapter-based architecture**:
@@ -11,6 +48,7 @@ This design system follows a **headless-first, adapter-based architecture**:
11
48
  - **Adapter Layer**: Switch between UI engines (shadcn, Material, etc.) without app changes
12
49
  - **Semantic Tokens**: Design tokens that work across themes
13
50
  - **Framework Agnostic**: Design tokens and semantics are framework-agnostic
51
+ - **Zero-Config Theming**: Automatic system detection and localStorage sync
14
52
 
15
53
  ## Installation
16
54
 
@@ -20,22 +58,34 @@ npm install @pd-design/system
20
58
 
21
59
  ## Quick Start
22
60
 
61
+ **Get started in 3 simple steps:**
62
+
23
63
  ```tsx
24
- import { PdThemeProvider, Button, Input } from '@pd-design/system';
64
+ import { ThemeProvider, Button } from '@pd-design/system';
25
65
  import '@pd-design/system/styles.css';
26
66
 
27
67
  function App() {
28
68
  return (
29
- <PdThemeProvider theme="base" mode="light">
30
- <Button variant="destructive" size="md">
31
- Delete
69
+ <ThemeProvider
70
+ adapter="shadcn"
71
+ theme="base"
72
+ storageKey="my-app-theme"
73
+ >
74
+ <Button variant="primary" size="md">
75
+ Click me
32
76
  </Button>
33
- <Input placeholder="Enter text..." size="md" />
34
- </PdThemeProvider>
77
+ </ThemeProvider>
35
78
  );
36
79
  }
37
80
  ```
38
81
 
82
+ That's it! 🎉 The `ThemeProvider` automatically handles:
83
+ - ✅ **System preference detection** - Follows OS dark/light mode
84
+ - ✅ **localStorage persistence** - Remembers user's theme choice
85
+ - ✅ **Cross-tab sync** - Theme changes sync across browser tabs
86
+ - ✅ **Class management** - Automatically adds `pd-root` and `pd-dark` classes
87
+ - ✅ **CSS variables** - Sets all theme variables automatically
88
+
39
89
  ### Important: Style Isolation
40
90
 
41
91
  The design system uses **scoped styling** to prevent style conflicts:
@@ -45,17 +95,65 @@ The design system uses **scoped styling** to prevent style conflicts:
45
95
  - ✅ **Preflight is disabled** - Consumer styles are never reset
46
96
  - ✅ **Works with any consumer setup** - Tailwind, MUI, AntD, Bootstrap, or plain CSS
47
97
 
48
- **Always wrap your components with `PdThemeProvider`** to create the scoped boundary:
98
+ **Always wrap your components with `ThemeProvider`** (or `PdThemeProvider`) to create the scoped boundary:
49
99
 
50
100
  ```tsx
51
- <PdThemeProvider theme="base" mode="light">
101
+ <ThemeProvider storageKey="my-theme">
52
102
  {/* Your design system components */}
53
- </PdThemeProvider>
103
+ </ThemeProvider>
104
+ ```
105
+
106
+ The `ThemeProvider` automatically adds the `pd-root` class to your body element, so all tokens are properly scoped.
107
+
108
+ ## Complete Example
109
+
110
+ Here's a complete example showing how easy it is:
111
+
112
+ ```tsx
113
+ import { ThemeProvider, Button, useTheme } from '@pd-design/system';
114
+ import '@pd-design/system/styles.css';
115
+
116
+ function App() {
117
+ return (
118
+ <ThemeProvider
119
+ adapter="shadcn"
120
+ theme="base"
121
+ storageKey="my-app-theme" // Enable localStorage persistence
122
+ >
123
+ <ThemeToggle />
124
+ <Button variant="primary">Hello World</Button>
125
+ </ThemeProvider>
126
+ );
127
+ }
128
+
129
+ function ThemeToggle() {
130
+ const { config, setConfig } = useTheme();
131
+
132
+ return (
133
+ <button onClick={() => {
134
+ const nextMode = config.mode === 'dark' ? 'light' : 'dark';
135
+ setConfig({ mode: nextMode });
136
+ // ✅ Automatically saved to localStorage
137
+ // ✅ Syncs across tabs
138
+ // ✅ Updates theme immediately
139
+ }}>
140
+ Switch to {config.mode === 'dark' ? 'Light' : 'Dark'} Mode
141
+ </button>
142
+ );
143
+ }
54
144
  ```
55
145
 
146
+ **What happens automatically:**
147
+ 1. ✅ Reads theme from localStorage on mount
148
+ 2. ✅ Detects system preference if mode is `'system'`
149
+ 3. ✅ Saves theme changes to localStorage
150
+ 4. ✅ Syncs changes across browser tabs
151
+ 5. ✅ Updates CSS variables and classes
152
+ 6. ✅ Manages `pd-root` and `pd-dark` classes
153
+
56
154
  ## Configuration
57
155
 
58
- Configure the design system globally:
156
+ For advanced use cases, you can configure the design system globally:
59
157
 
60
158
  ```tsx
61
159
  import { setDesignSystemConfig } from '@pd-design/system';
@@ -68,18 +166,21 @@ setDesignSystemConfig({
68
166
  });
69
167
  ```
70
168
 
71
- Or use the `ThemeProvider` (full-featured with context):
169
+ **Note:** When using `ThemeProvider` with `storageKey`, you don't need to call `setDesignSystemConfig` manually - it's handled automatically.
72
170
 
73
- ```tsx
74
- <ThemeProvider adapter="shadcn" theme="base" mode="light">
75
- {/* Your app */}
76
- </ThemeProvider>
77
- ```
171
+ ### ThemeProvider Props
172
+
173
+ | Prop | Type | Default | Description |
174
+ |------|------|---------|-------------|
175
+ | `adapter` | `'shadcn' \| 'material'` | `'shadcn'` | UI engine adapter |
176
+ | `theme` | `'base' \| 'brand'` | `'base'` | Theme name |
177
+ | `mode` | `'light' \| 'dark' \| 'system'` | `'system'` | Color mode (system follows OS) |
178
+ | `storageKey` | `string?` | `undefined` | localStorage key for persistence (enables sync) |
78
179
 
79
180
  ### PdThemeProvider vs ThemeProvider
80
181
 
81
- - **`PdThemeProvider`**: Lightweight wrapper that creates the `.pd-root` scoped boundary. Use for simple theming needs.
82
- - **`ThemeProvider`**: Full-featured provider with React context, system preference detection, and CSS variable management. Use when you need theme context access via `useTheme()` hook.
182
+ - **`PdThemeProvider`**: Lightweight wrapper that creates the `.pd-root` scoped boundary. Use for simple theming needs without context.
183
+ - **`ThemeProvider`**: Full-featured provider with React context, system preference detection, localStorage sync, and CSS variable management. **Recommended for most use cases.**
83
184
 
84
185
  Both support the same `theme` and `mode` props.
85
186
 
@@ -283,20 +384,69 @@ The design system supports **themes** and **modes** as separate concepts:
283
384
  - **Theme** (`theme`): The design theme name - `'base'` | `'brand'`
284
385
  - **Mode** (`mode`): The color scheme - `'light'` | `'dark'` | `'system'`
285
386
 
286
- The design system uses **scoped CSS variables** under `.pd-root`. Themes and modes can be switched without rebuilding:
387
+ ### System Mode 🌓
388
+
389
+ The `'system'` mode automatically follows your OS dark/light preference:
287
390
 
288
391
  ```tsx
289
- <PdThemeProvider theme="base" mode="dark">
290
- {/* Base theme, dark mode */}
291
- </PdThemeProvider>
392
+ <ThemeProvider storageKey="my-theme">
393
+ {/*
394
+ - If OS is dark → uses dark mode
395
+ - If OS is light → uses light mode
396
+ - Automatically updates when OS preference changes
397
+ - Works perfectly with localStorage persistence
398
+ */}
399
+ </ThemeProvider>
400
+ ```
292
401
 
293
- <PdThemeProvider theme="brand" mode="light">
294
- {/* Brand theme, light mode */}
295
- </PdThemeProvider>
402
+ **How it works:**
403
+ - On mount, detects OS preference
404
+ - Listens to OS preference changes in real-time
405
+ - Only applies system changes when mode is `'system'`
406
+ - When user manually selects `'light'` or `'dark'`, system changes are ignored
296
407
 
297
- <PdThemeProvider theme="base" mode="system">
298
- {/* Base theme, follows OS preference */}
299
- </PdThemeProvider>
408
+ ### localStorage Persistence 💾
409
+
410
+ Pass `storageKey` to enable automatic theme persistence:
411
+
412
+ ```tsx
413
+ <ThemeProvider storageKey="my-app-theme">
414
+ {/*
415
+ ✅ Reads saved preference on mount
416
+ ✅ Saves changes automatically
417
+ ✅ Syncs across browser tabs
418
+ ✅ Works with system mode
419
+ */}
420
+ </ThemeProvider>
421
+ ```
422
+
423
+ **What gets saved:**
424
+ - User's manual selection (`'light'` | `'dark'`)
425
+ - `'system'` preference (so it knows to follow OS)
426
+
427
+ **Example flow:**
428
+ 1. User selects "Dark" → Saved to localStorage
429
+ 2. User refreshes page → Reads "Dark" from localStorage
430
+ 3. User opens new tab → Reads "Dark" from localStorage (synced)
431
+ 4. User changes to "System" → Saved, now follows OS preference
432
+
433
+ ### Theme Examples
434
+
435
+ ```tsx
436
+ // Base theme, dark mode
437
+ <ThemeProvider theme="base" mode="dark" storageKey="my-theme">
438
+ {/* Your app */}
439
+ </ThemeProvider>
440
+
441
+ // Brand theme, light mode
442
+ <ThemeProvider theme="brand" mode="light" storageKey="my-theme">
443
+ {/* Your app */}
444
+ </ThemeProvider>
445
+
446
+ // Base theme, follows OS preference (recommended)
447
+ <ThemeProvider theme="base" storageKey="my-theme">
448
+ {/* Default mode is 'system' - follows OS */}
449
+ </ThemeProvider>
300
450
  ```
301
451
 
302
452
  ### Default Values
@@ -304,6 +454,7 @@ The design system uses **scoped CSS variables** under `.pd-root`. Themes and mod
304
454
  - **adapter**: `'shadcn'` (default)
305
455
  - **theme**: `'base'` (default)
306
456
  - **mode**: `'system'` (default - follows OS preference)
457
+ - **storageKey**: `undefined` (no persistence by default, pass a key to enable)
307
458
 
308
459
  ### Custom Themes
309
460
 
@@ -363,15 +514,16 @@ npm run storybook
363
514
  ```
364
515
 
365
516
  Storybook includes:
366
- - All component variants
367
- - Interactive controls
368
- - Theme switcher (base/brand)
369
- - Mode switcher (light/dark/system)
370
- - Adapter switcher (shadcn/material)
371
- - Icons browser with search
372
- - Accessibility panel
373
- - Code snippets
374
- - Live examples
517
+ - All component variants with live examples
518
+ - Interactive controls for all props
519
+ - ✅ **Theme switcher** (base/brand) - See components in different themes
520
+ - ✅ **Mode switcher** (light/dark/system) - Test system mode detection
521
+ - ✅ **Adapter switcher** (shadcn/material) - Switch UI engines
522
+ - ✅ **Icons browser** with search - Browse 1000+ Lucide icons
523
+ - ✅ **Accessibility panel** - WCAG compliance checks
524
+ - ✅ **Code snippets** - Copy-paste ready examples
525
+ - **Design tokens showcase** - See all color primitives and semantic tokens
526
+ - ✅ **Dark mode preview** - See how components look in dark mode
375
527
 
376
528
  ## Architecture
377
529
 
@@ -446,10 +598,10 @@ import {
446
598
  Icons
447
599
  } from '@pd-design/system';
448
600
 
449
- // Theme
601
+ // Theme (Recommended: ThemeProvider with storageKey)
450
602
  import {
451
- ThemeProvider,
452
- useTheme,
603
+ ThemeProvider, // Full-featured provider with localStorage sync
604
+ useTheme, // Hook to access/update theme
453
605
  setDesignSystemConfig,
454
606
  getDesignSystemConfig
455
607
  } from '@pd-design/system';
@@ -502,6 +654,74 @@ All components use consistent prop patterns:
502
654
  - ✅ Disabled state handling (aria-disabled, pointer-events)
503
655
  - ✅ Loading state indicators (aria-busy)
504
656
 
657
+ ## Common Use Cases
658
+
659
+ ### Use Case 1: Basic Setup with Persistence
660
+
661
+ ```tsx
662
+ <ThemeProvider storageKey="my-app-theme">
663
+ <App />
664
+ </ThemeProvider>
665
+ ```
666
+
667
+ **What you get:**
668
+ - ✅ System mode detection (follows OS)
669
+ - ✅ Theme persistence (remembers user choice)
670
+ - ✅ Cross-tab sync
671
+ - ✅ Zero configuration
672
+
673
+ ### Use Case 2: Force Light Mode
674
+
675
+ ```tsx
676
+ <ThemeProvider mode="light">
677
+ <App />
678
+ </ThemeProvider>
679
+ ```
680
+
681
+ **What you get:**
682
+ - ✅ Always light mode
683
+ - ✅ Ignores system preference
684
+ - ✅ No localStorage (no storageKey)
685
+
686
+ ### Use Case 3: Custom Theme with System Mode
687
+
688
+ ```tsx
689
+ <ThemeProvider
690
+ theme="brand"
691
+ storageKey="my-brand-theme"
692
+ >
693
+ <App />
694
+ </ThemeProvider>
695
+ ```
696
+
697
+ **What you get:**
698
+ - ✅ Brand theme
699
+ - ✅ System mode with persistence
700
+ - ✅ User can override system preference
701
+
702
+ ### Use Case 4: Theme Toggle Component
703
+
704
+ ```tsx
705
+ function ThemeToggle() {
706
+ const { config, setConfig } = useTheme();
707
+
708
+ const toggle = () => {
709
+ const modes: ThemeMode[] = ['light', 'dark', 'system'];
710
+ const currentIndex = modes.indexOf(config.mode);
711
+ const nextIndex = (currentIndex + 1) % modes.length;
712
+ setConfig({ mode: modes[nextIndex] });
713
+ };
714
+
715
+ return (
716
+ <button onClick={toggle}>
717
+ {config.mode === 'system' && '🌓 System'}
718
+ {config.mode === 'light' && '☀️ Light'}
719
+ {config.mode === 'dark' && '🌙 Dark'}
720
+ </button>
721
+ );
722
+ }
723
+ ```
724
+
505
725
  ## Browser Support
506
726
 
507
727
  - Chrome (latest)
@@ -510,6 +730,37 @@ All components use consistent prop patterns:
510
730
  - Edge (latest)
511
731
  - Mobile browsers (iOS Safari, Chrome Mobile)
512
732
 
733
+ ## Quick Reference
734
+
735
+ ### ThemeProvider Props
736
+
737
+ | Prop | Type | Default | Description |
738
+ |------|------|---------|-------------|
739
+ | `adapter` | `'shadcn' \| 'material'` | `'shadcn'` | UI engine adapter |
740
+ | `theme` | `'base' \| 'brand'` | `'base'` | Theme name |
741
+ | `mode` | `'light' \| 'dark' \| 'system'` | `'system'` | Color mode |
742
+ | `storageKey` | `string?` | `undefined` | localStorage key (enables persistence) |
743
+
744
+ ### What Happens When You Pass `storageKey`?
745
+
746
+ ✅ **Automatic localStorage sync** - Reads and writes theme preference
747
+ ✅ **Cross-tab synchronization** - Changes sync across browser tabs
748
+ ✅ **System mode support** - Follows OS preference when mode is `'system'`
749
+ ✅ **Class management** - Automatically adds `pd-root` and `pd-dark` classes
750
+ ✅ **CSS variables** - Sets all theme variables automatically
751
+
752
+ ### System Mode Behavior
753
+
754
+ - **`mode="system"`** (default): Follows OS dark/light preference, updates automatically
755
+ - **`mode="light"`**: Always light mode, ignores system preference
756
+ - **`mode="dark"`**: Always dark mode, ignores system preference
757
+
758
+ When `storageKey` is provided:
759
+ - User's manual selection (`light`/`dark`) is saved
760
+ - `system` preference is also saved
761
+ - On refresh, uses saved preference
762
+ - System changes only apply when mode is `'system'`
763
+
513
764
  ## Contributing
514
765
 
515
766
  This is an internal design system. For contributions, please follow the architecture guidelines in `ARCHITECTURE.md`.
package/dist/index.css CHANGED
@@ -616,6 +616,9 @@
616
616
  font-family: var(--pd-font-sans, Gist, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif);
617
617
  color: var(--pd-text-body, var(--pd-content-primary));
618
618
  background: var(--pd-background-primary);
619
+ /* Set font-size to 16px to ensure rem-based calculations use standard base */
620
+ /* This prevents consumer's root font-size (e.g., 10px) from affecting pd-design components */
621
+ font-size: 16px;
619
622
  }
620
623
  /* Ensure interactive elements behave correctly even with global resets */
621
624
  .pd-root button {
@@ -1147,6 +1150,9 @@
1147
1150
  .pd-overflow-hidden {
1148
1151
  overflow: hidden;
1149
1152
  }
1153
+ .pd-overflow-x-auto {
1154
+ overflow-x: auto;
1155
+ }
1150
1156
  .pd-truncate {
1151
1157
  overflow: hidden;
1152
1158
  text-overflow: ellipsis;
@@ -1244,6 +1250,9 @@
1244
1250
  .\!pd-bg-\[var\(--pd-background-tertiary\)\] {
1245
1251
  background-color: var(--pd-background-tertiary) !important;
1246
1252
  }
1253
+ .pd-bg-\[var\(--pd-background-blue\)\] {
1254
+ background-color: var(--pd-background-blue);
1255
+ }
1247
1256
  .pd-bg-\[var\(--pd-background-green\)\] {
1248
1257
  background-color: var(--pd-background-green);
1249
1258
  }
package/dist/styles.css CHANGED
@@ -625,6 +625,7 @@
625
625
  font-family: var(--pd-font-sans, Gist, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif);
626
626
  color: var(--pd-text-body, var(--pd-content-primary));
627
627
  background: var(--pd-background-primary);
628
+ font-size: 16px;
628
629
  }
629
630
  .pd-root button {
630
631
  font-family: var(--pd-font-sans, Gist, sans-serif);
@@ -1148,6 +1149,9 @@
1148
1149
  .pd-overflow-hidden {
1149
1150
  overflow: hidden;
1150
1151
  }
1152
+ .pd-overflow-x-auto {
1153
+ overflow-x: auto;
1154
+ }
1151
1155
  .pd-truncate {
1152
1156
  overflow: hidden;
1153
1157
  text-overflow: ellipsis;
@@ -1245,6 +1249,9 @@
1245
1249
  .\!pd-bg-\[var\(--pd-background-tertiary\)\] {
1246
1250
  background-color: var(--pd-background-tertiary) !important;
1247
1251
  }
1252
+ .pd-bg-\[var\(--pd-background-blue\)\] {
1253
+ background-color: var(--pd-background-blue);
1254
+ }
1248
1255
  .pd-bg-\[var\(--pd-background-green\)\] {
1249
1256
  background-color: var(--pd-background-green);
1250
1257
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abhir9/pd-design-system",
3
- "version": "0.1.22",
3
+ "version": "0.1.23",
4
4
  "description": "Production-grade design system with adapter layer support",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",