@kalink-ui/seedly 0.14.0 → 0.15.0
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/CHANGELOG.md +8 -0
- package/package.json +3 -3
- package/src/components/loader-overlay/loader-overlay.tsx +1 -1
- package/src/components/stack/stack.css.ts +31 -0
- package/src/components/stack/stack.tsx +5 -1
- package/src/hooks/index.ts +1 -0
- package/src/hooks/use-local-storage.ts +99 -0
- package/src/index.ts +1 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# @kalink-ui/seedly
|
|
2
2
|
|
|
3
|
+
## 0.15.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 7893c13: [Stack] handle items positioning
|
|
8
|
+
- b1e9483: [LoaderOverlay] Correctly center elements
|
|
9
|
+
- 57ca2b9: [useLocalStorage] Add new local storage management hook
|
|
10
|
+
|
|
3
11
|
## 0.14.0
|
|
4
12
|
|
|
5
13
|
### Minor Changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kalink-ui/seedly",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.15.0",
|
|
4
4
|
"description": "A set of components for building UIs with React and TypeScript",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"license": "MIT",
|
|
@@ -48,8 +48,8 @@
|
|
|
48
48
|
"vite-tsconfig-paths": "^5.1.4",
|
|
49
49
|
"vitest": "^3.0.8",
|
|
50
50
|
"@kalink-ui/dibbly": "0.4.0",
|
|
51
|
-
"@kalink-ui/
|
|
52
|
-
"@kalink-ui/
|
|
51
|
+
"@kalink-ui/eslint-config": "0.9.0",
|
|
52
|
+
"@kalink-ui/typescript-config": "0.4.0"
|
|
53
53
|
},
|
|
54
54
|
"peerDependencies": {
|
|
55
55
|
"@vanilla-extract/css": "^1.17.1",
|
|
@@ -21,7 +21,7 @@ export function LoaderOverlay({
|
|
|
21
21
|
}: LoaderOverlayProps) {
|
|
22
22
|
return (
|
|
23
23
|
<div className={clsx(loaderOverlay({ position }), className)}>
|
|
24
|
-
<Stack use={Center} spacing={spacing} intrinsic andText>
|
|
24
|
+
<Stack use={Center} align="center" spacing={spacing} intrinsic andText>
|
|
25
25
|
<MoonLoader active forceMount />
|
|
26
26
|
{text && <Text>{text}</Text>}
|
|
27
27
|
</Stack>
|
|
@@ -35,6 +35,37 @@ export const stackRecipe = recipe({
|
|
|
35
35
|
},
|
|
36
36
|
},
|
|
37
37
|
})),
|
|
38
|
+
|
|
39
|
+
align: {
|
|
40
|
+
start: {
|
|
41
|
+
'@layer': {
|
|
42
|
+
[components]: {
|
|
43
|
+
alignItems: 'flex-start',
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
center: {
|
|
48
|
+
'@layer': {
|
|
49
|
+
[components]: {
|
|
50
|
+
alignItems: 'center',
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
end: {
|
|
55
|
+
'@layer': {
|
|
56
|
+
[components]: {
|
|
57
|
+
alignItems: 'flex-end',
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
stretch: {
|
|
62
|
+
'@layer': {
|
|
63
|
+
[components]: {
|
|
64
|
+
alignItems: 'stretch',
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
},
|
|
38
69
|
},
|
|
39
70
|
});
|
|
40
71
|
|
|
@@ -20,11 +20,15 @@ export type StackProps<TUse extends ElementType> =
|
|
|
20
20
|
export function Stack<TUse extends ElementType = 'div'>({
|
|
21
21
|
spacing,
|
|
22
22
|
className,
|
|
23
|
+
align,
|
|
23
24
|
...props
|
|
24
25
|
}: StackProps<TUse>) {
|
|
25
26
|
const { use: Comp = 'div', ...rest } = props;
|
|
26
27
|
|
|
27
28
|
return (
|
|
28
|
-
<Comp
|
|
29
|
+
<Comp
|
|
30
|
+
className={clsx(stackRecipe({ spacing, align }), className)}
|
|
31
|
+
{...rest}
|
|
32
|
+
/>
|
|
29
33
|
);
|
|
30
34
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useLocalStorage } from './use-local-storage';
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { useCallback, useEffect, useSyncExternalStore } from 'react';
|
|
4
|
+
|
|
5
|
+
type Serializable =
|
|
6
|
+
| string
|
|
7
|
+
| number
|
|
8
|
+
| boolean
|
|
9
|
+
| null
|
|
10
|
+
| Serializable[]
|
|
11
|
+
| { [key: string]: Serializable };
|
|
12
|
+
|
|
13
|
+
type StateUpdater<T> = (oldValue: T) => T;
|
|
14
|
+
|
|
15
|
+
function dispatchStorageEvent(key: string, newValue: string | null) {
|
|
16
|
+
window.dispatchEvent(new StorageEvent('storage', { key, newValue }));
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function subscribeToStorageEvent(callback: () => void) {
|
|
20
|
+
window.addEventListener('storage', callback);
|
|
21
|
+
|
|
22
|
+
return () => window.removeEventListener('storage', callback);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function setLocalStorage<T>(key: string, value: T) {
|
|
26
|
+
const stringifiedValue = JSON.stringify(value);
|
|
27
|
+
|
|
28
|
+
window.localStorage.setItem(key, stringifiedValue);
|
|
29
|
+
|
|
30
|
+
dispatchStorageEvent(key, stringifiedValue);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function removeLocalStorage(key: string) {
|
|
34
|
+
window.localStorage.removeItem(key);
|
|
35
|
+
|
|
36
|
+
dispatchStorageEvent(key, null);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function getLocalStorage(key: string) {
|
|
40
|
+
return window.localStorage.getItem(key);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function getLocalStorageServerSnapshot<T>(initialValue: T) {
|
|
44
|
+
const initialSnapshot = JSON.stringify(initialValue);
|
|
45
|
+
|
|
46
|
+
return () => initialSnapshot;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const cachedStore = new Map<string, Serializable>();
|
|
50
|
+
|
|
51
|
+
export function useLocalStorage<T extends Serializable>(
|
|
52
|
+
key: string,
|
|
53
|
+
initialValue: T,
|
|
54
|
+
): [T, (value: T | StateUpdater<T>) => void] {
|
|
55
|
+
const getSnapshot = () => getLocalStorage(key);
|
|
56
|
+
|
|
57
|
+
const store = useSyncExternalStore(
|
|
58
|
+
subscribeToStorageEvent,
|
|
59
|
+
getSnapshot,
|
|
60
|
+
getLocalStorageServerSnapshot(initialValue),
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
const setValue = useCallback(
|
|
64
|
+
(value: T | StateUpdater<T>) => {
|
|
65
|
+
try {
|
|
66
|
+
const newValue =
|
|
67
|
+
typeof value === 'function'
|
|
68
|
+
? value(store ? JSON.parse(store) : null)
|
|
69
|
+
: value;
|
|
70
|
+
|
|
71
|
+
if (newValue === undefined || newValue === null) {
|
|
72
|
+
removeLocalStorage(key);
|
|
73
|
+
} else {
|
|
74
|
+
setLocalStorage(key, newValue);
|
|
75
|
+
}
|
|
76
|
+
} catch (error) {
|
|
77
|
+
console.error(error);
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
[key, store],
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
useEffect(() => {
|
|
84
|
+
if (getLocalStorage(key) === null && typeof initialValue !== 'undefined') {
|
|
85
|
+
setLocalStorage(key, initialValue);
|
|
86
|
+
}
|
|
87
|
+
}, [key, initialValue]);
|
|
88
|
+
|
|
89
|
+
if (!store) {
|
|
90
|
+
return [initialValue, setValue];
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if (!cachedStore.has(store)) {
|
|
94
|
+
cachedStore.clear();
|
|
95
|
+
cachedStore.set(store, JSON.parse(store));
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return [cachedStore.get(store) as T, setValue];
|
|
99
|
+
}
|
package/src/index.ts
CHANGED