@libs-ui/components-buttons-sort 0.2.355-9 → 0.2.356-1

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