@libs-ui/components-color-picker 0.2.355-9 → 0.2.356-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.
Files changed (2) hide show
  1. package/README.md +179 -2
  2. package/package.json +4 -4
package/README.md CHANGED
@@ -1,3 +1,180 @@
1
- # color-picker
1
+ # @libs-ui/components-color-picker
2
2
 
3
- This library was generated with [Nx](https://nx.dev).
3
+ > Component chọn màu sắc với giao diện trực quan, hỗ trợ nhiều định dạng màu và alpha channel
4
+
5
+ ## Giới thiệu
6
+
7
+ `LibsUiComponentsColorPickerComponent` là một standalone Angular component để chọn màu sắc một cách trực quan thông qua giao diện canvas-based color picker.
8
+
9
+ ### Tính năng
10
+
11
+ - ✅ Canvas-based color picker với Hue, Saturation/Lightness bars
12
+ - ✅ Hỗ trợ Alpha channel (độ trong suốt)
13
+ - ✅ Nhiều định dạng output (RGB, RGBA, HSL, HSLA, HEX, HEX with alpha)
14
+ - ✅ Input fields cho từng giá trị màu (R, G, B, H, S, L, Alpha, HEX)
15
+ - ✅ Preview màu real-time
16
+ - ✅ Copy mã màu nhanh chóng
17
+ - ✅ Tùy chỉnh kích thước bars và hiển thị fields
18
+ - ✅ OnPush Change Detection
19
+ - ✅ Angular Signals
20
+ - ✅ Standalone Component
21
+
22
+ ## Khi nào sử dụng
23
+
24
+ - Khi cần cho phép người dùng chọn màu sắc một cách trực quan
25
+ - Khi cần hỗ trợ nhiều định dạng màu (RGB, HSL, HEX)
26
+ - Khi cần điều chỉnh độ trong suốt (alpha channel)
27
+ - Khi cần preview màu đã chọn real-time
28
+ - Khi cần copy mã màu nhanh chóng
29
+
30
+ ## Cài đặt
31
+
32
+ ```bash
33
+ npm install @libs-ui/components-color-picker
34
+ ```
35
+
36
+ ## Sử dụng cơ bản
37
+
38
+ ```typescript
39
+ import { Component } from '@angular/core';
40
+ import { LibsUiComponentsColorPickerComponent } from '@libs-ui/components-color-picker';
41
+
42
+ @Component({
43
+ selector: 'app-example',
44
+ standalone: true,
45
+ imports: [LibsUiComponentsColorPickerComponent],
46
+ template: `
47
+ <libs_ui-components-color_picker (outColorChange)="onColorChange($event)" />
48
+ `,
49
+ })
50
+ export class ExampleComponent {
51
+ onColorChange(color: string): void {
52
+ console.log('Selected color:', color); // "#3b82f6"
53
+ }
54
+ }
55
+ ```
56
+
57
+ ## API
58
+
59
+ ### Inputs
60
+
61
+ | Property | Type | Default | Description |
62
+ | ------------------------------------- | ---------------------- | ----------- | --------------------------------------- |
63
+ | `[customOptions]` | `IPickerCustomOptions` | `undefined` | Tùy chỉnh options cho color picker |
64
+ | `[noEmitEventColorWhenInitComponent]` | `boolean` | `true` | Không emit event khi khởi tạo component |
65
+
66
+ ### Outputs
67
+
68
+ | Property | Type | Description |
69
+ | ------------------------------ | -------------------------------- | ------------------------------------- |
70
+ | `(outColorChange)` | `string` | Emit màu đã chọn dưới dạng HEX string |
71
+ | `(outColorChangeMultipleType)` | `IOutputColorChangeMultipleType` | Emit màu với nhiều format |
72
+
73
+ ## Interfaces
74
+
75
+ ### IPickerCustomOptions
76
+
77
+ ```typescript
78
+ export interface IPickerCustomOptions {
79
+ slBarSize?: Array<number>; // Kích thước Saturation/Lightness bar [width, height]
80
+ hueBarSize?: Array<number>; // Kích thước Hue bar [width, height]
81
+ alphaBarSize?: Array<number>; // Kích thước Alpha bar [width, height]
82
+ showHsl?: boolean; // Hiển thị HSL input fields
83
+ showRgb?: boolean; // Hiển thị RGB input fields
84
+ showHex?: boolean; // Hiển thị HEX input field
85
+ showAlpha?: boolean; // Hiển thị Alpha slider
86
+ color?: string | Array<number>; // Màu mặc định
87
+ format?: 'rgb' | 'rgba' | 'hsl' | 'hsla' | 'hex' | 'color';
88
+ }
89
+ ```
90
+
91
+ ### IOutputColorChangeMultipleType
92
+
93
+ ```typescript
94
+ export interface IOutputColorChangeMultipleType {
95
+ rgba: string; // "rgba(59, 130, 246, 1)"
96
+ rgb: string; // "rgb(59, 130, 246)"
97
+ hex: string; // "#3b82f6" hoặc "#3b82f6ff" (nếu có alpha)
98
+ hsl: string; // "hsl(217, 91, 60)"
99
+ hsla: string; // "hsla(217, 91, 60, 1)"
100
+ alpha: number; // 0-1
101
+ }
102
+ ```
103
+
104
+ ## Ví dụ nâng cao
105
+
106
+ ### Với Custom Options
107
+
108
+ ```typescript
109
+ import { Component, signal } from '@angular/core';
110
+ import { LibsUiComponentsColorPickerComponent, IPickerCustomOptions, IOutputColorChangeMultipleType } from '@libs-ui/components-color-picker';
111
+
112
+ @Component({
113
+ standalone: true,
114
+ imports: [LibsUiComponentsColorPickerComponent],
115
+ template: `
116
+ <libs_ui-components-color_picker
117
+ [customOptions]="pickerOptions()"
118
+ (outColorChange)="onColorChange($event)"
119
+ (outColorChangeMultipleType)="onColorChangeMultiple($event)" />
120
+ `,
121
+ })
122
+ export class ExampleComponent {
123
+ readonly pickerOptions = signal<IPickerCustomOptions>({
124
+ color: '#ff6b6b',
125
+ showAlpha: true,
126
+ showHex: true,
127
+ showRgb: true,
128
+ showHsl: false,
129
+ format: 'hex',
130
+ });
131
+
132
+ onColorChange(color: string): void {
133
+ console.log('HEX:', color);
134
+ }
135
+
136
+ onColorChangeMultiple(colors: IOutputColorChangeMultipleType): void {
137
+ console.log('RGB:', colors.rgb);
138
+ console.log('HSL:', colors.hsl);
139
+ console.log('Alpha:', colors.alpha);
140
+ }
141
+ }
142
+ ```
143
+
144
+ ### Custom Bar Sizes
145
+
146
+ ```typescript
147
+ readonly customSizeOptions = signal<IPickerCustomOptions>({
148
+ slBarSize: [300, 200], // Larger SL bar
149
+ hueBarSize: [300, 20], // Wider hue bar
150
+ alphaBarSize: [300, 20], // Wider alpha bar
151
+ showAlpha: true
152
+ });
153
+ ```
154
+
155
+ ## Important Notes
156
+
157
+ ⚠️ **Canvas Rendering**: Component sử dụng HTML5 Canvas để render color picker, cần browser hỗ trợ Canvas API.
158
+
159
+ ⚠️ **Signal-based**: Component sử dụng Angular Signals để quản lý state, đảm bảo reactivity tốt.
160
+
161
+ ⚠️ **Multiple Formats**: Hỗ trợ nhiều format output (RGB, RGBA, HSL, HSLA, HEX, HEX with alpha).
162
+
163
+ ⚠️ **Custom Options**: Có thể customize kích thước bars, hiển thị/ẩn các input fields.
164
+
165
+ ⚠️ **Event Timing**: Mặc định không emit event khi khởi tạo component (`noEmitEventColorWhenInitComponent = true`). Set thành `false` nếu muốn emit event ngay khi init.
166
+
167
+ ## Dependencies
168
+
169
+ - `@angular/core` >= 18.0.0
170
+ - `@libs-ui/components-inputs-input`
171
+ - `@libs-ui/services-notification`
172
+ - `@libs-ui/utils`
173
+
174
+ ## Demo
175
+
176
+ Xem demo tại: [http://localhost:4500/color-picker](http://localhost:4500/color-picker)
177
+
178
+ ## License
179
+
180
+ MIT
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@libs-ui/components-color-picker",
3
- "version": "0.2.355-9",
3
+ "version": "0.2.356-0",
4
4
  "peerDependencies": {
5
5
  "@angular/core": ">=18.0.0",
6
- "@libs-ui/components-inputs-input": "0.2.355-9",
7
- "@libs-ui/services-notification": "0.2.355-9",
8
- "@libs-ui/utils": "0.2.355-9",
6
+ "@libs-ui/components-inputs-input": "0.2.356-0",
7
+ "@libs-ui/services-notification": "0.2.356-0",
8
+ "@libs-ui/utils": "0.2.356-0",
9
9
  "rxjs": "~7.8.0"
10
10
  },
11
11
  "sideEffects": false,