@libs-ui/components-buttons-sort 0.2.355-14 → 0.2.355-15
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 +192 -0
- package/package.json +2 -2
package/README.md
ADDED
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
# Buttons Sort Component
|
|
2
|
+
|
|
3
|
+
> Version: `0.2.355-14`
|
|
4
|
+
>
|
|
5
|
+
> Component nút sort (asc/desc) gọn nhẹ, hỗ trợ disable theo chiều và emit payload `ISort` kèm hàm `reset()`.
|
|
6
|
+
|
|
7
|
+
## Giới thiệu
|
|
8
|
+
|
|
9
|
+
Package `@libs-ui/components-buttons-sort` cung cấp 2 component:
|
|
10
|
+
|
|
11
|
+
- `LibsUiComponentsButtonsSortComponent`: 2 nút riêng cho `asc` và `desc`
|
|
12
|
+
- `LibsUiComponentsButtonsSortArrowComponent`: 1 nút toggle `asc` ↔ `desc`, có thể bật popover mô tả
|
|
13
|
+
|
|
14
|
+
## Tính năng
|
|
15
|
+
|
|
16
|
+
- ✅ Có 2 kiểu UI: **2 nút (Sort)** và **1 nút toggle (Arrow)**
|
|
17
|
+
- ✅ Sort 2 chiều: `asc` / `desc`
|
|
18
|
+
- ✅ Two-way binding qua `[(mode)]`
|
|
19
|
+
- ✅ Emit payload `(outChange)` kiểu `ISort`
|
|
20
|
+
- ✅ Hỗ trợ disable toàn bộ hoặc disable từng chiều (`disableAsc`, `disableDesc`)
|
|
21
|
+
- ✅ Hỗ trợ `onlyEmit` để luôn emit event theo click
|
|
22
|
+
- ✅ Arrow hỗ trợ `defaultMode` và popover content (asc/desc)
|
|
23
|
+
- ✅ OnPush Change Detection
|
|
24
|
+
- ✅ Angular Signals
|
|
25
|
+
|
|
26
|
+
## Cài đặt
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
npm install @libs-ui/components-buttons-sort
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Import
|
|
33
|
+
|
|
34
|
+
```typescript
|
|
35
|
+
import { Component } from '@angular/core';
|
|
36
|
+
import { LibsUiComponentsButtonsSortArrowComponent, LibsUiComponentsButtonsSortComponent, ISort, TYPE_SORT_TYPE } from '@libs-ui/components-buttons-sort';
|
|
37
|
+
|
|
38
|
+
@Component({
|
|
39
|
+
standalone: true,
|
|
40
|
+
imports: [LibsUiComponentsButtonsSortArrowComponent, LibsUiComponentsButtonsSortComponent],
|
|
41
|
+
template: '',
|
|
42
|
+
})
|
|
43
|
+
export class ExampleComponent {}
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Cách sử dụng
|
|
47
|
+
|
|
48
|
+
### 1. Ví dụ inline template
|
|
49
|
+
|
|
50
|
+
```html
|
|
51
|
+
<libs_ui-components-buttons-sort
|
|
52
|
+
[fieldSort]="'name'"
|
|
53
|
+
[(mode)]="mode"
|
|
54
|
+
(outChange)="onChange($event)"
|
|
55
|
+
/>
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
```typescript
|
|
59
|
+
import { Component, signal } from '@angular/core';
|
|
60
|
+
import { LibsUiComponentsButtonsSortComponent, ISort, TYPE_SORT_TYPE } from '@libs-ui/components-buttons-sort';
|
|
61
|
+
|
|
62
|
+
@Component({
|
|
63
|
+
standalone: true,
|
|
64
|
+
imports: [LibsUiComponentsButtonsSortComponent],
|
|
65
|
+
template: `
|
|
66
|
+
<libs_ui-components-buttons-sort
|
|
67
|
+
[fieldSort]="'name'"
|
|
68
|
+
[(mode)]="mode()"
|
|
69
|
+
(outChange)="onChange($event)"
|
|
70
|
+
/>
|
|
71
|
+
`,
|
|
72
|
+
})
|
|
73
|
+
export class InlineExampleComponent {
|
|
74
|
+
readonly mode = signal<TYPE_SORT_TYPE>('');
|
|
75
|
+
|
|
76
|
+
onChange(sort: ISort): void {
|
|
77
|
+
console.log(sort.mode, sort.fieldSort);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### 2. Arrow - 1 nút toggle (có thể bật popover)
|
|
83
|
+
|
|
84
|
+
```html
|
|
85
|
+
<libs_ui-components-buttons-sort-arrow
|
|
86
|
+
[fieldSort]="'name'"
|
|
87
|
+
[ignorePopoverContent]="false"
|
|
88
|
+
[popoverContentAsc]="'Sắp xếp tăng dần (A → Z)'"
|
|
89
|
+
[popoverContentDesc]="'Sắp xếp giảm dần (Z → A)'"
|
|
90
|
+
[defaultMode]="'asc'"
|
|
91
|
+
[(mode)]="mode"
|
|
92
|
+
(outChange)="onChange($event)"
|
|
93
|
+
/>
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### 2. Ví dụ với file HTML riêng
|
|
97
|
+
|
|
98
|
+
`example.component.html`
|
|
99
|
+
|
|
100
|
+
```html
|
|
101
|
+
<libs_ui-components-buttons-sort
|
|
102
|
+
[size]="14"
|
|
103
|
+
[disableAsc]="true"
|
|
104
|
+
[fieldSort]="'createdAt'"
|
|
105
|
+
[(mode)]="mode"
|
|
106
|
+
(outChange)="onChange($event)"
|
|
107
|
+
/>
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
`example.component.ts`
|
|
111
|
+
|
|
112
|
+
```typescript
|
|
113
|
+
import { Component, signal } from '@angular/core';
|
|
114
|
+
import { LibsUiComponentsButtonsSortComponent, ISort, TYPE_SORT_TYPE } from '@libs-ui/components-buttons-sort';
|
|
115
|
+
|
|
116
|
+
@Component({
|
|
117
|
+
standalone: true,
|
|
118
|
+
imports: [LibsUiComponentsButtonsSortComponent],
|
|
119
|
+
templateUrl: './example.component.html',
|
|
120
|
+
})
|
|
121
|
+
export class HtmlFileExampleComponent {
|
|
122
|
+
readonly mode = signal<TYPE_SORT_TYPE>('');
|
|
123
|
+
|
|
124
|
+
onChange(sort: ISort): void {
|
|
125
|
+
// sort.reset() có thể dùng để reset mode về ''
|
|
126
|
+
console.log(sort);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
## Công nghệ
|
|
132
|
+
|
|
133
|
+
| Technology | Version | Purpose |
|
|
134
|
+
|------------|---------|---------|
|
|
135
|
+
| Angular | 18+ | Framework |
|
|
136
|
+
| Angular Signals | - | State management |
|
|
137
|
+
| TailwindCSS | 3.x | Styling (demo) |
|
|
138
|
+
| OnPush | - | Change Detection |
|
|
139
|
+
|
|
140
|
+
## API
|
|
141
|
+
|
|
142
|
+
### libs_ui-components-buttons-sort
|
|
143
|
+
|
|
144
|
+
#### Inputs
|
|
145
|
+
|
|
146
|
+
| Property | Type | Default | Description |
|
|
147
|
+
|----------|------|---------|-------------|
|
|
148
|
+
| `[disable]` | `boolean` | `false` | Disable toàn bộ sort |
|
|
149
|
+
| `[disableAsc]` | `boolean` | `false` | Disable chiều asc |
|
|
150
|
+
| `[disableDesc]` | `boolean` | `false` | Disable chiều desc |
|
|
151
|
+
| `[defaultMode]` | `TYPE_SORT_TYPE` | `''` | Chỉ áp dụng cho Arrow: mode mặc định khi click lần đầu |
|
|
152
|
+
| `[fieldSort]` | `string` | `''` | Field đang sort (được trả về trong `ISort`) |
|
|
153
|
+
| `[ignorePopoverContent]` | `boolean` | `true` | Chỉ áp dụng cho Arrow: bỏ qua hiển thị popover content |
|
|
154
|
+
| `[onlyEmit]` | `boolean` | `false` | Chỉ emit event, không chặn khi mode đang trùng |
|
|
155
|
+
| `[popoverContentAsc]` | `string \| undefined` | `undefined` | Chỉ áp dụng cho Arrow: nội dung popover khi asc |
|
|
156
|
+
| `[popoverContentDesc]` | `string \| undefined` | `undefined` | Chỉ áp dụng cho Arrow: nội dung popover khi desc |
|
|
157
|
+
| `[size]` | `number` | `10` | Kích thước icon sort (px) |
|
|
158
|
+
| `[zIndex]` | `number` | `10` | Chỉ áp dụng cho Arrow: zIndex của popover |
|
|
159
|
+
| `[(mode)]` | `TYPE_SORT_TYPE` | `''` | Mode sort hiện tại: `asc` / `desc` / `''` |
|
|
160
|
+
|
|
161
|
+
#### Outputs
|
|
162
|
+
|
|
163
|
+
| Property | Type | Description |
|
|
164
|
+
|----------|------|-------------|
|
|
165
|
+
| `(outChange)` | `EventEmitter<ISort>` | Emit khi người dùng click sort, trả về payload `ISort` |
|
|
166
|
+
|
|
167
|
+
## Types & Interfaces
|
|
168
|
+
|
|
169
|
+
```typescript
|
|
170
|
+
export type TYPE_SORT_TYPE = 'asc' | 'desc' | '';
|
|
171
|
+
|
|
172
|
+
export interface ISort {
|
|
173
|
+
mode: TYPE_SORT_TYPE;
|
|
174
|
+
modeNumber: 1 | 2; // 1: asc; 2:desc
|
|
175
|
+
fieldSort: string;
|
|
176
|
+
reset: () => void;
|
|
177
|
+
}
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
### Mô tả Types
|
|
181
|
+
|
|
182
|
+
- **TYPE_SORT_TYPE**: Kiểu mode sort: `asc`, `desc`, hoặc rỗng (không sort).
|
|
183
|
+
- **ISort**: Payload emit ra khi sort thay đổi, có `reset()` để reset mode.
|
|
184
|
+
|
|
185
|
+
## Demo
|
|
186
|
+
|
|
187
|
+
```bash
|
|
188
|
+
npx nx serve core-ui
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
Truy cập: `http://localhost:4500/buttons/sort`
|
|
192
|
+
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@libs-ui/components-buttons-sort",
|
|
3
|
-
"version": "0.2.355-
|
|
3
|
+
"version": "0.2.355-15",
|
|
4
4
|
"peerDependencies": {
|
|
5
5
|
"@angular/core": ">=18.0.0",
|
|
6
|
-
"@libs-ui/components-popover": "0.2.355-
|
|
6
|
+
"@libs-ui/components-popover": "0.2.355-15"
|
|
7
7
|
},
|
|
8
8
|
"sideEffects": false,
|
|
9
9
|
"module": "fesm2022/libs-ui-components-buttons-sort.mjs",
|