@spartan-ng/brain 0.0.1-alpha.450 → 0.0.1-alpha.452
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.
|
@@ -1,19 +1,23 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
|
-
import { Component, forwardRef, inject, DestroyRef, Renderer2, PLATFORM_ID, ElementRef, ChangeDetectorRef, signal, model, input,
|
|
2
|
+
import { Component, forwardRef, inject, DestroyRef, Renderer2, PLATFORM_ID, ElementRef, ChangeDetectorRef, signal, model, input, linkedSignal, booleanAttribute, output, viewChild, computed, effect, ViewEncapsulation, ChangeDetectionStrategy, NgModule } from '@angular/core';
|
|
3
3
|
import { FocusMonitor } from '@angular/cdk/a11y';
|
|
4
|
-
import { isPlatformBrowser,
|
|
4
|
+
import { isPlatformBrowser, DOCUMENT } from '@angular/common';
|
|
5
5
|
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
|
|
6
6
|
import { NG_VALUE_ACCESSOR } from '@angular/forms';
|
|
7
7
|
|
|
8
8
|
class BrnSwitchThumbComponent {
|
|
9
9
|
/** @nocollapse */ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.8", ngImport: i0, type: BrnSwitchThumbComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
10
|
-
/** @nocollapse */ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "19.2.8", type: BrnSwitchThumbComponent, isStandalone: true, selector: "brn-switch-thumb", ngImport: i0, template: '', isInline: true });
|
|
10
|
+
/** @nocollapse */ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "19.2.8", type: BrnSwitchThumbComponent, isStandalone: true, selector: "brn-switch-thumb", host: { attributes: { "role": "presentation" }, listeners: { "click": "$event.preventDefault()" } }, ngImport: i0, template: '', isInline: true });
|
|
11
11
|
}
|
|
12
12
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.8", ngImport: i0, type: BrnSwitchThumbComponent, decorators: [{
|
|
13
13
|
type: Component,
|
|
14
14
|
args: [{
|
|
15
15
|
selector: 'brn-switch-thumb',
|
|
16
16
|
template: '',
|
|
17
|
+
host: {
|
|
18
|
+
role: 'presentation',
|
|
19
|
+
'(click)': '$event.preventDefault()',
|
|
20
|
+
},
|
|
17
21
|
}]
|
|
18
22
|
}] });
|
|
19
23
|
|
|
@@ -23,6 +27,7 @@ const BRN_SWITCH_VALUE_ACCESSOR = {
|
|
|
23
27
|
multi: true,
|
|
24
28
|
};
|
|
25
29
|
const CONTAINER_POST_FIX = '-switch';
|
|
30
|
+
let uniqueIdCounter = 0;
|
|
26
31
|
class BrnSwitchComponent {
|
|
27
32
|
_destroyRef = inject(DestroyRef);
|
|
28
33
|
_renderer = inject(Renderer2);
|
|
@@ -30,30 +35,68 @@ class BrnSwitchComponent {
|
|
|
30
35
|
_elementRef = inject(ElementRef);
|
|
31
36
|
_focusMonitor = inject(FocusMonitor);
|
|
32
37
|
_cdr = inject(ChangeDetectorRef);
|
|
38
|
+
_document = inject(DOCUMENT);
|
|
33
39
|
focusVisible = signal(false);
|
|
34
40
|
focused = signal(false);
|
|
41
|
+
/**
|
|
42
|
+
* Whether the switch is checked.
|
|
43
|
+
* Can be bound with [(checked)]
|
|
44
|
+
*/
|
|
35
45
|
checked = model(false);
|
|
36
|
-
/**
|
|
37
|
-
|
|
38
|
-
|
|
46
|
+
/**
|
|
47
|
+
* Sets the ID on the switch.
|
|
48
|
+
* When provided, the inner button gets this ID without the '-switch' suffix.
|
|
49
|
+
*/
|
|
50
|
+
id = input(uniqueIdCounter++ + '');
|
|
51
|
+
/**
|
|
52
|
+
* Sets the name on the switch.
|
|
53
|
+
* When provided, the inner button gets this name without a '-switch' suffix.
|
|
54
|
+
*/
|
|
39
55
|
name = input(null);
|
|
40
|
-
/**
|
|
56
|
+
/**
|
|
57
|
+
* Sets class set on the inner button
|
|
58
|
+
*/
|
|
59
|
+
class = input(null);
|
|
60
|
+
/**
|
|
61
|
+
* Sets the aria-label attribute for accessibility.
|
|
62
|
+
*/
|
|
41
63
|
ariaLabel = input(null, { alias: 'aria-label' });
|
|
42
|
-
/**
|
|
64
|
+
/**
|
|
65
|
+
* Sets the aria-labelledby attribute for accessibility.
|
|
66
|
+
*/
|
|
43
67
|
ariaLabelledby = input(null, { alias: 'aria-labelledby' });
|
|
44
|
-
|
|
68
|
+
mutableAriaLabelledby = linkedSignal(() => this.ariaLabelledby());
|
|
69
|
+
/**
|
|
70
|
+
* Sets the aria-describedby attribute for accessibility.
|
|
71
|
+
*/
|
|
45
72
|
ariaDescribedby = input(null, { alias: 'aria-describedby' });
|
|
73
|
+
/**
|
|
74
|
+
* Whether the switch is required in a form.
|
|
75
|
+
*/
|
|
46
76
|
required = input(false, { transform: booleanAttribute });
|
|
77
|
+
/**
|
|
78
|
+
* Whether the switch is disabled.
|
|
79
|
+
*/
|
|
47
80
|
disabled = input(false, {
|
|
48
81
|
transform: booleanAttribute,
|
|
49
82
|
});
|
|
83
|
+
/**
|
|
84
|
+
* tabIndex of the switch.
|
|
85
|
+
*/
|
|
86
|
+
tabIndex = input(0);
|
|
87
|
+
/**
|
|
88
|
+
* Event emitted when the switch value changes.
|
|
89
|
+
*/
|
|
90
|
+
changed = output();
|
|
91
|
+
/**
|
|
92
|
+
* Event emitted when the switch is blurred (loses focus).
|
|
93
|
+
*/
|
|
94
|
+
touched = output();
|
|
50
95
|
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
51
96
|
_onChange = () => { };
|
|
52
97
|
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
53
98
|
_onTouched = () => { };
|
|
54
|
-
|
|
55
|
-
changed = output();
|
|
56
|
-
touched = output();
|
|
99
|
+
switch = viewChild.required('switch');
|
|
57
100
|
state = computed(() => {
|
|
58
101
|
const name = this.name();
|
|
59
102
|
const id = this.id();
|
|
@@ -65,33 +108,27 @@ class BrnSwitchComponent {
|
|
|
65
108
|
});
|
|
66
109
|
constructor() {
|
|
67
110
|
effect(() => {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
if (!
|
|
111
|
+
const state = this.state();
|
|
112
|
+
const isDisabled = state.disabled();
|
|
113
|
+
if (!this._elementRef.nativeElement || !this._isBrowser)
|
|
71
114
|
return;
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
if (!
|
|
77
|
-
return;
|
|
78
|
-
// check if parent is a label and assume it is for this checkbox
|
|
79
|
-
if (parent?.tagName === 'LABEL') {
|
|
80
|
-
this._renderer.setAttribute(parent, 'data-disabled', this.state().disabled() ? 'true' : 'false');
|
|
115
|
+
const newLabelId = state.id + '-label';
|
|
116
|
+
const switchButtonId = this.getSwitchButtonId(state.id);
|
|
117
|
+
const labelElement = this._elementRef.nativeElement.closest('label') ??
|
|
118
|
+
this._document.querySelector(`label[for="${switchButtonId}"]`);
|
|
119
|
+
if (!labelElement)
|
|
81
120
|
return;
|
|
121
|
+
const existingLabelId = labelElement.id;
|
|
122
|
+
this._renderer.setAttribute(labelElement, 'data-disabled', isDisabled ? 'true' : 'false');
|
|
123
|
+
this.mutableAriaLabelledby.set(existingLabelId || newLabelId);
|
|
124
|
+
if (!existingLabelId || existingLabelId.length === 0) {
|
|
125
|
+
this._renderer.setAttribute(labelElement, 'id', newLabelId);
|
|
82
126
|
}
|
|
83
|
-
if (!this._isBrowser)
|
|
84
|
-
return;
|
|
85
|
-
const label = parent?.querySelector(`label[for="${this.forChild(this.state().id)}"]`);
|
|
86
|
-
if (!label)
|
|
87
|
-
return;
|
|
88
|
-
this._renderer.setAttribute(label, 'data-disabled', this.state().disabled() ? 'true' : 'false');
|
|
89
127
|
});
|
|
90
128
|
}
|
|
91
|
-
toggle(
|
|
129
|
+
toggle() {
|
|
92
130
|
if (this.state().disabled())
|
|
93
131
|
return;
|
|
94
|
-
event.preventDefault();
|
|
95
132
|
this.checked.update((checked) => !checked);
|
|
96
133
|
this._onChange(this.checked());
|
|
97
134
|
this.changed.emit(this.checked());
|
|
@@ -122,16 +159,17 @@ class BrnSwitchComponent {
|
|
|
122
159
|
});
|
|
123
160
|
}
|
|
124
161
|
});
|
|
125
|
-
if (!this.
|
|
162
|
+
if (!this.switch())
|
|
126
163
|
return;
|
|
127
|
-
this.
|
|
128
|
-
this.
|
|
164
|
+
this.switch().nativeElement.value = this.checked() ? 'on' : 'off';
|
|
165
|
+
this.switch().nativeElement.dispatchEvent(new Event('change'));
|
|
129
166
|
}
|
|
130
167
|
ngOnDestroy() {
|
|
131
168
|
this._focusMonitor.stopMonitoring(this._elementRef);
|
|
132
169
|
}
|
|
133
|
-
|
|
134
|
-
|
|
170
|
+
/** We intercept the id passed to the wrapper component and pass it to the underlying button switch control **/
|
|
171
|
+
getSwitchButtonId(idPassedToContainer) {
|
|
172
|
+
return idPassedToContainer ? idPassedToContainer.replace(CONTAINER_POST_FIX, '') : null;
|
|
135
173
|
}
|
|
136
174
|
writeValue(value) {
|
|
137
175
|
this.checked.set(Boolean(value));
|
|
@@ -147,104 +185,77 @@ class BrnSwitchComponent {
|
|
|
147
185
|
this.state().disabled.set(isDisabled);
|
|
148
186
|
this._cdr.markForCheck();
|
|
149
187
|
}
|
|
150
|
-
/**
|
|
151
|
-
* If the space key is pressed, prevent the default action to stop the page from scrolling.
|
|
152
|
-
*/
|
|
153
|
-
preventScrolling(event) {
|
|
154
|
-
event.preventDefault();
|
|
155
|
-
}
|
|
156
188
|
/** @nocollapse */ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.8", ngImport: i0, type: BrnSwitchComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
157
|
-
/** @nocollapse */ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.2.0", version: "19.2.8", type: BrnSwitchComponent, isStandalone: true, selector: "brn-switch", inputs: { checked: { classPropertyName: "checked", publicName: "checked", isSignal: true, isRequired: false, transformFunction: null }, id: { classPropertyName: "id", publicName: "id", isSignal: true, isRequired: false, transformFunction: null }, name: { classPropertyName: "name", publicName: "name", isSignal: true, isRequired: false, transformFunction: null }, ariaLabel: { classPropertyName: "ariaLabel", publicName: "aria-label", isSignal: true, isRequired: false, transformFunction: null }, ariaLabelledby: { classPropertyName: "ariaLabelledby", publicName: "aria-labelledby", isSignal: true, isRequired: false, transformFunction: null }, ariaDescribedby: { classPropertyName: "ariaDescribedby", publicName: "aria-describedby", isSignal: true, isRequired: false, transformFunction: null }, required: { classPropertyName: "required", publicName: "required", isSignal: true, isRequired: false, transformFunction: null }, disabled: { classPropertyName: "disabled", publicName: "disabled", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { checked: "checkedChange", changed: "changed", touched: "touched" }, host: {
|
|
158
|
-
<
|
|
159
|
-
#
|
|
160
|
-
tabindex="-1"
|
|
161
|
-
type="checkbox"
|
|
189
|
+
/** @nocollapse */ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.2.0", version: "19.2.8", type: BrnSwitchComponent, isStandalone: true, selector: "brn-switch", inputs: { checked: { classPropertyName: "checked", publicName: "checked", isSignal: true, isRequired: false, transformFunction: null }, id: { classPropertyName: "id", publicName: "id", isSignal: true, isRequired: false, transformFunction: null }, name: { classPropertyName: "name", publicName: "name", isSignal: true, isRequired: false, transformFunction: null }, class: { classPropertyName: "class", publicName: "class", isSignal: true, isRequired: false, transformFunction: null }, ariaLabel: { classPropertyName: "ariaLabel", publicName: "aria-label", isSignal: true, isRequired: false, transformFunction: null }, ariaLabelledby: { classPropertyName: "ariaLabelledby", publicName: "aria-labelledby", isSignal: true, isRequired: false, transformFunction: null }, ariaDescribedby: { classPropertyName: "ariaDescribedby", publicName: "aria-describedby", isSignal: true, isRequired: false, transformFunction: null }, required: { classPropertyName: "required", publicName: "required", isSignal: true, isRequired: false, transformFunction: null }, disabled: { classPropertyName: "disabled", publicName: "disabled", isSignal: true, isRequired: false, transformFunction: null }, tabIndex: { classPropertyName: "tabIndex", publicName: "tabIndex", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { checked: "checkedChange", changed: "changed", touched: "touched" }, host: { properties: { "style": "{display: \"contents\"}", "attr.id": "state().id", "attr.name": "state().name", "attr.aria-labelledby": "null", "attr.aria-label": "null", "attr.aria-describedby": "null", "attr.data-state": "checked() ? \"checked\" : \"unchecked\"", "attr.data-focus-visible": "focusVisible()", "attr.data-focus": "focused()", "attr.data-disabled": "state().disabled()" } }, providers: [BRN_SWITCH_VALUE_ACCESSOR], viewQueries: [{ propertyName: "switch", first: true, predicate: ["switch"], descendants: true, isSignal: true }], ngImport: i0, template: `
|
|
190
|
+
<button
|
|
191
|
+
#switch
|
|
162
192
|
role="switch"
|
|
163
|
-
|
|
164
|
-
[
|
|
193
|
+
type="button"
|
|
194
|
+
[class]="class()"
|
|
195
|
+
[id]="getSwitchButtonId(state().id) ?? ''"
|
|
196
|
+
[name]="getSwitchButtonId(state().name) ?? ''"
|
|
165
197
|
[value]="checked() ? 'on' : 'off'"
|
|
166
|
-
[
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
[attr.aria-required]="required() || null"
|
|
182
|
-
/>
|
|
183
|
-
<ng-content select="brn-switch-thumb" />
|
|
184
|
-
`, isInline: true, dependencies: [{ kind: "directive", type: NgStyle, selector: "[ngStyle]", inputs: ["ngStyle"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None });
|
|
198
|
+
[attr.aria-checked]="checked()"
|
|
199
|
+
[attr.aria-label]="ariaLabel() || null"
|
|
200
|
+
[attr.aria-labelledby]="mutableAriaLabelledby() || null"
|
|
201
|
+
[attr.aria-describedby]="ariaDescribedby() || null"
|
|
202
|
+
[attr.data-state]="checked() ? 'checked' : 'unchecked'"
|
|
203
|
+
[attr.data-focus-visible]="focusVisible()"
|
|
204
|
+
[attr.data-focus]="focused()"
|
|
205
|
+
[attr.data-disabled]="state().disabled()"
|
|
206
|
+
[disabled]="state().disabled()"
|
|
207
|
+
[tabIndex]="tabIndex()"
|
|
208
|
+
(click)="$event.preventDefault(); toggle()"
|
|
209
|
+
>
|
|
210
|
+
<ng-content select="brn-switch-thumb" />
|
|
211
|
+
</button>
|
|
212
|
+
`, isInline: true, changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None });
|
|
185
213
|
}
|
|
186
214
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.8", ngImport: i0, type: BrnSwitchComponent, decorators: [{
|
|
187
215
|
type: Component,
|
|
188
216
|
args: [{
|
|
189
217
|
selector: 'brn-switch',
|
|
190
|
-
imports: [NgStyle],
|
|
191
218
|
template: `
|
|
192
|
-
<
|
|
193
|
-
#
|
|
194
|
-
tabindex="-1"
|
|
195
|
-
type="checkbox"
|
|
219
|
+
<button
|
|
220
|
+
#switch
|
|
196
221
|
role="switch"
|
|
197
|
-
|
|
198
|
-
[
|
|
222
|
+
type="button"
|
|
223
|
+
[class]="class()"
|
|
224
|
+
[id]="getSwitchButtonId(state().id) ?? ''"
|
|
225
|
+
[name]="getSwitchButtonId(state().name) ?? ''"
|
|
199
226
|
[value]="checked() ? 'on' : 'off'"
|
|
200
|
-
[
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
[attr.aria-describedby]="ariaDescribedby()"
|
|
215
|
-
[attr.aria-required]="required() || null"
|
|
216
|
-
/>
|
|
217
|
-
<ng-content select="brn-switch-thumb" />
|
|
227
|
+
[attr.aria-checked]="checked()"
|
|
228
|
+
[attr.aria-label]="ariaLabel() || null"
|
|
229
|
+
[attr.aria-labelledby]="mutableAriaLabelledby() || null"
|
|
230
|
+
[attr.aria-describedby]="ariaDescribedby() || null"
|
|
231
|
+
[attr.data-state]="checked() ? 'checked' : 'unchecked'"
|
|
232
|
+
[attr.data-focus-visible]="focusVisible()"
|
|
233
|
+
[attr.data-focus]="focused()"
|
|
234
|
+
[attr.data-disabled]="state().disabled()"
|
|
235
|
+
[disabled]="state().disabled()"
|
|
236
|
+
[tabIndex]="tabIndex()"
|
|
237
|
+
(click)="$event.preventDefault(); toggle()"
|
|
238
|
+
>
|
|
239
|
+
<ng-content select="brn-switch-thumb" />
|
|
240
|
+
</button>
|
|
218
241
|
`,
|
|
219
242
|
host: {
|
|
220
|
-
|
|
243
|
+
'[style]': '{display: "contents"}',
|
|
244
|
+
'[attr.id]': 'state().id',
|
|
245
|
+
'[attr.name]': 'state().name',
|
|
246
|
+
'[attr.aria-labelledby]': 'null',
|
|
247
|
+
'[attr.aria-label]': 'null',
|
|
248
|
+
'[attr.aria-describedby]': 'null',
|
|
221
249
|
'[attr.data-state]': 'checked() ? "checked" : "unchecked"',
|
|
222
250
|
'[attr.data-focus-visible]': 'focusVisible()',
|
|
223
251
|
'[attr.data-focus]': 'focused()',
|
|
224
252
|
'[attr.data-disabled]': 'state().disabled()',
|
|
225
|
-
'[attr.aria-labelledby]': 'null',
|
|
226
|
-
'[attr.aria-label]': 'null',
|
|
227
|
-
'[attr.aria-describedby]': 'null',
|
|
228
|
-
'[attr.id]': 'state().id',
|
|
229
|
-
'[attr.name]': 'state().name',
|
|
230
253
|
},
|
|
231
254
|
providers: [BRN_SWITCH_VALUE_ACCESSOR],
|
|
232
255
|
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
233
256
|
encapsulation: ViewEncapsulation.None,
|
|
234
257
|
}]
|
|
235
|
-
}], ctorParameters: () => []
|
|
236
|
-
type: HostListener,
|
|
237
|
-
args: ['click', ['$event']]
|
|
238
|
-
}, {
|
|
239
|
-
type: HostListener,
|
|
240
|
-
args: ['keyup.enter', ['$event']]
|
|
241
|
-
}, {
|
|
242
|
-
type: HostListener,
|
|
243
|
-
args: ['keyup.space', ['$event']]
|
|
244
|
-
}], preventScrolling: [{
|
|
245
|
-
type: HostListener,
|
|
246
|
-
args: ['keydown.space', ['$event']]
|
|
247
|
-
}] } });
|
|
258
|
+
}], ctorParameters: () => [] });
|
|
248
259
|
|
|
249
260
|
const BrnSwitchImports = [BrnSwitchComponent, BrnSwitchThumbComponent];
|
|
250
261
|
class BrnSwitchModule {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"spartan-ng-brain-switch.mjs","sources":["../../../../libs/brain/switch/src/lib/brn-switch-thumb.component.ts","../../../../libs/brain/switch/src/lib/brn-switch.component.ts","../../../../libs/brain/switch/src/index.ts","../../../../libs/brain/switch/src/spartan-ng-brain-switch.ts"],"sourcesContent":["import { Component } from '@angular/core';\n\n@Component({\n\tselector: 'brn-switch-thumb',\n\ttemplate: '',\n})\nexport class BrnSwitchThumbComponent {}\n","import { FocusMonitor } from '@angular/cdk/a11y';\nimport { BooleanInput } from '@angular/cdk/coercion';\nimport { NgStyle, isPlatformBrowser } from '@angular/common';\nimport {\n\ttype AfterContentInit,\n\tChangeDetectionStrategy,\n\tChangeDetectorRef,\n\tComponent,\n\tDestroyRef,\n\tElementRef,\n\tHostListener,\n\ttype OnDestroy,\n\tPLATFORM_ID,\n\tRenderer2,\n\tViewEncapsulation,\n\tbooleanAttribute,\n\tcomputed,\n\teffect,\n\tforwardRef,\n\tinject,\n\tinput,\n\tmodel,\n\toutput,\n\tsignal,\n\tviewChild,\n} from '@angular/core';\nimport { takeUntilDestroyed } from '@angular/core/rxjs-interop';\nimport { NG_VALUE_ACCESSOR } from '@angular/forms';\nimport { ChangeFn, TouchFn } from '@spartan-ng/brain/forms';\n\nexport const BRN_SWITCH_VALUE_ACCESSOR = {\n\tprovide: NG_VALUE_ACCESSOR,\n\tuseExisting: forwardRef(() => BrnSwitchComponent),\n\tmulti: true,\n};\n\nconst CONTAINER_POST_FIX = '-switch';\n\n@Component({\n\tselector: 'brn-switch',\n\timports: [NgStyle],\n\ttemplate: `\n\t\t<input\n\t\t\t#checkBox\n\t\t\ttabindex=\"-1\"\n\t\t\ttype=\"checkbox\"\n\t\t\trole=\"switch\"\n\t\t\t[id]=\"forChild(state().id) ?? ''\"\n\t\t\t[name]=\"forChild(state().name) ?? ''\"\n\t\t\t[value]=\"checked() ? 'on' : 'off'\"\n\t\t\t[ngStyle]=\"{\n\t\t\t\tposition: 'absolute',\n\t\t\t\twidth: '1px',\n\t\t\t\theight: '1px',\n\t\t\t\tpadding: '0',\n\t\t\t\tmargin: -'1px',\n\t\t\t\toverflow: 'hidden',\n\t\t\t\tclip: 'rect(0, 0, 0, 0)',\n\t\t\t\twhiteSpace: 'nowrap',\n\t\t\t\tborderWidth: '0',\n\t\t\t}\"\n\t\t\t[checked]=\"checked()\"\n\t\t\t[attr.aria-label]=\"ariaLabel()\"\n\t\t\t[attr.aria-labelledby]=\"ariaLabelledby()\"\n\t\t\t[attr.aria-describedby]=\"ariaDescribedby()\"\n\t\t\t[attr.aria-required]=\"required() || null\"\n\t\t/>\n\t\t<ng-content select=\"brn-switch-thumb\" />\n\t`,\n\thost: {\n\t\ttabindex: '0',\n\t\t'[attr.data-state]': 'checked() ? \"checked\" : \"unchecked\"',\n\t\t'[attr.data-focus-visible]': 'focusVisible()',\n\t\t'[attr.data-focus]': 'focused()',\n\t\t'[attr.data-disabled]': 'state().disabled()',\n\t\t'[attr.aria-labelledby]': 'null',\n\t\t'[attr.aria-label]': 'null',\n\t\t'[attr.aria-describedby]': 'null',\n\t\t'[attr.id]': 'state().id',\n\t\t'[attr.name]': 'state().name',\n\t},\n\tproviders: [BRN_SWITCH_VALUE_ACCESSOR],\n\tchangeDetection: ChangeDetectionStrategy.OnPush,\n\tencapsulation: ViewEncapsulation.None,\n})\nexport class BrnSwitchComponent implements AfterContentInit, OnDestroy {\n\tprivate readonly _destroyRef = inject(DestroyRef);\n\tprivate readonly _renderer = inject(Renderer2);\n\tprivate readonly _isBrowser = isPlatformBrowser(inject(PLATFORM_ID));\n\tprivate readonly _elementRef = inject<ElementRef<HTMLElement>>(ElementRef);\n\tprivate readonly _focusMonitor = inject(FocusMonitor);\n\tprivate readonly _cdr = inject(ChangeDetectorRef);\n\n\tprotected readonly focusVisible = signal(false);\n\tprotected readonly focused = signal(false);\n\n\tpublic readonly checked = model<boolean>(false);\n\n\t/** Used to set the id on the underlying input element. */\n\n\tpublic readonly id = input<string | null>(null);\n\n\t/** Used to set the name attribute on the underlying input element. */\n\tpublic readonly name = input<string | null>(null);\n\n\t/** Used to set the aria-label attribute on the underlying input element. */\n\tpublic readonly ariaLabel = input<string | null>(null, { alias: 'aria-label' });\n\n\t/** Used to set the aria-labelledby attribute on the underlying input element. */\n\tpublic readonly ariaLabelledby = input<string | null>(null, { alias: 'aria-labelledby' });\n\n\t/** Used to set the aria-describedby attribute on the underlying input element. */\n\tpublic readonly ariaDescribedby = input<string | null>(null, { alias: 'aria-describedby' });\n\n\tpublic readonly required = input(false, { transform: booleanAttribute });\n\n\tpublic readonly disabled = input<boolean, BooleanInput>(false, {\n\t\ttransform: booleanAttribute,\n\t});\n\n\t// eslint-disable-next-line @typescript-eslint/no-empty-function\n\tprotected _onChange: ChangeFn<boolean> = () => {};\n\t// eslint-disable-next-line @typescript-eslint/no-empty-function\n\tprivate _onTouched: TouchFn = () => {};\n\n\tpublic readonly checkbox = viewChild.required<ElementRef<HTMLInputElement>>('checkBox');\n\n\tpublic readonly changed = output<boolean>();\n\n\tpublic readonly touched = output<void>();\n\n\tprotected readonly state = computed(() => {\n\t\tconst name = this.name();\n\t\tconst id = this.id();\n\t\treturn {\n\t\t\tdisabled: signal(this.disabled()),\n\t\t\tname: name ? name + CONTAINER_POST_FIX : null,\n\t\t\tid: id ? id + CONTAINER_POST_FIX : null,\n\t\t};\n\t});\n\n\tconstructor() {\n\t\teffect(() => {\n\t\t\t/** search for the label and set the disabled state */\n\t\t\tlet parent = this._renderer.parentNode(this._elementRef.nativeElement);\n\t\t\tif (!parent) return;\n\t\t\t// if parent is a HLM-SWITCH, then we need to go up one more level to get the label\n\t\t\tif (parent?.tagName === 'HLM-SWITCH') {\n\t\t\t\tparent = this._renderer.parentNode(parent);\n\t\t\t}\n\t\t\tif (!parent) return;\n\t\t\t// check if parent is a label and assume it is for this checkbox\n\t\t\tif (parent?.tagName === 'LABEL') {\n\t\t\t\tthis._renderer.setAttribute(parent, 'data-disabled', this.state().disabled() ? 'true' : 'false');\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (!this._isBrowser) return;\n\n\t\t\tconst label = parent?.querySelector(`label[for=\"${this.forChild(this.state().id)}\"]`);\n\t\t\tif (!label) return;\n\t\t\tthis._renderer.setAttribute(label, 'data-disabled', this.state().disabled() ? 'true' : 'false');\n\t\t});\n\t}\n\n\t@HostListener('click', ['$event'])\n\t@HostListener('keyup.enter', ['$event'])\n\t@HostListener('keyup.space', ['$event'])\n\tprotected toggle(event: Event): void {\n\t\tif (this.state().disabled()) return;\n\t\tevent.preventDefault();\n\n\t\tthis.checked.update((checked) => !checked);\n\t\tthis._onChange(this.checked());\n\t\tthis.changed.emit(this.checked());\n\t}\n\n\tngAfterContentInit() {\n\t\tthis._focusMonitor\n\t\t\t.monitor(this._elementRef, true)\n\t\t\t.pipe(takeUntilDestroyed(this._destroyRef))\n\t\t\t.subscribe((focusOrigin) => {\n\t\t\t\tif (focusOrigin) this.focused.set(true);\n\t\t\t\tif (focusOrigin === 'keyboard' || focusOrigin === 'program') {\n\t\t\t\t\tthis.focusVisible.set(true);\n\t\t\t\t\tthis._cdr.markForCheck();\n\t\t\t\t}\n\t\t\t\tif (!focusOrigin) {\n\t\t\t\t\t// When a focused element becomes disabled, the browser *immediately* fires a blur event.\n\t\t\t\t\t// Angular does not expect events to be raised during change detection, so any state\n\t\t\t\t\t// change (such as a form control's ng-touched) will cause a changed-after-checked error.\n\t\t\t\t\t// See https://github.com/angular/angular/issues/17793. To work around this, we defer\n\t\t\t\t\t// telling the form control it has been touched until the next tick.\n\t\t\t\t\tPromise.resolve().then(() => {\n\t\t\t\t\t\tthis.focusVisible.set(false);\n\t\t\t\t\t\tthis.focused.set(false);\n\t\t\t\t\t\tthis._onTouched();\n\t\t\t\t\t\tthis.touched.emit();\n\t\t\t\t\t\tthis._cdr.markForCheck();\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t});\n\n\t\tif (!this.checkbox()) return;\n\t\tthis.checkbox().nativeElement.value = this.checked() ? 'on' : 'off';\n\t\tthis.checkbox().nativeElement.dispatchEvent(new Event('change'));\n\t}\n\n\tngOnDestroy() {\n\t\tthis._focusMonitor.stopMonitoring(this._elementRef);\n\t}\n\n\tprotected forChild(parentValue: string | null | undefined): string | null {\n\t\treturn parentValue ? parentValue.replace(CONTAINER_POST_FIX, '') : null;\n\t}\n\n\twriteValue(value: boolean): void {\n\t\tthis.checked.set(Boolean(value));\n\t}\n\n\tregisterOnChange(fn: ChangeFn<boolean>): void {\n\t\tthis._onChange = fn;\n\t}\n\n\tregisterOnTouched(fn: TouchFn): void {\n\t\tthis._onTouched = fn;\n\t}\n\n\t/** Implemented as a part of ControlValueAccessor. */\n\tsetDisabledState(isDisabled: boolean): void {\n\t\tthis.state().disabled.set(isDisabled);\n\t\tthis._cdr.markForCheck();\n\t}\n\n\t/**\n\t * If the space key is pressed, prevent the default action to stop the page from scrolling.\n\t */\n\t@HostListener('keydown.space', ['$event'])\n\tprotected preventScrolling(event: KeyboardEvent): void {\n\t\tevent.preventDefault();\n\t}\n}\n","import { NgModule } from '@angular/core';\n\nimport { BrnSwitchThumbComponent } from './lib/brn-switch-thumb.component';\nimport { BrnSwitchComponent } from './lib/brn-switch.component';\n\nexport * from './lib/brn-switch-thumb.component';\nexport * from './lib/brn-switch.component';\n\nexport const BrnSwitchImports = [BrnSwitchComponent, BrnSwitchThumbComponent] as const;\n\n@NgModule({\n\timports: [...BrnSwitchImports],\n\tex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"}
|
|
1
|
+
{"version":3,"file":"spartan-ng-brain-switch.mjs","sources":["../../../../libs/brain/switch/src/lib/brn-switch-thumb.component.ts","../../../../libs/brain/switch/src/lib/brn-switch.component.ts","../../../../libs/brain/switch/src/index.ts","../../../../libs/brain/switch/src/spartan-ng-brain-switch.ts"],"sourcesContent":["import { Component } from '@angular/core';\n\n@Component({\n\tselector: 'brn-switch-thumb',\n\ttemplate: '',\n\thost: {\n\t\trole: 'presentation',\n\t\t'(click)': '$event.preventDefault()',\n\t},\n})\nexport class BrnSwitchThumbComponent {}\n","import { FocusMonitor } from '@angular/cdk/a11y';\nimport { BooleanInput } from '@angular/cdk/coercion';\nimport { DOCUMENT, isPlatformBrowser } from '@angular/common';\nimport {\n\ttype AfterContentInit,\n\tbooleanAttribute,\n\tChangeDetectionStrategy,\n\tChangeDetectorRef,\n\tComponent,\n\tcomputed,\n\tDestroyRef,\n\teffect,\n\tElementRef,\n\tforwardRef,\n\tinject,\n\tinput,\n\tlinkedSignal,\n\tmodel,\n\ttype OnDestroy,\n\toutput,\n\tPLATFORM_ID,\n\tRenderer2,\n\tsignal,\n\tviewChild,\n\tViewEncapsulation,\n} from '@angular/core';\nimport { takeUntilDestroyed } from '@angular/core/rxjs-interop';\nimport { NG_VALUE_ACCESSOR } from '@angular/forms';\nimport { ChangeFn, TouchFn } from '@spartan-ng/brain/forms';\n\nexport const BRN_SWITCH_VALUE_ACCESSOR = {\n\tprovide: NG_VALUE_ACCESSOR,\n\tuseExisting: forwardRef(() => BrnSwitchComponent),\n\tmulti: true,\n};\n\nconst CONTAINER_POST_FIX = '-switch';\n\nlet uniqueIdCounter = 0;\n\n@Component({\n\tselector: 'brn-switch',\n\ttemplate: `\n\t\t<button\n\t\t\t#switch\n\t\t\trole=\"switch\"\n\t\t\ttype=\"button\"\n\t\t\t[class]=\"class()\"\n\t\t\t[id]=\"getSwitchButtonId(state().id) ?? ''\"\n\t\t\t[name]=\"getSwitchButtonId(state().name) ?? ''\"\n\t\t\t[value]=\"checked() ? 'on' : 'off'\"\n\t\t\t[attr.aria-checked]=\"checked()\"\n\t\t\t[attr.aria-label]=\"ariaLabel() || null\"\n\t\t\t[attr.aria-labelledby]=\"mutableAriaLabelledby() || null\"\n\t\t\t[attr.aria-describedby]=\"ariaDescribedby() || null\"\n\t\t\t[attr.data-state]=\"checked() ? 'checked' : 'unchecked'\"\n\t\t\t[attr.data-focus-visible]=\"focusVisible()\"\n\t\t\t[attr.data-focus]=\"focused()\"\n\t\t\t[attr.data-disabled]=\"state().disabled()\"\n\t\t\t[disabled]=\"state().disabled()\"\n\t\t\t[tabIndex]=\"tabIndex()\"\n\t\t\t(click)=\"$event.preventDefault(); toggle()\"\n\t\t>\n\t\t\t<ng-content select=\"brn-switch-thumb\" />\n\t\t</button>\n\t`,\n\thost: {\n\t\t'[style]': '{display: \"contents\"}',\n\t\t'[attr.id]': 'state().id',\n\t\t'[attr.name]': 'state().name',\n\t\t'[attr.aria-labelledby]': 'null',\n\t\t'[attr.aria-label]': 'null',\n\t\t'[attr.aria-describedby]': 'null',\n\t\t'[attr.data-state]': 'checked() ? \"checked\" : \"unchecked\"',\n\t\t'[attr.data-focus-visible]': 'focusVisible()',\n\t\t'[attr.data-focus]': 'focused()',\n\t\t'[attr.data-disabled]': 'state().disabled()',\n\t},\n\tproviders: [BRN_SWITCH_VALUE_ACCESSOR],\n\tchangeDetection: ChangeDetectionStrategy.OnPush,\n\tencapsulation: ViewEncapsulation.None,\n})\nexport class BrnSwitchComponent implements AfterContentInit, OnDestroy {\n\tprivate readonly _destroyRef = inject(DestroyRef);\n\tprivate readonly _renderer = inject(Renderer2);\n\tprivate readonly _isBrowser = isPlatformBrowser(inject(PLATFORM_ID));\n\tprivate readonly _elementRef = inject<ElementRef<HTMLElement>>(ElementRef);\n\tprivate readonly _focusMonitor = inject(FocusMonitor);\n\tprivate readonly _cdr = inject(ChangeDetectorRef);\n\tprivate readonly _document = inject(DOCUMENT);\n\n\tprotected readonly focusVisible = signal(false);\n\tprotected readonly focused = signal(false);\n\n\t/**\n\t * Whether the switch is checked.\n\t * Can be bound with [(checked)]\n\t */\n\tpublic readonly checked = model<boolean>(false);\n\n\t/**\n\t * Sets the ID on the switch.\n\t * When provided, the inner button gets this ID without the '-switch' suffix.\n\t */\n\tpublic readonly id = input<string | null>(uniqueIdCounter++ + '');\n\n\t/**\n\t * Sets the name on the switch.\n\t * When provided, the inner button gets this name without a '-switch' suffix.\n\t */\n\tpublic readonly name = input<string | null>(null);\n\n\t/**\n\t * Sets class set on the inner button\n\t */\n\tpublic readonly class = input<string | null>(null);\n\n\t/**\n\t * Sets the aria-label attribute for accessibility.\n\t */\n\tpublic readonly ariaLabel = input<string | null>(null, { alias: 'aria-label' });\n\n\t/**\n\t * Sets the aria-labelledby attribute for accessibility.\n\t */\n\tpublic readonly ariaLabelledby = input<string | null>(null, { alias: 'aria-labelledby' });\n\tpublic readonly mutableAriaLabelledby = linkedSignal(() => this.ariaLabelledby());\n\n\t/**\n\t * Sets the aria-describedby attribute for accessibility.\n\t */\n\tpublic readonly ariaDescribedby = input<string | null>(null, { alias: 'aria-describedby' });\n\n\t/**\n\t * Whether the switch is required in a form.\n\t */\n\tpublic readonly required = input(false, { transform: booleanAttribute });\n\n\t/**\n\t * Whether the switch is disabled.\n\t */\n\tpublic readonly disabled = input<boolean, BooleanInput>(false, {\n\t\ttransform: booleanAttribute,\n\t});\n\n\t/**\n\t * tabIndex of the switch.\n\t */\n\tpublic readonly tabIndex = input(0);\n\n\t/**\n\t * Event emitted when the switch value changes.\n\t */\n\tpublic readonly changed = output<boolean>();\n\n\t/**\n\t * Event emitted when the switch is blurred (loses focus).\n\t */\n\tpublic readonly touched = output<void>();\n\n\t// eslint-disable-next-line @typescript-eslint/no-empty-function\n\tprotected _onChange: ChangeFn<boolean> = () => {};\n\t// eslint-disable-next-line @typescript-eslint/no-empty-function\n\tprivate _onTouched: TouchFn = () => {};\n\n\tpublic readonly switch = viewChild.required<ElementRef<HTMLInputElement>>('switch');\n\n\tprotected readonly state = computed(() => {\n\t\tconst name = this.name();\n\t\tconst id = this.id();\n\t\treturn {\n\t\t\tdisabled: signal(this.disabled()),\n\t\t\tname: name ? name + CONTAINER_POST_FIX : null,\n\t\t\tid: id ? id + CONTAINER_POST_FIX : null,\n\t\t};\n\t});\n\n\tconstructor() {\n\t\teffect(() => {\n\t\t\tconst state = this.state();\n\t\t\tconst isDisabled = state.disabled();\n\n\t\t\tif (!this._elementRef.nativeElement || !this._isBrowser) return;\n\n\t\t\tconst newLabelId = state.id + '-label';\n\t\t\tconst switchButtonId = this.getSwitchButtonId(state.id);\n\t\t\tconst labelElement =\n\t\t\t\tthis._elementRef.nativeElement.closest('label') ??\n\t\t\t\tthis._document.querySelector(`label[for=\"${switchButtonId}\"]`);\n\n\t\t\tif (!labelElement) return;\n\t\t\tconst existingLabelId = labelElement.id;\n\n\t\t\tthis._renderer.setAttribute(labelElement, 'data-disabled', isDisabled ? 'true' : 'false');\n\t\t\tthis.mutableAriaLabelledby.set(existingLabelId || newLabelId);\n\n\t\t\tif (!existingLabelId || existingLabelId.length === 0) {\n\t\t\t\tthis._renderer.setAttribute(labelElement, 'id', newLabelId);\n\t\t\t}\n\t\t});\n\t}\n\n\tprotected toggle(): void {\n\t\tif (this.state().disabled()) return;\n\n\t\tthis.checked.update((checked) => !checked);\n\t\tthis._onChange(this.checked());\n\t\tthis.changed.emit(this.checked());\n\t}\n\n\tngAfterContentInit() {\n\t\tthis._focusMonitor\n\t\t\t.monitor(this._elementRef, true)\n\t\t\t.pipe(takeUntilDestroyed(this._destroyRef))\n\t\t\t.subscribe((focusOrigin) => {\n\t\t\t\tif (focusOrigin) this.focused.set(true);\n\t\t\t\tif (focusOrigin === 'keyboard' || focusOrigin === 'program') {\n\t\t\t\t\tthis.focusVisible.set(true);\n\t\t\t\t\tthis._cdr.markForCheck();\n\t\t\t\t}\n\t\t\t\tif (!focusOrigin) {\n\t\t\t\t\t// When a focused element becomes disabled, the browser *immediately* fires a blur event.\n\t\t\t\t\t// Angular does not expect events to be raised during change detection, so any state\n\t\t\t\t\t// change (such as a form control's ng-touched) will cause a changed-after-checked error.\n\t\t\t\t\t// See https://github.com/angular/angular/issues/17793. To work around this, we defer\n\t\t\t\t\t// telling the form control it has been touched until the next tick.\n\t\t\t\t\tPromise.resolve().then(() => {\n\t\t\t\t\t\tthis.focusVisible.set(false);\n\t\t\t\t\t\tthis.focused.set(false);\n\t\t\t\t\t\tthis._onTouched();\n\t\t\t\t\t\tthis.touched.emit();\n\t\t\t\t\t\tthis._cdr.markForCheck();\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t});\n\n\t\tif (!this.switch()) return;\n\t\tthis.switch().nativeElement.value = this.checked() ? 'on' : 'off';\n\t\tthis.switch().nativeElement.dispatchEvent(new Event('change'));\n\t}\n\n\tngOnDestroy() {\n\t\tthis._focusMonitor.stopMonitoring(this._elementRef);\n\t}\n\n\t/** We intercept the id passed to the wrapper component and pass it to the underlying button switch control **/\n\tprotected getSwitchButtonId(idPassedToContainer: string | null | undefined): string | null {\n\t\treturn idPassedToContainer ? idPassedToContainer.replace(CONTAINER_POST_FIX, '') : null;\n\t}\n\n\twriteValue(value: boolean): void {\n\t\tthis.checked.set(Boolean(value));\n\t}\n\n\tregisterOnChange(fn: ChangeFn<boolean>): void {\n\t\tthis._onChange = fn;\n\t}\n\n\tregisterOnTouched(fn: TouchFn): void {\n\t\tthis._onTouched = fn;\n\t}\n\n\t/** Implemented as a part of ControlValueAccessor. */\n\tsetDisabledState(isDisabled: boolean): void {\n\t\tthis.state().disabled.set(isDisabled);\n\t\tthis._cdr.markForCheck();\n\t}\n}\n","import { NgModule } from '@angular/core';\n\nimport { BrnSwitchThumbComponent } from './lib/brn-switch-thumb.component';\nimport { BrnSwitchComponent } from './lib/brn-switch.component';\n\nexport * from './lib/brn-switch-thumb.component';\nexport * from './lib/brn-switch.component';\n\nexport const BrnSwitchImports = [BrnSwitchComponent, BrnSwitchThumbComponent] as const;\n\n@NgModule({\n\timports: [...BrnSwitchImports],\n\texports: [...BrnSwitchImports],\n})\nexport class BrnSwitchModule {}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;;;;MAUa,uBAAuB,CAAA;0HAAvB,uBAAuB,EAAA,IAAA,EAAA,EAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,SAAA,EAAA,CAAA;AAAvB,uBAAA,OAAA,IAAA,GAAA,EAAA,CAAA,oBAAA,CAAA,EAAA,UAAA,EAAA,QAAA,EAAA,OAAA,EAAA,QAAA,EAAA,IAAA,EAAA,uBAAuB,iLANzB,EAAE,EAAA,QAAA,EAAA,IAAA,EAAA,CAAA;;2FAMA,uBAAuB,EAAA,UAAA,EAAA,CAAA;kBARnC,SAAS;AAAC,YAAA,IAAA,EAAA,CAAA;AACV,oBAAA,QAAQ,EAAE,kBAAkB;AAC5B,oBAAA,QAAQ,EAAE,EAAE;AACZ,oBAAA,IAAI,EAAE;AACL,wBAAA,IAAI,EAAE,cAAc;AACpB,wBAAA,SAAS,EAAE,yBAAyB;AACpC,qBAAA;AACD,iBAAA;;;ACqBY,MAAA,yBAAyB,GAAG;AACxC,IAAA,OAAO,EAAE,iBAAiB;AAC1B,IAAA,WAAW,EAAE,UAAU,CAAC,MAAM,kBAAkB,CAAC;AACjD,IAAA,KAAK,EAAE,IAAI;;AAGZ,MAAM,kBAAkB,GAAG,SAAS;AAEpC,IAAI,eAAe,GAAG,CAAC;MA4CV,kBAAkB,CAAA;AACb,IAAA,WAAW,GAAG,MAAM,CAAC,UAAU,CAAC;AAChC,IAAA,SAAS,GAAG,MAAM,CAAC,SAAS,CAAC;IAC7B,UAAU,GAAG,iBAAiB,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;AACnD,IAAA,WAAW,GAAG,MAAM,CAA0B,UAAU,CAAC;AACzD,IAAA,aAAa,GAAG,MAAM,CAAC,YAAY,CAAC;AACpC,IAAA,IAAI,GAAG,MAAM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AAO,EAAE,CAAC,GAAG,gBAAgB,CAAC;AAC9B,oBAAA,OAAO,EAAE,CAAC,GAAG,gBAAgB,CAAC;AAC9B,iBAAA;;;ACbD;;AAEG;;;;"}
|
package/package.json
CHANGED
|
@@ -14,45 +14,80 @@ export declare class BrnSwitchComponent implements AfterContentInit, OnDestroy {
|
|
|
14
14
|
private readonly _elementRef;
|
|
15
15
|
private readonly _focusMonitor;
|
|
16
16
|
private readonly _cdr;
|
|
17
|
+
private readonly _document;
|
|
17
18
|
protected readonly focusVisible: import("@angular/core").WritableSignal<boolean>;
|
|
18
19
|
protected readonly focused: import("@angular/core").WritableSignal<boolean>;
|
|
20
|
+
/**
|
|
21
|
+
* Whether the switch is checked.
|
|
22
|
+
* Can be bound with [(checked)]
|
|
23
|
+
*/
|
|
19
24
|
readonly checked: import("@angular/core").ModelSignal<boolean>;
|
|
20
|
-
/**
|
|
25
|
+
/**
|
|
26
|
+
* Sets the ID on the switch.
|
|
27
|
+
* When provided, the inner button gets this ID without the '-switch' suffix.
|
|
28
|
+
*/
|
|
21
29
|
readonly id: import("@angular/core").InputSignal<string | null>;
|
|
22
|
-
/**
|
|
30
|
+
/**
|
|
31
|
+
* Sets the name on the switch.
|
|
32
|
+
* When provided, the inner button gets this name without a '-switch' suffix.
|
|
33
|
+
*/
|
|
23
34
|
readonly name: import("@angular/core").InputSignal<string | null>;
|
|
24
|
-
/**
|
|
35
|
+
/**
|
|
36
|
+
* Sets class set on the inner button
|
|
37
|
+
*/
|
|
38
|
+
readonly class: import("@angular/core").InputSignal<string | null>;
|
|
39
|
+
/**
|
|
40
|
+
* Sets the aria-label attribute for accessibility.
|
|
41
|
+
*/
|
|
25
42
|
readonly ariaLabel: import("@angular/core").InputSignal<string | null>;
|
|
26
|
-
/**
|
|
43
|
+
/**
|
|
44
|
+
* Sets the aria-labelledby attribute for accessibility.
|
|
45
|
+
*/
|
|
27
46
|
readonly ariaLabelledby: import("@angular/core").InputSignal<string | null>;
|
|
28
|
-
|
|
47
|
+
readonly mutableAriaLabelledby: import("@angular/core").WritableSignal<string | null>;
|
|
48
|
+
/**
|
|
49
|
+
* Sets the aria-describedby attribute for accessibility.
|
|
50
|
+
*/
|
|
29
51
|
readonly ariaDescribedby: import("@angular/core").InputSignal<string | null>;
|
|
52
|
+
/**
|
|
53
|
+
* Whether the switch is required in a form.
|
|
54
|
+
*/
|
|
30
55
|
readonly required: import("@angular/core").InputSignalWithTransform<boolean, unknown>;
|
|
56
|
+
/**
|
|
57
|
+
* Whether the switch is disabled.
|
|
58
|
+
*/
|
|
31
59
|
readonly disabled: import("@angular/core").InputSignalWithTransform<boolean, BooleanInput>;
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
60
|
+
/**
|
|
61
|
+
* tabIndex of the switch.
|
|
62
|
+
*/
|
|
63
|
+
readonly tabIndex: import("@angular/core").InputSignal<number>;
|
|
64
|
+
/**
|
|
65
|
+
* Event emitted when the switch value changes.
|
|
66
|
+
*/
|
|
35
67
|
readonly changed: import("@angular/core").OutputEmitterRef<boolean>;
|
|
68
|
+
/**
|
|
69
|
+
* Event emitted when the switch is blurred (loses focus).
|
|
70
|
+
*/
|
|
36
71
|
readonly touched: import("@angular/core").OutputEmitterRef<void>;
|
|
72
|
+
protected _onChange: ChangeFn<boolean>;
|
|
73
|
+
private _onTouched;
|
|
74
|
+
readonly switch: import("@angular/core").Signal<ElementRef<HTMLInputElement>>;
|
|
37
75
|
protected readonly state: import("@angular/core").Signal<{
|
|
38
76
|
disabled: import("@angular/core").WritableSignal<boolean>;
|
|
39
77
|
name: string | null;
|
|
40
78
|
id: string | null;
|
|
41
79
|
}>;
|
|
42
80
|
constructor();
|
|
43
|
-
protected toggle(
|
|
81
|
+
protected toggle(): void;
|
|
44
82
|
ngAfterContentInit(): void;
|
|
45
83
|
ngOnDestroy(): void;
|
|
46
|
-
|
|
84
|
+
/** We intercept the id passed to the wrapper component and pass it to the underlying button switch control **/
|
|
85
|
+
protected getSwitchButtonId(idPassedToContainer: string | null | undefined): string | null;
|
|
47
86
|
writeValue(value: boolean): void;
|
|
48
87
|
registerOnChange(fn: ChangeFn<boolean>): void;
|
|
49
88
|
registerOnTouched(fn: TouchFn): void;
|
|
50
89
|
/** Implemented as a part of ControlValueAccessor. */
|
|
51
90
|
setDisabledState(isDisabled: boolean): void;
|
|
52
|
-
/**
|
|
53
|
-
* If the space key is pressed, prevent the default action to stop the page from scrolling.
|
|
54
|
-
*/
|
|
55
|
-
protected preventScrolling(event: KeyboardEvent): void;
|
|
56
91
|
static ɵfac: i0.ɵɵFactoryDeclaration<BrnSwitchComponent, never>;
|
|
57
|
-
static ɵcmp: i0.ɵɵComponentDeclaration<BrnSwitchComponent, "brn-switch", never, { "checked": { "alias": "checked"; "required": false; "isSignal": true; }; "id": { "alias": "id"; "required": false; "isSignal": true; }; "name": { "alias": "name"; "required": false; "isSignal": true; }; "ariaLabel": { "alias": "aria-label"; "required": false; "isSignal": true; }; "ariaLabelledby": { "alias": "aria-labelledby"; "required": false; "isSignal": true; }; "ariaDescribedby": { "alias": "aria-describedby"; "required": false; "isSignal": true; }; "required": { "alias": "required"; "required": false; "isSignal": true; }; "disabled": { "alias": "disabled"; "required": false; "isSignal": true; }; }, { "checked": "checkedChange"; "changed": "changed"; "touched": "touched"; }, never, ["brn-switch-thumb"], true, never>;
|
|
92
|
+
static ɵcmp: i0.ɵɵComponentDeclaration<BrnSwitchComponent, "brn-switch", never, { "checked": { "alias": "checked"; "required": false; "isSignal": true; }; "id": { "alias": "id"; "required": false; "isSignal": true; }; "name": { "alias": "name"; "required": false; "isSignal": true; }; "class": { "alias": "class"; "required": false; "isSignal": true; }; "ariaLabel": { "alias": "aria-label"; "required": false; "isSignal": true; }; "ariaLabelledby": { "alias": "aria-labelledby"; "required": false; "isSignal": true; }; "ariaDescribedby": { "alias": "aria-describedby"; "required": false; "isSignal": true; }; "required": { "alias": "required"; "required": false; "isSignal": true; }; "disabled": { "alias": "disabled"; "required": false; "isSignal": true; }; "tabIndex": { "alias": "tabIndex"; "required": false; "isSignal": true; }; }, { "checked": "checkedChange"; "changed": "changed"; "touched": "touched"; }, never, ["brn-switch-thumb"], true, never>;
|
|
58
93
|
}
|