From 18be0066b33dbb6e443d869ab75ddd54e46e3d0d Mon Sep 17 00:00:00 2001 From: Gavin Golden Date: Mon, 16 Dec 2024 19:02:06 -0600 Subject: [PATCH] feat(ThemeSwitch) Allow custom classes for icon (#525) * Allow custom icon colors in ThemeSwitcher * prettier * Support global ThemeSwitch class settings * Use dynamic color class * format * doc on wrong method * Add changeset * Change structure of settings obj --- .changeset/beige-pugs-boil.md | 5 +++ .../src/lib/components/ThemeSwitch.svelte | 34 +++++++++++++++---- .../svelte-ux/src/lib/components/settings.ts | 4 +++ .../svelte-ux/src/lib/components/theme.ts | 5 +++ .../docs/components/ThemeSwitch/+page.svelte | 8 +++++ 5 files changed, 50 insertions(+), 6 deletions(-) create mode 100644 .changeset/beige-pugs-boil.md diff --git a/.changeset/beige-pugs-boil.md b/.changeset/beige-pugs-boil.md new file mode 100644 index 000000000..4bef4118d --- /dev/null +++ b/.changeset/beige-pugs-boil.md @@ -0,0 +1,5 @@ +--- +'svelte-ux': minor +--- + +Allow custom styling of ThemeSwitch component diff --git a/packages/svelte-ux/src/lib/components/ThemeSwitch.svelte b/packages/svelte-ux/src/lib/components/ThemeSwitch.svelte index 24b64c764..1307c8e93 100644 --- a/packages/svelte-ux/src/lib/components/ThemeSwitch.svelte +++ b/packages/svelte-ux/src/lib/components/ThemeSwitch.svelte @@ -5,8 +5,18 @@ import Icon from './Icon.svelte'; import { getSettings } from './settings.js'; + import { cls } from '../utils/index.js'; + import type { ComponentProps } from 'svelte'; + import { clsMerge } from '$lib/utils/styles.js'; + import { getComponentClasses } from '$lib/components/theme.js'; const { currentTheme } = getSettings(); + + const { icon: iconClasses, ...otherClasses } = getComponentClasses('ThemeSwitch'); + + export let classes: { + icon?: string; + } & ComponentProps['classes'] = {};
diff --git a/packages/svelte-ux/src/lib/components/settings.ts b/packages/svelte-ux/src/lib/components/settings.ts index 991bf38b3..74bc3a6aa 100644 --- a/packages/svelte-ux/src/lib/components/settings.ts +++ b/packages/svelte-ux/src/lib/components/settings.ts @@ -165,6 +165,10 @@ export function resolveComponentSettings( return output; } +/** + * Returns default component props and classes for a given component. + * @param name component name + */ export function getComponentSettings( name: NAME ): ResolvedComponentSettings { diff --git a/packages/svelte-ux/src/lib/components/theme.ts b/packages/svelte-ux/src/lib/components/theme.ts index c8598132d..d2db62f95 100644 --- a/packages/svelte-ux/src/lib/components/theme.ts +++ b/packages/svelte-ux/src/lib/components/theme.ts @@ -121,6 +121,11 @@ export function resolveComponentClasses( return typeof theme === 'string' ? { root: theme } : (theme ?? {}); } +/** + * Returns default component classes for a given component. See {@link resolveComponentSettings} + * to get both default props and classes. + * @param name component name + */ export function getComponentClasses( name: NAME ): ResolvedComponentClasses[NAME] { diff --git a/packages/svelte-ux/src/routes/docs/components/ThemeSwitch/+page.svelte b/packages/svelte-ux/src/routes/docs/components/ThemeSwitch/+page.svelte index ad2daa6dd..286f24169 100644 --- a/packages/svelte-ux/src/routes/docs/components/ThemeSwitch/+page.svelte +++ b/packages/svelte-ux/src/routes/docs/components/ThemeSwitch/+page.svelte @@ -10,3 +10,11 @@ + +

Customize Switch

+ + + +