@libs-ui/components-click-outside 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 +28 -58
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -51,28 +51,26 @@ import { Component } from '@angular/core';
51
51
  import { LibsUiComponentsClickOutsideDirective } from '@libs-ui/components-click-outside';
52
52
 
53
53
  @Component({
54
- selector: 'app-basic-example',
54
+ selector: 'app-example',
55
55
  standalone: true,
56
56
  imports: [LibsUiComponentsClickOutsideDirective],
57
57
  template: `
58
58
  <div
59
59
  LibsUiComponentsClickOutsideDirective
60
- (outOutside)="handlerClickOutside($event)"
61
- (outInSide)="handlerClickInside($event)"
62
- class="p-6 border-2 border-blue-500 rounded-lg">
63
- <p>Click vào trong hoặc ngoài vùng này để thử</p>
60
+ (outOutside)="onClickOutside($event)"
61
+ (outInSide)="onClickInside($event)"
62
+ class="p-4 border-2 border-blue-500 rounded-lg">
63
+ <p>Click inside or outside this box</p>
64
64
  </div>
65
65
  `,
66
66
  })
67
- export class BasicExampleComponent {
68
- handlerClickOutside(event: Event): void {
69
- event.stopPropagation();
70
- console.log('Đã click bên ngoài');
67
+ export class ExampleComponent {
68
+ onClickOutside(event: Event): void {
69
+ console.log('Clicked outside!', event);
71
70
  }
72
71
 
73
- handlerClickInside(event: Event): void {
74
- event.stopPropagation();
75
- console.log('Đã click bên trong');
72
+ onClickInside(event: Event): void {
73
+ console.log('Clicked inside!', event);
76
74
  }
77
75
  }
78
76
  ```
@@ -84,7 +82,6 @@ import { Component, signal } from '@angular/core';
84
82
  import { LibsUiComponentsClickOutsideDirective } from '@libs-ui/components-click-outside';
85
83
 
86
84
  @Component({
87
- selector: 'app-dropdown-example',
88
85
  standalone: true,
89
86
  imports: [LibsUiComponentsClickOutsideDirective],
90
87
  template: `
@@ -98,7 +95,7 @@ import { LibsUiComponentsClickOutsideDirective } from '@libs-ui/components-click
98
95
  @if (isOpen()) {
99
96
  <div
100
97
  LibsUiComponentsClickOutsideDirective
101
- (outOutside)="handlerClose($event)"
98
+ (outOutside)="isOpen.set(false)"
102
99
  class="absolute mt-2 w-48 bg-white border rounded-lg shadow-lg">
103
100
  <ul class="py-2">
104
101
  <li class="px-4 py-2 hover:bg-gray-100 cursor-pointer">Option 1</li>
@@ -110,13 +107,8 @@ import { LibsUiComponentsClickOutsideDirective } from '@libs-ui/components-click
110
107
  </div>
111
108
  `,
112
109
  })
113
- export class DropdownExampleComponent {
110
+ export class DropdownExample {
114
111
  readonly isOpen = signal<boolean>(false);
115
-
116
- handlerClose(event: Event): void {
117
- event.stopPropagation();
118
- this.isOpen.set(false);
119
- }
120
112
  }
121
113
  ```
122
114
 
@@ -127,41 +119,29 @@ import { Component, signal } from '@angular/core';
127
119
  import { LibsUiComponentsClickOutsideDirective } from '@libs-ui/components-click-outside';
128
120
 
129
121
  @Component({
130
- selector: 'app-modal-example',
131
122
  standalone: true,
132
123
  imports: [LibsUiComponentsClickOutsideDirective],
133
124
  template: `
134
- <button
135
- (click)="showModal.set(true)"
136
- class="px-4 py-2 bg-blue-500 text-white rounded">
137
- Mở Modal
138
- </button>
139
-
140
125
  @if (showModal()) {
141
126
  <div class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center">
142
127
  <div
143
128
  LibsUiComponentsClickOutsideDirective
144
- (outOutside)="handlerCloseModal($event)"
145
- class="bg-white p-6 rounded-lg shadow-xl max-w-md w-full">
146
- <h3 class="text-lg font-semibold mb-4">Tiêu đề modal</h3>
147
- <p class="text-gray-600 mb-4">Click ra ngoài vùng trắng này để đóng modal.</p>
129
+ (outOutside)="showModal.set(false)"
130
+ class="bg-white p-6 rounded-lg shadow-xl max-w-md">
131
+ <h3 class="text-lg font-semibold mb-4">Modal Title</h3>
132
+ <p class="text-gray-600 mb-4">Click outside to close this modal</p>
148
133
  <button
149
134
  (click)="showModal.set(false)"
150
- class="px-4 py-2 bg-gray-200 rounded">
151
- Đóng
135
+ class="px-4 py-2 bg-blue-500 text-white rounded">
136
+ Close
152
137
  </button>
153
138
  </div>
154
139
  </div>
155
140
  }
156
141
  `,
157
142
  })
158
- export class ModalExampleComponent {
143
+ export class ModalExample {
159
144
  readonly showModal = signal<boolean>(false);
160
-
161
- handlerCloseModal(event: Event): void {
162
- event.stopPropagation();
163
- this.showModal.set(false);
164
- }
165
145
  }
166
146
  ```
167
147
 
@@ -172,31 +152,29 @@ import { Component, signal } from '@angular/core';
172
152
  import { LibsUiComponentsClickOutsideDirective } from '@libs-ui/components-click-outside';
173
153
 
174
154
  @Component({
175
- selector: 'app-counter-example',
176
155
  standalone: true,
177
156
  imports: [LibsUiComponentsClickOutsideDirective],
178
157
  template: `
179
158
  <div
180
159
  LibsUiComponentsClickOutsideDirective
181
- (outOutside)="handlerOutside($event)"
182
- (outInSide)="handlerInside($event)"
183
- class="p-6 border-2 border-purple-500 rounded-lg">
184
- <p>Click bên trong: {{ insideCount() }}</p>
185
- <p>Click bên ngoài: {{ outsideCount() }}</p>
160
+ (outOutside)="onClickOutside()"
161
+ (outInSide)="onClickInside()"
162
+ class="p-6 border-2 border-purple-500 rounded-lg bg-purple-50">
163
+ <h4 class="font-semibold mb-2">Click Counter</h4>
164
+ <p>Inside clicks: {{ insideCount() }}</p>
165
+ <p>Outside clicks: {{ outsideCount() }}</p>
186
166
  </div>
187
167
  `,
188
168
  })
189
- export class CounterExampleComponent {
169
+ export class CounterExample {
190
170
  readonly insideCount = signal<number>(0);
191
171
  readonly outsideCount = signal<number>(0);
192
172
 
193
- handlerInside(event: Event): void {
194
- event.stopPropagation();
173
+ onClickInside(): void {
195
174
  this.insideCount.update((count) => count + 1);
196
175
  }
197
176
 
198
- handlerOutside(event: Event): void {
199
- event.stopPropagation();
177
+ onClickOutside(): void {
200
178
  this.outsideCount.update((count) => count + 1);
201
179
  }
202
180
  }
@@ -230,11 +208,3 @@ Directive được gắn vào element bằng **attribute selector**:
230
208
  ⚠️ **Không có @Input()**: Directive này không nhận bất kỳ input nào — chỉ cần gắn vào element và lắng nghe output.
231
209
 
232
210
  ⚠️ **Cleanup tự động**: Subscription được dọn dẹp qua `takeUntilDestroyed(destroyRef)` — không cần tự unsubscribe hay implement `ngOnDestroy`.
233
-
234
- ## Demo
235
-
236
- ```bash
237
- npx nx serve core-ui
238
- ```
239
-
240
- Truy cập: http://localhost:4500/directives/click-outside
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@libs-ui/components-click-outside",
3
- "version": "0.2.357-7",
3
+ "version": "0.2.357-9",
4
4
  "peerDependencies": {
5
5
  "@angular/core": ">=18.0.0",
6
6
  "rxjs": "~7.8.0"