@libs-ui/components-component-outlet 0.2.357-7 → 0.2.357-9

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 +153 -8
  2. package/package.json +2 -2
package/README.md CHANGED
@@ -131,6 +131,33 @@ configTemplateText: signal({
131
131
 
132
132
  ## Ví dụ sử dụng
133
133
 
134
+ ### Ví dụ 0 — Base component (Deprecated, chỉ tham khảo)
135
+
136
+ ```typescript
137
+ import { Component, signal } from '@angular/core';
138
+ import { LibsUiComponentsComponentOutletComponent } from '@libs-ui/components-component-outlet';
139
+ import { TYPE_OBJECT } from '@libs-ui/interfaces-types';
140
+
141
+ // KHÔNG sử dụng trực tiếp — base component có template rỗng, không render gì
142
+ @Component({
143
+ selector: 'app-example',
144
+ standalone: true,
145
+ imports: [LibsUiComponentsComponentOutletComponent],
146
+ template: `
147
+ <!-- Base component không render UI -->
148
+ <libs_ui-components-component_outlet
149
+ [item]="sampleData()"
150
+ />
151
+ `,
152
+ })
153
+ export class ExampleComponent {
154
+ readonly sampleData = signal<TYPE_OBJECT>({
155
+ id: 1,
156
+ name: 'Sample Item',
157
+ });
158
+ }
159
+ ```
160
+
134
161
  ### Ví dụ 1 — Custom status component trong List (Cách mới)
135
162
 
136
163
  ```typescript
@@ -269,6 +296,132 @@ listConfig = signal({
269
296
  });
270
297
  ```
271
298
 
299
+ ### Ví dụ 4 — Real-World: List Component với custom cell extend base (Legacy)
300
+
301
+ ```typescript
302
+ import { Component, signal } from '@angular/core';
303
+ import { LibsUiComponentsListComponent } from '@libs-ui/components-list';
304
+ import { LibsUiComponentsComponentOutletComponent } from '@libs-ui/components-component-outlet';
305
+ import { of } from 'rxjs';
306
+
307
+ // 1. Tạo Custom Cell Component extend base
308
+ @Component({
309
+ selector: 'app-custom-list-item',
310
+ standalone: true,
311
+ template: `
312
+ <div class="flex items-center gap-2">
313
+ <span class="font-bold">{{ item().name }}</span>
314
+ <span class="text-xs text-gray-500">ID: {{ item().id }}</span>
315
+ @if (item().status === 'active') {
316
+ <span class="px-2 py-1 bg-green-100 text-green-800 rounded text-xs">
317
+ Active
318
+ </span>
319
+ }
320
+ </div>
321
+ `,
322
+ })
323
+ export class CustomListItemComponent extends LibsUiComponentsComponentOutletComponent {
324
+ // Inherit input 'item' từ base component
325
+ }
326
+
327
+ // 2. Sử dụng trong List Config
328
+ @Component({
329
+ selector: 'app-list-example',
330
+ standalone: true,
331
+ imports: [LibsUiComponentsListComponent],
332
+ template: `
333
+ <libs_ui-components-list
334
+ [config]="listConfig()"
335
+ (outSelectedKey)="onItemSelected($event)"
336
+ />
337
+ `,
338
+ })
339
+ export class ListExampleComponent {
340
+ readonly listConfig = signal({
341
+ type: 'text',
342
+ configTemplateText: signal({
343
+ fieldKey: 'id',
344
+ // Trả về custom component class
345
+ getComponentOutlet: () => of(CustomListItemComponent),
346
+ // Trả về data cho component
347
+ getDataComponentOutlet: (item: any) => item,
348
+ }),
349
+ });
350
+
351
+ onItemSelected(event: any) {
352
+ console.log('Selected:', event);
353
+ }
354
+ }
355
+ ```
356
+
357
+ ### Ví dụ 5 — Nhiều custom components trong List rows config (Legacy)
358
+
359
+ ```typescript
360
+ import { Component } from '@angular/core';
361
+ import { LibsUiComponentsComponentOutletComponent } from '@libs-ui/components-component-outlet';
362
+ import { LibsUiComponentsListComponent } from '@libs-ui/components-list';
363
+ import { of } from 'rxjs';
364
+
365
+ // Status Cell Component
366
+ @Component({
367
+ selector: 'app-status-cell',
368
+ standalone: true,
369
+ template: `
370
+ <span [class]="getStatusClass()">
371
+ {{ item().status }}
372
+ </span>
373
+ `,
374
+ })
375
+ export class StatusCellComponent extends LibsUiComponentsComponentOutletComponent {
376
+ getStatusClass(): string {
377
+ return this.item().status === 'active' ? 'text-green-600' : 'text-gray-400';
378
+ }
379
+ }
380
+
381
+ // Action Cell Component
382
+ @Component({
383
+ selector: 'app-action-cell',
384
+ standalone: true,
385
+ template: `
386
+ <button (click)="handleAction()">
387
+ Action for {{ item().name }}
388
+ </button>
389
+ `,
390
+ })
391
+ export class ActionCellComponent extends LibsUiComponentsComponentOutletComponent {
392
+ handleAction(): void {
393
+ console.log('Action for:', this.item());
394
+ }
395
+ }
396
+
397
+ // Sử dụng trong List với rows config
398
+ @Component({
399
+ standalone: true,
400
+ imports: [LibsUiComponentsListComponent],
401
+ template: `<libs_ui-components-list [config]="listConfig()" />`,
402
+ })
403
+ export class ListWithMultipleComponentsExample {
404
+ readonly listConfig = signal({
405
+ type: 'text',
406
+ configTemplateText: signal({
407
+ fieldKey: 'id',
408
+ rows: signal([
409
+ // Row 1: Status component
410
+ signal({
411
+ getComponentOutlet: () => of(StatusCellComponent),
412
+ getDataComponentOutlet: (item: any) => item,
413
+ }),
414
+ // Row 2: Action component
415
+ signal({
416
+ getComponentOutlet: () => of(ActionCellComponent),
417
+ getDataComponentOutlet: (item: any) => item,
418
+ }),
419
+ ]),
420
+ }),
421
+ });
422
+ }
423
+ ```
424
+
272
425
  ---
273
426
 
274
427
  ## @Input()
@@ -313,11 +466,3 @@ const data: TYPE_COMPONENT_OUTLET_DATA = signal({ id: 1, name: 'Item A' });
313
466
  ⚠️ **Chỉ extend, không dùng trực tiếp**: Nếu render `<libs_ui-components-component_outlet [item]="data()">` trực tiếp, component sẽ không hiển thị gì cả do template rỗng.
314
467
 
315
468
  ---
316
-
317
- ## Demo
318
-
319
- ```bash
320
- npx nx serve core-ui
321
- ```
322
-
323
- Truy cập: [http://localhost:4500/components/component-outlet](http://localhost:4500/components/component-outlet)
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@libs-ui/components-component-outlet",
3
- "version": "0.2.357-7",
3
+ "version": "0.2.357-9",
4
4
  "peerDependencies": {
5
5
  "@angular/core": ">=18.0.0",
6
- "@libs-ui/interfaces-types": "0.2.357-7"
6
+ "@libs-ui/interfaces-types": "0.2.357-9"
7
7
  },
8
8
  "sideEffects": false,
9
9
  "module": "fesm2022/libs-ui-components-component-outlet.mjs",