File tree Expand file tree Collapse file tree 5 files changed +50
-6
lines changed
routes/docs/components/ThemeSwitch Expand file tree Collapse file tree 5 files changed +50
-6
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ ' svelte-ux ' : minor
3
+ ---
4
+
5
+ Allow custom styling of ThemeSwitch component
Original file line number Diff line number Diff line change 5
5
import Icon from ' ./Icon.svelte' ;
6
6
7
7
import { getSettings } from ' ./settings.js' ;
8
+ import { cls } from ' ../utils/index.js' ;
9
+ import type { ComponentProps } from ' svelte' ;
10
+ import { clsMerge } from ' $lib/utils/styles.js' ;
11
+ import { getComponentClasses } from ' $lib/components/theme.js' ;
8
12
9
13
const { currentTheme } = getSettings ();
14
+
15
+ const { icon : iconClasses, ... otherClasses } = getComponentClasses (' ThemeSwitch' );
16
+
17
+ export let classes: {
18
+ icon? : string ;
19
+ } & ComponentProps <Switch >[' classes' ] = {};
10
20
</script >
11
21
12
22
<Switch
16
26
let newTheme = e .target ?.checked ? ' dark' : ' light' ;
17
27
currentTheme .setTheme (newTheme );
18
28
}}
19
- classes ={{
20
- switch : ' dark:bg-primary dark:border-primary' ,
21
- toggle : ' translate-x-0 dark:translate-x-full' ,
22
- }}
29
+ classes ={clsMerge (
30
+ {
31
+ switch: ' dark:bg-primary dark:border-primary' ,
32
+ toggle: ' translate-x-0 dark:translate-x-full' ,
33
+ },
34
+ otherClasses ,
35
+ classes
36
+ )}
23
37
{...$$restProps }
24
38
>
25
39
<div class =" grid grid-cols-1 grid-rows-1" >
26
40
<Icon
27
41
data ={mdiWeatherNight }
28
42
size =" .8rem"
29
- class =" row-[1] col-[1] text-primary opacity-0 dark:opacity-100"
43
+ class ={cls (
44
+ ' row-[1] col-[1] text-primary opacity-0 dark:opacity-100' ,
45
+ iconClasses ,
46
+ classes .icon
47
+ )}
30
48
/>
31
49
<Icon
32
50
data ={mdiWhiteBalanceSunny }
33
51
size =" .8rem"
34
- class =" row-[1] col-[1] text-primary opacity-100 dark:opacity-0"
52
+ class ={cls (
53
+ ' row-[1] col-[1] text-primary opacity-100 dark:opacity-0' ,
54
+ iconClasses ,
55
+ classes .icon
56
+ )}
35
57
/>
36
58
</div >
37
59
</Switch >
Original file line number Diff line number Diff line change @@ -165,6 +165,10 @@ export function resolveComponentSettings<NAME extends ComponentName>(
165
165
return output ;
166
166
}
167
167
168
+ /**
169
+ * Returns default component props and classes for a given component.
170
+ * @param name component name
171
+ */
168
172
export function getComponentSettings < NAME extends ComponentName > (
169
173
name : NAME
170
174
) : ResolvedComponentSettings < NAME > {
Original file line number Diff line number Diff line change @@ -121,6 +121,11 @@ export function resolveComponentClasses<NAME extends ComponentName>(
121
121
return typeof theme === 'string' ? { root : theme } : ( theme ?? { } ) ;
122
122
}
123
123
124
+ /**
125
+ * Returns default component classes for a given component. See {@link resolveComponentSettings}
126
+ * to get both default props and classes.
127
+ * @param name component name
128
+ */
124
129
export function getComponentClasses < NAME extends ComponentName > (
125
130
name : NAME
126
131
) : ResolvedComponentClasses [ NAME ] {
Original file line number Diff line number Diff line change 10
10
<Preview >
11
11
<ThemeSwitch />
12
12
</Preview >
13
+
14
+ <h2 >Customize Switch</h2 >
15
+
16
+ <Preview >
17
+ <ThemeSwitch
18
+ classes ={{ icon : ' text-primary-content' , switch : ' bg-secondary w-20' , toggle : ' bg-accent' }}
19
+ />
20
+ </Preview >
You can’t perform that action at this time.
0 commit comments