@libs-ui/components-click-outside 0.2.357-8 → 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.
- package/README.md +28 -58
- 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-
|
|
54
|
+
selector: 'app-example',
|
|
55
55
|
standalone: true,
|
|
56
56
|
imports: [LibsUiComponentsClickOutsideDirective],
|
|
57
57
|
template: `
|
|
58
58
|
<div
|
|
59
59
|
LibsUiComponentsClickOutsideDirective
|
|
60
|
-
(outOutside)="
|
|
61
|
-
(outInSide)="
|
|
62
|
-
class="p-
|
|
63
|
-
<p>Click
|
|
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
|
|
68
|
-
|
|
69
|
-
|
|
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
|
-
|
|
74
|
-
|
|
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)="
|
|
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
|
|
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)="
|
|
145
|
-
class="bg-white p-6 rounded-lg shadow-xl max-w-md
|
|
146
|
-
<h3 class="text-lg font-semibold mb-4">
|
|
147
|
-
<p class="text-gray-600 mb-4">Click
|
|
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-
|
|
151
|
-
|
|
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
|
|
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)="
|
|
182
|
-
(outInSide)="
|
|
183
|
-
class="p-6 border-2 border-purple-500 rounded-lg">
|
|
184
|
-
<
|
|
185
|
-
<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
|
|
169
|
+
export class CounterExample {
|
|
190
170
|
readonly insideCount = signal<number>(0);
|
|
191
171
|
readonly outsideCount = signal<number>(0);
|
|
192
172
|
|
|
193
|
-
|
|
194
|
-
event.stopPropagation();
|
|
173
|
+
onClickInside(): void {
|
|
195
174
|
this.insideCount.update((count) => count + 1);
|
|
196
175
|
}
|
|
197
176
|
|
|
198
|
-
|
|
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
|