Skip to content

Commit 147b36d

Browse files
committed
Theme generator (#192)
* Rename `cssVars` action to `styleVars` and do not prefix properties with `--` by default (more flexible) * [SelectField] Fix toggling display of options menu using toggleIcon. Ignore toggling when clicking on SelectField border. Support hiding toggleIcon (`<SelectField toggleIcon={null} /> * [SelectField] Add `stepper` prop to iterate through options (like `MenuField`) * [MenuField] Expose `selected` option via prop (similar to `SelectField`) * [SelectField Add stepper example * Move `processThemeColors()` from tailwind plugin to $lib/styles/theme to allow calling at runtime (theme generator frontend). Add types * Update skeleton.ts to match skeleton.cjs (to be removed) * Beginning work of theme generator * Read themes from `themes.json` file for both tailwind config and theme selector. Remove daisy/skeleton commonjs modules. Add `getThemeNames` to split based on `color-scheme`. Ultimately simplifies a lot * Add "Copy all" daisy and skeleton options * Use <ThemeSelect> or <ThemeSwitch> based on more than 1 light/dark theme * Fix skeleton dark themes after refactor * Add explicit daisy themeName list to hopefully fix build (similar to skeleton) * Set initial theme selections (fix reactivity infinite loop) * [SelectField] Use `selectValue(...)` instead of `value = ...` so `change` is dispatched (and other consistent updating) * Change light/dark preview based on which input was last changed * Support overriding doc themes wtih generator (custom) themes * Fix setting `prefers-color-scheme: dark` override * Use a local copy of Skeleton themes to fix Cloudflare build (work around Node.js runtime issue) * Improve handling of `-50` shade when `-100` exists (ex. Skeleton) * Update site dark/light mode with preview for better experience (previewing and applying) * Support custom Ior exisitng) theme editing * Add state colors and support showing/hiding optoinal colors * Add "Copy all themes" menu item * [ColorField] Support `hex` entry * Register all themes (daisy + skeleton) * Format files (fix lint error) * Add changeset
1 parent 5a9aa80 commit 147b36d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+4286
-592
lines changed

.changeset/cool-hotels-own.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+
[SelectField] Add `stepper` prop to iterate through options (like `MenuField`)

.changeset/fair-trees-sparkle.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+
[MenuField] Expose `selected` option via prop (similar to `SelectField`)

.changeset/quick-carrots-grab.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"svelte-ux": minor
3+
---
4+
5+
Add theme selection/creation page and simplify loading themes

.changeset/selfish-hounds-dance.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+
[SelectField] Fix toggling display of options menu using toggleIcon. Support hiding toggleIcon (`<SelectField toggleIcon={null} />

.changeset/yellow-nails-vanish.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte-ux': minor
3+
---
4+
5+
Rename `cssVars` action to `styleVars` and do not prefix properties with `--` by default (more flexible)

packages/svelte-ux/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"@sveltejs/kit": "^1.30.3",
2828
"@sveltejs/package": "^2.2.5",
2929
"@tailwindcss/typography": "^0.5.10",
30+
"@types/culori": "^2.0.4",
3031
"@types/d3-array": "^3.2.1",
3132
"@types/d3-scale": "^4.0.8",
3233
"@types/lodash-es": "^4.17.12",

packages/svelte-ux/src/lib/actions/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
export * from './cssVars';
21
export * from './dataBackground';
32
export * from './input';
43
export * from './layout';
@@ -9,4 +8,5 @@ export * from './portal';
98
export * from './scroll';
109
export * from './spotlight';
1110
export * from './sticky';
11+
export * from './styleProps';
1212
export * from './table';

packages/svelte-ux/src/lib/actions/cssVars.ts renamed to packages/svelte-ux/src/lib/actions/styleProps.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ import type { Action } from 'svelte/action';
22

33
type CSSProps = { [key: string]: string | number | boolean | null | undefined };
44

5-
export const cssVars: Action<HTMLElement, CSSProps> = (node, props) => {
5+
export const styleProps: Action<HTMLElement, CSSProps> = (node, props) => {
66
Object.entries(props ?? {}).forEach(([key, value]) => {
77
// Ignore if null or undefined
88
if (value != null) {
99
value = typeof value === 'boolean' ? (value ? 1 : 0) : value;
10-
node.style.setProperty(`--${key}`, `${value}`);
10+
node.style.setProperty(key, `${value}`);
1111
}
1212
});
1313

@@ -17,13 +17,13 @@ export const cssVars: Action<HTMLElement, CSSProps> = (node, props) => {
1717
update(newProps: CSSProps) {
1818
const newKeys = Object.keys(newProps);
1919
Object.keys(lastProps)
20-
.filter((name) => !newKeys.includes(name))
21-
.forEach((name) => node.style.removeProperty(`--${name}`));
20+
.filter((key) => !newKeys.includes(key))
21+
.forEach((key) => node.style.removeProperty(key));
2222

2323
Object.entries(newProps).forEach(([key, value]) => {
2424
// Ignore if null or undefined
2525
if (value != null) {
26-
node.style.setProperty(`--${key}`, `${value}`);
26+
node.style.setProperty(key, `${value}`);
2727
}
2828
if (props) {
2929
delete props[key];

packages/svelte-ux/src/lib/components/Grid.svelte

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
<script lang="ts">
2-
import { cssVars } from '../actions/cssVars';
3-
42
export let columns = 0;
53
export let gap = 0;
64
export let columnGap = gap;
@@ -38,28 +36,23 @@
3836
templateColumns ??
3937
template ??
4038
(autoColumns ? `repeat(auto-fill, minmax(${autoColumns}, 1fr))` : `repeat(${columns}, 1fr)`);
41-
42-
$: styleVars = {
43-
templateColumns: templateColumnsResolved,
44-
templateRows,
45-
gap,
46-
columnGap,
47-
rowGap,
48-
autoFlow,
49-
items, // TODO: Map start: flex-start?, end: flex-end?
50-
justify, // TODO: Map start: flex-start?, end: flex-end?, between: space-between, around: space-around, evenly: space-evenly
51-
justifyItems, // TODO: Map start: flex-start?, end: flex-end?, between: space-between, around: space-around, evenly: space-evenly
52-
content, // TODO: Map start: flex-start?, end: flex-end?, between: space-between, around: space-around, evenly: space-evenly
53-
// place, // TODO: Map start: flex-start?, end: flex-end?, between: space-between, around: space-around, evenly: space-evenly
54-
};
5539
</script>
5640

5741
<div
58-
use:cssVars={styleVars}
5942
class="Grid"
6043
class:grid={!inline}
6144
class:inline-grid={inline}
6245
class:stack
46+
style:--templateColumns={templateColumnsResolved}
47+
style:--templateRows={templateRows}
48+
style:--gap={gap}
49+
style:--columnGap={columnGap}
50+
style:--rowGap={rowGap}
51+
style:--autoFlow={autoFlow}
52+
style:--items={items}
53+
style:--justify={justify}
54+
style:--justifyItems={justifyItems}
55+
style:--content={content}
6356
on:click
6457
{...$$restProps}
6558
>

packages/svelte-ux/src/lib/components/MenuField.svelte

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
const settingsClasses = getComponentClasses('MenuField');
3333
3434
let open = false;
35+
export let selected: any = undefined;
3536
$: selected = options?.find((x) => x.value === value);
3637
3738
$: previous = () => {

0 commit comments

Comments
 (0)