@hellboy/ds 0.1.3 → 0.2.7
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 +512 -162
- package/{src/style/components/badge → dist/components}/badge.css +9 -25
- package/dist/components/badge.d.mts +12 -0
- package/dist/components/badge.d.ts +12 -0
- package/dist/components/badge.js +42 -0
- package/dist/components/badge.mjs +15 -0
- package/dist/components/banner.css +280 -0
- package/dist/components/banner.d.mts +12 -0
- package/dist/components/banner.d.ts +12 -0
- package/dist/components/banner.js +184 -0
- package/dist/components/banner.mjs +147 -0
- package/dist/components/button-group.css +289 -0
- package/dist/components/button-group.d.mts +81 -0
- package/dist/components/button-group.d.ts +81 -0
- package/dist/components/button-group.js +180 -0
- package/dist/components/button-group.mjs +143 -0
- package/{src/style/components/button → dist/components}/button.css +59 -62
- package/dist/components/button.d.mts +57 -0
- package/dist/components/button.d.ts +57 -0
- package/dist/components/button.js +129 -0
- package/dist/components/button.mjs +92 -0
- package/{src/style/components/card → dist/components}/card.css +9 -30
- package/dist/components/card.d.mts +31 -0
- package/dist/components/card.d.ts +31 -0
- package/dist/components/card.js +59 -0
- package/dist/components/card.mjs +32 -0
- package/{src/style → dist}/components/checkbox.css +51 -43
- package/dist/components/checkbox.d.mts +31 -0
- package/dist/components/checkbox.d.ts +31 -0
- package/dist/components/checkbox.js +130 -0
- package/dist/components/checkbox.mjs +93 -0
- package/{src/style/components/code-block → dist/components}/code-block.css +3 -7
- package/dist/components/code-block.d.mts +24 -0
- package/dist/components/code-block.d.ts +24 -0
- package/dist/components/code-block.js +43 -0
- package/dist/components/code-block.mjs +16 -0
- package/dist/components/color-control.css +285 -0
- package/dist/components/color-control.d.mts +5 -0
- package/dist/components/color-control.d.ts +5 -0
- package/dist/components/color-control.js +534 -0
- package/dist/components/color-control.mjs +497 -0
- package/dist/components/dialog.css +930 -0
- package/dist/components/dialog.d.mts +32 -0
- package/dist/components/dialog.d.ts +32 -0
- package/dist/components/dialog.js +1111 -0
- package/dist/components/dialog.mjs +1074 -0
- package/dist/components/divider.css +356 -0
- package/dist/components/divider.d.mts +32 -0
- package/dist/components/divider.d.ts +32 -0
- package/dist/components/divider.js +344 -0
- package/dist/components/divider.mjs +307 -0
- package/{src/style/components/drag-handle → dist/components}/drag-handle.css +3 -18
- package/dist/components/drag-handle.d.mts +11 -0
- package/dist/components/drag-handle.d.ts +11 -0
- package/dist/components/drag-handle.js +103 -0
- package/dist/components/drag-handle.mjs +66 -0
- package/dist/components/drawer.css +1027 -0
- package/dist/components/drawer.d.mts +14 -0
- package/dist/components/drawer.d.ts +14 -0
- package/dist/components/drawer.js +1072 -0
- package/dist/components/drawer.mjs +1035 -0
- package/dist/components/floating-bar.css +17 -0
- package/dist/components/floating-bar.d.mts +25 -0
- package/dist/components/floating-bar.d.ts +25 -0
- package/dist/components/floating-bar.js +52 -0
- package/dist/components/floating-bar.mjs +25 -0
- package/dist/components/footer.css +40 -0
- package/dist/components/footer.d.mts +8 -0
- package/dist/components/footer.d.ts +8 -0
- package/dist/components/footer.js +44 -0
- package/dist/components/footer.mjs +17 -0
- package/dist/components/grid.css +47 -0
- package/dist/components/grid.d.mts +27 -0
- package/dist/components/grid.d.ts +27 -0
- package/dist/components/grid.js +52 -0
- package/dist/components/grid.mjs +25 -0
- package/dist/components/header.css +1075 -0
- package/dist/components/header.d.mts +35 -0
- package/dist/components/header.d.ts +35 -0
- package/dist/components/header.js +1402 -0
- package/dist/components/header.mjs +1365 -0
- package/dist/components/hero.css +121 -0
- package/dist/components/hero.d.mts +111 -0
- package/dist/components/hero.d.ts +111 -0
- package/dist/components/hero.js +285 -0
- package/dist/components/hero.mjs +248 -0
- package/{src/style/components/icons → dist/components}/icons.css +14 -15
- package/dist/components/icons.d.mts +104 -0
- package/dist/components/icons.d.ts +104 -0
- package/dist/components/icons.js +239 -0
- package/dist/components/icons.mjs +203 -0
- package/{src/style/components/input → dist/components}/input.css +189 -102
- package/dist/components/input.d.mts +114 -0
- package/dist/components/input.d.ts +114 -0
- package/dist/components/input.js +926 -0
- package/dist/components/input.mjs +879 -0
- package/dist/components/layout.css +551 -0
- package/dist/components/layout.d.mts +16 -0
- package/dist/components/layout.d.ts +16 -0
- package/dist/components/layout.js +387 -0
- package/dist/components/layout.mjs +352 -0
- package/{src/style/components/list → dist/components}/list.css +47 -41
- package/dist/components/list.d.mts +46 -0
- package/dist/components/list.d.ts +46 -0
- package/dist/components/list.js +124 -0
- package/dist/components/list.mjs +96 -0
- package/dist/components/navbar.css +706 -0
- package/dist/components/navbar.d.mts +56 -0
- package/dist/components/navbar.d.ts +56 -0
- package/dist/components/navbar.js +994 -0
- package/dist/components/navbar.mjs +952 -0
- package/{src/style/components/page-index → dist/components}/page-index.css +2 -47
- package/dist/components/page-index.d.mts +25 -0
- package/dist/components/page-index.d.ts +25 -0
- package/dist/components/page-index.js +239 -0
- package/dist/components/page-index.mjs +202 -0
- package/{src/style/components/page → dist/components}/page.css +4 -15
- package/dist/components/page.d.mts +30 -0
- package/dist/components/page.d.ts +30 -0
- package/dist/components/page.js +40 -0
- package/dist/components/page.mjs +13 -0
- package/dist/components/popover.css +87 -0
- package/dist/components/popover.d.mts +22 -0
- package/dist/components/popover.d.ts +22 -0
- package/dist/components/popover.js +243 -0
- package/dist/components/popover.mjs +206 -0
- package/{src/style → dist}/components/radio.css +8 -51
- package/dist/components/radio.d.mts +59 -0
- package/dist/components/radio.d.ts +59 -0
- package/dist/components/radio.js +133 -0
- package/dist/components/radio.mjs +95 -0
- package/dist/components/section.css +993 -0
- package/dist/components/section.d.mts +33 -0
- package/dist/components/section.d.ts +33 -0
- package/dist/components/section.js +1401 -0
- package/dist/components/section.mjs +1364 -0
- package/dist/components/select.css +391 -0
- package/dist/components/select.d.mts +63 -0
- package/dist/components/select.d.ts +63 -0
- package/dist/components/select.js +452 -0
- package/dist/components/select.mjs +415 -0
- package/{src/style/components/slider → dist/components}/slider.css +55 -33
- package/dist/components/slider.d.mts +69 -0
- package/dist/components/slider.d.ts +69 -0
- package/dist/components/slider.js +254 -0
- package/dist/components/slider.mjs +217 -0
- package/dist/components/switch.css +1081 -0
- package/dist/components/switch.d.mts +33 -0
- package/dist/components/switch.d.ts +33 -0
- package/dist/components/switch.js +1092 -0
- package/dist/components/switch.mjs +1055 -0
- package/{src/style/components/table → dist/components}/table.css +3 -28
- package/dist/components/table.d.mts +42 -0
- package/dist/components/table.d.ts +42 -0
- package/dist/components/table.js +108 -0
- package/dist/components/table.mjs +76 -0
- package/dist/components/tag.css +97 -0
- package/dist/components/tag.d.mts +12 -0
- package/dist/components/tag.d.ts +12 -0
- package/dist/components/tag.js +42 -0
- package/dist/components/tag.mjs +15 -0
- package/dist/components/textarea.css +1359 -0
- package/dist/components/textarea.d.mts +84 -0
- package/dist/components/textarea.d.ts +84 -0
- package/dist/components/textarea.js +1962 -0
- package/dist/components/textarea.mjs +1924 -0
- package/{src/style/components/theme-control → dist/components}/theme-control.css +3 -7
- package/dist/components/theme-control.d.mts +9 -0
- package/dist/components/theme-control.d.ts +9 -0
- package/dist/components/theme-control.js +235 -0
- package/dist/components/theme-control.mjs +200 -0
- package/{src/style/components/tooltip → dist/components}/tooltip.css +5 -13
- package/dist/components/tooltip.d.mts +12 -0
- package/dist/components/tooltip.d.ts +12 -0
- package/dist/components/tooltip.js +200 -0
- package/dist/components/tooltip.mjs +163 -0
- package/dist/icons-Czahnf-r.d.mts +15 -0
- package/dist/icons-Czahnf-r.d.ts +15 -0
- package/dist/index.css +2914 -2067
- package/dist/index.d.mts +144 -721
- package/dist/index.d.ts +144 -721
- package/dist/index.js +4076 -2282
- package/dist/index.mjs +4132 -2366
- package/dist/theme.css +34 -34
- package/package.json +27 -8
- package/dist/index.css.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/index.mjs.map +0 -1
- package/hellboy-ds-0.1.2.tgz +0 -0
- package/src/components/badge/Badge.tsx +0 -29
- package/src/components/badge/index.ts +0 -1
- package/src/components/banner/Banner.tsx +0 -48
- package/src/components/banner/banner.css +0 -44
- package/src/components/banner/index.ts +0 -1
- package/src/components/button/button.tsx +0 -127
- package/src/components/button/index.ts +0 -1
- package/src/components/card/card.tsx +0 -57
- package/src/components/card/index.ts +0 -1
- package/src/components/checkbox/Checkbox.tsx +0 -98
- package/src/components/checkbox/index.ts +0 -1
- package/src/components/code-block/code-block.tsx +0 -44
- package/src/components/code-block/index.ts +0 -1
- package/src/components/color-control/color-control.tsx +0 -322
- package/src/components/color-control/index.ts +0 -1
- package/src/components/drag-handle/DragHandle.tsx +0 -78
- package/src/components/drag-handle/index.ts +0 -1
- package/src/components/drawer/drawer.tsx +0 -82
- package/src/components/drawer/index.ts +0 -1
- package/src/components/floating-bar/floating-bar.tsx +0 -52
- package/src/components/floating-bar/index.ts +0 -2
- package/src/components/footer/footer.tsx +0 -28
- package/src/components/footer/index.ts +0 -1
- package/src/components/grid/Grid.tsx +0 -53
- package/src/components/grid/index.ts +0 -1
- package/src/components/header/header.tsx +0 -57
- package/src/components/header/index.ts +0 -1
- package/src/components/icons/icons.tsx +0 -44
- package/src/components/icons/index.ts +0 -1
- package/src/components/index.ts +0 -29
- package/src/components/input/DatePicker.tsx +0 -133
- package/src/components/input/Input.tsx +0 -220
- package/src/components/input/InputDate.tsx +0 -10
- package/src/components/input/InputDateTime.tsx +0 -10
- package/src/components/input/InputEmail.tsx +0 -10
- package/src/components/input/InputField.tsx +0 -137
- package/src/components/input/InputNumber.tsx +0 -10
- package/src/components/input/InputPassword.tsx +0 -10
- package/src/components/input/InputSearch.tsx +0 -10
- package/src/components/input/InputTel.tsx +0 -10
- package/src/components/input/InputText.tsx +0 -10
- package/src/components/input/InputTime.tsx +0 -10
- package/src/components/input/InputUrl.tsx +0 -10
- package/src/components/input/TimePicker.tsx +0 -151
- package/src/components/input/index.ts +0 -11
- package/src/components/layout/Layout.tsx +0 -244
- package/src/components/layout/index.ts +0 -1
- package/src/components/list/List.tsx +0 -159
- package/src/components/list/index.ts +0 -1
- package/src/components/navbar/MenuCategory.tsx +0 -20
- package/src/components/navbar/MenuGroup.tsx +0 -288
- package/src/components/navbar/MenuItem.tsx +0 -65
- package/src/components/navbar/Navbar.tsx +0 -23
- package/src/components/navbar/index.ts +0 -4
- package/src/components/page/index.ts +0 -1
- package/src/components/page/page.tsx +0 -46
- package/src/components/page-index/PageIndex.tsx +0 -275
- package/src/components/page-index/index.ts +0 -1
- package/src/components/popover/index.ts +0 -1
- package/src/components/popover/popover.tsx +0 -199
- package/src/components/radio/Radio.tsx +0 -176
- package/src/components/radio/index.ts +0 -1
- package/src/components/section/index.ts +0 -1
- package/src/components/section/section.tsx +0 -66
- package/src/components/select/Select.tsx +0 -212
- package/src/components/select/index.ts +0 -1
- package/src/components/slider/Slider.tsx +0 -267
- package/src/components/slider/index.ts +0 -1
- package/src/components/switch/index.ts +0 -1
- package/src/components/switch/switch.tsx +0 -99
- package/src/components/table/Table.tsx +0 -147
- package/src/components/table/index.ts +0 -1
- package/src/components/theme-control/index.ts +0 -1
- package/src/components/theme-control/theme-control.tsx +0 -78
- package/src/components/tooltip/index.ts +0 -1
- package/src/components/tooltip/tooltip.tsx +0 -207
- package/src/contexts/NavbarTooltipContext.tsx +0 -48
- package/src/contexts/index.ts +0 -1
- package/src/foundations/motion.md +0 -136
- package/src/index.ts +0 -40
- package/src/style/_shared/field.css +0 -69
- package/src/style/components/color-control/color-control.css +0 -126
- package/src/style/components/drawer/drawer.css +0 -210
- package/src/style/components/floating-bar/floating-bar.css +0 -39
- package/src/style/components/footer/footer.css +0 -108
- package/src/style/components/grid/grid.css +0 -33
- package/src/style/components/header/header.css +0 -44
- package/src/style/components/layout/layout.css +0 -205
- package/src/style/components/navbar/navbar.css +0 -342
- package/src/style/components/popover/popover.css +0 -44
- package/src/style/components/section/section.css +0 -67
- package/src/style/components/select/select.css +0 -143
- package/src/style/components/switch/switch.css +0 -267
- package/src/style/foundations/global.css +0 -316
- package/src/style/foundations/motion.css +0 -164
- package/src/style/foundations/spacing.css +0 -51
- package/src/style/foundations/typography.css +0 -39
- package/src/style/foundations/z-index.css +0 -81
- package/src/style/modes/dark.css +0 -146
- package/src/style/modes/light.css +0 -147
- package/src/style/semantic.css +0 -52
- package/src/style/styles.css +0 -51
- package/src/style/themes/theme.json +0 -37
- package/src/utils/README.md +0 -305
- package/src/utils/USER_PREFERENCES.md +0 -558
- package/src/utils/theme.ts +0 -127
- package/src/utils/user-preferences.ts +0 -577
- package/tsconfig.json +0 -25
- package/tsup.config.ts +0 -52
package/src/style/styles.css
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Hellboy Design System - Main Styles
|
|
3
|
-
* Central import for all tokens, foundations, themes, and component styles
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
/* Google Fonts */
|
|
7
|
-
@import url('https://fonts.googleapis.com/css2?family=Signika:wght@300..700&family=Rubik:ital,wght@0,300;0,500;0,600;0,700;1,400;1,500;1,600;1,700&display=swap');
|
|
8
|
-
|
|
9
|
-
/* Theme (replaceable)
|
|
10
|
-
NOTE: `theme.json` is the source of truth for theme values (7 core colors).
|
|
11
|
-
During build we generate `theme.css` from `src/style/themes/theme.json` and
|
|
12
|
-
write it to `dist/theme.css` so consumers can load `/theme.css` directly.
|
|
13
|
-
Do NOT import `theme.css` into this bundled stylesheet; keep the file
|
|
14
|
-
separate so end-users can override or replace `theme.json` as needed.
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
/* Foundations */
|
|
18
|
-
@import './foundations/typography.css';
|
|
19
|
-
@import './foundations/spacing.css';
|
|
20
|
-
@import './foundations/motion.css';
|
|
21
|
-
@import './foundations/z-index.css';
|
|
22
|
-
@import './foundations/global.css';
|
|
23
|
-
|
|
24
|
-
/* Modes */
|
|
25
|
-
@import './modes/light.css';
|
|
26
|
-
@import './modes/dark.css';
|
|
27
|
-
|
|
28
|
-
/* Semantic (color mappings) */
|
|
29
|
-
@import './semantic.css';
|
|
30
|
-
|
|
31
|
-
/* Component Styles */
|
|
32
|
-
@import './components/button/button.css';
|
|
33
|
-
@import './components/checkbox.css';
|
|
34
|
-
@import './components/switch/switch.css';
|
|
35
|
-
@import './components/header/header.css';
|
|
36
|
-
@import './components/page/page.css';
|
|
37
|
-
@import './components/section/section.css';
|
|
38
|
-
@import './components/layout/layout.css';
|
|
39
|
-
@import './components/navbar/navbar.css';
|
|
40
|
-
@import './components/code-block/code-block.css';
|
|
41
|
-
@import './components/popover/popover.css';
|
|
42
|
-
@import './components/theme-control/theme-control.css';
|
|
43
|
-
@import './components/card/card.css';
|
|
44
|
-
@import './components/color-control/color-control.css';
|
|
45
|
-
@import './components/grid/grid.css';
|
|
46
|
-
@import './components/slider/slider.css';
|
|
47
|
-
@import './components/input/input.css';
|
|
48
|
-
@import './components/list/list.css';
|
|
49
|
-
@import './components/radio.css';
|
|
50
|
-
@import './components/select/select.css';
|
|
51
|
-
@import './components/page-index/page-index.css';
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"primary": {
|
|
3
|
-
"hue": 0,
|
|
4
|
-
"saturation": 69,
|
|
5
|
-
"lightness": 31
|
|
6
|
-
},
|
|
7
|
-
"secondary": {
|
|
8
|
-
"hue": 16,
|
|
9
|
-
"saturation": 63,
|
|
10
|
-
"lightness": 23
|
|
11
|
-
},
|
|
12
|
-
"accent": {
|
|
13
|
-
"hue": 0,
|
|
14
|
-
"saturation": 89,
|
|
15
|
-
"lightness": 41
|
|
16
|
-
},
|
|
17
|
-
"success": {
|
|
18
|
-
"hue": 140,
|
|
19
|
-
"saturation": 100,
|
|
20
|
-
"lightness": 19
|
|
21
|
-
},
|
|
22
|
-
"warning": {
|
|
23
|
-
"hue": 34,
|
|
24
|
-
"saturation": 100,
|
|
25
|
-
"lightness": 31
|
|
26
|
-
},
|
|
27
|
-
"error": {
|
|
28
|
-
"hue": 264,
|
|
29
|
-
"saturation": 0,
|
|
30
|
-
"lightness": 14
|
|
31
|
-
},
|
|
32
|
-
"info": {
|
|
33
|
-
"hue": 261,
|
|
34
|
-
"saturation": 69,
|
|
35
|
-
"lightness": 31
|
|
36
|
-
}
|
|
37
|
-
}
|
package/src/utils/README.md
DELETED
|
@@ -1,305 +0,0 @@
|
|
|
1
|
-
# Design System Utilities
|
|
2
|
-
|
|
3
|
-
This directory contains utility modules that provide practical, production-ready solutions for common application needs.
|
|
4
|
-
|
|
5
|
-
## Philosophy
|
|
6
|
-
|
|
7
|
-
The Hellboy Design System utilities are designed to **accelerate development** by providing complete, opinionated solutions that go beyond basic component libraries. While we remain framework-agnostic where possible, we prioritize **developer productivity** and **real-world usability** over pure abstraction.
|
|
8
|
-
|
|
9
|
-
## Available Utilities
|
|
10
|
-
|
|
11
|
-
### 🎨 Theme Utilities (`theme.ts`)
|
|
12
|
-
|
|
13
|
-
Theme management with support for:
|
|
14
|
-
- Light/dark mode switching
|
|
15
|
-
- System preference detection
|
|
16
|
-
- Custom color configuration
|
|
17
|
-
- Persistent storage across sessions
|
|
18
|
-
|
|
19
|
-
**Key Features:**
|
|
20
|
-
- Automatic OS theme detection
|
|
21
|
-
- localStorage persistence (now using User Preferences system)
|
|
22
|
-
- CSS variable management
|
|
23
|
-
- TypeScript type safety
|
|
24
|
-
|
|
25
|
-
**Documentation:** See inline JSDoc comments in `theme.ts`
|
|
26
|
-
|
|
27
|
-
**Quick Start:**
|
|
28
|
-
```typescript
|
|
29
|
-
import { getTheme, setTheme, toggleTheme } from '@hellboy/ds';
|
|
30
|
-
|
|
31
|
-
// Get current theme
|
|
32
|
-
const theme = getTheme(); // 'light' | 'dark'
|
|
33
|
-
|
|
34
|
-
// Set theme
|
|
35
|
-
setTheme('dark');
|
|
36
|
-
|
|
37
|
-
// Toggle theme
|
|
38
|
-
toggleTheme();
|
|
39
|
-
```
|
|
40
|
-
|
|
41
|
-
---
|
|
42
|
-
|
|
43
|
-
### 💾 User Preferences (`user-preferences.ts`)
|
|
44
|
-
|
|
45
|
-
Comprehensive preference management system for storing user settings, configurations, and UI state.
|
|
46
|
-
|
|
47
|
-
**Key Features:**
|
|
48
|
-
- Type-safe preference storage
|
|
49
|
-
- localStorage with optional IndexedDB fallback
|
|
50
|
-
- Namespace support for organization
|
|
51
|
-
- Export/import functionality
|
|
52
|
-
- Framework-agnostic design
|
|
53
|
-
- Automatic migration from legacy storage
|
|
54
|
-
|
|
55
|
-
**Use Cases:**
|
|
56
|
-
- Theme preferences (light/dark, custom colors)
|
|
57
|
-
- Layout dimensions (sidebar widths, panel sizes)
|
|
58
|
-
- Component states (drawer positions, table settings)
|
|
59
|
-
- User-specific settings (language, timezone, etc.)
|
|
60
|
-
|
|
61
|
-
**Documentation:** See `USER_PREFERENCES.md` for comprehensive guide
|
|
62
|
-
|
|
63
|
-
**Quick Start:**
|
|
64
|
-
```typescript
|
|
65
|
-
import { getPreference, setPreference } from '@hellboy/ds';
|
|
66
|
-
|
|
67
|
-
// Save a preference
|
|
68
|
-
setPreference('sidebarWidth', 300);
|
|
69
|
-
|
|
70
|
-
// Load a preference with default
|
|
71
|
-
const width = getPreference('sidebarWidth', 280);
|
|
72
|
-
|
|
73
|
-
// Use with namespaces
|
|
74
|
-
import { createPreferenceNamespace } from '@hellboy/ds';
|
|
75
|
-
const layoutPrefs = createPreferenceNamespace('layout');
|
|
76
|
-
layoutPrefs.set('collapsed', true);
|
|
77
|
-
```
|
|
78
|
-
|
|
79
|
-
---
|
|
80
|
-
|
|
81
|
-
## Integration Examples
|
|
82
|
-
|
|
83
|
-
### Theme + User Preferences
|
|
84
|
-
|
|
85
|
-
The theme utilities now use the User Preferences system under the hood, providing automatic migration from legacy storage:
|
|
86
|
-
|
|
87
|
-
```typescript
|
|
88
|
-
import { setTheme, getTheme } from '@hellboy/ds';
|
|
89
|
-
|
|
90
|
-
// Theme is automatically stored using the preference system
|
|
91
|
-
setTheme('dark'); // Saved to preferences as 'theme': 'dark'
|
|
92
|
-
|
|
93
|
-
// Retrieve theme (checks preferences, then legacy localStorage)
|
|
94
|
-
const theme = getTheme();
|
|
95
|
-
```
|
|
96
|
-
|
|
97
|
-
### Layout with Persistent Dimensions
|
|
98
|
-
|
|
99
|
-
The `Layout` component automatically saves sidebar widths:
|
|
100
|
-
|
|
101
|
-
```tsx
|
|
102
|
-
import { Layout } from '@hellboy/ds';
|
|
103
|
-
|
|
104
|
-
// Sidebar widths are automatically saved and restored
|
|
105
|
-
<Layout
|
|
106
|
-
variant="sidebar-main-sidebar"
|
|
107
|
-
resizable
|
|
108
|
-
sidebarLeft={<Sidebar />}
|
|
109
|
-
sidebarRight={<RightPanel />}
|
|
110
|
-
>
|
|
111
|
-
<MainContent />
|
|
112
|
-
</Layout>
|
|
113
|
-
```
|
|
114
|
-
|
|
115
|
-
Internally, the Layout component uses:
|
|
116
|
-
```typescript
|
|
117
|
-
const leftWidth = getPreference('layout.leftSidebarWidth', 280);
|
|
118
|
-
// User resizes sidebar...
|
|
119
|
-
setPreference('layout.leftSidebarWidth', newWidth);
|
|
120
|
-
```
|
|
121
|
-
|
|
122
|
-
### React Hook Pattern
|
|
123
|
-
|
|
124
|
-
Create reusable hooks for your app:
|
|
125
|
-
|
|
126
|
-
```typescript
|
|
127
|
-
// hooks/usePreference.ts
|
|
128
|
-
import { useState } from 'react';
|
|
129
|
-
import { getPreference, setPreference } from '@hellboy/ds';
|
|
130
|
-
|
|
131
|
-
export function usePreference<T>(key: string, defaultValue: T) {
|
|
132
|
-
const [value, setValue] = useState<T>(() =>
|
|
133
|
-
getPreference(key, defaultValue) ?? defaultValue
|
|
134
|
-
);
|
|
135
|
-
|
|
136
|
-
const updateValue = (newValue: T) => {
|
|
137
|
-
setValue(newValue);
|
|
138
|
-
setPreference(key, newValue);
|
|
139
|
-
};
|
|
140
|
-
|
|
141
|
-
return [value, updateValue] as const;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
// Use in components
|
|
145
|
-
function MyComponent() {
|
|
146
|
-
const [theme, setTheme] = usePreference('theme', 'light');
|
|
147
|
-
const [sidebarWidth, setSidebarWidth] = usePreference('layout.sidebarWidth', 280);
|
|
148
|
-
|
|
149
|
-
return (
|
|
150
|
-
<div>
|
|
151
|
-
<button onClick={() => setTheme(theme === 'light' ? 'dark' : 'light')}>
|
|
152
|
-
Toggle Theme
|
|
153
|
-
</button>
|
|
154
|
-
</div>
|
|
155
|
-
);
|
|
156
|
-
}
|
|
157
|
-
```
|
|
158
|
-
|
|
159
|
-
## Design Decisions
|
|
160
|
-
|
|
161
|
-
### Why User Preferences?
|
|
162
|
-
|
|
163
|
-
Many design systems stop at providing UI components. We believe that's only half the story. Real applications need:
|
|
164
|
-
|
|
165
|
-
1. **State Persistence**: Users expect their preferences to be remembered
|
|
166
|
-
2. **Type Safety**: TypeScript support prevents runtime errors
|
|
167
|
-
3. **Organization**: Namespaces keep large apps maintainable
|
|
168
|
-
4. **Portability**: Export/import allows users to backup settings
|
|
169
|
-
5. **Migration**: Automatic legacy storage migration prevents breaking changes
|
|
170
|
-
|
|
171
|
-
### Why localStorage by Default?
|
|
172
|
-
|
|
173
|
-
- ✅ **Synchronous**: No async complexity for simple use cases
|
|
174
|
-
- ✅ **Universal**: Supported in all browsers (even old ones)
|
|
175
|
-
- ✅ **Simple**: No setup required, works out of the box
|
|
176
|
-
- ✅ **Adequate**: 5-10MB is sufficient for most preferences
|
|
177
|
-
|
|
178
|
-
IndexedDB support is included for future expansion when dealing with larger datasets.
|
|
179
|
-
|
|
180
|
-
### Integration with Components
|
|
181
|
-
|
|
182
|
-
Where appropriate, design system components integrate with the preference system automatically:
|
|
183
|
-
|
|
184
|
-
- **Layout**: Saves sidebar/panel dimensions
|
|
185
|
-
- **Theme**: Persists theme mode and custom colors
|
|
186
|
-
- **Future components**: Will leverage preferences for state persistence
|
|
187
|
-
|
|
188
|
-
This integration is **opt-in** via the `resizable` prop or similar, ensuring components remain flexible.
|
|
189
|
-
|
|
190
|
-
## Best Practices
|
|
191
|
-
|
|
192
|
-
### 1. Use Meaningful Key Names
|
|
193
|
-
|
|
194
|
-
Organize preferences with dot notation:
|
|
195
|
-
|
|
196
|
-
```typescript
|
|
197
|
-
// Good
|
|
198
|
-
setPreference('layout.sidebar.width', 300);
|
|
199
|
-
setPreference('components.drawer.position', 'right');
|
|
200
|
-
setPreference('user.language', 'pt-BR');
|
|
201
|
-
|
|
202
|
-
// Avoid
|
|
203
|
-
setPreference('w', 300);
|
|
204
|
-
setPreference('pos', 'right');
|
|
205
|
-
```
|
|
206
|
-
|
|
207
|
-
### 2. Always Provide Defaults
|
|
208
|
-
|
|
209
|
-
Ensure your app works on first load:
|
|
210
|
-
|
|
211
|
-
```typescript
|
|
212
|
-
// Good
|
|
213
|
-
const width = getPreference('sidebarWidth', 280);
|
|
214
|
-
|
|
215
|
-
// Avoid
|
|
216
|
-
const width = getPreference('sidebarWidth'); // Could be undefined
|
|
217
|
-
```
|
|
218
|
-
|
|
219
|
-
### 3. Use Namespaces for Related Preferences
|
|
220
|
-
|
|
221
|
-
Keep things organized:
|
|
222
|
-
|
|
223
|
-
```typescript
|
|
224
|
-
const layoutPrefs = createPreferenceNamespace('layout');
|
|
225
|
-
const userPrefs = createPreferenceNamespace('user');
|
|
226
|
-
|
|
227
|
-
layoutPrefs.set('sidebarWidth', 300);
|
|
228
|
-
userPrefs.set('language', 'pt-BR');
|
|
229
|
-
```
|
|
230
|
-
|
|
231
|
-
### 4. Type Your Preferences
|
|
232
|
-
|
|
233
|
-
Leverage TypeScript:
|
|
234
|
-
|
|
235
|
-
```typescript
|
|
236
|
-
type Theme = 'light' | 'dark';
|
|
237
|
-
const theme = getPreference<Theme>('theme', 'light');
|
|
238
|
-
```
|
|
239
|
-
|
|
240
|
-
### 5. Consider User Privacy
|
|
241
|
-
|
|
242
|
-
Allow users to export/clear their data:
|
|
243
|
-
|
|
244
|
-
```typescript
|
|
245
|
-
import { exportPreferences, clearPreferences } from '@hellboy/ds';
|
|
246
|
-
|
|
247
|
-
// Export for backup
|
|
248
|
-
const json = exportPreferences();
|
|
249
|
-
|
|
250
|
-
// Clear all data
|
|
251
|
-
clearPreferences();
|
|
252
|
-
```
|
|
253
|
-
|
|
254
|
-
## Migration Guide
|
|
255
|
-
|
|
256
|
-
### From Direct localStorage
|
|
257
|
-
|
|
258
|
-
If you're currently using `localStorage` directly:
|
|
259
|
-
|
|
260
|
-
```typescript
|
|
261
|
-
// Before
|
|
262
|
-
localStorage.setItem('myTheme', 'dark');
|
|
263
|
-
const theme = localStorage.getItem('myTheme') || 'light';
|
|
264
|
-
|
|
265
|
-
// After
|
|
266
|
-
import { setPreference, getPreference } from '@hellboy/ds';
|
|
267
|
-
setPreference('myTheme', 'dark');
|
|
268
|
-
const theme = getPreference('myTheme', 'light');
|
|
269
|
-
```
|
|
270
|
-
|
|
271
|
-
### From Legacy DS Theme Utils
|
|
272
|
-
|
|
273
|
-
The theme utilities automatically migrate:
|
|
274
|
-
|
|
275
|
-
```typescript
|
|
276
|
-
// No changes needed! Your existing code works:
|
|
277
|
-
import { setTheme, getTheme } from '@hellboy/ds';
|
|
278
|
-
|
|
279
|
-
setTheme('dark'); // Now uses User Preferences internally
|
|
280
|
-
const theme = getTheme(); // Checks new system, falls back to legacy
|
|
281
|
-
```
|
|
282
|
-
|
|
283
|
-
## Contributing
|
|
284
|
-
|
|
285
|
-
When adding new utilities:
|
|
286
|
-
|
|
287
|
-
1. **Document thoroughly**: Include JSDoc comments and examples
|
|
288
|
-
2. **Provide TypeScript types**: Full type safety is required
|
|
289
|
-
3. **Stay framework-agnostic**: Utilities should work in any environment
|
|
290
|
-
4. **Write tests**: Ensure reliability
|
|
291
|
-
5. **Update this README**: Keep documentation current
|
|
292
|
-
|
|
293
|
-
## Future Utilities
|
|
294
|
-
|
|
295
|
-
Planned additions:
|
|
296
|
-
|
|
297
|
-
- 🔄 **State Management**: Simple state sync across tabs
|
|
298
|
-
- 🌐 **i18n**: Internationalization helpers
|
|
299
|
-
- 📊 **Analytics**: Privacy-focused analytics utilities
|
|
300
|
-
- 🔒 **Validation**: Form validation helpers
|
|
301
|
-
- 📱 **Responsive**: Breakpoint utilities
|
|
302
|
-
|
|
303
|
-
---
|
|
304
|
-
|
|
305
|
-
**Remember**: The goal is to provide **practical, production-ready solutions** that make developers' lives easier. If you find yourself writing the same code across multiple projects, it might be a good candidate for a utility in this directory.
|