dynamic-ds 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/README.md ADDED
@@ -0,0 +1,555 @@
1
+ # Dynamic-DS - Dynamic Design System
2
+
3
+ [English](#english) | [Tiếng Việt](#tiếng-việt)
4
+
5
+ ---
6
+
7
+ ## English
8
+
9
+ ### 📖 Overview
10
+
11
+ **Dynamic-DS (Dynamic Design System)** is an Angular library that provides a comprehensive design system with dynamic theming capabilities. It allows applications to customize brand colors while maintaining a consistent design language across all components.
12
+
13
+ ### ✨ Key Features
14
+
15
+ - **Dynamic Color Theming**: Customize brand, primary, secondary, functional, and utility colors
16
+ - **Automatic Palette Generation**: Generates 14 color shades (900-10) from a single base color
17
+ - **CSS Custom Properties**: All colors exposed as CSS variables for easy access
18
+ - **Semantic Color Classes**: Pre-built utility classes for backgrounds, text, borders, and icons
19
+ - **Theme Badge Palettes**: 12 predefined color themes for badges and tags
20
+ - **RGB Mix Algorithm**: Accurate color shade generation using RGB mixing
21
+ - **Runtime Color Updates**: Change theme colors dynamically without page reload
22
+
23
+ ### 📦 Installation
24
+
25
+ ```bash
26
+ npm install dynamic-ds
27
+ ```
28
+
29
+ ### 🚀 Quick Start
30
+
31
+ #### 1. Import Styles
32
+
33
+ Add the design system styles to your `angular.json`:
34
+
35
+ ```json
36
+ {
37
+ "styles": [
38
+ "node_modules/dynamic-ds/styles/system-design.scss"
39
+ ]
40
+ }
41
+ ```
42
+
43
+ #### 2. Provide Configuration (Optional)
44
+
45
+ In your `app.config.ts` or module:
46
+
47
+ ```typescript
48
+ import { ApplicationConfig } from '@angular/core';
49
+ import { SYSTEM_DESIGN_CONFIG } from 'dynamic-ds';
50
+
51
+ export const appConfig: ApplicationConfig = {
52
+ providers: [
53
+ {
54
+ provide: SYSTEM_DESIGN_CONFIG,
55
+ useValue: {
56
+ brand: '#2740B4',
57
+ primary: '#006BDF',
58
+ secondary: '#9F5100',
59
+ functional: '#006BDF',
60
+ utility: '#CF0026'
61
+ }
62
+ }
63
+ ]
64
+ };
65
+ ```
66
+
67
+ #### 3. Initialize Theme
68
+
69
+ In your `app.component.ts`:
70
+
71
+ ```typescript
72
+ import { Component, inject, OnInit } from '@angular/core';
73
+ import { DynamicDsService } from 'dynamic-ds';
74
+
75
+ @Component({
76
+ selector: 'app-root',
77
+ template: `...`
78
+ })
79
+ export class AppComponent implements OnInit {
80
+ private themeService = inject(DynamicDsService);
81
+
82
+ ngOnInit() {
83
+ // Initialize theme with config or defaults
84
+ this.themeService.initializeTheme().subscribe();
85
+ }
86
+ }
87
+ ```
88
+
89
+ ### 🎨 Usage
90
+
91
+ #### Using CSS Classes
92
+
93
+ ```html
94
+ <!-- Background colors -->
95
+ <div class="bg-primary-canvas">Lightest background</div>
96
+ <div class="bg-primary-soft">Soft background</div>
97
+ <div class="bg-primary-accent">Accent background</div>
98
+
99
+ <!-- Text colors -->
100
+ <p class="text-primary-strong">Strong text</p>
101
+ <p class="text-neutral-soft">Soft neutral text</p>
102
+
103
+ <!-- Borders -->
104
+ <div class="stroke-primary-sub">Primary border</div>
105
+
106
+ <!-- Direct color utilities -->
107
+ <div class="color-bg-primary-500">Primary 500 background</div>
108
+ <p class="color-text-neutral-900">Neutral 900 text</p>
109
+ ```
110
+
111
+ #### Using CSS Variables
112
+
113
+ ```scss
114
+ .my-component {
115
+ background-color: var(--primary-600);
116
+ color: var(--neutral-900);
117
+ border: 1px solid var(--primary-200);
118
+ }
119
+
120
+ // With alpha transparency
121
+ .overlay {
122
+ background-color: rgba(var(--primary-600-rgb), 0.5);
123
+ }
124
+ ```
125
+
126
+ #### Dynamic Color Updates
127
+
128
+ ```typescript
129
+ import { DynamicDsService } from 'dynamic-ds';
130
+
131
+ export class SettingsComponent {
132
+ constructor(private themeService: DynamicDsService) {}
133
+
134
+ updateTheme() {
135
+ this.themeService.updateSystemDesignColor({
136
+ primaryColor: '#FF5733',
137
+ secondaryColor: '#33FF57'
138
+ });
139
+ }
140
+
141
+ resetTheme() {
142
+ this.themeService.resetToDefaults();
143
+ }
144
+
145
+ getCurrentColors() {
146
+ const colors = this.themeService.getCurrentColors();
147
+ console.log(colors);
148
+ // { brand: '#...', primary: '#...', secondary: '#...', ... }
149
+ }
150
+ }
151
+ ```
152
+
153
+ ### 🎯 Color Palettes
154
+
155
+ Each color type generates 14 shades:
156
+
157
+ | Shade | Usage | Mix Ratio |
158
+ |-------|-------|-----------|
159
+ | 900 | Darkest | -73.5% black |
160
+ | 875 | Very dark | -62.5% black |
161
+ | 850 | Darker | -47.0% black |
162
+ | 800 | Dark | -34.5% black |
163
+ | 700 | Medium dark | -18.5% black |
164
+ | 600 | **Base color** | 0% |
165
+ | 500 | Medium light | +17.5% white |
166
+ | 400 | Light | +33.0% white |
167
+ | 300 | Lighter | +53.0% white |
168
+ | 200 | Very light | +72.0% white |
169
+ | 100 | Ultra light | +85.0% white |
170
+ | 50 | Canvas | +89.5% white |
171
+ | 25 | Soft | +93.5% white |
172
+ | 10 | Lightest | +97.0% white |
173
+
174
+ ### 🏷️ Semantic Classes
175
+
176
+ #### Backgrounds
177
+ - `.bg-{type}-canvas` - Lightest background
178
+ - `.bg-{type}-soft` - Soft background
179
+ - `.bg-{type}-sub` - Subtle background
180
+ - `.bg-{type}-accent` - Accent/primary background
181
+
182
+ #### Text
183
+ - `.text-{type}-soft` - Soft text color
184
+ - `.text-{type}-sub` - Subtle text color
185
+ - `.text-{type}-strong` - Strong/bold text color
186
+ - `.text-{type}-white` - White text
187
+
188
+ #### Strokes (Borders)
189
+ - `.stroke-{type}-soft` - Soft border
190
+ - `.stroke-{type}-sub` - Subtle border
191
+ - `.stroke-{type}-strong` - Strong border
192
+ - `.stroke-{type}-strong-alpha` - 50% opacity border
193
+
194
+ #### Icons
195
+ - `.icon-{type}-soft` - Soft icon color
196
+ - `.icon-{type}-sub` - Subtle icon color
197
+ - `.icon-{type}-strong` - Strong icon color
198
+ - `.icon-{type}-white` - White icon
199
+
200
+ *Where `{type}` can be: `brand`, `primary`, `secondary`, `functional`, `utility`, `neutral`, or badge themes like `red`, `blue`, `green`, etc.*
201
+
202
+ ### 🎨 Badge Theme Colors
203
+
204
+ Pre-defined badge/tag color themes:
205
+ - `neutral`, `neutral-light`
206
+ - `red`, `orange`, `yellow`
207
+ - `lime`, `green`, `ocean`
208
+ - `blue`, `indigo`, `violet`, `pink`
209
+
210
+ Example:
211
+ ```html
212
+ <span class="bg-blue-soft text-blue-strong stroke-blue-sub">Blue Badge</span>
213
+ <span class="bg-green-canvas text-green-strong">Success</span>
214
+ ```
215
+
216
+ ### 📐 Sizing Utilities
217
+
218
+ ```html
219
+ <!-- Heights -->
220
+ <div class="h-xxs">16px height</div>
221
+ <div class="h-xs">24px height</div>
222
+ <div class="h-sm">28px height</div>
223
+ <div class="h-md">36px height</div>
224
+ <div class="h-lg">44px height</div>
225
+
226
+ <!-- Widths -->
227
+ <div class="w-md">36px width</div>
228
+
229
+ <!-- Font sizes -->
230
+ <p class="text-xs">12px font</p>
231
+ <p class="text-sm">14px font</p>
232
+ <p class="text-lg">16px font</p>
233
+ <p class="text-xl">20px font</p>
234
+
235
+ <!-- Border radius -->
236
+ <div class="rounded-xs">4px radius</div>
237
+ <div class="rounded-md">8px radius</div>
238
+ <div class="rounded-full">999px radius</div>
239
+ ```
240
+
241
+ ### 🔧 API Reference
242
+
243
+ #### DynamicDsService
244
+
245
+ **Methods:**
246
+
247
+ - `initializeTheme(): Observable<any>` - Initialize theme from config or defaults
248
+ - `reloadThemeFromConfig(): Observable<any>` - Reload theme from current config
249
+ - `updateSystemDesignColor(colors): void` - Update specific colors dynamically
250
+ - `getCurrentColors(): object` - Get current theme colors
251
+ - `resetToDefaults(): void` - Reset all colors to default values
252
+
253
+ **Example:**
254
+ ```typescript
255
+ // Initialize on app start
256
+ themeService.initializeTheme().subscribe();
257
+
258
+ // Update colors later
259
+ themeService.updateSystemDesignColor({
260
+ primaryColor: '#FF6B00',
261
+ brandColor: '#2740B4'
262
+ });
263
+
264
+ // Get current colors
265
+ const colors = themeService.getCurrentColors();
266
+ ```
267
+
268
+ ### 🎯 Default Colors
269
+
270
+ | Type | Default Value |
271
+ |------|---------------|
272
+ | Brand | `#2740B4` |
273
+ | Primary | `#006BDF` |
274
+ | Secondary | `#9F5100` |
275
+ | Functional | `#006BDF` |
276
+ | Utility | `#CF0026` |
277
+ | Neutral | `#505A5F` |
278
+
279
+ ### 📝 License
280
+
281
+ MIT License
282
+
283
+ ---
284
+
285
+ ## Tiếng Việt
286
+
287
+ ### 📖 Tổng quan
288
+
289
+ **Dynamic-DS (Dynamic Design System)** là thư viện Angular cung cấp hệ thống thiết kế toàn diện với khả năng tùy chỉnh theme động. Nó cho phép ứng dụng tùy chỉnh màu thương hiệu trong khi vẫn duy trì ngôn ngữ thiết kế nhất quán trên tất cả các component.
290
+
291
+ ### ✨ Tính năng chính
292
+
293
+ - **Theme màu động**: Tùy chỉnh màu brand, primary, secondary, functional và utility
294
+ - **Tự động tạo bảng màu**: Tạo 14 sắc độ màu (900-10) từ một màu cơ sở
295
+ - **CSS Custom Properties**: Tất cả màu được export dưới dạng CSS variables
296
+ - **Semantic Color Classes**: Các lớp tiện ích sẵn có cho background, text, border và icon
297
+ - **Theme Badge Palettes**: 12 bảng màu định sẵn cho badge và tag
298
+ - **RGB Mix Algorithm**: Tạo sắc độ màu chính xác bằng thuật toán pha trộn RGB
299
+ - **Cập nhật màu Runtime**: Thay đổi màu theme động mà không cần tải lại trang
300
+
301
+ ### 📦 Cài đặt
302
+
303
+ ```bash
304
+ npm install dynamic-ds
305
+ ```
306
+
307
+ ### 🚀 Bắt đầu nhanh
308
+
309
+ #### 1. Import Styles
310
+
311
+ Thêm styles của design system vào `angular.json`:
312
+
313
+ ```json
314
+ {
315
+ "styles": [
316
+ "node_modules/dynamic-ds/styles/system-design.scss"
317
+ ]
318
+ }
319
+ ```
320
+
321
+ #### 2. Cung cấp Configuration (Tùy chọn)
322
+
323
+ Trong `app.config.ts` hoặc module:
324
+
325
+ ```typescript
326
+ import { ApplicationConfig } from '@angular/core';
327
+ import { SYSTEM_DESIGN_CONFIG } from 'dynamic-ds';
328
+
329
+ export const appConfig: ApplicationConfig = {
330
+ providers: [
331
+ {
332
+ provide: SYSTEM_DESIGN_CONFIG,
333
+ useValue: {
334
+ brand: '#2740B4',
335
+ primary: '#006BDF',
336
+ secondary: '#9F5100',
337
+ functional: '#006BDF',
338
+ utility: '#CF0026'
339
+ }
340
+ }
341
+ ]
342
+ };
343
+ ```
344
+
345
+ #### 3. Khởi tạo Theme
346
+
347
+ Trong `app.component.ts`:
348
+
349
+ ```typescript
350
+ import { Component, inject, OnInit } from '@angular/core';
351
+ import { DynamicDsService } from 'dynamic-ds';
352
+
353
+ @Component({
354
+ selector: 'app-root',
355
+ template: `...`
356
+ })
357
+ export class AppComponent implements OnInit {
358
+ private themeService = inject(DynamicDsService);
359
+
360
+ ngOnInit() {
361
+ // Khởi tạo theme với config hoặc giá trị mặc định
362
+ this.themeService.initializeTheme().subscribe();
363
+ }
364
+ }
365
+ ```
366
+
367
+ ### 🎨 Sử dụng
368
+
369
+ #### Sử dụng CSS Classes
370
+
371
+ ```html
372
+ <!-- Màu nền -->
373
+ <div class="bg-primary-canvas">Nền sáng nhất</div>
374
+ <div class="bg-primary-soft">Nền mềm</div>
375
+ <div class="bg-primary-accent">Nền nhấn</div>
376
+
377
+ <!-- Màu chữ -->
378
+ <p class="text-primary-strong">Chữ đậm</p>
379
+ <p class="text-neutral-soft">Chữ neutral nhẹ</p>
380
+
381
+ <!-- Viền -->
382
+ <div class="stroke-primary-sub">Viền primary</div>
383
+
384
+ <!-- Tiện ích màu trực tiếp -->
385
+ <div class="color-bg-primary-500">Nền Primary 500</div>
386
+ <p class="color-text-neutral-900">Chữ Neutral 900</p>
387
+ ```
388
+
389
+ #### Sử dụng CSS Variables
390
+
391
+ ```scss
392
+ .my-component {
393
+ background-color: var(--primary-600);
394
+ color: var(--neutral-900);
395
+ border: 1px solid var(--primary-200);
396
+ }
397
+
398
+ // Với độ trong suốt alpha
399
+ .overlay {
400
+ background-color: rgba(var(--primary-600-rgb), 0.5);
401
+ }
402
+ ```
403
+
404
+ #### Cập nhật màu động
405
+
406
+ ```typescript
407
+ import { DynamicDsService } from 'dynamic-ds';
408
+
409
+ export class SettingsComponent {
410
+ constructor(private themeService: DynamicDsService) {}
411
+
412
+ updateTheme() {
413
+ this.themeService.updateSystemDesignColor({
414
+ primaryColor: '#FF5733',
415
+ secondaryColor: '#33FF57'
416
+ });
417
+ }
418
+
419
+ resetTheme() {
420
+ this.themeService.resetToDefaults();
421
+ }
422
+
423
+ getCurrentColors() {
424
+ const colors = this.themeService.getCurrentColors();
425
+ console.log(colors);
426
+ // { brand: '#...', primary: '#...', secondary: '#...', ... }
427
+ }
428
+ }
429
+ ```
430
+
431
+ ### 🎯 Bảng màu
432
+
433
+ Mỗi loại màu tạo ra 14 sắc độ:
434
+
435
+ | Sắc độ | Cách dùng | Tỷ lệ pha trộn |
436
+ |--------|-----------|----------------|
437
+ | 900 | Tối nhất | -73.5% đen |
438
+ | 875 | Rất tối | -62.5% đen |
439
+ | 850 | Tối hơn | -47.0% đen |
440
+ | 800 | Tối | -34.5% đen |
441
+ | 700 | Tối vừa | -18.5% đen |
442
+ | 600 | **Màu gốc** | 0% |
443
+ | 500 | Sáng vừa | +17.5% trắng |
444
+ | 400 | Sáng | +33.0% trắng |
445
+ | 300 | Sáng hơn | +53.0% trắng |
446
+ | 200 | Rất sáng | +72.0% trắng |
447
+ | 100 | Cực sáng | +85.0% trắng |
448
+ | 50 | Canvas | +89.5% trắng |
449
+ | 25 | Mềm | +93.5% trắng |
450
+ | 10 | Sáng nhất | +97.0% trắng |
451
+
452
+ ### 🏷️ Semantic Classes
453
+
454
+ #### Backgrounds (Nền)
455
+ - `.bg-{type}-canvas` - Nền sáng nhất
456
+ - `.bg-{type}-soft` - Nền mềm
457
+ - `.bg-{type}-sub` - Nền tinh tế
458
+ - `.bg-{type}-accent` - Nền nhấn/chính
459
+
460
+ #### Text (Chữ)
461
+ - `.text-{type}-soft` - Màu chữ mềm
462
+ - `.text-{type}-sub` - Màu chữ tinh tế
463
+ - `.text-{type}-strong` - Màu chữ đậm/mạnh
464
+ - `.text-{type}-white` - Chữ trắng
465
+
466
+ #### Strokes (Viền)
467
+ - `.stroke-{type}-soft` - Viền mềm
468
+ - `.stroke-{type}-sub` - Viền tinh tế
469
+ - `.stroke-{type}-strong` - Viền mạnh
470
+ - `.stroke-{type}-strong-alpha` - Viền độ mờ 50%
471
+
472
+ #### Icons
473
+ - `.icon-{type}-soft` - Màu icon mềm
474
+ - `.icon-{type}-sub` - Màu icon tinh tế
475
+ - `.icon-{type}-strong` - Màu icon mạnh
476
+ - `.icon-{type}-white` - Icon trắng
477
+
478
+ *Trong đó `{type}` có thể là: `brand`, `primary`, `secondary`, `functional`, `utility`, `neutral`, hoặc các theme badge như `red`, `blue`, `green`, v.v.*
479
+
480
+ ### 🎨 Màu Badge Theme
481
+
482
+ Các theme màu định sẵn cho badge/tag:
483
+ - `neutral`, `neutral-light`
484
+ - `red`, `orange`, `yellow`
485
+ - `lime`, `green`, `ocean`
486
+ - `blue`, `indigo`, `violet`, `pink`
487
+
488
+ Ví dụ:
489
+ ```html
490
+ <span class="bg-blue-soft text-blue-strong stroke-blue-sub">Badge xanh</span>
491
+ <span class="bg-green-canvas text-green-strong">Thành công</span>
492
+ ```
493
+
494
+ ### 📐 Tiện ích kích thước
495
+
496
+ ```html
497
+ <!-- Chiều cao -->
498
+ <div class="h-xxs">Cao 16px</div>
499
+ <div class="h-xs">Cao 24px</div>
500
+ <div class="h-sm">Cao 28px</div>
501
+ <div class="h-md">Cao 36px</div>
502
+ <div class="h-lg">Cao 44px</div>
503
+
504
+ <!-- Chiều rộng -->
505
+ <div class="w-md">Rộng 36px</div>
506
+
507
+ <!-- Kích thước chữ -->
508
+ <p class="text-xs">Chữ 12px</p>
509
+ <p class="text-sm">Chữ 14px</p>
510
+ <p class="text-lg">Chữ 16px</p>
511
+ <p class="text-xl">Chữ 20px</p>
512
+
513
+ <!-- Bo góc -->
514
+ <div class="rounded-xs">Bo góc 4px</div>
515
+ <div class="rounded-md">Bo góc 8px</div>
516
+ <div class="rounded-full">Bo góc 999px</div>
517
+ ```
518
+
519
+ ### 🔧 Tham chiếu API
520
+
521
+ #### DynamicDsService
522
+
523
+ **Phương thức:**
524
+
525
+ - `initializeTheme(): Observable<any>` - Khởi tạo theme từ config hoặc giá trị mặc định
526
+ - `reloadThemeFromConfig(): Observable<any>` - Tải lại theme từ config hiện tại
527
+ - `updateSystemDesignColor(colors): void` - Cập nhật màu cụ thể một cách động
528
+ - `getCurrentColors(): object` - Lấy màu theme hiện tại
529
+ - `resetToDefaults(): void` - Đặt lại tất cả màu về giá trị mặc định
530
+
531
+ **Ví dụ:**
532
+ ```typescript
533
+ // Khởi tạo khi app start
534
+ themeService.initializeTheme().subscribe();
535
+
536
+ // Cập nhật màu sau đó
537
+ themeService.updateSystemDesignColor({
538
+ primaryColor: '#FF6B00',
539
+ brandColor: '#2740B4'
540
+ });
541
+
542
+ // Lấy màu hiện tại
543
+ const colors = themeService.getCurrentColors();
544
+ ```
545
+
546
+ ### 🎯 Màu mặc định
547
+
548
+ | Loại | Giá trị mặc định |
549
+ |------|------------------|
550
+ | Brand | `#2740B4` |
551
+ | Primary | `#006BDF` |
552
+ | Secondary | `#9F5100` |
553
+ | Functional | `#006BDF` |
554
+ | Utility | `#CF0026` |
555
+ | Neutral | `#505A5F` |