@libs-ui/components-switch 0.2.355-1 → 0.2.355-11
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/package.json +1 -1
- package/README.md +0 -163
package/package.json
CHANGED
package/README.md
DELETED
|
@@ -1,163 +0,0 @@
|
|
|
1
|
-
# Switch
|
|
2
|
-
|
|
3
|
-
## Giới thiệu
|
|
4
|
-
|
|
5
|
-
`@libs-ui/components-switch` là 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.
|
|
6
|
-
|
|
7
|
-
## Tính năng
|
|
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> }`
|
|
13
|
-
|
|
14
|
-
## Cài đặt
|
|
15
|
-
|
|
16
|
-
### Yêu cầu
|
|
17
|
-
|
|
18
|
-
- Angular 18.0.0 trở lên
|
|
19
|
-
- Tailwind CSS 3.3.0 trở lên
|
|
20
|
-
|
|
21
|
-
Để cài đặt, sử dụng npm hoặc yarn:
|
|
22
|
-
|
|
23
|
-
```bash
|
|
24
|
-
npm install @libs-ui/components-switch
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
hoặc
|
|
28
|
-
|
|
29
|
-
```bash
|
|
30
|
-
yarn add @libs-ui/components-switch
|
|
31
|
-
```
|
|
32
|
-
|
|
33
|
-
## Sử dụng
|
|
34
|
-
|
|
35
|
-
### Inline Template
|
|
36
|
-
|
|
37
|
-
```typescript
|
|
38
|
-
import { Component } from '@angular/core';
|
|
39
|
-
import { LibsUiComponentsSwitchComponent } from '@libs-ui/components-switch';
|
|
40
|
-
|
|
41
|
-
@Component({
|
|
42
|
-
selector: 'app-example',
|
|
43
|
-
standalone: true,
|
|
44
|
-
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
|
-
`,
|
|
52
|
-
})
|
|
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
|
-
}
|
|
60
|
-
```
|
|
61
|
-
|
|
62
|
-
### File HTML riêng
|
|
63
|
-
|
|
64
|
-
```typescript
|
|
65
|
-
import { Component } from '@angular/core';
|
|
66
|
-
import { LibsUiComponentsSwitchComponent } from '@libs-ui/components-switch';
|
|
67
|
-
|
|
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
|
-
}
|
|
77
|
-
```
|
|
78
|
-
|
|
79
|
-
```html
|
|
80
|
-
<libs_ui-components-switch
|
|
81
|
-
[size]="'default'"
|
|
82
|
-
[disable]="false"
|
|
83
|
-
[(active)]="isOn"
|
|
84
|
-
(outSwitch)="onSwitch($event)"></libs_ui-components-switch>
|
|
85
|
-
```
|
|
86
|
-
|
|
87
|
-
## Công nghệ sử dụng
|
|
88
|
-
|
|
89
|
-
- **Angular 18**: standalone components, Signals
|
|
90
|
-
- **Tailwind CSS**: cho styling
|
|
91
|
-
|
|
92
|
-
## API Reference
|
|
93
|
-
|
|
94
|
-
### Inputs
|
|
95
|
-
|
|
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) |
|
|
101
|
-
|
|
102
|
-
### Outputs
|
|
103
|
-
|
|
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` |
|
|
107
|
-
|
|
108
|
-
### Interfaces
|
|
109
|
-
|
|
110
|
-
#### `ISwitch`
|
|
111
|
-
|
|
112
|
-
```typescript
|
|
113
|
-
export interface ISwitch {
|
|
114
|
-
disable?: boolean;
|
|
115
|
-
active?: boolean;
|
|
116
|
-
action?: (event: ISwitchEvent) => Promise<void>;
|
|
117
|
-
}
|
|
118
|
-
```
|
|
119
|
-
|
|
120
|
-
Mô tả cấu hình switch (inputs):
|
|
121
|
-
|
|
122
|
-
- `disable`: vô hiệu hóa switch.
|
|
123
|
-
- `active`: trạng thái bật/tắt.
|
|
124
|
-
- `action`: hàm xử lý khi toggle (tùy chọn).
|
|
125
|
-
|
|
126
|
-
#### `ISwitchEvent`
|
|
127
|
-
|
|
128
|
-
```typescript
|
|
129
|
-
export interface ISwitchEvent {
|
|
130
|
-
active: boolean;
|
|
131
|
-
revert: () => Promise<void>;
|
|
132
|
-
}
|
|
133
|
-
```
|
|
134
|
-
|
|
135
|
-
Mô tả payload của sự kiện `outSwitch`:
|
|
136
|
-
|
|
137
|
-
- `active`: trạng thái mới.
|
|
138
|
-
- `revert`: hàm để hoàn nguyên về trạng thái trước đó.
|
|
139
|
-
|
|
140
|
-
## Demo
|
|
141
|
-
|
|
142
|
-
Để xem ví dụ tương tác về component Switch, bạn có thể sử dụng `LibsUiComponentsSwitchDemoComponent` trong ứng dụng của mình:
|
|
143
|
-
|
|
144
|
-
```typescript
|
|
145
|
-
import { Component } from '@angular/core';
|
|
146
|
-
import { LibsUiComponentsSwitchDemoComponent } from '@libs-ui/components-switch';
|
|
147
|
-
|
|
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 {}
|
|
157
|
-
```
|
|
158
|
-
|
|
159
|
-
Hoặc thêm trực tiếp trong template HTML:
|
|
160
|
-
|
|
161
|
-
```html
|
|
162
|
-
<lib-switch-demo></lib-switch-demo>
|
|
163
|
-
```
|