@libs-ui/components-switch 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 +74 -106
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,163 +1,131 @@
1
- # Switch
1
+ # @libs-ui/components-switch
2
2
 
3
- ## Giới thiệu
3
+ > Component chuyển đổi trạng thái (On/Off) dạng Switch (Toggle).
4
4
 
5
- `@libs-ui/components-switch` component Toggle Switch cho Angular, cho phép người dùng bật/tắt một tùy chọn với trạng thái hai chiều và sự kiện revert.
5
+ ## Giới thiệu
6
6
 
7
- ## Tính năng
7
+ `LibsUiComponentsSwitchComponent` một standalone Angular component cung cấp giao diện Switch Button. Component hỗ trợ 2 kích thước, trạng thái disable và hỗ trợ binding hai chiều (model) cho trạng thái active.
8
8
 
9
- - Kích thước: `'default'` | `'large'`
10
- - Hỗ trợ vô hiệu hóa switch (`disable`)
11
- - Two-way binding cho trạng thái `active`
12
- - Phát ra sự kiện `outSwitch` với payload `{ active: boolean; revert: () => Promise<void> }`
9
+ ### Tính năng
13
10
 
14
- ## Cài đặt
11
+ - 2 kích thước: Default và Large
12
+ - ✅ Hỗ trợ trạng thái Disabled
13
+ - ✅ Two-way binding với Signals (`active`)
14
+ - ✅ Event output chi tiết (kèm hàm revert để hoàn tác)
15
+ - ✅ Custom Styling với CSS Variable
15
16
 
16
- ### Yêu cầu
17
+ ## Khi nào sử dụng
17
18
 
18
- - Angular 18.0.0 trở lên
19
- - Tailwind CSS 3.3.0 trở lên
19
+ - Khi người dùng cần chuyển đổi nhanh giữa hai trạng thái (Bật/Tắt).
20
+ - Thay thế cho Checkbox khi muốn thể hiện hành động có hiệu lực tức thì.
21
+ - Trong các trang cài đặt hệ thống, kích hoạt tính năng.
20
22
 
21
- Để cài đặt, sử dụng npm hoặc yarn:
23
+ ## Cài đặt
22
24
 
23
25
  ```bash
26
+ # npm
24
27
  npm install @libs-ui/components-switch
25
- ```
26
-
27
- hoặc
28
28
 
29
- ```bash
29
+ # yarn
30
30
  yarn add @libs-ui/components-switch
31
31
  ```
32
32
 
33
- ## Sử dụng
34
-
35
- ### Inline Template
33
+ ## Import
36
34
 
37
35
  ```typescript
38
- import { Component } from '@angular/core';
39
36
  import { LibsUiComponentsSwitchComponent } from '@libs-ui/components-switch';
40
37
 
41
38
  @Component({
42
- selector: 'app-example',
43
39
  standalone: true,
44
40
  imports: [LibsUiComponentsSwitchComponent],
45
- template: `
46
- <libs_ui-components-switch
47
- [size]="'large'"
48
- [disable]="false"
49
- [(active)]="isOn"
50
- (outSwitch)="onSwitch($event)"></libs_ui-components-switch>
51
- `,
41
+ // ...
52
42
  })
53
- export class ExampleComponent {
54
- isOn = false;
55
-
56
- onSwitch(event: { active: boolean; revert: () => Promise<void> }) {
57
- console.log('Switch toggled:', event.active);
58
- }
59
- }
43
+ export class YourComponent {}
60
44
  ```
61
45
 
62
- ### File HTML riêng
46
+ ## dụ
63
47
 
64
- ```typescript
65
- import { Component } from '@angular/core';
66
- import { LibsUiComponentsSwitchComponent } from '@libs-ui/components-switch';
48
+ ### Basic (Default Size)
67
49
 
68
- @Component({
69
- selector: 'app-example',
70
- standalone: true,
71
- imports: [LibsUiComponentsSwitchComponent],
72
- templateUrl: './example.component.html',
73
- })
74
- export class ExampleComponent {
75
- isOn = true;
76
- }
50
+ ```html
51
+ <libs_ui-components-switch [(active)]="isActive" />
77
52
  ```
78
53
 
54
+ ### Large Size
55
+
79
56
  ```html
80
57
  <libs_ui-components-switch
81
- [size]="'default'"
82
- [disable]="false"
83
- [(active)]="isOn"
84
- (outSwitch)="onSwitch($event)"></libs_ui-components-switch>
58
+ size="large"
59
+ [(active)]="isActive" />
85
60
  ```
86
61
 
87
- ## Công nghệ sử dụng
62
+ ### Disabled State
88
63
 
89
- - **Angular 18**: standalone components, Signals
90
- - **Tailwind CSS**: cho styling
64
+ ```html
65
+ <libs_ui-components-switch
66
+ [disable]="true"
67
+ [active]="true" />
68
+ ```
91
69
 
92
- ## API Reference
70
+ ### Handling Change Event
93
71
 
94
- ### Inputs
72
+ Sử dụng `(outSwitch)` để xử lý sự kiện active thay đổi. Event cung cấp hàm `revert()` để quay lại trạng thái cũ nếu cần (ví dụ: API call thất bại).
95
73
 
96
- | Tên | Kiểu | Mặc định | Mô tả |
97
- | ------- | ---------------------- | ----------- | ------------------------------------ |
98
- | size | `'default' \| 'large'` | `'default'` | Kích thước của switch |
99
- | disable | `boolean` | `false` | Vô hiệu hóa switch |
100
- | active | `boolean` | `false` | Trạng thái bật/tắt (two-way binding) |
74
+ ```html
75
+ <libs_ui-components-switch (outSwitch)="onSwitchChange($event)" />
76
+ ```
101
77
 
102
- ### Outputs
78
+ ```typescript
79
+ onSwitchChange(event: ISwitchEvent) {
80
+ console.log('New state:', event.active);
81
+ // Nếu muốn hoàn tác:
82
+ // event.revert();
83
+ }
84
+ ```
103
85
 
104
- | Tên | Kiểu | Mô tả |
105
- | --------- | ------------------------------- | ----------------------------------------------------- |
106
- | outSwitch | `(event: ISwitchEvent) => void` | Sự kiện khi toggle, trả về trạng thái và hàm `revert` |
86
+ ## API
107
87
 
108
- ### Interfaces
88
+ ### LibsUiComponentsSwitchComponent
109
89
 
110
- #### `ISwitch`
90
+ Selector: `libs_ui-components-switch`
111
91
 
112
- ```typescript
113
- export interface ISwitch {
114
- disable?: boolean;
115
- active?: boolean;
116
- action?: (event: ISwitchEvent) => Promise<void>;
117
- }
118
- ```
92
+ #### Inputs
93
+
94
+ | Property | Type | Default | Description |
95
+ | ------------ | ---------------------- | ----------- | --------------------------------------------- |
96
+ | `[size]` | `'default' \| 'large'` | `'default'` | Kích thước của switch. |
97
+ | `[disable]` | `boolean` | `false` | Vô hiệu hóa switch (không thể click). |
98
+ | `[(active)]` | `boolean` | `false` | Trạng thái bật/tắt của switch (Model Signal). |
119
99
 
120
- tả cấu hình switch (inputs):
100
+ #### Outputs
121
101
 
122
- - `disable`: hiệu hóa switch.
123
- - `active`: trạng thái bật/tắt.
124
- - `action`: hàm xử khi toggle (tùy chọn).
102
+ | Property | Type | Description |
103
+ | ------------- | -------------- | ------------------------------------------------- |
104
+ | `(outSwitch)` | `ISwitchEvent` | Emit khi người dùng click để thay đổi trạng thái. |
105
+
106
+ ### Interfaces
125
107
 
126
- #### `ISwitchEvent`
108
+ #### ISwitchEvent
127
109
 
128
110
  ```typescript
129
111
  export interface ISwitchEvent {
130
- active: boolean;
131
- revert: () => Promise<void>;
112
+ active: boolean; // Trạng thái mới sau khi click
113
+ revert: () => Promise<void>; // Hàm utility để quay về trạng thái cũ
132
114
  }
133
115
  ```
134
116
 
135
- tả payload của sự kiện `outSwitch`:
117
+ ## Styling
136
118
 
137
- - `active`: trạng thái mới.
138
- - `revert`: hàm để hoàn nguyên về trạng thái trước đó.
119
+ Component sử dụng CSS Variables để tùy biến màu sắc:
139
120
 
140
- ## Demo
141
-
142
- Để xem dụ tương tác về component Switch, bạn có thể sử dụng `LibsUiComponentsSwitchDemoComponent` trong ứng dụng của mình:
121
+ | Variable | Default | Description |
122
+ | ------------------------- | ---------------- | ------------------- |
123
+ | `--libs-ui-color-default` | `#226ff5` (Blue) | Màu nền khi active. |
143
124
 
144
- ```typescript
145
- import { Component } from '@angular/core';
146
- import { LibsUiComponentsSwitchDemoComponent } from '@libs-ui/components-switch';
125
+ ## Demo
147
126
 
148
- @Component({
149
- selector: 'app-switch-demo',
150
- standalone: true,
151
- imports: [LibsUiComponentsSwitchDemoComponent],
152
- template: `
153
- <lib-switch-demo></lib-switch-demo>
154
- `,
155
- })
156
- export class SwitchDemoComponent {}
127
+ ```bash
128
+ npx nx serve core-ui
157
129
  ```
158
130
 
159
- Hoặc thêm trực tiếp trong template HTML:
160
-
161
- ```html
162
- <lib-switch-demo></lib-switch-demo>
163
- ```
131
+ Truy cập: `http://localhost:4500/switch`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@libs-ui/components-switch",
3
- "version": "0.2.355-9",
3
+ "version": "0.2.356-0",
4
4
  "peerDependencies": {
5
5
  "@angular/core": ">=18.0.0"
6
6
  },