@styloviz/toggle-switch 0.1.1

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 StyloViz
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,63 @@
1
+ # @styloviz/toggle-switch
2
+
3
+ > Accessible on/off toggle switch with labels, sizes and disabled state.
4
+
5
+ Part of the **StyloViz UI Kit** — a premium Angular 21 + Tailwind CSS 4 dashboard component library. Standalone, `OnPush`, strongly typed, dark-mode ready.
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ npm install @styloviz/core @styloviz/toggle-switch
11
+ ```
12
+
13
+ Requires `@angular/core` and `@angular/common` >= 21. `@styloviz/core` is a peer dependency shared by every component. Prefer everything at once? `@styloviz/all` installs the whole free tier in one command.
14
+
15
+ ## Usage
16
+
17
+ ```ts
18
+ import { SvToggleSwitchComponent } from '@styloviz/toggle-switch';
19
+
20
+ @Component({
21
+ standalone: true,
22
+ imports: [SvToggleSwitchComponent],
23
+ template: `
24
+ <sv-toggle-switch />
25
+ `,
26
+ })
27
+ export class DemoComponent {}
28
+ ```
29
+
30
+ ## Inputs
31
+
32
+ | Input | Type | Default | Description |
33
+ | --- | --- | --- | --- |
34
+ | `checked` | `boolean (two-way)` | `false` | Current on/off state. Use `[(checked)]` for two-way binding. |
35
+ | `label` | `string` | `''` | Visible label text. |
36
+ | `description` | `string` | `''` | Smaller descriptor line beneath the label. |
37
+ | `labelPosition` | `ToggleLabelPosition` | `'right'` | Position of the label relative to the track. |
38
+ | `onLabel` | `string` | `''` | Text shown inside the track when ON. Keep ≤ 3 characters for `md` size, fewer for smaller sizes. |
39
+ | `offLabel` | `string` | `''` | Text shown inside the track when OFF. |
40
+ | `onIconPath` | `string` | `''` | SVG `<path d="...">` rendered inside the thumb when the toggle is ON. Omit to show a plain thumb. |
41
+ | `offIconPath` | `string` | `''` | SVG `<path d="...">` rendered inside the thumb when the toggle is OFF. |
42
+ | `size` | `ToggleSize` | `'md'` | Size of the toggle track and thumb. |
43
+ | `variant` | `ToggleVariant` | `'primary'` | Active-state color variant. |
44
+ | `disabled` | `boolean` | `false` | Disable interaction. |
45
+ | `required` | `boolean` | `false` | Mark the control as required (sets `aria-required`). |
46
+ | `loading` | `boolean` | `false` | Show a spinner in the thumb — useful while an async action is in-flight. Implicitly disables interaction while true. |
47
+ | `ariaLabel` | `string` | `''` | `aria-label` override — required when `labelPosition === 'hidden'` so screen readers still announce the control's purpose. |
48
+ | `inputId` | `string` | `''` | id forwarded to the hidden `<input>` for `<label for="">` use. |
49
+ | `customClass` | `string` | `''` | Additional CSS classes on the root wrapper element. |
50
+
51
+ ## Outputs
52
+
53
+ | Output | Type | Description |
54
+ | --- | --- | --- |
55
+ | `toggled` | `boolean` | Emits the new boolean state after every toggle. |
56
+
57
+ ## Documentation
58
+
59
+ Full API reference and live demos: https://styloviz.dev/docs
60
+
61
+ ## License
62
+
63
+ MIT
@@ -0,0 +1,252 @@
1
+ import * as i0 from '@angular/core';
2
+ import { model, input, output, signal, computed, forwardRef, ChangeDetectionStrategy, Component } from '@angular/core';
3
+ import { NgClass } from '@angular/common';
4
+ import { NG_VALUE_ACCESSOR } from '@angular/forms';
5
+
6
+ /** Process-wide counter for generating unique fallback ids. */
7
+ let _svToggleUid = 0;
8
+ // ─── Component ───────────────────────────────────────────────────────────────
9
+ /**
10
+ * ToggleSwitch — An accessible on/off control for settings, feature flags,
11
+ * and boolean preferences.
12
+ *
13
+ * Supports:
14
+ * - Angular signals two-way binding via `[(checked)]`
15
+ * - Reactive Forms via `ControlValueAccessor` (`formControl` / `formControlName`)
16
+ * - 4 sizes × 5 color variants
17
+ * - Optional ON/OFF labels inside the track
18
+ * - Optional icon slots in the thumb (on/off state SVG paths)
19
+ * - Descriptive sub-label beneath the main label
20
+ * - Disabled & loading states
21
+ * - Full keyboard accessibility (Space / Enter toggle)
22
+ * - `aria-checked`, `role="switch"`, focus-visible ring
23
+ */
24
+ class SvToggleSwitchComponent {
25
+ // ── Two-way binding ───────────────────────────────────────────────────────
26
+ /** Current on/off state. Use `[(checked)]` for two-way binding. @default false */
27
+ checked = model(false, ...(ngDevMode ? [{ debugName: "checked" }] : /* istanbul ignore next */ []));
28
+ // ── Content ───────────────────────────────────────────────────────────────
29
+ /** Visible label text. */
30
+ label = input('', ...(ngDevMode ? [{ debugName: "label" }] : /* istanbul ignore next */ []));
31
+ /** Smaller descriptor line beneath the label. */
32
+ description = input('', ...(ngDevMode ? [{ debugName: "description" }] : /* istanbul ignore next */ []));
33
+ /** Position of the label relative to the track. @default 'right' */
34
+ labelPosition = input('right', ...(ngDevMode ? [{ debugName: "labelPosition" }] : /* istanbul ignore next */ []));
35
+ /**
36
+ * Text shown inside the track when ON.
37
+ * Keep ≤ 3 characters for `md` size, fewer for smaller sizes. @default ''
38
+ */
39
+ onLabel = input('', ...(ngDevMode ? [{ debugName: "onLabel" }] : /* istanbul ignore next */ []));
40
+ /**
41
+ * Text shown inside the track when OFF. @default ''
42
+ */
43
+ offLabel = input('', ...(ngDevMode ? [{ debugName: "offLabel" }] : /* istanbul ignore next */ []));
44
+ /**
45
+ * SVG `<path d="...">` rendered inside the thumb when the toggle is ON.
46
+ * Omit to show a plain thumb.
47
+ */
48
+ onIconPath = input('', ...(ngDevMode ? [{ debugName: "onIconPath" }] : /* istanbul ignore next */ []));
49
+ /**
50
+ * SVG `<path d="...">` rendered inside the thumb when the toggle is OFF.
51
+ */
52
+ offIconPath = input('', ...(ngDevMode ? [{ debugName: "offIconPath" }] : /* istanbul ignore next */ []));
53
+ // ── Appearance ────────────────────────────────────────────────────────────
54
+ /** Size of the toggle track and thumb. @default 'md' */
55
+ size = input('md', ...(ngDevMode ? [{ debugName: "size" }] : /* istanbul ignore next */ []));
56
+ /** Active-state color variant. @default 'primary' */
57
+ variant = input('primary', ...(ngDevMode ? [{ debugName: "variant" }] : /* istanbul ignore next */ []));
58
+ // ── State ─────────────────────────────────────────────────────────────────
59
+ /** Disable interaction. @default false */
60
+ disabled = input(false, ...(ngDevMode ? [{ debugName: "disabled" }] : /* istanbul ignore next */ []));
61
+ /** Mark the control as required (sets `aria-required`). @default false */
62
+ required = input(false, ...(ngDevMode ? [{ debugName: "required" }] : /* istanbul ignore next */ []));
63
+ /**
64
+ * Show a spinner in the thumb — useful while an async action is in-flight.
65
+ * Implicitly disables interaction while true. @default false
66
+ */
67
+ loading = input(false, ...(ngDevMode ? [{ debugName: "loading" }] : /* istanbul ignore next */ []));
68
+ // ── Accessibility ─────────────────────────────────────────────────────────
69
+ /**
70
+ * `aria-label` override — required when `labelPosition === 'hidden'`
71
+ * so screen readers still announce the control's purpose.
72
+ */
73
+ ariaLabel = input('', ...(ngDevMode ? [{ debugName: "ariaLabel" }] : /* istanbul ignore next */ []));
74
+ /** id forwarded to the hidden `<input>` for `<label for="">` use. */
75
+ inputId = input('', ...(ngDevMode ? [{ debugName: "inputId" }] : /* istanbul ignore next */ []));
76
+ // ── Extra ─────────────────────────────────────────────────────────────────
77
+ /** Additional CSS classes on the root wrapper element. */
78
+ customClass = input('', ...(ngDevMode ? [{ debugName: "customClass" }] : /* istanbul ignore next */ []));
79
+ // ── Outputs ───────────────────────────────────────────────────────────────
80
+ /** Emits the new boolean state after every toggle. */
81
+ toggled = output();
82
+ // ── CVA internals ────────────────────────────────────────────────────────
83
+ _onChange = () => { };
84
+ _onTouched = () => { };
85
+ /** Tracks disabled state set programmatically via formControl.disable(). */
86
+ _formDisabled = signal(false, ...(ngDevMode ? [{ debugName: "_formDisabled" }] : /* istanbul ignore next */ []));
87
+ /**
88
+ * Merged disabled state — true when either the [disabled] input or the
89
+ * parent FormControl is disabled. Use this everywhere instead of disabled().
90
+ */
91
+ resolvedDisabled = computed(() => this.disabled() || this._formDisabled(), ...(ngDevMode ? [{ debugName: "resolvedDisabled" }] : /* istanbul ignore next */ []));
92
+ writeValue(val) {
93
+ this.checked.set(!!val);
94
+ }
95
+ registerOnChange(fn) { this._onChange = fn; }
96
+ registerOnTouched(fn) { this._onTouched = fn; }
97
+ setDisabledState(isDisabled) { this._formDisabled.set(isDisabled); }
98
+ // ── Interaction ───────────────────────────────────────────────────────────
99
+ toggle() {
100
+ if (this.resolvedDisabled() || this.loading())
101
+ return;
102
+ const next = !this.checked();
103
+ this.checked.set(next);
104
+ this._onChange(next);
105
+ this._onTouched();
106
+ this.toggled.emit(next);
107
+ }
108
+ onKeydown(event) {
109
+ if (event.key === ' ' || event.key === 'Enter') {
110
+ event.preventDefault();
111
+ this.toggle();
112
+ }
113
+ }
114
+ // ── Computed class maps ───────────────────────────────────────────────────
115
+ /** Root wrapper layout class driven by labelPosition. */
116
+ rootClasses = computed(() => {
117
+ const pos = this.labelPosition();
118
+ const layout = pos === 'top'
119
+ ? 'flex flex-col gap-1.5'
120
+ : pos === 'left'
121
+ ? 'flex flex-row items-center gap-3'
122
+ : 'flex flex-row items-center gap-3';
123
+ return [
124
+ layout,
125
+ this.resolvedDisabled() || this.loading() ? 'cursor-not-allowed opacity-60' : 'cursor-pointer',
126
+ this.customClass(),
127
+ ].filter(Boolean).join(' ');
128
+ }, ...(ngDevMode ? [{ debugName: "rootClasses" }] : /* istanbul ignore next */ []));
129
+ /** Track background — variant color when ON, gray when OFF. */
130
+ trackClasses = computed(() => {
131
+ const on = this.checked();
132
+ const variantOn = {
133
+ primary: 'bg-primary-600 dark:bg-primary-500',
134
+ success: 'bg-emerald-600 dark:bg-emerald-500',
135
+ warning: 'bg-amber-500 dark:bg-amber-400',
136
+ danger: 'bg-red-600 dark:bg-red-500',
137
+ neutral: 'bg-gray-700 dark:bg-gray-400',
138
+ };
139
+ const sizeMap = {
140
+ xs: 'h-4 w-7',
141
+ sm: 'h-5 w-9',
142
+ md: 'h-6 w-11',
143
+ lg: 'h-7 w-14',
144
+ };
145
+ return [
146
+ 'relative inline-flex shrink-0 items-center rounded-full transition-colors duration-200 ease-in-out',
147
+ 'focus-visible:outline-none',
148
+ sizeMap[this.size()],
149
+ on ? variantOn[this.variant()] : 'bg-gray-200 dark:bg-gray-700',
150
+ ].join(' ');
151
+ }, ...(ngDevMode ? [{ debugName: "trackClasses" }] : /* istanbul ignore next */ []));
152
+ /** Thumb translate offset — moves right when ON. */
153
+ thumbClasses = computed(() => {
154
+ const on = this.checked();
155
+ const translateMap = {
156
+ xs: { off: 'translate-x-0.5', on: 'translate-x-3.5' },
157
+ sm: { off: 'translate-x-0.5', on: 'translate-x-4.5' },
158
+ md: { off: 'translate-x-0.5', on: 'translate-x-5.5' },
159
+ lg: { off: 'translate-x-1', on: 'translate-x-7.5' },
160
+ };
161
+ const sizeMap = {
162
+ xs: 'h-3 w-3',
163
+ sm: 'h-4 w-4',
164
+ md: 'h-5 w-5',
165
+ lg: 'h-5.5 w-5.5',
166
+ };
167
+ const t = translateMap[this.size()];
168
+ return [
169
+ 'pointer-events-none inline-flex items-center justify-center rounded-full bg-white shadow-sm',
170
+ 'transform transition-transform duration-200 ease-in-out ring-0',
171
+ sizeMap[this.size()],
172
+ on ? t.on : t.off,
173
+ ].join(' ');
174
+ }, ...(ngDevMode ? [{ debugName: "thumbClasses" }] : /* istanbul ignore next */ []));
175
+ /** Icon size inside the thumb. */
176
+ thumbIconClass = computed(() => {
177
+ switch (this.size()) {
178
+ case 'xs': return 'h-1.5 w-1.5';
179
+ case 'sm': return 'h-2.5 w-2.5';
180
+ case 'lg': return 'h-3.5 w-3.5';
181
+ default: return 'h-3 w-3';
182
+ }
183
+ }, ...(ngDevMode ? [{ debugName: "thumbIconClass" }] : /* istanbul ignore next */ []));
184
+ /** Track label text size. */
185
+ trackLabelClass = computed(() => {
186
+ switch (this.size()) {
187
+ case 'xs': return 'text-[7px]';
188
+ case 'sm': return 'text-[8px]';
189
+ case 'lg': return 'text-[10px]';
190
+ default: return 'text-[9px]';
191
+ }
192
+ }, ...(ngDevMode ? [{ debugName: "trackLabelClass" }] : /* istanbul ignore next */ []));
193
+ /** Main label text size. */
194
+ labelClass = computed(() => {
195
+ const base = 'font-medium text-gray-800 dark:text-gray-100 leading-none select-none';
196
+ switch (this.size()) {
197
+ case 'xs': return `${base} text-xs`;
198
+ case 'sm': return `${base} text-sm`;
199
+ case 'lg': return `${base} text-base`;
200
+ default: return `${base} text-sm`;
201
+ }
202
+ }, ...(ngDevMode ? [{ debugName: "labelClass" }] : /* istanbul ignore next */ []));
203
+ /** Description text size. */
204
+ descClass = computed(() => {
205
+ switch (this.size()) {
206
+ case 'lg': return 'text-sm text-gray-500 dark:text-gray-400 select-none mt-0.5';
207
+ default: return 'text-xs text-gray-500 dark:text-gray-400 select-none mt-0.5';
208
+ }
209
+ }, ...(ngDevMode ? [{ debugName: "descClass" }] : /* istanbul ignore next */ []));
210
+ /** Stable unique fallback id so label + ARIA associations always work. */
211
+ _autoId = `sv-toggle-${++_svToggleUid}`;
212
+ /** Effective id used by the switch and its <label for>. */
213
+ resolvedId = computed(() => this.inputId() || this._autoId, ...(ngDevMode ? [{ debugName: "resolvedId" }] : /* istanbul ignore next */ []));
214
+ /** id of the visible label (referenced by aria-labelledby). */
215
+ labelId = computed(() => `${this.resolvedId()}-label`, ...(ngDevMode ? [{ debugName: "labelId" }] : /* istanbul ignore next */ []));
216
+ /** id of the description (referenced by aria-describedby). */
217
+ descId = computed(() => `${this.resolvedId()}-desc`, ...(ngDevMode ? [{ debugName: "descId" }] : /* istanbul ignore next */ []));
218
+ /** True when a visible text label is rendered next to the switch. */
219
+ hasVisibleLabel = computed(() => !!this.label() && this.labelPosition() !== 'hidden', ...(ngDevMode ? [{ debugName: "hasVisibleLabel" }] : /* istanbul ignore next */ []));
220
+ /** Resolved aria-label for the button role. */
221
+ resolvedAriaLabel = computed(() => this.ariaLabel() || this.label() || 'Toggle', ...(ngDevMode ? [{ debugName: "resolvedAriaLabel" }] : /* istanbul ignore next */ []));
222
+ /** Whether to show the thumb icon. */
223
+ hasThumbIcon = computed(() => !!(this.checked() ? this.onIconPath() : this.offIconPath()), ...(ngDevMode ? [{ debugName: "hasThumbIcon" }] : /* istanbul ignore next */ []));
224
+ currentThumbIcon = computed(() => this.checked() ? this.onIconPath() : this.offIconPath(), ...(ngDevMode ? [{ debugName: "currentThumbIcon" }] : /* istanbul ignore next */ []));
225
+ showOnLabel = computed(() => !!this.onLabel() && this.checked(), ...(ngDevMode ? [{ debugName: "showOnLabel" }] : /* istanbul ignore next */ []));
226
+ showOffLabel = computed(() => !!this.offLabel() && !this.checked(), ...(ngDevMode ? [{ debugName: "showOffLabel" }] : /* istanbul ignore next */ []));
227
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.13", ngImport: i0, type: SvToggleSwitchComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
228
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.2.13", type: SvToggleSwitchComponent, isStandalone: true, selector: "sv-toggle-switch", inputs: { checked: { classPropertyName: "checked", publicName: "checked", isSignal: true, isRequired: false, transformFunction: null }, label: { classPropertyName: "label", publicName: "label", isSignal: true, isRequired: false, transformFunction: null }, description: { classPropertyName: "description", publicName: "description", isSignal: true, isRequired: false, transformFunction: null }, labelPosition: { classPropertyName: "labelPosition", publicName: "labelPosition", isSignal: true, isRequired: false, transformFunction: null }, onLabel: { classPropertyName: "onLabel", publicName: "onLabel", isSignal: true, isRequired: false, transformFunction: null }, offLabel: { classPropertyName: "offLabel", publicName: "offLabel", isSignal: true, isRequired: false, transformFunction: null }, onIconPath: { classPropertyName: "onIconPath", publicName: "onIconPath", isSignal: true, isRequired: false, transformFunction: null }, offIconPath: { classPropertyName: "offIconPath", publicName: "offIconPath", isSignal: true, isRequired: false, transformFunction: null }, size: { classPropertyName: "size", publicName: "size", isSignal: true, isRequired: false, transformFunction: null }, variant: { classPropertyName: "variant", publicName: "variant", isSignal: true, isRequired: false, transformFunction: null }, disabled: { classPropertyName: "disabled", publicName: "disabled", isSignal: true, isRequired: false, transformFunction: null }, required: { classPropertyName: "required", publicName: "required", isSignal: true, isRequired: false, transformFunction: null }, loading: { classPropertyName: "loading", publicName: "loading", isSignal: true, isRequired: false, transformFunction: null }, ariaLabel: { classPropertyName: "ariaLabel", publicName: "ariaLabel", isSignal: true, isRequired: false, transformFunction: null }, inputId: { classPropertyName: "inputId", publicName: "inputId", isSignal: true, isRequired: false, transformFunction: null }, customClass: { classPropertyName: "customClass", publicName: "customClass", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { checked: "checkedChange", toggled: "toggled" }, providers: [
229
+ {
230
+ provide: NG_VALUE_ACCESSOR,
231
+ useExisting: forwardRef(() => SvToggleSwitchComponent),
232
+ multi: true,
233
+ },
234
+ ], ngImport: i0, template: "<!--\n Root wrapper acts as the interactive region.\n We use a <div role=\"group\"> so a wrapping <label> remains optional.\n-->\n<div\n [ngClass]=\"rootClasses()\"\n [attr.aria-label]=\"labelPosition() === 'hidden' ? resolvedAriaLabel() : null\"\n>\n\n <!-- \u2500\u2500 Top label (only when labelPosition === 'top') \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 -->\n @if (label() && labelPosition() === 'top') {\n <label [attr.id]=\"labelId()\" [attr.for]=\"resolvedId()\" [ngClass]=\"[labelClass(), 'cursor-pointer']\">{{ label() }}</label>\n @if (description()) {\n <span [attr.id]=\"descId()\" [ngClass]=\"descClass()\">{{ description() }}</span>\n }\n }\n\n <!-- \u2500\u2500 Left label (only when labelPosition === 'left') \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 -->\n @if (label() && labelPosition() === 'left') {\n <div class=\"flex flex-col min-w-0\">\n <label [attr.id]=\"labelId()\" [attr.for]=\"resolvedId()\" [ngClass]=\"[labelClass(), 'cursor-pointer']\">{{ label() }}</label>\n @if (description()) {\n <span [attr.id]=\"descId()\" [ngClass]=\"descClass()\">{{ description() }}</span>\n }\n </div>\n }\n\n <!-- \u2500\u2500 Track \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 -->\n <button\n type=\"button\"\n role=\"switch\"\n [ngClass]=\"trackClasses()\"\n [attr.aria-checked]=\"checked()\"\n [attr.id]=\"resolvedId()\"\n [attr.aria-labelledby]=\"hasVisibleLabel() ? labelId() : null\"\n [attr.aria-label]=\"hasVisibleLabel() ? null : resolvedAriaLabel()\"\n [attr.aria-describedby]=\"description() ? descId() : null\"\n [attr.aria-required]=\"required() || null\"\n [attr.aria-busy]=\"loading() || null\"\n [attr.aria-disabled]=\"resolvedDisabled() || loading() || null\"\n [attr.tabindex]=\"resolvedDisabled() ? -1 : 0\"\n (click)=\"toggle()\"\n (keydown)=\"onKeydown($event)\"\n class=\"focus-visible:ring-2 focus-visible:ring-primary-500 focus-visible:ring-offset-2\n dark:focus-visible:ring-primary-400 dark:focus-visible:ring-offset-gray-900\"\n >\n <!-- Track ON label -->\n @if (showOnLabel()) {\n <span\n class=\"absolute left-1.5 font-semibold text-white/90 leading-none pointer-events-none\"\n [ngClass]=\"trackLabelClass()\"\n aria-hidden=\"true\"\n >\n {{ onLabel() }}\n </span>\n }\n\n <!-- Track OFF label -->\n @if (showOffLabel()) {\n <span\n class=\"absolute right-1.5 font-semibold leading-none pointer-events-none\"\n [ngClass]=\"[trackLabelClass(), 'text-gray-500 dark:text-gray-400']\"\n aria-hidden=\"true\"\n >\n {{ offLabel() }}\n </span>\n }\n\n <!-- Thumb -->\n <span [ngClass]=\"thumbClasses()\" aria-hidden=\"true\">\n\n <!-- Loading spinner -->\n @if (loading()) {\n <svg\n class=\"animate-spin text-gray-400\"\n [ngClass]=\"thumbIconClass()\"\n xmlns=\"http://www.w3.org/2000/svg\"\n fill=\"none\"\n viewBox=\"0 0 24 24\"\n >\n <circle class=\"opacity-25\" cx=\"12\" cy=\"12\" r=\"10\"\n stroke=\"currentColor\" stroke-width=\"4\"/>\n <path class=\"opacity-75\" fill=\"currentColor\"\n d=\"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z\"/>\n </svg>\n }\n\n <!-- State icon (ON or OFF path) -->\n @if (!loading() && hasThumbIcon()) {\n <svg\n [ngClass]=\"[thumbIconClass(), checked() ? 'text-primary-600' : 'text-gray-400']\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n stroke-width=\"2.5\"\n stroke-linecap=\"round\"\n stroke-linejoin=\"round\"\n >\n <path [attr.d]=\"currentThumbIcon()\" />\n </svg>\n }\n\n </span>\n </button>\n\n <!-- \u2500\u2500 Right label (default, labelPosition === 'right') \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 -->\n @if (label() && (labelPosition() === 'right' || labelPosition() === 'hidden')) {\n @if (labelPosition() !== 'hidden') {\n <div class=\"flex flex-col min-w-0\">\n <label [attr.id]=\"labelId()\" [attr.for]=\"resolvedId()\" [ngClass]=\"[labelClass(), 'cursor-pointer']\">{{ label() }}</label>\n @if (description()) {\n <span [attr.id]=\"descId()\" [ngClass]=\"descClass()\">{{ description() }}</span>\n }\n </div>\n }\n }\n\n</div>\n", dependencies: [{ kind: "directive", type: NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
235
+ }
236
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.13", ngImport: i0, type: SvToggleSwitchComponent, decorators: [{
237
+ type: Component,
238
+ args: [{ selector: 'sv-toggle-switch', standalone: true, imports: [NgClass], changeDetection: ChangeDetectionStrategy.OnPush, providers: [
239
+ {
240
+ provide: NG_VALUE_ACCESSOR,
241
+ useExisting: forwardRef(() => SvToggleSwitchComponent),
242
+ multi: true,
243
+ },
244
+ ], template: "<!--\n Root wrapper acts as the interactive region.\n We use a <div role=\"group\"> so a wrapping <label> remains optional.\n-->\n<div\n [ngClass]=\"rootClasses()\"\n [attr.aria-label]=\"labelPosition() === 'hidden' ? resolvedAriaLabel() : null\"\n>\n\n <!-- \u2500\u2500 Top label (only when labelPosition === 'top') \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 -->\n @if (label() && labelPosition() === 'top') {\n <label [attr.id]=\"labelId()\" [attr.for]=\"resolvedId()\" [ngClass]=\"[labelClass(), 'cursor-pointer']\">{{ label() }}</label>\n @if (description()) {\n <span [attr.id]=\"descId()\" [ngClass]=\"descClass()\">{{ description() }}</span>\n }\n }\n\n <!-- \u2500\u2500 Left label (only when labelPosition === 'left') \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 -->\n @if (label() && labelPosition() === 'left') {\n <div class=\"flex flex-col min-w-0\">\n <label [attr.id]=\"labelId()\" [attr.for]=\"resolvedId()\" [ngClass]=\"[labelClass(), 'cursor-pointer']\">{{ label() }}</label>\n @if (description()) {\n <span [attr.id]=\"descId()\" [ngClass]=\"descClass()\">{{ description() }}</span>\n }\n </div>\n }\n\n <!-- \u2500\u2500 Track \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 -->\n <button\n type=\"button\"\n role=\"switch\"\n [ngClass]=\"trackClasses()\"\n [attr.aria-checked]=\"checked()\"\n [attr.id]=\"resolvedId()\"\n [attr.aria-labelledby]=\"hasVisibleLabel() ? labelId() : null\"\n [attr.aria-label]=\"hasVisibleLabel() ? null : resolvedAriaLabel()\"\n [attr.aria-describedby]=\"description() ? descId() : null\"\n [attr.aria-required]=\"required() || null\"\n [attr.aria-busy]=\"loading() || null\"\n [attr.aria-disabled]=\"resolvedDisabled() || loading() || null\"\n [attr.tabindex]=\"resolvedDisabled() ? -1 : 0\"\n (click)=\"toggle()\"\n (keydown)=\"onKeydown($event)\"\n class=\"focus-visible:ring-2 focus-visible:ring-primary-500 focus-visible:ring-offset-2\n dark:focus-visible:ring-primary-400 dark:focus-visible:ring-offset-gray-900\"\n >\n <!-- Track ON label -->\n @if (showOnLabel()) {\n <span\n class=\"absolute left-1.5 font-semibold text-white/90 leading-none pointer-events-none\"\n [ngClass]=\"trackLabelClass()\"\n aria-hidden=\"true\"\n >\n {{ onLabel() }}\n </span>\n }\n\n <!-- Track OFF label -->\n @if (showOffLabel()) {\n <span\n class=\"absolute right-1.5 font-semibold leading-none pointer-events-none\"\n [ngClass]=\"[trackLabelClass(), 'text-gray-500 dark:text-gray-400']\"\n aria-hidden=\"true\"\n >\n {{ offLabel() }}\n </span>\n }\n\n <!-- Thumb -->\n <span [ngClass]=\"thumbClasses()\" aria-hidden=\"true\">\n\n <!-- Loading spinner -->\n @if (loading()) {\n <svg\n class=\"animate-spin text-gray-400\"\n [ngClass]=\"thumbIconClass()\"\n xmlns=\"http://www.w3.org/2000/svg\"\n fill=\"none\"\n viewBox=\"0 0 24 24\"\n >\n <circle class=\"opacity-25\" cx=\"12\" cy=\"12\" r=\"10\"\n stroke=\"currentColor\" stroke-width=\"4\"/>\n <path class=\"opacity-75\" fill=\"currentColor\"\n d=\"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z\"/>\n </svg>\n }\n\n <!-- State icon (ON or OFF path) -->\n @if (!loading() && hasThumbIcon()) {\n <svg\n [ngClass]=\"[thumbIconClass(), checked() ? 'text-primary-600' : 'text-gray-400']\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n stroke-width=\"2.5\"\n stroke-linecap=\"round\"\n stroke-linejoin=\"round\"\n >\n <path [attr.d]=\"currentThumbIcon()\" />\n </svg>\n }\n\n </span>\n </button>\n\n <!-- \u2500\u2500 Right label (default, labelPosition === 'right') \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 -->\n @if (label() && (labelPosition() === 'right' || labelPosition() === 'hidden')) {\n @if (labelPosition() !== 'hidden') {\n <div class=\"flex flex-col min-w-0\">\n <label [attr.id]=\"labelId()\" [attr.for]=\"resolvedId()\" [ngClass]=\"[labelClass(), 'cursor-pointer']\">{{ label() }}</label>\n @if (description()) {\n <span [attr.id]=\"descId()\" [ngClass]=\"descClass()\">{{ description() }}</span>\n }\n </div>\n }\n }\n\n</div>\n" }]
245
+ }], propDecorators: { checked: [{ type: i0.Input, args: [{ isSignal: true, alias: "checked", required: false }] }, { type: i0.Output, args: ["checkedChange"] }], label: [{ type: i0.Input, args: [{ isSignal: true, alias: "label", required: false }] }], description: [{ type: i0.Input, args: [{ isSignal: true, alias: "description", required: false }] }], labelPosition: [{ type: i0.Input, args: [{ isSignal: true, alias: "labelPosition", required: false }] }], onLabel: [{ type: i0.Input, args: [{ isSignal: true, alias: "onLabel", required: false }] }], offLabel: [{ type: i0.Input, args: [{ isSignal: true, alias: "offLabel", required: false }] }], onIconPath: [{ type: i0.Input, args: [{ isSignal: true, alias: "onIconPath", required: false }] }], offIconPath: [{ type: i0.Input, args: [{ isSignal: true, alias: "offIconPath", required: false }] }], size: [{ type: i0.Input, args: [{ isSignal: true, alias: "size", required: false }] }], variant: [{ type: i0.Input, args: [{ isSignal: true, alias: "variant", required: false }] }], disabled: [{ type: i0.Input, args: [{ isSignal: true, alias: "disabled", required: false }] }], required: [{ type: i0.Input, args: [{ isSignal: true, alias: "required", required: false }] }], loading: [{ type: i0.Input, args: [{ isSignal: true, alias: "loading", required: false }] }], ariaLabel: [{ type: i0.Input, args: [{ isSignal: true, alias: "ariaLabel", required: false }] }], inputId: [{ type: i0.Input, args: [{ isSignal: true, alias: "inputId", required: false }] }], customClass: [{ type: i0.Input, args: [{ isSignal: true, alias: "customClass", required: false }] }], toggled: [{ type: i0.Output, args: ["toggled"] }] } });
246
+
247
+ /**
248
+ * Generated bundle index. Do not edit.
249
+ */
250
+
251
+ export { SvToggleSwitchComponent };
252
+ //# sourceMappingURL=styloviz-toggle-switch.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"styloviz-toggle-switch.mjs","sources":["../../../../projects/toggle-switch/src/lib/toggle-switch.component.ts","../../../../projects/toggle-switch/src/lib/toggle-switch.component.html","../../../../projects/toggle-switch/src/styloviz-toggle-switch.ts"],"sourcesContent":["import {\n Component,\n input,\n output,\n computed,\n signal,\n model,\n ChangeDetectionStrategy,\n forwardRef,\n} from '@angular/core';\nimport { NgClass } from '@angular/common';\nimport { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';\n\n// ─── Types ────────────────────────────────────────────────────────────────────\n\nexport type ToggleSize = 'xs' | 'sm' | 'md' | 'lg';\nexport type ToggleVariant = 'primary' | 'success' | 'warning' | 'danger' | 'neutral';\n\n/**\n * Label position relative to the toggle track.\n * - `right` — label follows the track (default)\n * - `left` — label precedes the track\n * - `top` — label stacked above the track\n * - `hidden` — no visible label (aria-label still required for a11y)\n */\nexport type ToggleLabelPosition = 'right' | 'left' | 'top' | 'hidden';\n\n/** Process-wide counter for generating unique fallback ids. */\nlet _svToggleUid = 0;\n\n// ─── Component ───────────────────────────────────────────────────────────────\n\n/**\n * ToggleSwitch — An accessible on/off control for settings, feature flags,\n * and boolean preferences.\n *\n * Supports:\n * - Angular signals two-way binding via `[(checked)]`\n * - Reactive Forms via `ControlValueAccessor` (`formControl` / `formControlName`)\n * - 4 sizes × 5 color variants\n * - Optional ON/OFF labels inside the track\n * - Optional icon slots in the thumb (on/off state SVG paths)\n * - Descriptive sub-label beneath the main label\n * - Disabled & loading states\n * - Full keyboard accessibility (Space / Enter toggle)\n * - `aria-checked`, `role=\"switch\"`, focus-visible ring\n */\n@Component({\n selector: 'sv-toggle-switch',\n standalone: true,\n imports: [NgClass],\n templateUrl: './toggle-switch.component.html',\n changeDetection: ChangeDetectionStrategy.OnPush,\n providers: [\n {\n provide: NG_VALUE_ACCESSOR,\n useExisting: forwardRef(() => SvToggleSwitchComponent),\n multi: true,\n },\n ],\n})\nexport class SvToggleSwitchComponent implements ControlValueAccessor {\n // ── Two-way binding ───────────────────────────────────────────────────────\n\n /** Current on/off state. Use `[(checked)]` for two-way binding. @default false */\n checked = model<boolean>(false);\n\n // ── Content ───────────────────────────────────────────────────────────────\n\n /** Visible label text. */\n label = input<string>('');\n\n /** Smaller descriptor line beneath the label. */\n description = input<string>('');\n\n /** Position of the label relative to the track. @default 'right' */\n labelPosition = input<ToggleLabelPosition>('right');\n\n /**\n * Text shown inside the track when ON.\n * Keep ≤ 3 characters for `md` size, fewer for smaller sizes. @default ''\n */\n onLabel = input<string>('');\n\n /**\n * Text shown inside the track when OFF. @default ''\n */\n offLabel = input<string>('');\n\n /**\n * SVG `<path d=\"...\">` rendered inside the thumb when the toggle is ON.\n * Omit to show a plain thumb.\n */\n onIconPath = input<string>('');\n\n /**\n * SVG `<path d=\"...\">` rendered inside the thumb when the toggle is OFF.\n */\n offIconPath = input<string>('');\n\n // ── Appearance ────────────────────────────────────────────────────────────\n\n /** Size of the toggle track and thumb. @default 'md' */\n size = input<ToggleSize>('md');\n\n /** Active-state color variant. @default 'primary' */\n variant = input<ToggleVariant>('primary');\n\n // ── State ─────────────────────────────────────────────────────────────────\n\n /** Disable interaction. @default false */\n disabled = input<boolean>(false);\n\n /** Mark the control as required (sets `aria-required`). @default false */\n required = input<boolean>(false);\n\n /**\n * Show a spinner in the thumb — useful while an async action is in-flight.\n * Implicitly disables interaction while true. @default false\n */\n loading = input<boolean>(false);\n\n // ── Accessibility ─────────────────────────────────────────────────────────\n\n /**\n * `aria-label` override — required when `labelPosition === 'hidden'`\n * so screen readers still announce the control's purpose.\n */\n ariaLabel = input<string>('');\n\n /** id forwarded to the hidden `<input>` for `<label for=\"\">` use. */\n inputId = input<string>('');\n\n // ── Extra ─────────────────────────────────────────────────────────────────\n\n /** Additional CSS classes on the root wrapper element. */\n customClass = input<string>('');\n\n // ── Outputs ───────────────────────────────────────────────────────────────\n\n /** Emits the new boolean state after every toggle. */\n toggled = output<boolean>();\n\n // ── CVA internals ────────────────────────────────────────────────────────\n\n private _onChange: (v: boolean) => void = () => {};\n private _onTouched: () => void = () => {};\n\n /** Tracks disabled state set programmatically via formControl.disable(). */\n private readonly _formDisabled = signal(false);\n\n /**\n * Merged disabled state — true when either the [disabled] input or the\n * parent FormControl is disabled. Use this everywhere instead of disabled().\n */\n readonly resolvedDisabled = computed(() => this.disabled() || this._formDisabled());\n\n writeValue(val: boolean): void {\n this.checked.set(!!val);\n }\n registerOnChange(fn: (v: boolean) => void): void { this._onChange = fn; }\n registerOnTouched(fn: () => void): void { this._onTouched = fn; }\n setDisabledState(isDisabled: boolean): void { this._formDisabled.set(isDisabled); }\n\n // ── Interaction ───────────────────────────────────────────────────────────\n\n toggle(): void {\n if (this.resolvedDisabled() || this.loading()) return;\n const next = !this.checked();\n this.checked.set(next);\n this._onChange(next);\n this._onTouched();\n this.toggled.emit(next);\n }\n\n onKeydown(event: KeyboardEvent): void {\n if (event.key === ' ' || event.key === 'Enter') {\n event.preventDefault();\n this.toggle();\n }\n }\n\n // ── Computed class maps ───────────────────────────────────────────────────\n\n /** Root wrapper layout class driven by labelPosition. */\n rootClasses = computed<string>(() => {\n const pos = this.labelPosition();\n const layout = pos === 'top'\n ? 'flex flex-col gap-1.5'\n : pos === 'left'\n ? 'flex flex-row items-center gap-3'\n : 'flex flex-row items-center gap-3';\n\n return [\n layout,\n this.resolvedDisabled() || this.loading() ? 'cursor-not-allowed opacity-60' : 'cursor-pointer',\n this.customClass(),\n ].filter(Boolean).join(' ');\n });\n\n /** Track background — variant color when ON, gray when OFF. */\n trackClasses = computed<string>(() => {\n const on = this.checked();\n\n const variantOn: Record<ToggleVariant, string> = {\n primary: 'bg-primary-600 dark:bg-primary-500',\n success: 'bg-emerald-600 dark:bg-emerald-500',\n warning: 'bg-amber-500 dark:bg-amber-400',\n danger: 'bg-red-600 dark:bg-red-500',\n neutral: 'bg-gray-700 dark:bg-gray-400',\n };\n\n const sizeMap: Record<ToggleSize, string> = {\n xs: 'h-4 w-7',\n sm: 'h-5 w-9',\n md: 'h-6 w-11',\n lg: 'h-7 w-14',\n };\n\n return [\n 'relative inline-flex shrink-0 items-center rounded-full transition-colors duration-200 ease-in-out',\n 'focus-visible:outline-none',\n sizeMap[this.size()],\n on ? variantOn[this.variant()] : 'bg-gray-200 dark:bg-gray-700',\n ].join(' ');\n });\n\n /** Thumb translate offset — moves right when ON. */\n thumbClasses = computed<string>(() => {\n const on = this.checked();\n\n const translateMap: Record<ToggleSize, { off: string; on: string }> = {\n xs: { off: 'translate-x-0.5', on: 'translate-x-3.5' },\n sm: { off: 'translate-x-0.5', on: 'translate-x-4.5' },\n md: { off: 'translate-x-0.5', on: 'translate-x-5.5' },\n lg: { off: 'translate-x-1', on: 'translate-x-7.5' },\n };\n\n const sizeMap: Record<ToggleSize, string> = {\n xs: 'h-3 w-3',\n sm: 'h-4 w-4',\n md: 'h-5 w-5',\n lg: 'h-5.5 w-5.5',\n };\n\n const t = translateMap[this.size()];\n\n return [\n 'pointer-events-none inline-flex items-center justify-center rounded-full bg-white shadow-sm',\n 'transform transition-transform duration-200 ease-in-out ring-0',\n sizeMap[this.size()],\n on ? t.on : t.off,\n ].join(' ');\n });\n\n /** Icon size inside the thumb. */\n thumbIconClass = computed<string>(() => {\n switch (this.size()) {\n case 'xs': return 'h-1.5 w-1.5';\n case 'sm': return 'h-2.5 w-2.5';\n case 'lg': return 'h-3.5 w-3.5';\n default: return 'h-3 w-3';\n }\n });\n\n /** Track label text size. */\n trackLabelClass = computed<string>(() => {\n switch (this.size()) {\n case 'xs': return 'text-[7px]';\n case 'sm': return 'text-[8px]';\n case 'lg': return 'text-[10px]';\n default: return 'text-[9px]';\n }\n });\n\n /** Main label text size. */\n labelClass = computed<string>(() => {\n const base = 'font-medium text-gray-800 dark:text-gray-100 leading-none select-none';\n switch (this.size()) {\n case 'xs': return `${base} text-xs`;\n case 'sm': return `${base} text-sm`;\n case 'lg': return `${base} text-base`;\n default: return `${base} text-sm`;\n }\n });\n\n /** Description text size. */\n descClass = computed<string>(() => {\n switch (this.size()) {\n case 'lg': return 'text-sm text-gray-500 dark:text-gray-400 select-none mt-0.5';\n default: return 'text-xs text-gray-500 dark:text-gray-400 select-none mt-0.5';\n }\n });\n\n /** Stable unique fallback id so label + ARIA associations always work. */\n private readonly _autoId = `sv-toggle-${++_svToggleUid}`;\n /** Effective id used by the switch and its <label for>. */\n readonly resolvedId = computed(() => this.inputId() || this._autoId);\n /** id of the visible label (referenced by aria-labelledby). */\n readonly labelId = computed(() => `${this.resolvedId()}-label`);\n /** id of the description (referenced by aria-describedby). */\n readonly descId = computed(() => `${this.resolvedId()}-desc`);\n\n /** True when a visible text label is rendered next to the switch. */\n readonly hasVisibleLabel = computed<boolean>(\n () => !!this.label() && this.labelPosition() !== 'hidden'\n );\n\n /** Resolved aria-label for the button role. */\n resolvedAriaLabel = computed<string>(() =>\n this.ariaLabel() || this.label() || 'Toggle'\n );\n\n /** Whether to show the thumb icon. */\n hasThumbIcon = computed<boolean>(() =>\n !!(this.checked() ? this.onIconPath() : this.offIconPath())\n );\n\n currentThumbIcon = computed<string>(() =>\n this.checked() ? this.onIconPath() : this.offIconPath()\n );\n\n showOnLabel = computed(() => !!this.onLabel() && this.checked());\n showOffLabel = computed(() => !!this.offLabel() && !this.checked());\n}\n","<!--\n Root wrapper acts as the interactive region.\n We use a <div role=\"group\"> so a wrapping <label> remains optional.\n-->\n<div\n [ngClass]=\"rootClasses()\"\n [attr.aria-label]=\"labelPosition() === 'hidden' ? resolvedAriaLabel() : null\"\n>\n\n <!-- ── Top label (only when labelPosition === 'top') ─────────────────── -->\n @if (label() && labelPosition() === 'top') {\n <label [attr.id]=\"labelId()\" [attr.for]=\"resolvedId()\" [ngClass]=\"[labelClass(), 'cursor-pointer']\">{{ label() }}</label>\n @if (description()) {\n <span [attr.id]=\"descId()\" [ngClass]=\"descClass()\">{{ description() }}</span>\n }\n }\n\n <!-- ── Left label (only when labelPosition === 'left') ──────────────── -->\n @if (label() && labelPosition() === 'left') {\n <div class=\"flex flex-col min-w-0\">\n <label [attr.id]=\"labelId()\" [attr.for]=\"resolvedId()\" [ngClass]=\"[labelClass(), 'cursor-pointer']\">{{ label() }}</label>\n @if (description()) {\n <span [attr.id]=\"descId()\" [ngClass]=\"descClass()\">{{ description() }}</span>\n }\n </div>\n }\n\n <!-- ── Track ─────────────────────────────────────────────────────────── -->\n <button\n type=\"button\"\n role=\"switch\"\n [ngClass]=\"trackClasses()\"\n [attr.aria-checked]=\"checked()\"\n [attr.id]=\"resolvedId()\"\n [attr.aria-labelledby]=\"hasVisibleLabel() ? labelId() : null\"\n [attr.aria-label]=\"hasVisibleLabel() ? null : resolvedAriaLabel()\"\n [attr.aria-describedby]=\"description() ? descId() : null\"\n [attr.aria-required]=\"required() || null\"\n [attr.aria-busy]=\"loading() || null\"\n [attr.aria-disabled]=\"resolvedDisabled() || loading() || null\"\n [attr.tabindex]=\"resolvedDisabled() ? -1 : 0\"\n (click)=\"toggle()\"\n (keydown)=\"onKeydown($event)\"\n class=\"focus-visible:ring-2 focus-visible:ring-primary-500 focus-visible:ring-offset-2\n dark:focus-visible:ring-primary-400 dark:focus-visible:ring-offset-gray-900\"\n >\n <!-- Track ON label -->\n @if (showOnLabel()) {\n <span\n class=\"absolute left-1.5 font-semibold text-white/90 leading-none pointer-events-none\"\n [ngClass]=\"trackLabelClass()\"\n aria-hidden=\"true\"\n >\n {{ onLabel() }}\n </span>\n }\n\n <!-- Track OFF label -->\n @if (showOffLabel()) {\n <span\n class=\"absolute right-1.5 font-semibold leading-none pointer-events-none\"\n [ngClass]=\"[trackLabelClass(), 'text-gray-500 dark:text-gray-400']\"\n aria-hidden=\"true\"\n >\n {{ offLabel() }}\n </span>\n }\n\n <!-- Thumb -->\n <span [ngClass]=\"thumbClasses()\" aria-hidden=\"true\">\n\n <!-- Loading spinner -->\n @if (loading()) {\n <svg\n class=\"animate-spin text-gray-400\"\n [ngClass]=\"thumbIconClass()\"\n xmlns=\"http://www.w3.org/2000/svg\"\n fill=\"none\"\n viewBox=\"0 0 24 24\"\n >\n <circle class=\"opacity-25\" cx=\"12\" cy=\"12\" r=\"10\"\n stroke=\"currentColor\" stroke-width=\"4\"/>\n <path class=\"opacity-75\" fill=\"currentColor\"\n d=\"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z\"/>\n </svg>\n }\n\n <!-- State icon (ON or OFF path) -->\n @if (!loading() && hasThumbIcon()) {\n <svg\n [ngClass]=\"[thumbIconClass(), checked() ? 'text-primary-600' : 'text-gray-400']\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n stroke-width=\"2.5\"\n stroke-linecap=\"round\"\n stroke-linejoin=\"round\"\n >\n <path [attr.d]=\"currentThumbIcon()\" />\n </svg>\n }\n\n </span>\n </button>\n\n <!-- ── Right label (default, labelPosition === 'right') ─────────────── -->\n @if (label() && (labelPosition() === 'right' || labelPosition() === 'hidden')) {\n @if (labelPosition() !== 'hidden') {\n <div class=\"flex flex-col min-w-0\">\n <label [attr.id]=\"labelId()\" [attr.for]=\"resolvedId()\" [ngClass]=\"[labelClass(), 'cursor-pointer']\">{{ label() }}</label>\n @if (description()) {\n <span [attr.id]=\"descId()\" [ngClass]=\"descClass()\">{{ description() }}</span>\n }\n </div>\n }\n }\n\n</div>\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;;AA2BA;AACA,IAAI,YAAY,GAAG,CAAC;AAEpB;AAEA;;;;;;;;;;;;;;AAcG;MAeU,uBAAuB,CAAA;;;AAIlC,IAAA,OAAO,GAAG,KAAK,CAAU,KAAK,8EAAC;;;AAK/B,IAAA,KAAK,GAAa,KAAK,CAAS,EAAE,4EAAC;;AAGnC,IAAA,WAAW,GAAO,KAAK,CAAS,EAAE,kFAAC;;AAGnC,IAAA,aAAa,GAAK,KAAK,CAAsB,OAAO,oFAAC;AAErD;;;AAGG;AACH,IAAA,OAAO,GAAW,KAAK,CAAS,EAAE,8EAAC;AAEnC;;AAEG;AACH,IAAA,QAAQ,GAAU,KAAK,CAAS,EAAE,+EAAC;AAEnC;;;AAGG;AACH,IAAA,UAAU,GAAQ,KAAK,CAAS,EAAE,iFAAC;AAEnC;;AAEG;AACH,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A,EAAA,iBAAA,EAAA,aAAA,EAAA,UAAA,EAAA,aAAA,EAAA,QAAA,EAAA,IAAA,EAAA,UAAA,EAAA,KAAA,EAAA,iBAAA,EAAA,IAAA,EAAA,EAAA,EAAA,OAAA,EAAA,EAAA,OAAA,EAAA,eAAA,EAAA,OAAA,EAAA,SAAA,EAAA,EAAA,SAAA,EARvB;AACT,YAAA;AACE,gBAAA,OAAO,EAAE,iBAAiB;AAC1B,gBAAA,WAAW,EAAE,UAAU,CAAC,MAAM,uBAAuB,CAAC;AACtD,gBAAA,KAAK,EAAE,IAAI;AACZ,aAAA;SACF,EAAA,QAAA,EAAA,EAAA,EAAA,QAAA,EC3DH,m1JAsHA,4CDpEY,OAAO,EAAA,QAAA,EAAA,WAAA,EAAA,MAAA,EAAA,CAAA,OAAA,EAAA,SAAA,CAAA,EAAA,CAAA,EAAA,eAAA,EAAA,EAAA,CAAA,uBAAA,CAAA,MAAA,EAAA,CAAA;;4FAWN,uBAAuB,EAAA,UAAA,EAAA,CAAA;kBAdnC,SAAS;+BACE,kBAAkB,EAAA,UAAA,EAChB,IAAI,EAAA,OAAA,EACP,CAAC,OAAO,CAAC,EAAA,eAAA,EAED,uBAAuB,CAAC,MAAM,EAAA,SAAA,EACpC;AACT,wBAAA;AACE,4BAAA,OAAO,EAAE,iBAAiB;AAC1B,4BAAA,WAAW,EAAE,UAAU,CAAC,6BAA6B,CAAC;AACtD,4BAAA,KAAK,EAAE,IAAI;AACZ,yBAAA;AACF,qBAAA,EAAA,QAAA,EAAA,m1JAAA,EAAA;;;AE3DH;;AAEG;;;;"}
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "@styloviz/toggle-switch",
3
+ "version": "0.1.1",
4
+ "description": "Accessible on/off toggle switch with labels, sizes and disabled state.",
5
+ "license": "MIT",
6
+ "author": "sazzad-bs23",
7
+ "homepage": "https://styloviz.dev",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/rhossain/angular-tailwind-dashboard-components.git",
11
+ "directory": "projects/toggle-switch"
12
+ },
13
+ "bugs": {
14
+ "url": "https://github.com/rhossain/angular-tailwind-dashboard-components/issues"
15
+ },
16
+ "peerDependencies": {
17
+ "@angular/common": ">=21.0.0",
18
+ "@angular/core": ">=21.0.0",
19
+ "@angular/forms": ">=21.0.0"
20
+ },
21
+ "publishConfig": {
22
+ "access": "public"
23
+ },
24
+ "engines": {
25
+ "node": "^20.19.0 || ^22.12.0 || >=24.0.0"
26
+ },
27
+ "sideEffects": false,
28
+ "module": "fesm2022/styloviz-toggle-switch.mjs",
29
+ "typings": "types/styloviz-toggle-switch.d.ts",
30
+ "exports": {
31
+ "./package.json": {
32
+ "default": "./package.json"
33
+ },
34
+ ".": {
35
+ "types": "./types/styloviz-toggle-switch.d.ts",
36
+ "default": "./fesm2022/styloviz-toggle-switch.mjs"
37
+ }
38
+ },
39
+ "type": "module",
40
+ "dependencies": {
41
+ "tslib": "^2.3.0"
42
+ }
43
+ }
@@ -0,0 +1,131 @@
1
+ import * as _angular_core from '@angular/core';
2
+ import { ControlValueAccessor } from '@angular/forms';
3
+
4
+ type ToggleSize = 'xs' | 'sm' | 'md' | 'lg';
5
+ type ToggleVariant = 'primary' | 'success' | 'warning' | 'danger' | 'neutral';
6
+ /**
7
+ * Label position relative to the toggle track.
8
+ * - `right` — label follows the track (default)
9
+ * - `left` — label precedes the track
10
+ * - `top` — label stacked above the track
11
+ * - `hidden` — no visible label (aria-label still required for a11y)
12
+ */
13
+ type ToggleLabelPosition = 'right' | 'left' | 'top' | 'hidden';
14
+ /**
15
+ * ToggleSwitch — An accessible on/off control for settings, feature flags,
16
+ * and boolean preferences.
17
+ *
18
+ * Supports:
19
+ * - Angular signals two-way binding via `[(checked)]`
20
+ * - Reactive Forms via `ControlValueAccessor` (`formControl` / `formControlName`)
21
+ * - 4 sizes × 5 color variants
22
+ * - Optional ON/OFF labels inside the track
23
+ * - Optional icon slots in the thumb (on/off state SVG paths)
24
+ * - Descriptive sub-label beneath the main label
25
+ * - Disabled & loading states
26
+ * - Full keyboard accessibility (Space / Enter toggle)
27
+ * - `aria-checked`, `role="switch"`, focus-visible ring
28
+ */
29
+ declare class SvToggleSwitchComponent implements ControlValueAccessor {
30
+ /** Current on/off state. Use `[(checked)]` for two-way binding. @default false */
31
+ checked: _angular_core.ModelSignal<boolean>;
32
+ /** Visible label text. */
33
+ label: _angular_core.InputSignal<string>;
34
+ /** Smaller descriptor line beneath the label. */
35
+ description: _angular_core.InputSignal<string>;
36
+ /** Position of the label relative to the track. @default 'right' */
37
+ labelPosition: _angular_core.InputSignal<ToggleLabelPosition>;
38
+ /**
39
+ * Text shown inside the track when ON.
40
+ * Keep ≤ 3 characters for `md` size, fewer for smaller sizes. @default ''
41
+ */
42
+ onLabel: _angular_core.InputSignal<string>;
43
+ /**
44
+ * Text shown inside the track when OFF. @default ''
45
+ */
46
+ offLabel: _angular_core.InputSignal<string>;
47
+ /**
48
+ * SVG `<path d="...">` rendered inside the thumb when the toggle is ON.
49
+ * Omit to show a plain thumb.
50
+ */
51
+ onIconPath: _angular_core.InputSignal<string>;
52
+ /**
53
+ * SVG `<path d="...">` rendered inside the thumb when the toggle is OFF.
54
+ */
55
+ offIconPath: _angular_core.InputSignal<string>;
56
+ /** Size of the toggle track and thumb. @default 'md' */
57
+ size: _angular_core.InputSignal<ToggleSize>;
58
+ /** Active-state color variant. @default 'primary' */
59
+ variant: _angular_core.InputSignal<ToggleVariant>;
60
+ /** Disable interaction. @default false */
61
+ disabled: _angular_core.InputSignal<boolean>;
62
+ /** Mark the control as required (sets `aria-required`). @default false */
63
+ required: _angular_core.InputSignal<boolean>;
64
+ /**
65
+ * Show a spinner in the thumb — useful while an async action is in-flight.
66
+ * Implicitly disables interaction while true. @default false
67
+ */
68
+ loading: _angular_core.InputSignal<boolean>;
69
+ /**
70
+ * `aria-label` override — required when `labelPosition === 'hidden'`
71
+ * so screen readers still announce the control's purpose.
72
+ */
73
+ ariaLabel: _angular_core.InputSignal<string>;
74
+ /** id forwarded to the hidden `<input>` for `<label for="">` use. */
75
+ inputId: _angular_core.InputSignal<string>;
76
+ /** Additional CSS classes on the root wrapper element. */
77
+ customClass: _angular_core.InputSignal<string>;
78
+ /** Emits the new boolean state after every toggle. */
79
+ toggled: _angular_core.OutputEmitterRef<boolean>;
80
+ private _onChange;
81
+ private _onTouched;
82
+ /** Tracks disabled state set programmatically via formControl.disable(). */
83
+ private readonly _formDisabled;
84
+ /**
85
+ * Merged disabled state — true when either the [disabled] input or the
86
+ * parent FormControl is disabled. Use this everywhere instead of disabled().
87
+ */
88
+ readonly resolvedDisabled: _angular_core.Signal<boolean>;
89
+ writeValue(val: boolean): void;
90
+ registerOnChange(fn: (v: boolean) => void): void;
91
+ registerOnTouched(fn: () => void): void;
92
+ setDisabledState(isDisabled: boolean): void;
93
+ toggle(): void;
94
+ onKeydown(event: KeyboardEvent): void;
95
+ /** Root wrapper layout class driven by labelPosition. */
96
+ rootClasses: _angular_core.Signal<string>;
97
+ /** Track background — variant color when ON, gray when OFF. */
98
+ trackClasses: _angular_core.Signal<string>;
99
+ /** Thumb translate offset — moves right when ON. */
100
+ thumbClasses: _angular_core.Signal<string>;
101
+ /** Icon size inside the thumb. */
102
+ thumbIconClass: _angular_core.Signal<string>;
103
+ /** Track label text size. */
104
+ trackLabelClass: _angular_core.Signal<string>;
105
+ /** Main label text size. */
106
+ labelClass: _angular_core.Signal<string>;
107
+ /** Description text size. */
108
+ descClass: _angular_core.Signal<string>;
109
+ /** Stable unique fallback id so label + ARIA associations always work. */
110
+ private readonly _autoId;
111
+ /** Effective id used by the switch and its <label for>. */
112
+ readonly resolvedId: _angular_core.Signal<string>;
113
+ /** id of the visible label (referenced by aria-labelledby). */
114
+ readonly labelId: _angular_core.Signal<string>;
115
+ /** id of the description (referenced by aria-describedby). */
116
+ readonly descId: _angular_core.Signal<string>;
117
+ /** True when a visible text label is rendered next to the switch. */
118
+ readonly hasVisibleLabel: _angular_core.Signal<boolean>;
119
+ /** Resolved aria-label for the button role. */
120
+ resolvedAriaLabel: _angular_core.Signal<string>;
121
+ /** Whether to show the thumb icon. */
122
+ hasThumbIcon: _angular_core.Signal<boolean>;
123
+ currentThumbIcon: _angular_core.Signal<string>;
124
+ showOnLabel: _angular_core.Signal<boolean>;
125
+ showOffLabel: _angular_core.Signal<boolean>;
126
+ static ɵfac: _angular_core.ɵɵFactoryDeclaration<SvToggleSwitchComponent, never>;
127
+ static ɵcmp: _angular_core.ɵɵComponentDeclaration<SvToggleSwitchComponent, "sv-toggle-switch", never, { "checked": { "alias": "checked"; "required": false; "isSignal": true; }; "label": { "alias": "label"; "required": false; "isSignal": true; }; "description": { "alias": "description"; "required": false; "isSignal": true; }; "labelPosition": { "alias": "labelPosition"; "required": false; "isSignal": true; }; "onLabel": { "alias": "onLabel"; "required": false; "isSignal": true; }; "offLabel": { "alias": "offLabel"; "required": false; "isSignal": true; }; "onIconPath": { "alias": "onIconPath"; "required": false; "isSignal": true; }; "offIconPath": { "alias": "offIconPath"; "required": false; "isSignal": true; }; "size": { "alias": "size"; "required": false; "isSignal": true; }; "variant": { "alias": "variant"; "required": false; "isSignal": true; }; "disabled": { "alias": "disabled"; "required": false; "isSignal": true; }; "required": { "alias": "required"; "required": false; "isSignal": true; }; "loading": { "alias": "loading"; "required": false; "isSignal": true; }; "ariaLabel": { "alias": "ariaLabel"; "required": false; "isSignal": true; }; "inputId": { "alias": "inputId"; "required": false; "isSignal": true; }; "customClass": { "alias": "customClass"; "required": false; "isSignal": true; }; }, { "checked": "checkedChange"; "toggled": "toggled"; }, never, never, true, never>;
128
+ }
129
+
130
+ export { SvToggleSwitchComponent };
131
+ export type { ToggleLabelPosition, ToggleSize, ToggleVariant };