@libs-ui/components-avatar 0.2.355-10 → 0.2.355-12

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 +209 -0
  2. package/package.json +3 -3
package/README.md ADDED
@@ -0,0 +1,209 @@
1
+ # Avatar Component
2
+
3
+ > Version: `0.2.355-10`
4
+ >
5
+ > Component hiển thị avatar (ảnh đại diện) với khả năng fallback sang text/icon khi ảnh lỗi hoặc không có.
6
+
7
+ ## Giới thiệu
8
+
9
+ `LibsUiComponentsAvatarComponent` là một standalone Angular component để hiển thị avatar (ảnh đại diện) của người dùng. Component hỗ trợ nhiều kích thước, hình dạng (circle/rectangle), và có cơ chế fallback thông minh khi ảnh lỗi.
10
+
11
+ ### Tính năng
12
+
13
+ - ✅ Hiển thị ảnh avatar từ URL
14
+ - ✅ Fallback tự động sang text/icon khi ảnh lỗi
15
+ - ✅ Hỗ trợ nhiều kích thước: 16, 24, 32, 40, 48, 64px
16
+ - ✅ Hỗ trợ 2 hình dạng: circle (mặc định) và rectangle
17
+ - ✅ Tự động tạo màu nền dựa trên ID (hash color)
18
+ - ✅ Preview ảnh khi click (tùy chọn)
19
+ - ✅ OnPush Change Detection
20
+ - ✅ Angular Signals
21
+
22
+ ## Lưu ý quan trọng (Important Notes)
23
+
24
+ > ⚠️ **Caveats**:
25
+ >
26
+ > - **Thứ tự Input quan trọng**: Nếu sử dụng `getLastTextAfterSpace`, phải truyền input này **TRƯỚC** `textAvatar` để logic transform hoạt động đúng.
27
+ > - **Error Handling Chain**: Component có chuỗi xử lý lỗi: `linkAvatar` → `linkAvatarError` → `textAvatar` + `idGenColor`. Nếu tất cả đều fail, sẽ hiển thị icon với text.
28
+ > - **Màu nền tự động**: Màu nền được tạo từ `idGenColor` thông qua hàm hash. Cùng ID sẽ luôn có cùng màu.
29
+ > - **Font size tự động**: Font size của text avatar được tính tự động dựa trên `size` (16/24 → 6, 32 → 4, 40 → 3, 64 → 1, default → 4).
30
+ > - **Preview Image**: Khi `clickPreviewImage = true`, click vào ảnh sẽ mở gallery viewer. Component tự quản lý lifecycle của gallery viewer.
31
+
32
+ ## Khi nào sử dụng
33
+
34
+ - Hiển thị ảnh đại diện người dùng trong danh sách, comment, profile
35
+ - Hiển thị avatar với fallback khi ảnh không tải được
36
+ - Cần hiển thị avatar với nhiều kích thước khác nhau
37
+ - Cần preview ảnh khi click vào avatar
38
+
39
+ ## Cài đặt
40
+
41
+ ```bash
42
+ npm install @libs-ui/components-avatar
43
+ ```
44
+
45
+ ## Import
46
+
47
+ ```typescript
48
+ import { LibsUiComponentsAvatarComponent, TYPE_SHAPE_AVATAR, TYPE_SIZE_AVATAR_CONFIG, IAvatarConfig } from '@libs-ui/components-avatar';
49
+
50
+ @Component({
51
+ standalone: true,
52
+ imports: [LibsUiComponentsAvatarComponent],
53
+ // ...
54
+ })
55
+ ```
56
+
57
+ ## Cách sử dụng
58
+
59
+ ### 1. Basic - Avatar với ảnh
60
+
61
+ ```html
62
+ <libs_ui-components-avatar
63
+ [linkAvatar]="'https://example.com/avatar.jpg'"
64
+ [size]="32" />
65
+ ```
66
+
67
+ ### 2. Avatar với fallback text
68
+
69
+ ```html
70
+ <libs_ui-components-avatar
71
+ [linkAvatar]="'https://example.com/avatar.jpg'"
72
+ [linkAvatarError]="'https://example.com/fallback.jpg'"
73
+ [textAvatar]="'John Doe'"
74
+ [idGenColor]="'user-123'"
75
+ [size]="40" />
76
+ ```
77
+
78
+ ### 3. Avatar rectangle
79
+
80
+ ```html
81
+ <libs_ui-components-avatar
82
+ [linkAvatar]="'https://example.com/avatar.jpg'"
83
+ [typeShape]="'rectangle'"
84
+ [size]="48" />
85
+ ```
86
+
87
+ ### 4. Avatar với preview
88
+
89
+ ```html
90
+ <libs_ui-components-avatar
91
+ [linkAvatar]="'https://example.com/avatar.jpg'"
92
+ [clickPreviewImage]="true"
93
+ [zIndexPreviewImage]="1000"
94
+ [size]="64" />
95
+ ```
96
+
97
+ ### 5. Avatar với custom classes
98
+
99
+ ```html
100
+ <libs_ui-components-avatar
101
+ [linkAvatar]="'https://example.com/avatar.jpg'"
102
+ [classInclude]="'mr-4 mb-2'"
103
+ [classImageInclude]="'rounded-lg'"
104
+ [size]="32" />
105
+ ```
106
+
107
+ ## API
108
+
109
+ ### libs_ui-components-avatar
110
+
111
+ #### Inputs
112
+
113
+ | Property | Type | Default | Description |
114
+ |----------|------|---------|-------------|
115
+ | `[typeShape]` | `TYPE_SHAPE_AVATAR \| undefined` | `'circle'` | Hình dạng avatar: 'circle' hoặc 'rectangle' |
116
+ | `[classInclude]` | `string \| undefined` | `'mr-[8px]'` | Class CSS tùy chỉnh cho container |
117
+ | `[size]` | `TYPE_SIZE_AVATAR_CONFIG \| undefined` | `32` | Kích thước avatar: 16, 24, 32, 40, 48, 64 |
118
+ | `[linkAvatar]` | `string` | `-` | URL ảnh avatar chính |
119
+ | `[linkAvatarError]` | `string` | `-` | URL ảnh fallback khi `linkAvatar` lỗi |
120
+ | `[classImageInclude]` | `string \| undefined` | `''` | Class CSS tùy chỉnh cho thẻ img |
121
+ | `[zIndexPreviewImage]` | `number` | `-` | Z-index cho gallery viewer khi preview |
122
+ | `[clickPreviewImage]` | `boolean` | `-` | Bật preview ảnh khi click |
123
+ | `[idGenColor]` | `string` | `-` | ID để generate màu nền (hash color) |
124
+ | `[getLastTextAfterSpace]` | `boolean` | `-` | Lấy text cuối cùng sau khoảng trắng (phải truyền TRƯỚC textAvatar) |
125
+ | `[textAvatar]` | `string \| undefined` | `''` | Text hiển thị khi không có ảnh (tự động clean unicode và ký tự đặc biệt) |
126
+ | `[textAvatarClassInclude]` | `string` | `''` | Class CSS tùy chỉnh cho text |
127
+ | `[containertextAvatarClassInclude]` | `string` | `''` | Class CSS tùy chỉnh cho container text |
128
+
129
+ #### Outputs
130
+
131
+ | Property | Type | Description |
132
+ |----------|------|-------------|
133
+ | `(outAvatarError)` | `EventEmitter<void>` | Emit khi cả `linkAvatar` và `linkAvatarError` đều lỗi |
134
+ | `(outEventPreviewImage)` | `EventEmitter<'open' \| 'remove'>` | Emit khi mở/đóng gallery viewer |
135
+
136
+ ## Types & Interfaces
137
+
138
+ ```typescript
139
+ export type TYPE_SIZE_AVATAR_CONFIG = 16 | 24 | 32 | 40 | 48 | 64;
140
+
141
+ export type TYPE_SHAPE_AVATAR = 'circle' | 'rectangle';
142
+
143
+ export interface IAvatarConfig {
144
+ classImageInclude?: string;
145
+ classInclude?: string;
146
+ size?: TYPE_SIZE_AVATAR_CONFIG;
147
+ linkAvatar?: string;
148
+ linkAvatarError?: string;
149
+ idGenColor?: string;
150
+ textAvatar?: string;
151
+ typeShape?: TYPE_SHAPE_AVATAR;
152
+ getLastTextAfterSpace?: boolean;
153
+ }
154
+ ```
155
+
156
+ ### Type Descriptions
157
+
158
+ - **TYPE_SIZE_AVATAR_CONFIG**: Các kích thước avatar được hỗ trợ. Font size của text sẽ tự động điều chỉnh theo size.
159
+ - **TYPE_SHAPE_AVATAR**: Hình dạng avatar. 'circle' có border-radius 50%, 'rectangle' có border-radius 4px.
160
+ - **IAvatarConfig**: Interface để định nghĩa object config, hữu ích khi truyền config từ parent component.
161
+
162
+ ## Styling
163
+
164
+ ### CSS Classes
165
+
166
+ | Class | Description |
167
+ |-------|-------------|
168
+ | `.libs_ui-component-avatar` | Container chính của avatar |
169
+ | `.libs_ui-component-avatar-rectangle` | Class khi `typeShape = 'rectangle'` |
170
+ | `.libs_ui-component-avatar-icon` | Container cho text/icon fallback |
171
+
172
+ ### CSS Variables
173
+
174
+ Component không sử dụng CSS variables, màu nền được generate từ `idGenColor` thông qua hàm hash.
175
+
176
+ ## Công nghệ
177
+
178
+ | Technology | Version | Purpose |
179
+ |------------|---------|---------|
180
+ | Angular | 18+ | Framework |
181
+ | Angular Signals | - | State management |
182
+ | TailwindCSS | 3.x | Styling |
183
+ | OnPush | - | Change Detection |
184
+
185
+ ## Demo
186
+
187
+ ```bash
188
+ npx nx serve core-ui
189
+ ```
190
+
191
+ Truy cập: `http://localhost:4500/avatar`
192
+
193
+ ## Unit Tests
194
+
195
+ ```bash
196
+ # Chạy tests
197
+ npx nx test components-avatar
198
+
199
+ # Coverage
200
+ npx nx test components-avatar --coverage
201
+
202
+ # Watch mode
203
+ npx nx test components-avatar --watch
204
+ ```
205
+
206
+ ## License
207
+
208
+ MIT
209
+
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@libs-ui/components-avatar",
3
- "version": "0.2.355-10",
3
+ "version": "0.2.355-12",
4
4
  "peerDependencies": {
5
5
  "@angular/core": ">=18.0.0",
6
- "@libs-ui/interfaces-types": "0.2.355-10",
7
- "@libs-ui/utils": "0.2.355-10"
6
+ "@libs-ui/interfaces-types": "0.2.355-12",
7
+ "@libs-ui/utils": "0.2.355-12"
8
8
  },
9
9
  "sideEffects": false,
10
10
  "module": "fesm2022/libs-ui-components-avatar.mjs",