@kanso-protocol/theme-toggle 0.1.0
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.
|
@@ -0,0 +1,302 @@
|
|
|
1
|
+
import * as i0 from '@angular/core';
|
|
2
|
+
import { EventEmitter, signal, inject, ElementRef, HostListener, ViewChild, Output, Input, ChangeDetectionStrategy, Component } from '@angular/core';
|
|
3
|
+
import { DOCUMENT } from '@angular/common';
|
|
4
|
+
import { KpIconComponent } from '@kanso-protocol/icon';
|
|
5
|
+
|
|
6
|
+
const THEMES = ['light', 'dark', 'system'];
|
|
7
|
+
/**
|
|
8
|
+
* Kanso Protocol — ThemeToggle
|
|
9
|
+
*
|
|
10
|
+
* Three presentations for switching between light / dark / system
|
|
11
|
+
* themes:
|
|
12
|
+
* - `icon` — single icon button that cycles
|
|
13
|
+
* - `segmented` — three inline icon segments, one selected
|
|
14
|
+
* - `dropdown` — ghost button showing the current theme label; opens a menu
|
|
15
|
+
*
|
|
16
|
+
* The component emits `themeChange` when the user selects a value;
|
|
17
|
+
* keeping the chosen theme (including `system`) up to the consumer.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* <kp-theme-toggle
|
|
21
|
+
* variant="segmented"
|
|
22
|
+
* [showLabel]="true"
|
|
23
|
+
* [currentTheme]="theme()"
|
|
24
|
+
* (themeChange)="theme.set($event)"
|
|
25
|
+
* />
|
|
26
|
+
*/
|
|
27
|
+
class KpThemeToggleComponent {
|
|
28
|
+
variant = 'icon';
|
|
29
|
+
size = 'md';
|
|
30
|
+
currentTheme = 'light';
|
|
31
|
+
showLabel = false;
|
|
32
|
+
themeChange = new EventEmitter();
|
|
33
|
+
dropdownClick = new EventEmitter();
|
|
34
|
+
themes = THEMES;
|
|
35
|
+
isOpen = signal(false, ...(ngDevMode ? [{ debugName: "isOpen" }] : /* istanbul ignore next */ []));
|
|
36
|
+
menuEl;
|
|
37
|
+
hostRef = inject((ElementRef));
|
|
38
|
+
doc = inject(DOCUMENT);
|
|
39
|
+
portaledMenu = null;
|
|
40
|
+
ngAfterViewChecked() {
|
|
41
|
+
if (!this.isOpen())
|
|
42
|
+
return;
|
|
43
|
+
const menu = this.menuEl?.nativeElement;
|
|
44
|
+
// Portal menu to <body> so transformed/clipped ancestors can't clip it.
|
|
45
|
+
if (menu && this.doc?.body && menu.parentElement !== this.doc.body) {
|
|
46
|
+
// Tag the menu with the current size so size-scoped CSS applies after portal
|
|
47
|
+
menu.classList.add(`kp-theme-toggle__menu--${this.size}`);
|
|
48
|
+
this.doc.body.appendChild(menu);
|
|
49
|
+
this.portaledMenu = menu;
|
|
50
|
+
window.addEventListener('scroll', this.reposition, true);
|
|
51
|
+
window.addEventListener('resize', this.reposition);
|
|
52
|
+
}
|
|
53
|
+
this.positionMenu();
|
|
54
|
+
}
|
|
55
|
+
ngOnDestroy() {
|
|
56
|
+
this.cleanupMenu();
|
|
57
|
+
}
|
|
58
|
+
cleanupMenu() {
|
|
59
|
+
window.removeEventListener('scroll', this.reposition, true);
|
|
60
|
+
window.removeEventListener('resize', this.reposition);
|
|
61
|
+
if (this.portaledMenu && this.portaledMenu.parentElement === this.doc?.body) {
|
|
62
|
+
this.portaledMenu.remove();
|
|
63
|
+
}
|
|
64
|
+
this.portaledMenu = null;
|
|
65
|
+
}
|
|
66
|
+
closeMenu() {
|
|
67
|
+
if (!this.isOpen())
|
|
68
|
+
return;
|
|
69
|
+
this.cleanupMenu();
|
|
70
|
+
this.isOpen.set(false);
|
|
71
|
+
}
|
|
72
|
+
reposition = () => this.positionMenu();
|
|
73
|
+
positionMenu() {
|
|
74
|
+
const menu = this.menuEl?.nativeElement;
|
|
75
|
+
const trigger = this.hostRef.nativeElement.querySelector('.kp-theme-toggle__dropdown');
|
|
76
|
+
if (!menu || !trigger)
|
|
77
|
+
return;
|
|
78
|
+
const rect = trigger.getBoundingClientRect();
|
|
79
|
+
menu.style.top = `${rect.bottom + 6}px`;
|
|
80
|
+
menu.style.left = `${rect.left}px`;
|
|
81
|
+
menu.style.right = 'auto';
|
|
82
|
+
menu.style.width = `${rect.width}px`;
|
|
83
|
+
}
|
|
84
|
+
onDocClick(event) {
|
|
85
|
+
if (!this.isOpen())
|
|
86
|
+
return;
|
|
87
|
+
const target = event.target;
|
|
88
|
+
const host = this.hostRef.nativeElement;
|
|
89
|
+
const portaled = this.portaledMenu;
|
|
90
|
+
const insideHost = host && host.contains(target);
|
|
91
|
+
const insideMenu = portaled && portaled.contains(target);
|
|
92
|
+
if (!insideHost && !insideMenu)
|
|
93
|
+
this.closeMenu();
|
|
94
|
+
}
|
|
95
|
+
onEsc() {
|
|
96
|
+
this.closeMenu();
|
|
97
|
+
}
|
|
98
|
+
toggleOpen() {
|
|
99
|
+
if (this.isOpen()) {
|
|
100
|
+
this.closeMenu();
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
this.isOpen.set(true);
|
|
104
|
+
this.dropdownClick.emit();
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
selectFromMenu(t) {
|
|
108
|
+
this.select(t);
|
|
109
|
+
this.closeMenu();
|
|
110
|
+
}
|
|
111
|
+
get hostClasses() {
|
|
112
|
+
return `kp-theme-toggle kp-theme-toggle--${this.variant} kp-theme-toggle--${this.size}`;
|
|
113
|
+
}
|
|
114
|
+
cycle() {
|
|
115
|
+
const idx = THEMES.indexOf(this.currentTheme);
|
|
116
|
+
const next = THEMES[(idx + 1) % THEMES.length];
|
|
117
|
+
this.currentTheme = next;
|
|
118
|
+
this.themeChange.emit(next);
|
|
119
|
+
}
|
|
120
|
+
select(t) {
|
|
121
|
+
if (t === this.currentTheme)
|
|
122
|
+
return;
|
|
123
|
+
this.currentTheme = t;
|
|
124
|
+
this.themeChange.emit(t);
|
|
125
|
+
}
|
|
126
|
+
themeLabel(t) {
|
|
127
|
+
return t === 'light' ? 'Light' : t === 'dark' ? 'Dark' : 'System';
|
|
128
|
+
}
|
|
129
|
+
iconName(t) {
|
|
130
|
+
return t === 'light' ? 'sun-high' : t === 'dark' ? 'moon' : 'device-desktop';
|
|
131
|
+
}
|
|
132
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.7", ngImport: i0, type: KpThemeToggleComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
133
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.2.7", type: KpThemeToggleComponent, isStandalone: true, selector: "kp-theme-toggle", inputs: { variant: "variant", size: "size", currentTheme: "currentTheme", showLabel: "showLabel" }, outputs: { themeChange: "themeChange", dropdownClick: "dropdownClick" }, host: { listeners: { "document:click": "onDocClick($event)", "document:keydown.escape": "onEsc()" }, properties: { "class": "hostClasses" } }, viewQueries: [{ propertyName: "menuEl", first: true, predicate: ["menu"], descendants: true }], ngImport: i0, template: `
|
|
134
|
+
@if (variant === 'icon') {
|
|
135
|
+
<button
|
|
136
|
+
type="button"
|
|
137
|
+
class="kp-theme-toggle__icon-btn"
|
|
138
|
+
[attr.aria-label]="'Toggle theme (current: ' + currentTheme + ')'"
|
|
139
|
+
(click)="cycle()"
|
|
140
|
+
>
|
|
141
|
+
<kp-icon [name]="iconName(currentTheme)" />
|
|
142
|
+
</button>
|
|
143
|
+
} @else if (variant === 'segmented') {
|
|
144
|
+
@if (showLabel) {
|
|
145
|
+
<span class="kp-theme-toggle__label">Theme</span>
|
|
146
|
+
}
|
|
147
|
+
<div class="kp-theme-toggle__segments" role="tablist" aria-label="Theme">
|
|
148
|
+
@for (t of themes; track t) {
|
|
149
|
+
<button
|
|
150
|
+
type="button"
|
|
151
|
+
role="tab"
|
|
152
|
+
class="kp-theme-toggle__segment"
|
|
153
|
+
[class.kp-theme-toggle__segment--selected]="currentTheme === t"
|
|
154
|
+
[attr.aria-selected]="currentTheme === t"
|
|
155
|
+
[attr.aria-label]="t"
|
|
156
|
+
(click)="select(t)"
|
|
157
|
+
>
|
|
158
|
+
<kp-icon [name]="iconName(t)" />
|
|
159
|
+
</button>
|
|
160
|
+
}
|
|
161
|
+
</div>
|
|
162
|
+
} @else {
|
|
163
|
+
@if (showLabel) {
|
|
164
|
+
<span class="kp-theme-toggle__label">Theme</span>
|
|
165
|
+
}
|
|
166
|
+
<div class="kp-theme-toggle__dropdown-wrap">
|
|
167
|
+
<button
|
|
168
|
+
type="button"
|
|
169
|
+
class="kp-theme-toggle__dropdown"
|
|
170
|
+
[class.kp-theme-toggle__dropdown--open]="isOpen()"
|
|
171
|
+
[attr.aria-haspopup]="'listbox'"
|
|
172
|
+
[attr.aria-expanded]="isOpen()"
|
|
173
|
+
(click)="toggleOpen()"
|
|
174
|
+
>
|
|
175
|
+
<kp-icon [name]="iconName(currentTheme)" />
|
|
176
|
+
<span class="kp-theme-toggle__dropdown-label">{{ themeLabel(currentTheme) }}</span>
|
|
177
|
+
<kp-icon name="chevron-down" class="kp-theme-toggle__chevron" />
|
|
178
|
+
</button>
|
|
179
|
+
@if (isOpen()) {
|
|
180
|
+
<div #menu class="kp-theme-toggle__menu" role="listbox" aria-label="Theme">
|
|
181
|
+
@for (t of themes; track t) {
|
|
182
|
+
<button
|
|
183
|
+
type="button"
|
|
184
|
+
role="option"
|
|
185
|
+
class="kp-theme-toggle__option"
|
|
186
|
+
[class.kp-theme-toggle__option--selected]="currentTheme === t"
|
|
187
|
+
[attr.aria-selected]="currentTheme === t"
|
|
188
|
+
(click)="selectFromMenu(t)"
|
|
189
|
+
>
|
|
190
|
+
<kp-icon [name]="iconName(t)" />
|
|
191
|
+
<span>{{ themeLabel(t) }}</span>
|
|
192
|
+
@if (currentTheme === t) {
|
|
193
|
+
<kp-icon name="check" class="kp-theme-toggle__option-check" />
|
|
194
|
+
}
|
|
195
|
+
</button>
|
|
196
|
+
}
|
|
197
|
+
</div>
|
|
198
|
+
}
|
|
199
|
+
</div>
|
|
200
|
+
}
|
|
201
|
+
`, isInline: true, styles: [":host{display:inline-flex;align-items:center;gap:8px;font-family:var(--kp-font-family-sans, \"Onest\", system-ui, sans-serif)}.kp-theme-toggle__label{font-size:14px;color:var(--kp-color-gray-700, var(--kp-color-gray-700))}:host .ti{font-size:var(--kp-theme-glyph, 18px);line-height:1}:host .ti.kp-theme-toggle__chevron{font-size:14px;color:var(--kp-color-gray-500, var(--kp-color-gray-500))}.kp-theme-toggle__icon-btn{all:unset;display:inline-flex;align-items:center;justify-content:center;width:var(--kp-theme-btn, 36px);height:var(--kp-theme-btn, 36px);border-radius:8px;color:var(--kp-color-gray-600, var(--kp-color-gray-600));cursor:pointer;transition:background var(--kp-motion-duration-fast) ease,color .12s ease}.kp-theme-toggle__icon-btn:hover{background:var(--kp-color-gray-100, var(--kp-color-gray-100));color:var(--kp-color-gray-900, var(--kp-color-gray-900))}.kp-theme-toggle__segments{display:inline-flex;align-items:center;gap:2px;padding:2px;border:1px solid var(--kp-color-gray-200, var(--kp-color-gray-200));border-radius:8px;background:var(--kp-color-gray-50, var(--kp-color-gray-50))}.kp-theme-toggle__segment{all:unset;display:inline-flex;align-items:center;justify-content:center;width:var(--kp-theme-seg, 28px);height:var(--kp-theme-seg, 28px);border-radius:6px;color:var(--kp-color-gray-500, var(--kp-color-gray-500));cursor:pointer;transition:background var(--kp-motion-duration-fast) ease,color .12s ease}.kp-theme-toggle__segment:hover{color:var(--kp-color-gray-900, var(--kp-color-gray-900))}.kp-theme-toggle__segment--selected{background:var(--kp-color-white, var(--kp-color-white));color:var(--kp-color-gray-900, var(--kp-color-gray-900));box-shadow:var(--kp-elevation-raised)}.kp-theme-toggle__dropdown{all:unset;display:inline-flex;align-items:center;gap:8px;padding:6px 10px;border-radius:8px;color:var(--kp-color-gray-700, var(--kp-color-gray-700));font-size:13px;font-weight:500;cursor:pointer;transition:background var(--kp-motion-duration-fast) ease,color .12s ease}.kp-theme-toggle__dropdown:hover,.kp-theme-toggle__dropdown--open{background:var(--kp-color-gray-100, var(--kp-color-gray-100));color:var(--kp-color-gray-900, var(--kp-color-gray-900))}.kp-theme-toggle__dropdown-label{min-width:44px;text-align:start}.kp-theme-toggle__dropdown-wrap{position:relative;display:inline-block}.kp-theme-toggle__menu{position:fixed;display:flex;flex-direction:column;padding:4px;border-radius:10px;background:var(--kp-color-white, var(--kp-color-white));border:1px solid var(--kp-color-gray-200, var(--kp-color-gray-200));box-shadow:var(--kp-elevation-overlay);z-index:1000;font-family:var(--kp-font-family-sans, \"Onest\", system-ui, sans-serif)}.kp-theme-toggle__option{all:unset;display:flex;align-items:center;gap:10px;padding:7px 10px;border-radius:6px;font-size:13px;color:var(--kp-color-gray-700, var(--kp-color-gray-700));cursor:pointer;transition:background var(--kp-motion-duration-fast) ease,color .12s ease}.kp-theme-toggle__option:hover{background:var(--kp-color-gray-100, var(--kp-color-gray-100));color:var(--kp-color-gray-900, var(--kp-color-gray-900))}.kp-theme-toggle__option--selected{color:var(--kp-color-gray-900, var(--kp-color-gray-900));font-weight:500}.kp-theme-toggle__option-check{margin-inline-start:auto;color:var(--kp-color-blue-600, var(--kp-color-blue-600))}.kp-theme-toggle__menu .ti{font-size:18px;line-height:1}.kp-theme-toggle__menu--sm .ti{font-size:16px}.kp-theme-toggle__menu--md .ti{font-size:18px}.kp-theme-toggle__menu--lg .ti{font-size:20px}.kp-theme-toggle__menu .ti.kp-theme-toggle__option-check{font-size:14px}:host(.kp-theme-toggle--sm){--kp-theme-btn: 28px;--kp-theme-seg: 24px;--kp-theme-glyph: 16px}:host(.kp-theme-toggle--md){--kp-theme-btn: 36px;--kp-theme-seg: 28px;--kp-theme-glyph: 18px}:host(.kp-theme-toggle--lg){--kp-theme-btn: 44px;--kp-theme-seg: 36px;--kp-theme-glyph: 20px}\n"], dependencies: [{ kind: "component", type: KpIconComponent, selector: "kp-icon", inputs: ["name", "size"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
|
|
202
|
+
}
|
|
203
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.7", ngImport: i0, type: KpThemeToggleComponent, decorators: [{
|
|
204
|
+
type: Component,
|
|
205
|
+
args: [{ selector: 'kp-theme-toggle', imports: [KpIconComponent], changeDetection: ChangeDetectionStrategy.OnPush, host: { '[class]': 'hostClasses' }, template: `
|
|
206
|
+
@if (variant === 'icon') {
|
|
207
|
+
<button
|
|
208
|
+
type="button"
|
|
209
|
+
class="kp-theme-toggle__icon-btn"
|
|
210
|
+
[attr.aria-label]="'Toggle theme (current: ' + currentTheme + ')'"
|
|
211
|
+
(click)="cycle()"
|
|
212
|
+
>
|
|
213
|
+
<kp-icon [name]="iconName(currentTheme)" />
|
|
214
|
+
</button>
|
|
215
|
+
} @else if (variant === 'segmented') {
|
|
216
|
+
@if (showLabel) {
|
|
217
|
+
<span class="kp-theme-toggle__label">Theme</span>
|
|
218
|
+
}
|
|
219
|
+
<div class="kp-theme-toggle__segments" role="tablist" aria-label="Theme">
|
|
220
|
+
@for (t of themes; track t) {
|
|
221
|
+
<button
|
|
222
|
+
type="button"
|
|
223
|
+
role="tab"
|
|
224
|
+
class="kp-theme-toggle__segment"
|
|
225
|
+
[class.kp-theme-toggle__segment--selected]="currentTheme === t"
|
|
226
|
+
[attr.aria-selected]="currentTheme === t"
|
|
227
|
+
[attr.aria-label]="t"
|
|
228
|
+
(click)="select(t)"
|
|
229
|
+
>
|
|
230
|
+
<kp-icon [name]="iconName(t)" />
|
|
231
|
+
</button>
|
|
232
|
+
}
|
|
233
|
+
</div>
|
|
234
|
+
} @else {
|
|
235
|
+
@if (showLabel) {
|
|
236
|
+
<span class="kp-theme-toggle__label">Theme</span>
|
|
237
|
+
}
|
|
238
|
+
<div class="kp-theme-toggle__dropdown-wrap">
|
|
239
|
+
<button
|
|
240
|
+
type="button"
|
|
241
|
+
class="kp-theme-toggle__dropdown"
|
|
242
|
+
[class.kp-theme-toggle__dropdown--open]="isOpen()"
|
|
243
|
+
[attr.aria-haspopup]="'listbox'"
|
|
244
|
+
[attr.aria-expanded]="isOpen()"
|
|
245
|
+
(click)="toggleOpen()"
|
|
246
|
+
>
|
|
247
|
+
<kp-icon [name]="iconName(currentTheme)" />
|
|
248
|
+
<span class="kp-theme-toggle__dropdown-label">{{ themeLabel(currentTheme) }}</span>
|
|
249
|
+
<kp-icon name="chevron-down" class="kp-theme-toggle__chevron" />
|
|
250
|
+
</button>
|
|
251
|
+
@if (isOpen()) {
|
|
252
|
+
<div #menu class="kp-theme-toggle__menu" role="listbox" aria-label="Theme">
|
|
253
|
+
@for (t of themes; track t) {
|
|
254
|
+
<button
|
|
255
|
+
type="button"
|
|
256
|
+
role="option"
|
|
257
|
+
class="kp-theme-toggle__option"
|
|
258
|
+
[class.kp-theme-toggle__option--selected]="currentTheme === t"
|
|
259
|
+
[attr.aria-selected]="currentTheme === t"
|
|
260
|
+
(click)="selectFromMenu(t)"
|
|
261
|
+
>
|
|
262
|
+
<kp-icon [name]="iconName(t)" />
|
|
263
|
+
<span>{{ themeLabel(t) }}</span>
|
|
264
|
+
@if (currentTheme === t) {
|
|
265
|
+
<kp-icon name="check" class="kp-theme-toggle__option-check" />
|
|
266
|
+
}
|
|
267
|
+
</button>
|
|
268
|
+
}
|
|
269
|
+
</div>
|
|
270
|
+
}
|
|
271
|
+
</div>
|
|
272
|
+
}
|
|
273
|
+
`, styles: [":host{display:inline-flex;align-items:center;gap:8px;font-family:var(--kp-font-family-sans, \"Onest\", system-ui, sans-serif)}.kp-theme-toggle__label{font-size:14px;color:var(--kp-color-gray-700, var(--kp-color-gray-700))}:host .ti{font-size:var(--kp-theme-glyph, 18px);line-height:1}:host .ti.kp-theme-toggle__chevron{font-size:14px;color:var(--kp-color-gray-500, var(--kp-color-gray-500))}.kp-theme-toggle__icon-btn{all:unset;display:inline-flex;align-items:center;justify-content:center;width:var(--kp-theme-btn, 36px);height:var(--kp-theme-btn, 36px);border-radius:8px;color:var(--kp-color-gray-600, var(--kp-color-gray-600));cursor:pointer;transition:background var(--kp-motion-duration-fast) ease,color .12s ease}.kp-theme-toggle__icon-btn:hover{background:var(--kp-color-gray-100, var(--kp-color-gray-100));color:var(--kp-color-gray-900, var(--kp-color-gray-900))}.kp-theme-toggle__segments{display:inline-flex;align-items:center;gap:2px;padding:2px;border:1px solid var(--kp-color-gray-200, var(--kp-color-gray-200));border-radius:8px;background:var(--kp-color-gray-50, var(--kp-color-gray-50))}.kp-theme-toggle__segment{all:unset;display:inline-flex;align-items:center;justify-content:center;width:var(--kp-theme-seg, 28px);height:var(--kp-theme-seg, 28px);border-radius:6px;color:var(--kp-color-gray-500, var(--kp-color-gray-500));cursor:pointer;transition:background var(--kp-motion-duration-fast) ease,color .12s ease}.kp-theme-toggle__segment:hover{color:var(--kp-color-gray-900, var(--kp-color-gray-900))}.kp-theme-toggle__segment--selected{background:var(--kp-color-white, var(--kp-color-white));color:var(--kp-color-gray-900, var(--kp-color-gray-900));box-shadow:var(--kp-elevation-raised)}.kp-theme-toggle__dropdown{all:unset;display:inline-flex;align-items:center;gap:8px;padding:6px 10px;border-radius:8px;color:var(--kp-color-gray-700, var(--kp-color-gray-700));font-size:13px;font-weight:500;cursor:pointer;transition:background var(--kp-motion-duration-fast) ease,color .12s ease}.kp-theme-toggle__dropdown:hover,.kp-theme-toggle__dropdown--open{background:var(--kp-color-gray-100, var(--kp-color-gray-100));color:var(--kp-color-gray-900, var(--kp-color-gray-900))}.kp-theme-toggle__dropdown-label{min-width:44px;text-align:start}.kp-theme-toggle__dropdown-wrap{position:relative;display:inline-block}.kp-theme-toggle__menu{position:fixed;display:flex;flex-direction:column;padding:4px;border-radius:10px;background:var(--kp-color-white, var(--kp-color-white));border:1px solid var(--kp-color-gray-200, var(--kp-color-gray-200));box-shadow:var(--kp-elevation-overlay);z-index:1000;font-family:var(--kp-font-family-sans, \"Onest\", system-ui, sans-serif)}.kp-theme-toggle__option{all:unset;display:flex;align-items:center;gap:10px;padding:7px 10px;border-radius:6px;font-size:13px;color:var(--kp-color-gray-700, var(--kp-color-gray-700));cursor:pointer;transition:background var(--kp-motion-duration-fast) ease,color .12s ease}.kp-theme-toggle__option:hover{background:var(--kp-color-gray-100, var(--kp-color-gray-100));color:var(--kp-color-gray-900, var(--kp-color-gray-900))}.kp-theme-toggle__option--selected{color:var(--kp-color-gray-900, var(--kp-color-gray-900));font-weight:500}.kp-theme-toggle__option-check{margin-inline-start:auto;color:var(--kp-color-blue-600, var(--kp-color-blue-600))}.kp-theme-toggle__menu .ti{font-size:18px;line-height:1}.kp-theme-toggle__menu--sm .ti{font-size:16px}.kp-theme-toggle__menu--md .ti{font-size:18px}.kp-theme-toggle__menu--lg .ti{font-size:20px}.kp-theme-toggle__menu .ti.kp-theme-toggle__option-check{font-size:14px}:host(.kp-theme-toggle--sm){--kp-theme-btn: 28px;--kp-theme-seg: 24px;--kp-theme-glyph: 16px}:host(.kp-theme-toggle--md){--kp-theme-btn: 36px;--kp-theme-seg: 28px;--kp-theme-glyph: 18px}:host(.kp-theme-toggle--lg){--kp-theme-btn: 44px;--kp-theme-seg: 36px;--kp-theme-glyph: 20px}\n"] }]
|
|
274
|
+
}], propDecorators: { variant: [{
|
|
275
|
+
type: Input
|
|
276
|
+
}], size: [{
|
|
277
|
+
type: Input
|
|
278
|
+
}], currentTheme: [{
|
|
279
|
+
type: Input
|
|
280
|
+
}], showLabel: [{
|
|
281
|
+
type: Input
|
|
282
|
+
}], themeChange: [{
|
|
283
|
+
type: Output
|
|
284
|
+
}], dropdownClick: [{
|
|
285
|
+
type: Output
|
|
286
|
+
}], menuEl: [{
|
|
287
|
+
type: ViewChild,
|
|
288
|
+
args: ['menu']
|
|
289
|
+
}], onDocClick: [{
|
|
290
|
+
type: HostListener,
|
|
291
|
+
args: ['document:click', ['$event']]
|
|
292
|
+
}], onEsc: [{
|
|
293
|
+
type: HostListener,
|
|
294
|
+
args: ['document:keydown.escape']
|
|
295
|
+
}] } });
|
|
296
|
+
|
|
297
|
+
/**
|
|
298
|
+
* Generated bundle index. Do not edit.
|
|
299
|
+
*/
|
|
300
|
+
|
|
301
|
+
export { KpThemeToggleComponent };
|
|
302
|
+
//# sourceMappingURL=kanso-protocol-theme-toggle.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kanso-protocol-theme-toggle.mjs","sources":["../../../../../packages/patterns/theme-toggle/src/theme-toggle.component.ts","../../../../../packages/patterns/theme-toggle/src/kanso-protocol-theme-toggle.ts"],"sourcesContent":["import {\n AfterViewChecked,\n ChangeDetectionStrategy,\n Component,\n ElementRef,\n EventEmitter,\n HostListener,\n Input,\n OnDestroy,\n Output,\n ViewChild,\n inject,\n signal,\n} from '@angular/core';\nimport { DOCUMENT } from '@angular/common';\nimport { KpIconComponent } from '@kanso-protocol/icon';\n\nexport type KpThemeToggleVariant = 'icon' | 'segmented' | 'dropdown';\nexport type KpThemeToggleSize = 'sm' | 'md' | 'lg';\nexport type KpThemeValue = 'light' | 'dark' | 'system';\n\nconst THEMES: KpThemeValue[] = ['light', 'dark', 'system'];\n\n/**\n * Kanso Protocol — ThemeToggle\n *\n * Three presentations for switching between light / dark / system\n * themes:\n * - `icon` — single icon button that cycles\n * - `segmented` — three inline icon segments, one selected\n * - `dropdown` — ghost button showing the current theme label; opens a menu\n *\n * The component emits `themeChange` when the user selects a value;\n * keeping the chosen theme (including `system`) up to the consumer.\n *\n * @example\n * <kp-theme-toggle\n * variant=\"segmented\"\n * [showLabel]=\"true\"\n * [currentTheme]=\"theme()\"\n * (themeChange)=\"theme.set($event)\"\n * />\n */\n@Component({\n selector: 'kp-theme-toggle',\n imports: [KpIconComponent],\n changeDetection: ChangeDetectionStrategy.OnPush,\n host: { '[class]': 'hostClasses' },\n template: `\n @if (variant === 'icon') {\n <button\n type=\"button\"\n class=\"kp-theme-toggle__icon-btn\"\n [attr.aria-label]=\"'Toggle theme (current: ' + currentTheme + ')'\"\n (click)=\"cycle()\"\n >\n <kp-icon [name]=\"iconName(currentTheme)\" />\n </button>\n } @else if (variant === 'segmented') {\n @if (showLabel) {\n <span class=\"kp-theme-toggle__label\">Theme</span>\n }\n <div class=\"kp-theme-toggle__segments\" role=\"tablist\" aria-label=\"Theme\">\n @for (t of themes; track t) {\n <button\n type=\"button\"\n role=\"tab\"\n class=\"kp-theme-toggle__segment\"\n [class.kp-theme-toggle__segment--selected]=\"currentTheme === t\"\n [attr.aria-selected]=\"currentTheme === t\"\n [attr.aria-label]=\"t\"\n (click)=\"select(t)\"\n >\n <kp-icon [name]=\"iconName(t)\" />\n </button>\n }\n </div>\n } @else {\n @if (showLabel) {\n <span class=\"kp-theme-toggle__label\">Theme</span>\n }\n <div class=\"kp-theme-toggle__dropdown-wrap\">\n <button\n type=\"button\"\n class=\"kp-theme-toggle__dropdown\"\n [class.kp-theme-toggle__dropdown--open]=\"isOpen()\"\n [attr.aria-haspopup]=\"'listbox'\"\n [attr.aria-expanded]=\"isOpen()\"\n (click)=\"toggleOpen()\"\n >\n <kp-icon [name]=\"iconName(currentTheme)\" />\n <span class=\"kp-theme-toggle__dropdown-label\">{{ themeLabel(currentTheme) }}</span>\n <kp-icon name=\"chevron-down\" class=\"kp-theme-toggle__chevron\" />\n </button>\n @if (isOpen()) {\n <div #menu class=\"kp-theme-toggle__menu\" role=\"listbox\" aria-label=\"Theme\">\n @for (t of themes; track t) {\n <button\n type=\"button\"\n role=\"option\"\n class=\"kp-theme-toggle__option\"\n [class.kp-theme-toggle__option--selected]=\"currentTheme === t\"\n [attr.aria-selected]=\"currentTheme === t\"\n (click)=\"selectFromMenu(t)\"\n >\n <kp-icon [name]=\"iconName(t)\" />\n <span>{{ themeLabel(t) }}</span>\n @if (currentTheme === t) {\n <kp-icon name=\"check\" class=\"kp-theme-toggle__option-check\" />\n }\n </button>\n }\n </div>\n }\n </div>\n }\n `,\n styles: [`\n :host {\n display: inline-flex;\n align-items: center;\n gap: 8px;\n font-family: var(--kp-font-family-sans, 'Onest', system-ui, sans-serif);\n }\n\n .kp-theme-toggle__label {\n font-size: 14px;\n color: var(--kp-color-gray-700, var(--kp-color-gray-700));\n }\n\n :host .ti {\n font-size: var(--kp-theme-glyph, 18px);\n line-height: 1;\n }\n :host .ti.kp-theme-toggle__chevron {\n font-size: 14px;\n color: var(--kp-color-gray-500, var(--kp-color-gray-500));\n }\n\n /* Icon variant */\n .kp-theme-toggle__icon-btn {\n all: unset;\n display: inline-flex;\n align-items: center;\n justify-content: center;\n width: var(--kp-theme-btn, 36px);\n height: var(--kp-theme-btn, 36px);\n border-radius: 8px;\n color: var(--kp-color-gray-600, var(--kp-color-gray-600));\n cursor: pointer;\n transition: background var(--kp-motion-duration-fast) ease, color 120ms ease;\n }\n .kp-theme-toggle__icon-btn:hover { background: var(--kp-color-gray-100, var(--kp-color-gray-100)); color: var(--kp-color-gray-900, var(--kp-color-gray-900)); }\n\n /* Segmented variant */\n .kp-theme-toggle__segments {\n display: inline-flex;\n align-items: center;\n gap: 2px;\n padding: 2px;\n border: 1px solid var(--kp-color-gray-200, var(--kp-color-gray-200));\n border-radius: 8px;\n background: var(--kp-color-gray-50, var(--kp-color-gray-50));\n }\n .kp-theme-toggle__segment {\n all: unset;\n display: inline-flex;\n align-items: center;\n justify-content: center;\n width: var(--kp-theme-seg, 28px);\n height: var(--kp-theme-seg, 28px);\n border-radius: 6px;\n color: var(--kp-color-gray-500, var(--kp-color-gray-500));\n cursor: pointer;\n transition: background var(--kp-motion-duration-fast) ease, color 120ms ease;\n }\n .kp-theme-toggle__segment:hover { color: var(--kp-color-gray-900, var(--kp-color-gray-900)); }\n .kp-theme-toggle__segment--selected {\n background: var(--kp-color-white, var(--kp-color-white));\n color: var(--kp-color-gray-900, var(--kp-color-gray-900));\n box-shadow: var(--kp-elevation-raised);\n }\n\n /* Dropdown variant */\n .kp-theme-toggle__dropdown {\n all: unset;\n display: inline-flex;\n align-items: center;\n gap: 8px;\n padding: 6px 10px;\n border-radius: 8px;\n color: var(--kp-color-gray-700, var(--kp-color-gray-700));\n font-size: 13px;\n font-weight: 500;\n cursor: pointer;\n transition: background var(--kp-motion-duration-fast) ease, color 120ms ease;\n }\n .kp-theme-toggle__dropdown:hover,\n .kp-theme-toggle__dropdown--open {\n background: var(--kp-color-gray-100, var(--kp-color-gray-100));\n color: var(--kp-color-gray-900, var(--kp-color-gray-900));\n }\n .kp-theme-toggle__dropdown-label { min-width: 44px; text-align: start; }\n\n .kp-theme-toggle__dropdown-wrap {\n position: relative;\n display: inline-block;\n }\n .kp-theme-toggle__menu {\n position: fixed;\n display: flex;\n flex-direction: column;\n padding: 4px;\n border-radius: 10px;\n background: var(--kp-color-white, var(--kp-color-white));\n border: 1px solid var(--kp-color-gray-200, var(--kp-color-gray-200));\n box-shadow: var(--kp-elevation-overlay);\n z-index: 1000;\n font-family: var(--kp-font-family-sans, 'Onest', system-ui, sans-serif);\n }\n .kp-theme-toggle__option {\n all: unset;\n display: flex;\n align-items: center;\n gap: 10px;\n padding: 7px 10px;\n border-radius: 6px;\n font-size: 13px;\n color: var(--kp-color-gray-700, var(--kp-color-gray-700));\n cursor: pointer;\n transition: background var(--kp-motion-duration-fast) ease, color 120ms ease;\n }\n .kp-theme-toggle__option:hover {\n background: var(--kp-color-gray-100, var(--kp-color-gray-100));\n color: var(--kp-color-gray-900, var(--kp-color-gray-900));\n }\n .kp-theme-toggle__option--selected {\n color: var(--kp-color-gray-900, var(--kp-color-gray-900));\n font-weight: 500;\n }\n .kp-theme-toggle__option-check {\n margin-inline-start: auto;\n color: var(--kp-color-blue-600, var(--kp-color-blue-600));\n }\n\n /* Menu icons — match trigger size. Scoped by size class instead of :host\n because the menu is portaled to <body> and escapes the host context. */\n .kp-theme-toggle__menu .ti { font-size: 18px; line-height: 1; }\n .kp-theme-toggle__menu--sm .ti { font-size: 16px; }\n .kp-theme-toggle__menu--md .ti { font-size: 18px; }\n .kp-theme-toggle__menu--lg .ti { font-size: 20px; }\n .kp-theme-toggle__menu .ti.kp-theme-toggle__option-check { font-size: 14px; }\n\n /* Sizes */\n :host(.kp-theme-toggle--sm) {\n --kp-theme-btn: 28px;\n --kp-theme-seg: 24px;\n --kp-theme-glyph: 16px;\n }\n :host(.kp-theme-toggle--md) {\n --kp-theme-btn: 36px;\n --kp-theme-seg: 28px;\n --kp-theme-glyph: 18px;\n }\n :host(.kp-theme-toggle--lg) {\n --kp-theme-btn: 44px;\n --kp-theme-seg: 36px;\n --kp-theme-glyph: 20px;\n }\n `],\n})\nexport class KpThemeToggleComponent implements AfterViewChecked, OnDestroy {\n @Input() variant: KpThemeToggleVariant = 'icon';\n @Input() size: KpThemeToggleSize = 'md';\n @Input() currentTheme: KpThemeValue = 'light';\n @Input() showLabel = false;\n\n @Output() themeChange = new EventEmitter<KpThemeValue>();\n @Output() dropdownClick = new EventEmitter<void>();\n\n readonly themes = THEMES;\n readonly isOpen = signal(false);\n\n @ViewChild('menu') menuEl?: ElementRef<HTMLElement>;\n\n private readonly hostRef = inject(ElementRef<HTMLElement>);\n private readonly doc = inject(DOCUMENT);\n private portaledMenu: HTMLElement | null = null;\n\n ngAfterViewChecked(): void {\n if (!this.isOpen()) return;\n const menu = this.menuEl?.nativeElement;\n // Portal menu to <body> so transformed/clipped ancestors can't clip it.\n if (menu && this.doc?.body && menu.parentElement !== this.doc.body) {\n // Tag the menu with the current size so size-scoped CSS applies after portal\n menu.classList.add(`kp-theme-toggle__menu--${this.size}`);\n this.doc.body.appendChild(menu);\n this.portaledMenu = menu;\n window.addEventListener('scroll', this.reposition, true);\n window.addEventListener('resize', this.reposition);\n }\n this.positionMenu();\n }\n\n ngOnDestroy(): void {\n this.cleanupMenu();\n }\n\n private cleanupMenu(): void {\n window.removeEventListener('scroll', this.reposition, true);\n window.removeEventListener('resize', this.reposition);\n if (this.portaledMenu && this.portaledMenu.parentElement === this.doc?.body) {\n this.portaledMenu.remove();\n }\n this.portaledMenu = null;\n }\n\n private closeMenu(): void {\n if (!this.isOpen()) return;\n this.cleanupMenu();\n this.isOpen.set(false);\n }\n\n private readonly reposition = () => this.positionMenu();\n\n private positionMenu(): void {\n const menu = this.menuEl?.nativeElement;\n const trigger = this.hostRef.nativeElement.querySelector('.kp-theme-toggle__dropdown') as HTMLElement | null;\n if (!menu || !trigger) return;\n const rect = trigger.getBoundingClientRect();\n menu.style.top = `${rect.bottom + 6}px`;\n menu.style.left = `${rect.left}px`;\n menu.style.right = 'auto';\n menu.style.width = `${rect.width}px`;\n }\n\n @HostListener('document:click', ['$event'])\n onDocClick(event: Event): void {\n if (!this.isOpen()) return;\n const target = event.target as Node;\n const host = this.hostRef.nativeElement;\n const portaled = this.portaledMenu;\n const insideHost = host && host.contains(target);\n const insideMenu = portaled && portaled.contains(target);\n if (!insideHost && !insideMenu) this.closeMenu();\n }\n\n @HostListener('document:keydown.escape')\n onEsc(): void {\n this.closeMenu();\n }\n\n toggleOpen(): void {\n if (this.isOpen()) {\n this.closeMenu();\n } else {\n this.isOpen.set(true);\n this.dropdownClick.emit();\n }\n }\n\n selectFromMenu(t: KpThemeValue): void {\n this.select(t);\n this.closeMenu();\n }\n\n get hostClasses(): string {\n return `kp-theme-toggle kp-theme-toggle--${this.variant} kp-theme-toggle--${this.size}`;\n }\n\n cycle(): void {\n const idx = THEMES.indexOf(this.currentTheme);\n const next = THEMES[(idx + 1) % THEMES.length];\n this.currentTheme = next;\n this.themeChange.emit(next);\n }\n\n select(t: KpThemeValue): void {\n if (t === this.currentTheme) return;\n this.currentTheme = t;\n this.themeChange.emit(t);\n }\n\n themeLabel(t: KpThemeValue): string {\n return t === 'light' ? 'Light' : t === 'dark' ? 'Dark' : 'System';\n }\n\n iconName(t: KpThemeValue): string {\n return t === 'light' ? 'sun-high' : t === 'dark' ? 'moon' : 'device-desktop';\n }\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;;AAqBA,MAAM,MAAM,GAAmB,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,CAAC;AAE1D;;;;;;;;;;;;;;;;;;;AAmBG;MAqOU,sBAAsB,CAAA;IACxB,OAAO,GAAyB,MAAM;IACtC,IAAI,GAAsB,IAAI;IAC9B,YAAY,GAAiB,OAAO;IACpC,SAAS,GAAG,KAAK;AAEhB,IAAA,WAA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,QAAA,EAAA,IAAA,EAAA,MAAA,EAAA,CAAA,4xHAAA,CAAA,EAAA,YAAA,EAAA,CAAA,EAAA,IAAA,EAAA,WAAA,EAAA,IAAA,EAvES,eAAe,EAAA,QAAA,EAAA,SAAA,EAAA,MAAA,EAAA,CAAA,MAAA,EAAA,MAAA,CAAA,EAAA,CAAA,EAAA,eAAA,EAAA,EAAA,CAAA,uBAAA,CAAA,MAAA,EAAA,CAAA;;2FAkOd,sBAAsB,EAAA,UAAA,EAAA,CAAA;kBApOlC,SAAS;AACE,YAAA,IAAA,EAAA,CAAA,EAAA,QAAA,EAAA,iBAAiB,EAAA,OAAA,EAClB,CAAC,eAAe,CAAC,mBACT,uBAAuB,CAAC,MAAM,EAAA,IAAA,EACzC,EAAE,SAAS,EAAE,aAAa,EAAE,EAAA,QAAA,EACxB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoET,EAAA,CAAA,EAAA,MAAA,EAAA,CAAA,4xHAAA,CAAA,EAAA;;sBA4JA;;sBACA;;sBACA;;sBACA;;sBAEA;;sBACA;;sBAKA,SAAS;uBAAC,MAAM;;sBAqDhB,YAAY;uBAAC,gBAAgB,EAAE,CAAC,QAAQ,CAAC;;sBAWzC,YAAY;uBAAC,yBAAyB;;;AC3VzC;;AAEG;;;;"}
|
package/package.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@kanso-protocol/theme-toggle",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"peerDependencies": {
|
|
6
|
+
"@angular/core": "^18.0.0",
|
|
7
|
+
"@angular/common": "^18.0.0",
|
|
8
|
+
"@kanso-protocol/core": "^0.0.1"
|
|
9
|
+
},
|
|
10
|
+
"description": "Kanso Protocol — theme-toggle (pattern).",
|
|
11
|
+
"author": "GregNBlack",
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "https://github.com/GregNBlack/kanso-protocol.git",
|
|
15
|
+
"directory": "packages/patterns/theme-toggle"
|
|
16
|
+
},
|
|
17
|
+
"homepage": "https://gregnblack.github.io/kanso-protocol/?path=/docs/patterns-themetoggle--docs",
|
|
18
|
+
"bugs": "https://github.com/GregNBlack/kanso-protocol/issues",
|
|
19
|
+
"keywords": [
|
|
20
|
+
"design-system",
|
|
21
|
+
"angular",
|
|
22
|
+
"kanso",
|
|
23
|
+
"theme-toggle"
|
|
24
|
+
],
|
|
25
|
+
"sideEffects": false,
|
|
26
|
+
"module": "fesm2022/kanso-protocol-theme-toggle.mjs",
|
|
27
|
+
"typings": "types/kanso-protocol-theme-toggle.d.ts",
|
|
28
|
+
"exports": {
|
|
29
|
+
"./package.json": {
|
|
30
|
+
"default": "./package.json"
|
|
31
|
+
},
|
|
32
|
+
".": {
|
|
33
|
+
"types": "./types/kanso-protocol-theme-toggle.d.ts",
|
|
34
|
+
"default": "./fesm2022/kanso-protocol-theme-toggle.mjs"
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
"type": "module",
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"tslib": "^2.3.0"
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import * as i0 from '@angular/core';
|
|
2
|
+
import { AfterViewChecked, OnDestroy, EventEmitter, ElementRef } from '@angular/core';
|
|
3
|
+
|
|
4
|
+
type KpThemeToggleVariant = 'icon' | 'segmented' | 'dropdown';
|
|
5
|
+
type KpThemeToggleSize = 'sm' | 'md' | 'lg';
|
|
6
|
+
type KpThemeValue = 'light' | 'dark' | 'system';
|
|
7
|
+
/**
|
|
8
|
+
* Kanso Protocol — ThemeToggle
|
|
9
|
+
*
|
|
10
|
+
* Three presentations for switching between light / dark / system
|
|
11
|
+
* themes:
|
|
12
|
+
* - `icon` — single icon button that cycles
|
|
13
|
+
* - `segmented` — three inline icon segments, one selected
|
|
14
|
+
* - `dropdown` — ghost button showing the current theme label; opens a menu
|
|
15
|
+
*
|
|
16
|
+
* The component emits `themeChange` when the user selects a value;
|
|
17
|
+
* keeping the chosen theme (including `system`) up to the consumer.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* <kp-theme-toggle
|
|
21
|
+
* variant="segmented"
|
|
22
|
+
* [showLabel]="true"
|
|
23
|
+
* [currentTheme]="theme()"
|
|
24
|
+
* (themeChange)="theme.set($event)"
|
|
25
|
+
* />
|
|
26
|
+
*/
|
|
27
|
+
declare class KpThemeToggleComponent implements AfterViewChecked, OnDestroy {
|
|
28
|
+
variant: KpThemeToggleVariant;
|
|
29
|
+
size: KpThemeToggleSize;
|
|
30
|
+
currentTheme: KpThemeValue;
|
|
31
|
+
showLabel: boolean;
|
|
32
|
+
themeChange: EventEmitter<KpThemeValue>;
|
|
33
|
+
dropdownClick: EventEmitter<void>;
|
|
34
|
+
readonly themes: KpThemeValue[];
|
|
35
|
+
readonly isOpen: i0.WritableSignal<boolean>;
|
|
36
|
+
menuEl?: ElementRef<HTMLElement>;
|
|
37
|
+
private readonly hostRef;
|
|
38
|
+
private readonly doc;
|
|
39
|
+
private portaledMenu;
|
|
40
|
+
ngAfterViewChecked(): void;
|
|
41
|
+
ngOnDestroy(): void;
|
|
42
|
+
private cleanupMenu;
|
|
43
|
+
private closeMenu;
|
|
44
|
+
private readonly reposition;
|
|
45
|
+
private positionMenu;
|
|
46
|
+
onDocClick(event: Event): void;
|
|
47
|
+
onEsc(): void;
|
|
48
|
+
toggleOpen(): void;
|
|
49
|
+
selectFromMenu(t: KpThemeValue): void;
|
|
50
|
+
get hostClasses(): string;
|
|
51
|
+
cycle(): void;
|
|
52
|
+
select(t: KpThemeValue): void;
|
|
53
|
+
themeLabel(t: KpThemeValue): string;
|
|
54
|
+
iconName(t: KpThemeValue): string;
|
|
55
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<KpThemeToggleComponent, never>;
|
|
56
|
+
static ɵcmp: i0.ɵɵComponentDeclaration<KpThemeToggleComponent, "kp-theme-toggle", never, { "variant": { "alias": "variant"; "required": false; }; "size": { "alias": "size"; "required": false; }; "currentTheme": { "alias": "currentTheme"; "required": false; }; "showLabel": { "alias": "showLabel"; "required": false; }; }, { "themeChange": "themeChange"; "dropdownClick": "dropdownClick"; }, never, never, true, never>;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export { KpThemeToggleComponent };
|
|
60
|
+
export type { KpThemeToggleSize, KpThemeToggleVariant, KpThemeValue };
|