lapikit 0.6.1 → 0.6.3
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/dist/@types/actions.d.ts +13 -0
- package/dist/@types/props.d.ts +7 -0
- package/dist/components/app/app.svelte +161 -114
- package/dist/components/app/app.svelte.d.ts +2 -4
- package/dist/components/app/app.types.d.ts +4 -0
- package/dist/components/app/app.types.js +1 -0
- package/dist/components/card/card.svelte +16 -11
- package/dist/components/card/card.types.d.ts +2 -1
- package/dist/components/card/modules/card-title.svelte +4 -0
- package/dist/components/list/list.svelte +126 -93
- package/dist/components/list/list.types.d.ts +4 -5
- package/dist/components/list/modules/list-item.svelte +104 -66
- package/dist/components/textfield/textfield.svelte.d.ts +1 -1
- package/dist/hooks/actions.d.ts +2 -0
- package/dist/hooks/actions.js +2 -0
- package/dist/hooks/themes.svelte.d.ts +12 -0
- package/dist/hooks/themes.svelte.js +125 -0
- package/dist/utils/components.d.ts +8 -1
- package/dist/utils/components.js +19 -0
- package/package.json +2 -2
- package/dist/actions.d.ts +0 -2
- package/dist/actions.js +0 -2
- package/dist/utils/themes.d.ts +0 -3
- package/dist/utils/themes.js +0 -21
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
// states
|
|
2
|
+
const isBrowser = typeof window !== 'undefined';
|
|
3
|
+
// presets
|
|
4
|
+
const default_theme = 'light';
|
|
5
|
+
const default_storage_key = '@lapikit/theme';
|
|
6
|
+
function generateGlobalTheme() {
|
|
7
|
+
let active = $state(default_theme);
|
|
8
|
+
let key = default_storage_key;
|
|
9
|
+
let initialized = false;
|
|
10
|
+
function applyToHtml(name) {
|
|
11
|
+
if (!isBrowser)
|
|
12
|
+
return;
|
|
13
|
+
document.documentElement.setAttribute('data-kit-theme', name);
|
|
14
|
+
active = name;
|
|
15
|
+
}
|
|
16
|
+
function set(name) {
|
|
17
|
+
applyToHtml(name);
|
|
18
|
+
if (isBrowser) {
|
|
19
|
+
localStorage.setItem(key, name);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
function init(params = {}) {
|
|
23
|
+
if (initialized)
|
|
24
|
+
return;
|
|
25
|
+
initialized = true;
|
|
26
|
+
key = params.key ?? default_storage_key;
|
|
27
|
+
const stored = isBrowser ? localStorage.getItem(key) : null;
|
|
28
|
+
applyToHtml(stored ?? params.name ?? default_theme);
|
|
29
|
+
}
|
|
30
|
+
return {
|
|
31
|
+
init,
|
|
32
|
+
set,
|
|
33
|
+
get active() {
|
|
34
|
+
return active;
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
const refGlobalTheme = generateGlobalTheme();
|
|
39
|
+
export const useTheme = refGlobalTheme.set;
|
|
40
|
+
export function createGlobalTheme(params) {
|
|
41
|
+
refGlobalTheme.init(params);
|
|
42
|
+
return {
|
|
43
|
+
get active() {
|
|
44
|
+
return refGlobalTheme.active;
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
export function createTheme() {
|
|
49
|
+
let active = $state(default_theme);
|
|
50
|
+
let node;
|
|
51
|
+
let key;
|
|
52
|
+
let overridden = $state(false);
|
|
53
|
+
function applyTheme(name) {
|
|
54
|
+
const target = node;
|
|
55
|
+
if (!target)
|
|
56
|
+
return;
|
|
57
|
+
target.setAttribute('data-kit-theme', name);
|
|
58
|
+
active = name;
|
|
59
|
+
}
|
|
60
|
+
function set(name) {
|
|
61
|
+
applyTheme(name);
|
|
62
|
+
if (isBrowser && key) {
|
|
63
|
+
localStorage.setItem(key, name);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
// skip the effect's first automatic pass so the mount's own initial value (from
|
|
67
|
+
// `name`, storage or default) isn't immediately clobbered by the current global value
|
|
68
|
+
let firstRun = true;
|
|
69
|
+
// re-syncs to the global theme whenever it changes, unless this zone is overridden
|
|
70
|
+
$effect(() => {
|
|
71
|
+
const value = refGlobalTheme.active;
|
|
72
|
+
const isOverridden = overridden;
|
|
73
|
+
const skip = firstRun;
|
|
74
|
+
firstRun = false;
|
|
75
|
+
if (!skip && !isOverridden) {
|
|
76
|
+
applyTheme(value);
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
const action = (n, params = {}) => {
|
|
80
|
+
node = n;
|
|
81
|
+
key = params.key;
|
|
82
|
+
overridden = params.overridden ?? false;
|
|
83
|
+
const stored = isBrowser && key ? localStorage.getItem(key) : null;
|
|
84
|
+
applyTheme(stored ?? params.name ?? (overridden ? default_theme : refGlobalTheme.active));
|
|
85
|
+
return {
|
|
86
|
+
update(newParams = {}) {
|
|
87
|
+
key = newParams.key;
|
|
88
|
+
overridden = newParams.overridden ?? false;
|
|
89
|
+
},
|
|
90
|
+
destroy() {
|
|
91
|
+
node = undefined;
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
};
|
|
95
|
+
return {
|
|
96
|
+
action,
|
|
97
|
+
set,
|
|
98
|
+
get active() {
|
|
99
|
+
return active;
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
/** LEGACY CODE
|
|
104
|
+
* NEED UPDATE documentation with new theme system before removing this legacy code. The new theme system is designed to be more flexible and easier to use, allowing for better integration with Svelte's reactivity and component structure. It also provides a more consistent API for managing themes across different components and contexts.
|
|
105
|
+
* TODO: Remove this legacy code once the new theme system is fully implemented and tested. This code is kept for backward compatibility with existing components that rely on the old theme system.
|
|
106
|
+
*/
|
|
107
|
+
import { writable } from 'svelte/store';
|
|
108
|
+
// presets
|
|
109
|
+
const themeRef = 'light';
|
|
110
|
+
export const theme = writable(themeRef);
|
|
111
|
+
// export function useTheme(name: string, key: string = '@lapikit/theme') {
|
|
112
|
+
// theme.update(() => {
|
|
113
|
+
// if (isBrowser) {
|
|
114
|
+
// const html = document.documentElement;
|
|
115
|
+
// html.classList.forEach((cls) => {
|
|
116
|
+
// if (cls.startsWith('kit-theme--')) {
|
|
117
|
+
// html.classList.remove(cls);
|
|
118
|
+
// }
|
|
119
|
+
// });
|
|
120
|
+
// html.classList.add(`kit-theme--${name}`);
|
|
121
|
+
// localStorage.setItem(key, name);
|
|
122
|
+
// }
|
|
123
|
+
// return name;
|
|
124
|
+
// });
|
|
125
|
+
// }
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { useClassNameProps, useStylesProps } from '../@types';
|
|
1
|
+
import type { ElevationProps, ElevationState, useClassNameProps, useStylesProps } from '../@types';
|
|
2
2
|
/**
|
|
3
3
|
* useClassName - Utility to compute class names for a component.
|
|
4
4
|
* @param baseClass - The base class name for the component.
|
|
@@ -17,3 +17,10 @@ export declare function useIsInteractive(props: Record<string, unknown>, tag: st
|
|
|
17
17
|
* @returns A computed style string.
|
|
18
18
|
*/
|
|
19
19
|
export declare function useStyles({ styleAttr, sStyle, styleProps }?: useStylesProps): string;
|
|
20
|
+
/**
|
|
21
|
+
* useElevation - Utility to resolve the `elevation` prop into its base/hover/active states.
|
|
22
|
+
* @param elevation - Either a single elevation value applied as `base`, or an object with
|
|
23
|
+
* independent `base`, `hover` and `active` values (each key is optional).
|
|
24
|
+
* @returns An object with `base`, `hover` and `active` keys, `undefined` when not provided.
|
|
25
|
+
*/
|
|
26
|
+
export declare function useElevation(elevation?: ElevationProps | null): ElevationState;
|
package/dist/utils/components.js
CHANGED
|
@@ -106,3 +106,22 @@ export function useStyles({ styleAttr, sStyle, styleProps } = {}) {
|
|
|
106
106
|
}
|
|
107
107
|
return styles.filter(Boolean).join('; ');
|
|
108
108
|
}
|
|
109
|
+
/**
|
|
110
|
+
* useElevation - Utility to resolve the `elevation` prop into its base/hover/active states.
|
|
111
|
+
* @param elevation - Either a single elevation value applied as `base`, or an object with
|
|
112
|
+
* independent `base`, `hover` and `active` values (each key is optional).
|
|
113
|
+
* @returns An object with `base`, `hover` and `active` keys, `undefined` when not provided.
|
|
114
|
+
*/
|
|
115
|
+
export function useElevation(elevation) {
|
|
116
|
+
if (elevation === undefined || elevation === null) {
|
|
117
|
+
return { base: undefined, hover: undefined, active: undefined };
|
|
118
|
+
}
|
|
119
|
+
if (typeof elevation === 'string') {
|
|
120
|
+
return { base: elevation, hover: undefined, active: undefined };
|
|
121
|
+
}
|
|
122
|
+
return {
|
|
123
|
+
base: elevation.base,
|
|
124
|
+
hover: elevation.hover,
|
|
125
|
+
active: elevation.active
|
|
126
|
+
};
|
|
127
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lapikit",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.3",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
"default": "./dist/labs/index.js"
|
|
67
67
|
},
|
|
68
68
|
"./actions": {
|
|
69
|
-
"default": "./dist/actions.js"
|
|
69
|
+
"default": "./dist/hooks/actions.js"
|
|
70
70
|
}
|
|
71
71
|
},
|
|
72
72
|
"peerDependencies": {
|
package/dist/actions.d.ts
DELETED
package/dist/actions.js
DELETED
package/dist/utils/themes.d.ts
DELETED
package/dist/utils/themes.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { writable } from 'svelte/store';
|
|
2
|
-
// states
|
|
3
|
-
const isBrowser = typeof window !== 'undefined';
|
|
4
|
-
// presets
|
|
5
|
-
const themeRef = 'light';
|
|
6
|
-
export const theme = writable(themeRef);
|
|
7
|
-
export function useTheme(name, key = '@lapikit/theme') {
|
|
8
|
-
theme.update(() => {
|
|
9
|
-
if (isBrowser) {
|
|
10
|
-
const html = document.documentElement;
|
|
11
|
-
html.classList.forEach((cls) => {
|
|
12
|
-
if (cls.startsWith('kit-theme--')) {
|
|
13
|
-
html.classList.remove(cls);
|
|
14
|
-
}
|
|
15
|
-
});
|
|
16
|
-
html.classList.add(`kit-theme--${name}`);
|
|
17
|
-
localStorage.setItem(key, name);
|
|
18
|
-
}
|
|
19
|
-
return name;
|
|
20
|
-
});
|
|
21
|
-
}
|