Skip to content

Commit c7e87ec

Browse files
committed
Map Skeleton themes to Svelte UX themes
1 parent a87c934 commit c7e87ec

File tree

7 files changed

+141
-3
lines changed

7 files changed

+141
-3
lines changed

.changeset/rare-flowers-flash.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"svelte-ux": patch
3+
---
4+
5+
Map Skeleton themes to Svelte UX themes

packages/svelte-ux/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"prepare": "svelte-kit sync"
2121
},
2222
"devDependencies": {
23+
"@skeletonlabs/tw-plugin": "^0.3.1",
2324
"@sveltejs/adapter-auto": "^2.1.1",
2425
"@sveltejs/kit": "^1.30.3",
2526
"@sveltejs/package": "^2.2.5",
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
const { getThemeProperties } = require('@skeletonlabs/tw-plugin');
2+
3+
const themeNames = [
4+
'skeleton',
5+
'wintry',
6+
'modern',
7+
'rocket',
8+
'seafoam',
9+
'vintage',
10+
'sahara',
11+
'hamlindigo',
12+
'gold-nouveau',
13+
];
14+
15+
// Map Skeleton to Svelte UX theme colors
16+
const skeletonColorMap = {
17+
// Semantic
18+
primary: 'primary',
19+
secondary: 'secondary',
20+
tertiary: 'accent',
21+
// '': 'neutral',
22+
// State
23+
success: 'success',
24+
warning: 'warning',
25+
error: 'danger',
26+
// Surface
27+
surface: 'surface',
28+
};
29+
30+
function processTheme(themeName, scheme) {
31+
const properties = getThemeProperties(themeName);
32+
33+
let mappedThemeProperties = Object.entries(properties)
34+
.map(([key, value]) => {
35+
if (key.startsWith('--color')) {
36+
// `--color-primary-500` => `primary-500`
37+
// `--color-primary-500` => `primary`
38+
const matches = key.match(/--color-(\w*)-([0-9]{3})/);
39+
const skeletonColorName = matches?.[1];
40+
const skeletonColorShade = matches?.[2];
41+
const themeColorName = skeletonColorMap[skeletonColorName];
42+
if (themeColorName) {
43+
return [`${themeColorName}-${skeletonColorShade}`, `rgb(${value})`];
44+
}
45+
} else if (key.startsWith('--on-')) {
46+
// `--on-primary` => `primary-content`
47+
const matches = key.match(/--on-(\w*)/);
48+
const skeletonColorName = matches?.[1];
49+
const themeColorName = skeletonColorMap[skeletonColorName];
50+
if (themeColorName) {
51+
return [`${themeColorName}-content`, `rgb(${value})`];
52+
}
53+
} else {
54+
// consider mapping additional properties
55+
// '--theme-font-family-base': 'system-ui',
56+
// '--theme-font-family-heading': 'system-ui',
57+
// '--theme-font-color-base': '0 0 0',
58+
// '--theme-font-color-dark': '255 255 255',
59+
// '--theme-rounded-base': '9999px',
60+
// '--theme-rounded-container': '8px',
61+
// '--theme-border-base': '1px',
62+
}
63+
})
64+
.filter((d) => d);
65+
66+
mappedThemeProperties =
67+
scheme === 'light'
68+
? [
69+
...mappedThemeProperties,
70+
['color-scheme', 'light'],
71+
['surface-100', `rgb(${properties['--color-surface-50']})`],
72+
['surface-200', `rgb(${properties['--color-surface-100']})`],
73+
['surface-300', `rgb(${properties['--color-surface-200']})`],
74+
['surface-content', `rgb(0 0 0)`],
75+
]
76+
: [
77+
...mappedThemeProperties,
78+
['color-scheme', 'dark'],
79+
['surface-100', `rgb(${properties['--color-surface-700']})`],
80+
['surface-200', `rgb(${properties['--color-surface-800']})`],
81+
['surface-300', `rgb(${properties['--color-surface-900']})`],
82+
['surface-content', `rgb(255 255 255)`],
83+
];
84+
85+
return [
86+
themeName === 'skeleton' ? scheme : scheme === 'dark' ? themeName + '-dark' : themeName,
87+
Object.fromEntries(mappedThemeProperties),
88+
];
89+
}
90+
91+
const themes = Object.fromEntries(
92+
themeNames.flatMap((themeName) => {
93+
return [processTheme(themeName, 'light'), processTheme(themeName, 'dark')];
94+
})
95+
);
96+
97+
const lightThemes = Object.keys(themes).filter((themeName) => !themeName.endsWith('dark'));
98+
const darkThemes = Object.keys(themes).filter((themeName) => themeName.endsWith('dark'));
99+
100+
module.exports = { themes, lightThemes, darkThemes };
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
const themeNames = [
2+
'skeleton',
3+
'wintry',
4+
'modern',
5+
'rocket',
6+
'seafoam',
7+
'vintage',
8+
'sahara',
9+
'hamlindigo',
10+
'gold-nouveau',
11+
];
12+
13+
const lightThemes = themeNames.map((themeName) => (themeName === 'skeleton' ? 'light' : themeName));
14+
const darkThemes = themeNames.map((themeName) =>
15+
themeName === 'skeleton' ? 'dark' : themeName + '-dark'
16+
);
17+
18+
export { lightThemes, darkThemes };

packages/svelte-ux/src/routes/+layout.svelte

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
import { settings } from '$lib/components/settings';
2121
import type { PageData } from './$types';
2222
import { DateToken } from '$lib/utils/date';
23-
import { lightThemes, darkThemes } from '$lib/styles/daisy';
23+
// import { lightThemes, darkThemes } from '$lib/styles/daisy';
24+
import { lightThemes, darkThemes } from '$lib/styles/skeleton';
2425
2526
export let data: PageData;
2627

packages/svelte-ux/tailwind.config.cjs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@ const plugin = require('tailwindcss/plugin');
22
const colors = require('tailwindcss/colors');
33

44
const svelteUx = require('./src/lib/plugins/tailwind.cjs');
5-
const { themes } = require('./src/lib/styles/daisy.cjs');
5+
const { themes: daisyThemes } = require('./src/lib/styles/daisy.cjs');
6+
const { themes: skeletonThemes } = require('./src/lib/styles/skeleton.cjs');
67

78
module.exports = {
89
content: ['./src/**/*.{html,svelte,md,ts,js}'],
910
ux: {
10-
themes,
11+
// themes: daisyThemes,
12+
themes: skeletonThemes,
1113
// themes: {
1214
// light: {
1315
// primary: colors['blue']['500'],

pnpm-lock.yaml

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)