@libs-ui/components-device-support 0.2.357-3 → 0.2.357-30

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 +57 -64
  2. package/package.json +2 -2
package/README.md CHANGED
@@ -50,22 +50,21 @@ import { Component } from '@angular/core';
50
50
  import { LibsUiComponentsDeviceSupportHandleClickDirective } from '@libs-ui/components-device-support';
51
51
 
52
52
  @Component({
53
- selector: 'app-basic-example',
53
+ selector: 'app-example',
54
54
  standalone: true,
55
55
  imports: [LibsUiComponentsDeviceSupportHandleClickDirective],
56
56
  template: `
57
57
  <button
58
58
  libsUiComponentsDeviceSupportHandleClickDirective
59
- (outClick)="handlerButtonClick($event)"
59
+ (outClick)="onButtonClick($event)"
60
60
  class="px-4 py-2 bg-blue-500 text-white rounded">
61
61
  Click me
62
62
  </button>
63
63
  `
64
64
  })
65
- export class BasicExampleComponent {
66
- handlerButtonClick(event: Event): void {
67
- event.stopPropagation();
68
- console.log('Clicked! Event type:', event.type);
65
+ export class ExampleComponent {
66
+ onButtonClick(event: Event): void {
67
+ console.log('Clicked!', event.type);
69
68
  }
70
69
  }
71
70
  ```
@@ -79,28 +78,27 @@ import { Component } from '@angular/core';
79
78
  import { LibsUiComponentsDeviceSupportHandleClickDirective } from '@libs-ui/components-device-support';
80
79
 
81
80
  @Component({
82
- selector: 'app-custom-target-example',
81
+ selector: 'app-example',
83
82
  standalone: true,
84
83
  imports: [LibsUiComponentsDeviceSupportHandleClickDirective],
85
84
  template: `
86
85
  <!-- Element sẽ được lắng nghe click -->
87
- <div #targetEl class="p-4 border rounded cursor-pointer">
88
- Click vào đây để trigger event
86
+ <div #targetElement class="p-4 border rounded bg-gray-50">
87
+ Target Element - Click vào đây
89
88
  </div>
90
89
 
91
- <!-- Directive host — lắng nghe trên targetEl, không phải div này -->
90
+ <!-- Directive host — lắng nghe trên targetElement, không phải div này -->
92
91
  <div
93
92
  libsUiComponentsDeviceSupportHandleClickDirective
94
- [elementHandleClick]="targetEl"
95
- (outClick)="handlerTargetClick($event)"
96
- class="hidden">
93
+ [elementHandleClick]="targetElement"
94
+ (outClick)="onTargetClick($event)">
95
+ Directive host (không click vào đây)
97
96
  </div>
98
97
  `
99
98
  })
100
- export class CustomTargetExampleComponent {
101
- handlerTargetClick(event: Event): void {
102
- event.stopPropagation();
103
- console.log('Target element clicked, event type:', event.type);
99
+ export class ExampleComponent {
100
+ onTargetClick(event: Event): void {
101
+ console.log('Target clicked!', event.type);
104
102
  }
105
103
  }
106
104
  ```
@@ -112,39 +110,36 @@ import { Component } from '@angular/core';
112
110
  import { LibsUiComponentsDeviceSupportHandleClickDirective } from '@libs-ui/components-device-support';
113
111
 
114
112
  @Component({
115
- selector: 'app-propagation-example',
113
+ selector: 'app-example',
116
114
  standalone: true,
117
115
  imports: [LibsUiComponentsDeviceSupportHandleClickDirective],
118
116
  template: `
119
- <div (click)="handlerParentClick()">
120
- <span class="text-xs text-gray-500">Parent container</span>
121
-
122
- <!-- stopPropagation BẬT (mặc định) — parent sẽ KHÔNG nhận được click -->
117
+ <!-- Với stopPropagation (mặc định) -->
118
+ <div (click)="onParentClick()">
123
119
  <button
124
120
  libsUiComponentsDeviceSupportHandleClickDirective
125
- (outClick)="handlerChildClick($event)"
126
- class="px-3 py-2 bg-green-500 text-white rounded">
127
- stopPropagation: ON (parent không nhận click)
121
+ (outClick)="onChildClick($event)">
122
+ stopPropagation: ON (parent sẽ KHÔNG nhận click)
128
123
  </button>
124
+ </div>
129
125
 
130
- <!-- stopPropagation TẮT — event bubble lên parent bình thường -->
126
+ <!-- Không stopPropagation -->
127
+ <div (click)="onParentClick()">
131
128
  <button
132
129
  libsUiComponentsDeviceSupportHandleClickDirective
133
130
  [ignoreStopPropagation]="true"
134
- (outClick)="handlerChildClick($event)"
135
- class="px-3 py-2 bg-orange-500 text-white rounded">
136
- stopPropagation: OFF (parent cũng nhận click)
131
+ (outClick)="onChildClick($event)">
132
+ stopPropagation: OFF (parent SẼ nhận click)
137
133
  </button>
138
134
  </div>
139
135
  `
140
136
  })
141
- export class PropagationExampleComponent {
142
- handlerChildClick(event: Event): void {
143
- event.stopPropagation();
137
+ export class ExampleComponent {
138
+ onChildClick(event: Event): void {
144
139
  console.log('Child clicked');
145
140
  }
146
141
 
147
- handlerParentClick(): void {
142
+ onParentClick(): void {
148
143
  console.log('Parent clicked');
149
144
  }
150
145
  }
@@ -157,41 +152,47 @@ import { Component, signal } from '@angular/core';
157
152
  import { LibsUiComponentsDeviceSupportHandleClickDirective } from '@libs-ui/components-device-support';
158
153
 
159
154
  @Component({
160
- selector: 'app-interactive-example',
155
+ selector: 'app-example',
161
156
  standalone: true,
162
157
  imports: [LibsUiComponentsDeviceSupportHandleClickDirective],
163
158
  template: `
164
159
  <div>
165
- <button
166
- libsUiComponentsDeviceSupportHandleClickDirective
167
- [ignoreStopPropagation]="ignoreStop()"
168
- (outClick)="handlerClick($event)"
169
- class="px-4 py-2 bg-blue-500 text-white rounded">
170
- Click me
160
+ <button (click)="toggleStopPropagation()">
161
+ Toggle stopPropagation
171
162
  </button>
172
163
 
173
- <p>Số lần click: {{ clickCount() }}</p>
174
- <p>Loại event: {{ lastEventType() }}</p>
175
-
176
- <button (click)="toggleStop()">
177
- Toggle stopPropagation (hiện tại: {{ ignoreStop() ? 'OFF' : 'ON' }})
178
- </button>
164
+ <div (click)="onParentClick()">
165
+ <button
166
+ libsUiComponentsDeviceSupportHandleClickDirective
167
+ [ignoreStopPropagation]="ignoreStopPropagation()"
168
+ (outClick)="onInteractiveClick($event)"
169
+ class="px-4 py-2 bg-blue-500 text-white rounded">
170
+ Click me
171
+ </button>
172
+ </div>
173
+
174
+ <p>Click count: {{ clickCount() }}</p>
175
+ <p>Last event type: {{ lastEventType() }}</p>
176
+ <p>ignoreStopPropagation: {{ ignoreStopPropagation() }}</p>
179
177
  </div>
180
178
  `
181
179
  })
182
- export class InteractiveExampleComponent {
183
- protected clickCount = signal<number>(0);
184
- protected lastEventType = signal<string>('');
185
- protected ignoreStop = signal<boolean>(false);
186
-
187
- handlerClick(event: Event): void {
188
- event.stopPropagation();
189
- this.clickCount.update(count => count + 1);
180
+ export class ExampleComponent {
181
+ readonly ignoreStopPropagation = signal<boolean>(false);
182
+ readonly clickCount = signal<number>(0);
183
+ readonly lastEventType = signal<string>('');
184
+
185
+ toggleStopPropagation(): void {
186
+ this.ignoreStopPropagation.update((v) => !v);
187
+ }
188
+
189
+ onInteractiveClick(event: Event): void {
190
+ this.clickCount.update((count) => count + 1);
190
191
  this.lastEventType.set(event.type);
191
192
  }
192
193
 
193
- toggleStop(): void {
194
- this.ignoreStop.update(v => !v);
194
+ onParentClick(): void {
195
+ console.log('Parent clicked');
195
196
  }
196
197
  }
197
198
  ```
@@ -244,11 +245,3 @@ Directive sử dụng `fromEvent()` từ RxJS kết hợp với `takeUntilDestro
244
245
  ⚠️ **Selector dạng attribute**: Đây là attribute directive, selector là `[libsUiComponentsDeviceSupportHandleClickDirective]`. Phải dùng dạng attribute trên element, không dùng dạng tag.
245
246
 
246
247
  ⚠️ **window / document làm target**: Khi truyền `window` hoặc `document` vào `[elementHandleClick]`, directive sẽ lắng nghe click toàn trang. Hãy đảm bảo chỉ có một instance directive làm điều này tại một thời điểm, và component chứa directive phải được destroy đúng cách khi không còn dùng nữa.
247
-
248
- ## Demo
249
-
250
- ```bash
251
- npx nx serve core-ui
252
- ```
253
-
254
- Truy cập: http://localhost:4500/device-support
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@libs-ui/components-device-support",
3
- "version": "0.2.357-3",
3
+ "version": "0.2.357-30",
4
4
  "peerDependencies": {
5
5
  "@angular/core": ">=18.0.0",
6
- "@libs-ui/utils": "0.2.357-3",
6
+ "@libs-ui/utils": "0.2.357-30",
7
7
  "rxjs": "~7.8.0"
8
8
  },
9
9
  "sideEffects": false,