@miozu/jera 0.8.0 → 0.8.2
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/CLAUDE.md +21 -6
- package/README.md +53 -8
- package/package.json +6 -4
- package/src/components/layout/PageHeader.svelte +3 -3
- package/src/components/navigation/ScrollNav.svelte +4 -4
- package/src/components/primitives/MemberCard.svelte +7 -7
- package/src/components/primitives/MetricCard.svelte +33 -56
- package/src/components/primitives/ThemeSelect.svelte +260 -0
- package/src/components/primitives/ThemeToggle.svelte +263 -0
- package/src/components/primitives/Tooltip.svelte +10 -1
- package/src/index.js +2 -0
package/CLAUDE.md
CHANGED
|
@@ -58,13 +58,28 @@ Singleton pattern with `miozu-theme` storage key.
|
|
|
58
58
|
|
|
59
59
|
**Full reference:** `docs/ai-context/theme-management.md`
|
|
60
60
|
|
|
61
|
+
**ThemeToggle:** Accessible toggle with animated sun/moon icons
|
|
61
62
|
```svelte
|
|
62
|
-
|
|
63
|
-
<
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
63
|
+
import { ThemeToggle } from '@miozu/jera';
|
|
64
|
+
<ThemeToggle />
|
|
65
|
+
<ThemeToggle size="sm" variant="outline" />
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
**ThemeSelect:** Three-option selector (light/dark/system)
|
|
69
|
+
```svelte
|
|
70
|
+
import { ThemeSelect } from '@miozu/jera';
|
|
71
|
+
<ThemeSelect />
|
|
72
|
+
<ThemeSelect variant="dropdown" />
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
**ThemeState API:**
|
|
76
|
+
```javascript
|
|
77
|
+
import { getTheme } from '@miozu/jera';
|
|
78
|
+
const theme = getTheme();
|
|
79
|
+
theme.init(); // Call once in root onMount
|
|
80
|
+
theme.toggle(); // Switch dark/light
|
|
81
|
+
theme.set('system'); // Follow OS preference
|
|
82
|
+
theme.isDark; // boolean reactive property
|
|
68
83
|
```
|
|
69
84
|
|
|
70
85
|
## Svelte 5 Patterns
|
package/README.md
CHANGED
|
@@ -176,23 +176,68 @@ button({ variant: 'secondary' }); // => "inline-flex items-center bg-surface h-1
|
|
|
176
176
|
|
|
177
177
|
Dark theme is default. Uses singleton pattern with `miozu-theme` storage key.
|
|
178
178
|
|
|
179
|
-
|
|
180
|
-
// In root +layout.svelte
|
|
181
|
-
import { getTheme } from '@miozu/jera';
|
|
182
|
-
import { onMount } from 'svelte';
|
|
179
|
+
### Setup
|
|
183
180
|
|
|
184
|
-
|
|
185
|
-
|
|
181
|
+
```svelte
|
|
182
|
+
<!-- +layout.svelte -->
|
|
183
|
+
<script>
|
|
184
|
+
import { getTheme } from '@miozu/jera';
|
|
185
|
+
import { onMount } from 'svelte';
|
|
186
|
+
|
|
187
|
+
const theme = getTheme();
|
|
188
|
+
onMount(() => theme.init());
|
|
189
|
+
</script>
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
### ThemeToggle
|
|
193
|
+
|
|
194
|
+
Accessible toggle button with animated sun/moon icons.
|
|
195
|
+
|
|
196
|
+
```svelte
|
|
197
|
+
<script>
|
|
198
|
+
import { ThemeToggle } from '@miozu/jera';
|
|
199
|
+
</script>
|
|
200
|
+
|
|
201
|
+
<ThemeToggle />
|
|
202
|
+
<ThemeToggle size="sm" variant="outline" />
|
|
203
|
+
<ThemeToggle size="lg" variant="subtle" />
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
Props: `size` (sm|md|lg), `variant` (ghost|outline|subtle), `themeState` (optional)
|
|
207
|
+
|
|
208
|
+
### ThemeSelect
|
|
209
|
+
|
|
210
|
+
Three-option selector for light/dark/system preference.
|
|
211
|
+
|
|
212
|
+
```svelte
|
|
213
|
+
<script>
|
|
214
|
+
import { ThemeSelect } from '@miozu/jera';
|
|
215
|
+
</script>
|
|
216
|
+
|
|
217
|
+
<!-- Segmented control (default) -->
|
|
218
|
+
<ThemeSelect />
|
|
219
|
+
|
|
220
|
+
<!-- Dropdown -->
|
|
221
|
+
<ThemeSelect variant="dropdown" />
|
|
222
|
+
|
|
223
|
+
<!-- Custom labels -->
|
|
224
|
+
<ThemeSelect labels={{ light: 'Light', dark: 'Dark', system: 'Auto' }} />
|
|
186
225
|
```
|
|
187
226
|
|
|
227
|
+
Props: `variant` (segmented|dropdown), `size` (sm|md|lg), `labels`, `showIcons`
|
|
228
|
+
|
|
229
|
+
### ThemeState API
|
|
230
|
+
|
|
188
231
|
```javascript
|
|
189
|
-
// Anywhere in your app
|
|
190
232
|
import { getTheme } from '@miozu/jera';
|
|
191
233
|
|
|
192
234
|
const theme = getTheme();
|
|
193
235
|
theme.toggle(); // Switch between light/dark
|
|
194
236
|
theme.set('system'); // Follow system preference
|
|
195
|
-
theme.isDark; // boolean
|
|
237
|
+
theme.isDark; // boolean - resolved dark mode
|
|
238
|
+
theme.isLight; // boolean - resolved light mode
|
|
239
|
+
theme.current; // 'light' | 'dark' | 'system'
|
|
240
|
+
theme.dataTheme; // 'miozu-light' | 'miozu-dark'
|
|
196
241
|
```
|
|
197
242
|
|
|
198
243
|
Data-theme values: `miozu-dark` (default) or `miozu-light`.
|
package/package.json
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@miozu/jera",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.2",
|
|
4
4
|
"description": "Zero-dependency, AI-first component library for Svelte 5",
|
|
5
5
|
"type": "module",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"prepublishOnly": "echo 'Publishing @miozu/jera...' && test -f src/index.js"
|
|
8
|
+
},
|
|
6
9
|
"svelte": "./src/index.js",
|
|
7
10
|
"exports": {
|
|
8
11
|
".": {
|
|
@@ -55,6 +58,5 @@
|
|
|
55
58
|
"bugs": {
|
|
56
59
|
"url": "https://github.com/miozu-com/jera/issues"
|
|
57
60
|
},
|
|
58
|
-
"dependencies": {}
|
|
59
|
-
|
|
60
|
-
}
|
|
61
|
+
"dependencies": {}
|
|
62
|
+
}
|
|
@@ -142,8 +142,8 @@
|
|
|
142
142
|
display: flex;
|
|
143
143
|
align-items: center;
|
|
144
144
|
justify-content: center;
|
|
145
|
-
width:
|
|
146
|
-
height:
|
|
145
|
+
width: var(--space-10);
|
|
146
|
+
height: var(--space-10);
|
|
147
147
|
border-radius: var(--radius-lg);
|
|
148
148
|
background: color-mix(in srgb, var(--color-base0D) 10%, transparent);
|
|
149
149
|
color: var(--color-base0D);
|
|
@@ -255,7 +255,7 @@
|
|
|
255
255
|
.toolbar-search {
|
|
256
256
|
flex: 1;
|
|
257
257
|
min-width: 0;
|
|
258
|
-
max-width: 24rem;
|
|
258
|
+
max-width: var(--page-header-search-max-width, 24rem);
|
|
259
259
|
}
|
|
260
260
|
|
|
261
261
|
.toolbar-filters {
|
|
@@ -145,17 +145,17 @@
|
|
|
145
145
|
display: flex;
|
|
146
146
|
align-items: center;
|
|
147
147
|
justify-content: center;
|
|
148
|
-
width:
|
|
149
|
-
height:
|
|
148
|
+
width: var(--space-8);
|
|
149
|
+
height: var(--space-8);
|
|
150
150
|
padding: 0;
|
|
151
151
|
background: var(--color-base01);
|
|
152
152
|
border: 1px solid var(--color-base02);
|
|
153
|
-
border-radius:
|
|
153
|
+
border-radius: var(--radius-full);
|
|
154
154
|
color: var(--color-base05);
|
|
155
155
|
cursor: pointer;
|
|
156
156
|
pointer-events: all;
|
|
157
157
|
transition: all 0.15s ease;
|
|
158
|
-
box-shadow:
|
|
158
|
+
box-shadow: var(--shadow-sm);
|
|
159
159
|
}
|
|
160
160
|
|
|
161
161
|
.scroll-btn:hover {
|
|
@@ -164,16 +164,16 @@
|
|
|
164
164
|
.member-avatar {
|
|
165
165
|
position: relative;
|
|
166
166
|
flex-shrink: 0;
|
|
167
|
-
width:
|
|
168
|
-
height:
|
|
167
|
+
width: var(--space-10);
|
|
168
|
+
height: var(--space-10);
|
|
169
169
|
border-radius: var(--radius-lg);
|
|
170
170
|
background: color-mix(in srgb, var(--color-base0D) 15%, transparent);
|
|
171
171
|
overflow: hidden;
|
|
172
172
|
}
|
|
173
173
|
|
|
174
174
|
.member-card-compact .member-avatar {
|
|
175
|
-
width:
|
|
176
|
-
height:
|
|
175
|
+
width: var(--space-8);
|
|
176
|
+
height: var(--space-8);
|
|
177
177
|
border-radius: var(--radius-md);
|
|
178
178
|
}
|
|
179
179
|
|
|
@@ -202,9 +202,9 @@
|
|
|
202
202
|
position: absolute;
|
|
203
203
|
bottom: 0;
|
|
204
204
|
right: 0;
|
|
205
|
-
width:
|
|
206
|
-
height:
|
|
207
|
-
border-radius:
|
|
205
|
+
width: var(--space-3);
|
|
206
|
+
height: var(--space-3);
|
|
207
|
+
border-radius: var(--radius-full);
|
|
208
208
|
border: 2px solid var(--color-base00);
|
|
209
209
|
}
|
|
210
210
|
|
|
@@ -67,39 +67,43 @@
|
|
|
67
67
|
});
|
|
68
68
|
</script>
|
|
69
69
|
|
|
70
|
+
{#snippet cardContent()}
|
|
71
|
+
<div class="metric-header">
|
|
72
|
+
{#if icon}
|
|
73
|
+
<span class="metric-icon">
|
|
74
|
+
{@render icon()}
|
|
75
|
+
</span>
|
|
76
|
+
{/if}
|
|
77
|
+
<span class="metric-label">{label}</span>
|
|
78
|
+
{#if badge}
|
|
79
|
+
<span class="metric-badge">
|
|
80
|
+
{@render badge()}
|
|
81
|
+
</span>
|
|
82
|
+
{/if}
|
|
83
|
+
</div>
|
|
84
|
+
|
|
85
|
+
<div class="metric-body">
|
|
86
|
+
<span class="metric-value {status ? `metric-value-${status}` : ''}">
|
|
87
|
+
{value}{#if unit}<span class="metric-unit">{unit}</span>{/if}
|
|
88
|
+
</span>
|
|
89
|
+
{#if sublabel}
|
|
90
|
+
<span class="metric-sublabel">{sublabel}</span>
|
|
91
|
+
{/if}
|
|
92
|
+
</div>
|
|
93
|
+
|
|
94
|
+
{#if progress !== null}
|
|
95
|
+
<div class="metric-progress">
|
|
96
|
+
<div class="metric-progress-bar {progressVariant}" style="width: {Math.min(100, Math.max(0, progress))}%"></div>
|
|
97
|
+
</div>
|
|
98
|
+
{/if}
|
|
99
|
+
{/snippet}
|
|
100
|
+
|
|
70
101
|
{#if href}
|
|
71
102
|
<a
|
|
72
103
|
{href}
|
|
73
104
|
class="metric-card {status ? `metric-card-${status}` : ''} metric-card-clickable {className}"
|
|
74
105
|
>
|
|
75
|
-
|
|
76
|
-
{#if icon}
|
|
77
|
-
<span class="metric-icon">
|
|
78
|
-
{@render icon()}
|
|
79
|
-
</span>
|
|
80
|
-
{/if}
|
|
81
|
-
<span class="metric-label">{label}</span>
|
|
82
|
-
{#if badge}
|
|
83
|
-
<span class="metric-badge">
|
|
84
|
-
{@render badge()}
|
|
85
|
-
</span>
|
|
86
|
-
{/if}
|
|
87
|
-
</div>
|
|
88
|
-
|
|
89
|
-
<div class="metric-body">
|
|
90
|
-
<span class="metric-value {status ? `metric-value-${status}` : ''}">
|
|
91
|
-
{value}{#if unit}<span class="metric-unit">{unit}</span>{/if}
|
|
92
|
-
</span>
|
|
93
|
-
{#if sublabel}
|
|
94
|
-
<span class="metric-sublabel">{sublabel}</span>
|
|
95
|
-
{/if}
|
|
96
|
-
</div>
|
|
97
|
-
|
|
98
|
-
{#if progress !== null}
|
|
99
|
-
<div class="metric-progress">
|
|
100
|
-
<div class="metric-progress-bar {progressVariant}" style="width: {Math.min(100, Math.max(0, progress))}%"></div>
|
|
101
|
-
</div>
|
|
102
|
-
{/if}
|
|
106
|
+
{@render cardContent()}
|
|
103
107
|
</a>
|
|
104
108
|
{:else}
|
|
105
109
|
<div
|
|
@@ -108,34 +112,7 @@
|
|
|
108
112
|
role={onclick ? 'button' : undefined}
|
|
109
113
|
tabindex={onclick ? 0 : undefined}
|
|
110
114
|
>
|
|
111
|
-
|
|
112
|
-
{#if icon}
|
|
113
|
-
<span class="metric-icon">
|
|
114
|
-
{@render icon()}
|
|
115
|
-
</span>
|
|
116
|
-
{/if}
|
|
117
|
-
<span class="metric-label">{label}</span>
|
|
118
|
-
{#if badge}
|
|
119
|
-
<span class="metric-badge">
|
|
120
|
-
{@render badge()}
|
|
121
|
-
</span>
|
|
122
|
-
{/if}
|
|
123
|
-
</div>
|
|
124
|
-
|
|
125
|
-
<div class="metric-body">
|
|
126
|
-
<span class="metric-value {status ? `metric-value-${status}` : ''}">
|
|
127
|
-
{value}{#if unit}<span class="metric-unit">{unit}</span>{/if}
|
|
128
|
-
</span>
|
|
129
|
-
{#if sublabel}
|
|
130
|
-
<span class="metric-sublabel">{sublabel}</span>
|
|
131
|
-
{/if}
|
|
132
|
-
</div>
|
|
133
|
-
|
|
134
|
-
{#if progress !== null}
|
|
135
|
-
<div class="metric-progress">
|
|
136
|
-
<div class="metric-progress-bar {progressVariant}" style="width: {Math.min(100, Math.max(0, progress))}%"></div>
|
|
137
|
-
</div>
|
|
138
|
-
{/if}
|
|
115
|
+
{@render cardContent()}
|
|
139
116
|
</div>
|
|
140
117
|
{/if}
|
|
141
118
|
|
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
@component ThemeSelect
|
|
3
|
+
|
|
4
|
+
A dropdown/segmented selector for theme preference with light/dark/system options.
|
|
5
|
+
Uses the Jera ThemeState singleton for theme management.
|
|
6
|
+
|
|
7
|
+
@example Basic dropdown
|
|
8
|
+
<ThemeSelect />
|
|
9
|
+
|
|
10
|
+
@example Segmented control style
|
|
11
|
+
<ThemeSelect variant="segmented" />
|
|
12
|
+
|
|
13
|
+
@example With custom theme state
|
|
14
|
+
<ThemeSelect themeState={myThemeState} />
|
|
15
|
+
|
|
16
|
+
@example Custom labels
|
|
17
|
+
<ThemeSelect
|
|
18
|
+
labels={{ light: 'Light', dark: 'Dark', system: 'Auto' }}
|
|
19
|
+
/>
|
|
20
|
+
-->
|
|
21
|
+
<script>
|
|
22
|
+
import { cn } from '../../utils/cn.svelte.js';
|
|
23
|
+
import { getTheme, generateId } from '../../utils/reactive.svelte.js';
|
|
24
|
+
|
|
25
|
+
let {
|
|
26
|
+
themeState,
|
|
27
|
+
variant = 'segmented',
|
|
28
|
+
size = 'md',
|
|
29
|
+
labels = { light: 'Light', dark: 'Dark', system: 'System' },
|
|
30
|
+
showIcons = true,
|
|
31
|
+
class: className = '',
|
|
32
|
+
...rest
|
|
33
|
+
} = $props();
|
|
34
|
+
|
|
35
|
+
// Use provided themeState or fall back to singleton
|
|
36
|
+
const theme = themeState ?? getTheme();
|
|
37
|
+
const groupId = generateId();
|
|
38
|
+
|
|
39
|
+
// Current preference (not resolved)
|
|
40
|
+
const current = $derived(theme.current);
|
|
41
|
+
|
|
42
|
+
// Size mappings
|
|
43
|
+
const sizes = {
|
|
44
|
+
sm: { wrapper: 'theme-select-sm', icon: 14 },
|
|
45
|
+
md: { wrapper: 'theme-select-md', icon: 16 },
|
|
46
|
+
lg: { wrapper: 'theme-select-lg', icon: 18 }
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const currentSize = $derived(sizes[size] || sizes.md);
|
|
50
|
+
|
|
51
|
+
const options = [
|
|
52
|
+
{ value: 'light', label: labels.light, icon: 'sun' },
|
|
53
|
+
{ value: 'dark', label: labels.dark, icon: 'moon' },
|
|
54
|
+
{ value: 'system', label: labels.system, icon: 'monitor' }
|
|
55
|
+
];
|
|
56
|
+
|
|
57
|
+
function handleChange(value) {
|
|
58
|
+
theme.set(value);
|
|
59
|
+
}
|
|
60
|
+
</script>
|
|
61
|
+
|
|
62
|
+
{#if variant === 'segmented'}
|
|
63
|
+
<div
|
|
64
|
+
class={cn('theme-select-segmented', currentSize.wrapper, className)}
|
|
65
|
+
role="radiogroup"
|
|
66
|
+
aria-label="Theme preference"
|
|
67
|
+
{...rest}
|
|
68
|
+
>
|
|
69
|
+
{#each options as option (option.value)}
|
|
70
|
+
{@const isActive = current === option.value}
|
|
71
|
+
<button
|
|
72
|
+
type="button"
|
|
73
|
+
role="radio"
|
|
74
|
+
aria-checked={isActive}
|
|
75
|
+
class={cn('theme-select-option', isActive && 'theme-select-option-active')}
|
|
76
|
+
onclick={() => handleChange(option.value)}
|
|
77
|
+
>
|
|
78
|
+
{#if showIcons}
|
|
79
|
+
<span class="theme-select-icon" aria-hidden="true">
|
|
80
|
+
{#if option.icon === 'sun'}
|
|
81
|
+
<svg width={currentSize.icon} height={currentSize.icon} viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
82
|
+
<circle cx="12" cy="12" r="4" />
|
|
83
|
+
<path d="M12 2v2M12 20v2M4.93 4.93l1.41 1.41M17.66 17.66l1.41 1.41M2 12h2M20 12h2M6.34 17.66l-1.41 1.41M19.07 4.93l-1.41 1.41" />
|
|
84
|
+
</svg>
|
|
85
|
+
{:else if option.icon === 'moon'}
|
|
86
|
+
<svg width={currentSize.icon} height={currentSize.icon} viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
87
|
+
<path d="M12 3a6 6 0 0 0 9 9 9 9 0 1 1-9-9Z" />
|
|
88
|
+
</svg>
|
|
89
|
+
{:else if option.icon === 'monitor'}
|
|
90
|
+
<svg width={currentSize.icon} height={currentSize.icon} viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
91
|
+
<rect width="20" height="14" x="2" y="3" rx="2" />
|
|
92
|
+
<line x1="8" x2="16" y1="21" y2="21" />
|
|
93
|
+
<line x1="12" x2="12" y1="17" y2="21" />
|
|
94
|
+
</svg>
|
|
95
|
+
{/if}
|
|
96
|
+
</span>
|
|
97
|
+
{/if}
|
|
98
|
+
<span class="theme-select-label">{option.label}</span>
|
|
99
|
+
</button>
|
|
100
|
+
{/each}
|
|
101
|
+
</div>
|
|
102
|
+
{:else}
|
|
103
|
+
<!-- Dropdown variant -->
|
|
104
|
+
<div class={cn('theme-select-dropdown', currentSize.wrapper, className)} {...rest}>
|
|
105
|
+
<select
|
|
106
|
+
id={groupId}
|
|
107
|
+
value={current}
|
|
108
|
+
onchange={(e) => handleChange(e.target.value)}
|
|
109
|
+
aria-label="Theme preference"
|
|
110
|
+
class="theme-select-native"
|
|
111
|
+
>
|
|
112
|
+
{#each options as option (option.value)}
|
|
113
|
+
<option value={option.value}>{option.label}</option>
|
|
114
|
+
{/each}
|
|
115
|
+
</select>
|
|
116
|
+
<span class="theme-select-dropdown-icon" aria-hidden="true">
|
|
117
|
+
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
118
|
+
<path d="m6 9 6 6 6-6" />
|
|
119
|
+
</svg>
|
|
120
|
+
</span>
|
|
121
|
+
</div>
|
|
122
|
+
{/if}
|
|
123
|
+
|
|
124
|
+
<style>
|
|
125
|
+
/* ============================================
|
|
126
|
+
SEGMENTED CONTROL
|
|
127
|
+
============================================ */
|
|
128
|
+
.theme-select-segmented {
|
|
129
|
+
display: inline-flex;
|
|
130
|
+
align-items: center;
|
|
131
|
+
background-color: var(--color-base01, #282828);
|
|
132
|
+
border-radius: var(--radius-md, 0.375rem);
|
|
133
|
+
padding: 2px;
|
|
134
|
+
gap: 2px;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
.theme-select-option {
|
|
138
|
+
display: inline-flex;
|
|
139
|
+
align-items: center;
|
|
140
|
+
justify-content: center;
|
|
141
|
+
gap: var(--space-1, 0.25rem);
|
|
142
|
+
padding: var(--space-1, 0.25rem) var(--space-3, 0.75rem);
|
|
143
|
+
border: none;
|
|
144
|
+
border-radius: calc(var(--radius-md, 0.375rem) - 2px);
|
|
145
|
+
background-color: transparent;
|
|
146
|
+
color: var(--color-base04, #665c54);
|
|
147
|
+
font-size: var(--text-sm, 0.875rem);
|
|
148
|
+
font-weight: 500;
|
|
149
|
+
cursor: pointer;
|
|
150
|
+
transition:
|
|
151
|
+
background-color var(--duration-fast, 150ms) var(--ease-out, ease-out),
|
|
152
|
+
color var(--duration-fast, 150ms) var(--ease-out, ease-out);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
.theme-select-option:hover:not(.theme-select-option-active) {
|
|
156
|
+
color: var(--color-base05, #a89984);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
.theme-select-option:focus-visible {
|
|
160
|
+
outline: 2px solid var(--color-base0D, #83a598);
|
|
161
|
+
outline-offset: -2px;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
.theme-select-option-active {
|
|
165
|
+
background-color: var(--color-base02, #3c3836);
|
|
166
|
+
color: var(--color-base06, #d5c4a1);
|
|
167
|
+
box-shadow: var(--shadow-sm, 0 1px 2px rgba(0, 0, 0, 0.1));
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
.theme-select-icon {
|
|
171
|
+
display: flex;
|
|
172
|
+
align-items: center;
|
|
173
|
+
justify-content: center;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
.theme-select-label {
|
|
177
|
+
white-space: nowrap;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/* ============================================
|
|
181
|
+
SIZES - SEGMENTED
|
|
182
|
+
============================================ */
|
|
183
|
+
.theme-select-sm .theme-select-option {
|
|
184
|
+
padding: 2px var(--space-2, 0.5rem);
|
|
185
|
+
font-size: var(--text-xs, 0.75rem);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
.theme-select-md .theme-select-option {
|
|
189
|
+
padding: var(--space-1, 0.25rem) var(--space-3, 0.75rem);
|
|
190
|
+
font-size: var(--text-sm, 0.875rem);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
.theme-select-lg .theme-select-option {
|
|
194
|
+
padding: var(--space-2, 0.5rem) var(--space-4, 1rem);
|
|
195
|
+
font-size: var(--text-base, 1rem);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/* ============================================
|
|
199
|
+
DROPDOWN
|
|
200
|
+
============================================ */
|
|
201
|
+
.theme-select-dropdown {
|
|
202
|
+
position: relative;
|
|
203
|
+
display: inline-flex;
|
|
204
|
+
align-items: center;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
.theme-select-native {
|
|
208
|
+
appearance: none;
|
|
209
|
+
background-color: var(--color-base01, #282828);
|
|
210
|
+
border: 1px solid var(--color-base03, #504945);
|
|
211
|
+
border-radius: var(--radius-md, 0.375rem);
|
|
212
|
+
color: var(--color-base06, #d5c4a1);
|
|
213
|
+
font-size: var(--text-sm, 0.875rem);
|
|
214
|
+
padding: var(--space-2, 0.5rem) var(--space-8, 2rem) var(--space-2, 0.5rem) var(--space-3, 0.75rem);
|
|
215
|
+
cursor: pointer;
|
|
216
|
+
transition:
|
|
217
|
+
border-color var(--duration-fast, 150ms) var(--ease-out, ease-out),
|
|
218
|
+
background-color var(--duration-fast, 150ms) var(--ease-out, ease-out);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
.theme-select-native:hover {
|
|
222
|
+
border-color: var(--color-base04, #665c54);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
.theme-select-native:focus {
|
|
226
|
+
outline: none;
|
|
227
|
+
border-color: var(--color-base0D, #83a598);
|
|
228
|
+
box-shadow: 0 0 0 2px color-mix(in srgb, var(--color-base0D, #83a598) 20%, transparent);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
.theme-select-dropdown-icon {
|
|
232
|
+
position: absolute;
|
|
233
|
+
right: var(--space-2, 0.5rem);
|
|
234
|
+
pointer-events: none;
|
|
235
|
+
color: var(--color-base04, #665c54);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/* ============================================
|
|
239
|
+
SIZES - DROPDOWN
|
|
240
|
+
============================================ */
|
|
241
|
+
.theme-select-dropdown.theme-select-sm .theme-select-native {
|
|
242
|
+
padding: var(--space-1, 0.25rem) var(--space-6, 1.5rem) var(--space-1, 0.25rem) var(--space-2, 0.5rem);
|
|
243
|
+
font-size: var(--text-xs, 0.75rem);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
.theme-select-dropdown.theme-select-lg .theme-select-native {
|
|
247
|
+
padding: var(--space-3, 0.75rem) var(--space-10, 2.5rem) var(--space-3, 0.75rem) var(--space-4, 1rem);
|
|
248
|
+
font-size: var(--text-base, 1rem);
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/* ============================================
|
|
252
|
+
REDUCED MOTION
|
|
253
|
+
============================================ */
|
|
254
|
+
@media (prefers-reduced-motion: reduce) {
|
|
255
|
+
.theme-select-option,
|
|
256
|
+
.theme-select-native {
|
|
257
|
+
transition: none;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
</style>
|
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
@component ThemeToggle
|
|
3
|
+
|
|
4
|
+
An accessible theme toggle button with animated sun/moon icons.
|
|
5
|
+
Uses the Jera ThemeState singleton for theme management.
|
|
6
|
+
|
|
7
|
+
@example Basic usage
|
|
8
|
+
<ThemeToggle />
|
|
9
|
+
|
|
10
|
+
@example With custom theme state
|
|
11
|
+
<ThemeToggle themeState={myThemeState} />
|
|
12
|
+
|
|
13
|
+
@example Different sizes
|
|
14
|
+
<ThemeToggle size="sm" />
|
|
15
|
+
<ThemeToggle size="lg" />
|
|
16
|
+
|
|
17
|
+
@example With label
|
|
18
|
+
<ThemeToggle>
|
|
19
|
+
{#snippet label()}Dark mode{/snippet}
|
|
20
|
+
</ThemeToggle>
|
|
21
|
+
|
|
22
|
+
@example Custom icons via snippets
|
|
23
|
+
<ThemeToggle>
|
|
24
|
+
{#snippet sunIcon()}<MyCustomSun />{/snippet}
|
|
25
|
+
{#snippet moonIcon()}<MyCustomMoon />{/snippet}
|
|
26
|
+
</ThemeToggle>
|
|
27
|
+
-->
|
|
28
|
+
<script>
|
|
29
|
+
import { cn } from '../../utils/cn.svelte.js';
|
|
30
|
+
import { getTheme } from '../../utils/reactive.svelte.js';
|
|
31
|
+
|
|
32
|
+
let {
|
|
33
|
+
themeState,
|
|
34
|
+
size = 'md',
|
|
35
|
+
variant = 'ghost',
|
|
36
|
+
class: className = '',
|
|
37
|
+
sunIcon,
|
|
38
|
+
moonIcon,
|
|
39
|
+
label,
|
|
40
|
+
...rest
|
|
41
|
+
} = $props();
|
|
42
|
+
|
|
43
|
+
// Use provided themeState or fall back to singleton
|
|
44
|
+
const theme = themeState ?? getTheme();
|
|
45
|
+
|
|
46
|
+
// Derive current state
|
|
47
|
+
const isDark = $derived(theme.isDark);
|
|
48
|
+
|
|
49
|
+
// Size mappings
|
|
50
|
+
const sizes = {
|
|
51
|
+
sm: { button: 'theme-toggle-sm', icon: 16 },
|
|
52
|
+
md: { button: 'theme-toggle-md', icon: 20 },
|
|
53
|
+
lg: { button: 'theme-toggle-lg', icon: 24 }
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const currentSize = $derived(sizes[size] || sizes.md);
|
|
57
|
+
|
|
58
|
+
function handleToggle() {
|
|
59
|
+
theme.toggle();
|
|
60
|
+
}
|
|
61
|
+
</script>
|
|
62
|
+
|
|
63
|
+
<button
|
|
64
|
+
type="button"
|
|
65
|
+
onclick={handleToggle}
|
|
66
|
+
aria-pressed={isDark}
|
|
67
|
+
aria-label={isDark ? 'Switch to light mode' : 'Switch to dark mode'}
|
|
68
|
+
class={cn('theme-toggle', `theme-toggle-${variant}`, currentSize.button, className)}
|
|
69
|
+
{...rest}
|
|
70
|
+
>
|
|
71
|
+
<span class="theme-toggle-icon-wrapper">
|
|
72
|
+
<!-- Sun icon (visible in dark mode, click to switch to light) -->
|
|
73
|
+
<span class={cn('theme-toggle-icon', 'theme-toggle-sun', isDark && 'theme-toggle-icon-active')}>
|
|
74
|
+
{#if sunIcon}
|
|
75
|
+
{@render sunIcon()}
|
|
76
|
+
{:else}
|
|
77
|
+
<svg
|
|
78
|
+
width={currentSize.icon}
|
|
79
|
+
height={currentSize.icon}
|
|
80
|
+
viewBox="0 0 24 24"
|
|
81
|
+
fill="none"
|
|
82
|
+
stroke="currentColor"
|
|
83
|
+
stroke-width="2"
|
|
84
|
+
stroke-linecap="round"
|
|
85
|
+
stroke-linejoin="round"
|
|
86
|
+
aria-hidden="true"
|
|
87
|
+
>
|
|
88
|
+
<circle cx="12" cy="12" r="4" />
|
|
89
|
+
<path d="M12 2v2M12 20v2M4.93 4.93l1.41 1.41M17.66 17.66l1.41 1.41M2 12h2M20 12h2M6.34 17.66l-1.41 1.41M19.07 4.93l-1.41 1.41" />
|
|
90
|
+
</svg>
|
|
91
|
+
{/if}
|
|
92
|
+
</span>
|
|
93
|
+
|
|
94
|
+
<!-- Moon icon (visible in light mode, click to switch to dark) -->
|
|
95
|
+
<span class={cn('theme-toggle-icon', 'theme-toggle-moon', !isDark && 'theme-toggle-icon-active')}>
|
|
96
|
+
{#if moonIcon}
|
|
97
|
+
{@render moonIcon()}
|
|
98
|
+
{:else}
|
|
99
|
+
<svg
|
|
100
|
+
width={currentSize.icon}
|
|
101
|
+
height={currentSize.icon}
|
|
102
|
+
viewBox="0 0 24 24"
|
|
103
|
+
fill="none"
|
|
104
|
+
stroke="currentColor"
|
|
105
|
+
stroke-width="2"
|
|
106
|
+
stroke-linecap="round"
|
|
107
|
+
stroke-linejoin="round"
|
|
108
|
+
aria-hidden="true"
|
|
109
|
+
>
|
|
110
|
+
<path d="M12 3a6 6 0 0 0 9 9 9 9 0 1 1-9-9Z" />
|
|
111
|
+
</svg>
|
|
112
|
+
{/if}
|
|
113
|
+
</span>
|
|
114
|
+
</span>
|
|
115
|
+
|
|
116
|
+
{#if label}
|
|
117
|
+
<span class="theme-toggle-label">
|
|
118
|
+
{@render label()}
|
|
119
|
+
</span>
|
|
120
|
+
{/if}
|
|
121
|
+
</button>
|
|
122
|
+
|
|
123
|
+
<style>
|
|
124
|
+
/* ============================================
|
|
125
|
+
BASE STYLES
|
|
126
|
+
============================================ */
|
|
127
|
+
.theme-toggle {
|
|
128
|
+
position: relative;
|
|
129
|
+
display: inline-flex;
|
|
130
|
+
align-items: center;
|
|
131
|
+
justify-content: center;
|
|
132
|
+
gap: var(--space-2, 0.5rem);
|
|
133
|
+
border: none;
|
|
134
|
+
border-radius: var(--radius-md, 0.375rem);
|
|
135
|
+
cursor: pointer;
|
|
136
|
+
transition: background-color var(--duration-fast, 150ms) var(--ease-out, ease-out);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
.theme-toggle:focus-visible {
|
|
140
|
+
outline: 2px solid var(--color-base0D, #83a598);
|
|
141
|
+
outline-offset: 2px;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/* ============================================
|
|
145
|
+
VARIANTS
|
|
146
|
+
============================================ */
|
|
147
|
+
.theme-toggle-ghost {
|
|
148
|
+
background-color: transparent;
|
|
149
|
+
color: var(--color-base05, #a89984);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
.theme-toggle-ghost:hover {
|
|
153
|
+
background-color: var(--color-base02, #3c3836);
|
|
154
|
+
color: var(--color-base06, #d5c4a1);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
.theme-toggle-outline {
|
|
158
|
+
background-color: transparent;
|
|
159
|
+
color: var(--color-base05, #a89984);
|
|
160
|
+
border: 1px solid var(--color-base03, #504945);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
.theme-toggle-outline:hover {
|
|
164
|
+
background-color: var(--color-base02, #3c3836);
|
|
165
|
+
border-color: var(--color-base04, #665c54);
|
|
166
|
+
color: var(--color-base06, #d5c4a1);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
.theme-toggle-subtle {
|
|
170
|
+
background-color: var(--color-base01, #282828);
|
|
171
|
+
color: var(--color-base05, #a89984);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
.theme-toggle-subtle:hover {
|
|
175
|
+
background-color: var(--color-base02, #3c3836);
|
|
176
|
+
color: var(--color-base06, #d5c4a1);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/* ============================================
|
|
180
|
+
SIZES
|
|
181
|
+
============================================ */
|
|
182
|
+
.theme-toggle-sm {
|
|
183
|
+
padding: var(--space-1, 0.25rem);
|
|
184
|
+
min-width: 1.75rem;
|
|
185
|
+
min-height: 1.75rem;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
.theme-toggle-md {
|
|
189
|
+
padding: var(--space-2, 0.5rem);
|
|
190
|
+
min-width: 2.25rem;
|
|
191
|
+
min-height: 2.25rem;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
.theme-toggle-lg {
|
|
195
|
+
padding: var(--space-3, 0.75rem);
|
|
196
|
+
min-width: 2.75rem;
|
|
197
|
+
min-height: 2.75rem;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/* ============================================
|
|
201
|
+
ICON ANIMATION
|
|
202
|
+
============================================ */
|
|
203
|
+
.theme-toggle-icon-wrapper {
|
|
204
|
+
position: relative;
|
|
205
|
+
display: flex;
|
|
206
|
+
align-items: center;
|
|
207
|
+
justify-content: center;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
.theme-toggle-icon {
|
|
211
|
+
position: absolute;
|
|
212
|
+
display: flex;
|
|
213
|
+
align-items: center;
|
|
214
|
+
justify-content: center;
|
|
215
|
+
opacity: 0;
|
|
216
|
+
transform: rotate(-90deg) scale(0.5);
|
|
217
|
+
transition:
|
|
218
|
+
opacity var(--duration-normal, 200ms) var(--ease-out, ease-out),
|
|
219
|
+
transform var(--duration-normal, 200ms) var(--ease-out, ease-out);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
.theme-toggle-icon-active {
|
|
223
|
+
position: relative;
|
|
224
|
+
opacity: 1;
|
|
225
|
+
transform: rotate(0deg) scale(1);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/* Sun specific - warm color when active */
|
|
229
|
+
.theme-toggle-sun.theme-toggle-icon-active {
|
|
230
|
+
color: var(--color-base0A, #fabd2f);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/* Moon specific - cool color when active */
|
|
234
|
+
.theme-toggle-moon.theme-toggle-icon-active {
|
|
235
|
+
color: var(--color-base0D, #83a598);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/* ============================================
|
|
239
|
+
REDUCED MOTION
|
|
240
|
+
============================================ */
|
|
241
|
+
@media (prefers-reduced-motion: reduce) {
|
|
242
|
+
.theme-toggle-icon {
|
|
243
|
+
transition: opacity var(--duration-fast, 150ms) var(--ease-out, ease-out);
|
|
244
|
+
transform: none;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
.theme-toggle-icon-active {
|
|
248
|
+
transform: none;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/* ============================================
|
|
253
|
+
LABEL
|
|
254
|
+
============================================ */
|
|
255
|
+
.theme-toggle-label {
|
|
256
|
+
font-size: var(--text-sm, 0.875rem);
|
|
257
|
+
color: var(--color-base05, #a89984);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
.theme-toggle:hover .theme-toggle-label {
|
|
261
|
+
color: var(--color-base06, #d5c4a1);
|
|
262
|
+
}
|
|
263
|
+
</style>
|
|
@@ -76,7 +76,12 @@
|
|
|
76
76
|
{/if}
|
|
77
77
|
|
|
78
78
|
{#if visible && (text || content)}
|
|
79
|
-
<div
|
|
79
|
+
<div
|
|
80
|
+
class="tooltip tooltip-{position} {content ? 'tooltip-interactive' : ''}"
|
|
81
|
+
role="tooltip"
|
|
82
|
+
onmouseenter={content ? show : undefined}
|
|
83
|
+
onmouseleave={content ? hide : undefined}
|
|
84
|
+
>
|
|
80
85
|
<div class="tooltip-content">
|
|
81
86
|
{#if content}
|
|
82
87
|
{@render content()}
|
|
@@ -102,6 +107,10 @@
|
|
|
102
107
|
animation: tooltip-enter 0.15s ease-out;
|
|
103
108
|
}
|
|
104
109
|
|
|
110
|
+
.tooltip-interactive {
|
|
111
|
+
pointer-events: auto;
|
|
112
|
+
}
|
|
113
|
+
|
|
105
114
|
@keyframes tooltip-enter {
|
|
106
115
|
from {
|
|
107
116
|
opacity: 0;
|
package/src/index.js
CHANGED
|
@@ -40,6 +40,8 @@ export { default as FilterChip } from './components/primitives/FilterChip.svelte
|
|
|
40
40
|
export { default as StatusLine } from './components/primitives/StatusLine.svelte';
|
|
41
41
|
export { default as Tooltip } from './components/primitives/Tooltip.svelte';
|
|
42
42
|
export { default as MemberCard } from './components/primitives/MemberCard.svelte';
|
|
43
|
+
export { default as ThemeToggle } from './components/primitives/ThemeToggle.svelte';
|
|
44
|
+
export { default as ThemeSelect } from './components/primitives/ThemeSelect.svelte';
|
|
43
45
|
|
|
44
46
|
// ============================================
|
|
45
47
|
// COMPONENTS - Forms
|