@swan-io/lake 11.1.6 → 11.1.8
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/package.json
CHANGED
package/src/components/Icon.d.ts
CHANGED
|
@@ -196,7 +196,7 @@ export const MultiSelect = ({ color = "gray", disabled = false, emptyResultText,
|
|
|
196
196
|
}, [filteredItems]);
|
|
197
197
|
const ListHeaderComponent = useMemo(() => (_jsxs(Box, { direction: "row", alignItems: "center", style: styles.filterContainer, children: [_jsx(TextInput, { autoComplete: "off", inputMode: "search", multiline: false, rows: 1, onChangeText: filterValue => setFilter(filterValue), placeholder: filterPlaceholder, value: filter, onFocus: setFilterFocused.on, onBlur: setFilterFocused.off, style: [styles.filterInput, filterFocused && styles.filterFocused] }), _jsx(Icon, { name: "search-filled", color: colors[color].primary, size: 20, style: styles.searchIcon })] })), [filter, filterFocused, setFilterFocused, filterPlaceholder, color]);
|
|
198
198
|
const ListEmptyComponent = useMemo(() => (_jsxs(Box, { justifyContent: "center", alignItems: "center", style: styles.emptyList, children: [_jsx(Icon, { name: "clipboard-search-regular", size: 24, color: colors.gray.primary }), isNotNullishOrEmpty(emptyResultText) && (_jsxs(_Fragment, { children: [_jsx(Space, { height: 8 }), _jsx(Text, { style: styles.emptyListText, children: emptyResultText })] }))] })), [emptyResultText]);
|
|
199
|
-
return (_jsxs(View, { style: style, children: [_jsxs(Pressable, { id: id, ref: inputRef, "aria-haspopup": "listbox",
|
|
199
|
+
return (_jsxs(View, { style: style, children: [_jsxs(Pressable, { id: id, ref: inputRef, "aria-haspopup": "listbox", "aria-expanded": visible, disabled: disabled, onPress: open, style: ({ hovered, focused }) => [
|
|
200
200
|
styles.base,
|
|
201
201
|
hovered && styles.hovered,
|
|
202
202
|
(focused || visible) && styles.focused,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const usePersistedState: <T>(key: string, defaultValue: T) => readonly [T, (
|
|
1
|
+
export declare const usePersistedState: <T>(key: string, defaultValue: T) => readonly [T, (value: T | null) => void];
|
|
@@ -1,21 +1,55 @@
|
|
|
1
1
|
import { Option, Result } from "@swan-io/boxed";
|
|
2
|
-
import { useCallback, useState } from "react";
|
|
2
|
+
import { useCallback, useEffect, useState } from "react";
|
|
3
|
+
const getItem = (key) => Result.fromExecution(() => localStorage.getItem(key)).getOr(null);
|
|
4
|
+
const parseRawValue = (rawValue, defaultValue) => Result.fromExecution(() => (rawValue != null ? JSON.parse(rawValue) : rawValue))
|
|
5
|
+
.toOption()
|
|
6
|
+
.flatMap(Option.fromNullable)
|
|
7
|
+
.getOr(defaultValue);
|
|
3
8
|
export const usePersistedState = (key, defaultValue) => {
|
|
4
9
|
const [state, setState] = useState(() => {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
.map(value => JSON.parse(value))
|
|
9
|
-
.getOr(defaultValue);
|
|
10
|
+
const rawValue = getItem(key);
|
|
11
|
+
const value = parseRawValue(rawValue, defaultValue);
|
|
12
|
+
return { defaultValue, value, rawValue };
|
|
10
13
|
});
|
|
11
|
-
const
|
|
12
|
-
setState(
|
|
14
|
+
const updateRawValue = useCallback((rawValue) => {
|
|
15
|
+
setState(prevState => {
|
|
16
|
+
if (rawValue === prevState.rawValue) {
|
|
17
|
+
return prevState; // skip update if rawValue didn't changed
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
const { defaultValue } = prevState;
|
|
21
|
+
const value = parseRawValue(rawValue, defaultValue);
|
|
22
|
+
return { defaultValue, value, rawValue };
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
}, []);
|
|
26
|
+
const setPersistedState = useCallback((value) => {
|
|
13
27
|
try {
|
|
14
|
-
|
|
28
|
+
if (value != null) {
|
|
29
|
+
const rawValue = JSON.stringify(value);
|
|
30
|
+
updateRawValue(rawValue);
|
|
31
|
+
localStorage.setItem(key, rawValue);
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
updateRawValue(null);
|
|
35
|
+
localStorage.removeItem(key);
|
|
36
|
+
}
|
|
15
37
|
}
|
|
16
38
|
catch {
|
|
17
39
|
// ignore
|
|
18
40
|
}
|
|
19
|
-
}, [key]);
|
|
20
|
-
|
|
41
|
+
}, [key, updateRawValue]);
|
|
42
|
+
useEffect(() => {
|
|
43
|
+
const listener = (event) => {
|
|
44
|
+
if (event.storageArea === localStorage && (event.key === key || event.key === null)) {
|
|
45
|
+
const rawValue = getItem(key);
|
|
46
|
+
updateRawValue(rawValue);
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
window.addEventListener("storage", listener);
|
|
50
|
+
return () => {
|
|
51
|
+
window.removeEventListener("storage", listener);
|
|
52
|
+
};
|
|
53
|
+
}, [key, updateRawValue]);
|
|
54
|
+
return [state.value, setPersistedState];
|
|
21
55
|
};
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
"add-circle-filled": "M12 2a10 10 0 1 1 0 20 10 10 0 0 1 0-20Zm0 5c-.38 0-.7.28-.74.65l-.01.1v3.5h-3.5a.75.75 0 0 0-.1 1.5h3.6v3.5a.75.75 0 0 0 1.5.1v-3.6h3.5a.75.75 0 0 0 .1-1.5h-3.6v-3.5A.75.75 0 0 0 12 7Z",
|
|
3
3
|
"add-circle-regular": "M12 2a10 10 0 1 1 0 20 10 10 0 0 1 0-20Zm0 1.5a8.5 8.5 0 1 0 0 17 8.5 8.5 0 0 0 0-17ZM12 7c.41 0 .75.34.75.75v3.5h3.5a.75.75 0 0 1 0 1.5h-3.5v3.5a.75.75 0 0 1-1.5 0v-3.5h-3.5a.75.75 0 0 1 0-1.5h3.5v-3.5c0-.41.34-.75.75-.75Z",
|
|
4
4
|
"add-filled": "M11.88 3H12a1 1 0 0 1 1 .88V11h7a1 1 0 0 1 1 .88V12a1 1 0 0 1-.88 1H13v7a1 1 0 0 1-.88 1H12a1 1 0 0 1-1-.88V13H4a1 1 0 0 1-1-.88V12a1 1 0 0 1 .88-1H11V4a1 1 0 0 1 .88-1H12h-.12Z",
|
|
5
|
+
"alert-regular": "M12 2a7.5 7.5 0 0 1 7.5 7.25v4.35l1.38 3.15a1.25 1.25 0 0 1-1.15 1.75H15a3 3 0 0 1-6 .18v-.18H4.27a1.25 1.25 0 0 1-1.14-1.75L4.5 13.6V9.5C4.5 5.35 7.85 2 12 2Zm1.5 16.5h-3a1.5 1.5 0 0 0 3 .15v-.15ZM12 3.5c-3.32 0-6 2.67-6 6v4.4L4.66 17h14.7L18 13.9V9.29a5.99 5.99 0 0 0-6-5.78Z",
|
|
5
6
|
"airplane-regular": "m9.47 9.64-.7-5.87v-.08c0-.88.72-1.6 1.6-1.6.8 0 1.55.42 1.98 1.13l.1.16 2.94 6.09 3.95-.12a2.6 2.6 0 0 1 2.68 2.53v.07a2.6 2.6 0 0 1-2.62 2.6l-3.97-.12-2.99 6.19a2.3 2.3 0 0 1-2.06 1.3c-.9 0-1.61-.73-1.61-1.64v-.12l.71-5.9-2.13-.07-.27.74a1.95 1.95 0 0 1-1.83 1.28c-.87 0-1.58-.71-1.58-1.59v-.76l-.16-.03a1.92 1.92 0 0 1 0-3.76l.16-.03v-.76c0-.8.6-1.48 1.43-1.58h.15c.75 0 1.43.42 1.77 1.12l.06.15.27.74 2.12-.07Zm.9-6.05c-.05 0-.1.04-.1.08l.88 7.42-4.84.15-.62-1.72-.04-.08c-.07-.15-.23-.25-.35-.25h-.06a.09.09 0 0 0-.07.09v1.98l-1.35.28a.42.42 0 0 0 0 .82l1.35.28v1.98c0 .05.03.09.08.09.19 0 .36-.12.42-.3l.64-1.75 4.86.15-.9 7.47v.03c0 .06.05.1.1.1a.8.8 0 0 0 .72-.44l3.42-7.07 4.9.15c.61 0 1.1-.5 1.1-1.09v-.04a1.1 1.1 0 0 0-1.12-1.07l-4.93.15-3.35-6.93-.06-.1a.8.8 0 0 0-.67-.38Z",
|
|
6
7
|
"approvals-app-filled": "M10.54 1.8a1 1 0 0 1 1.42 0l2.5 2.5a1 1 0 0 1 0 1.4l-2.5 2.5a1 1 0 1 1-1.42-1.4l.76-.77a7 7 0 1 0 7.65 7.85 1 1 0 1 1 1.98.24 9 9 0 1 1-9.57-10.1l-.82-.81a1 1 0 0 1 0-1.42Zm5.67 8a1 1 0 0 1 0 1.4l-4.5 4.5a1 1 0 0 1-1.42 0l-2-2a1 1 0 1 1 1.42-1.4L11 13.58l3.8-3.8a1 1 0 0 1 1.4 0Z",
|
|
7
8
|
"apps-list-filled": "M6.25 16C7.2 16 8 16.8 8 17.75v2.5C8 21.22 7.2 22 6.25 22h-2.5C2.78 22 2 21.22 2 20.25v-2.5C2 16.8 2.78 16 3.75 16h2.5Zm3.5 2h11.5a.75.75 0 0 1 .1 1.5H9.75a.75.75 0 0 1-.1-1.5h11.6-11.5Zm-3.5-9C7.2 9 8 9.78 8 10.75v2.5C8 14.22 7.2 15 6.25 15h-2.5C2.78 15 2 14.22 2 13.25v-2.5C2 9.78 2.78 9 3.75 9h2.5Zm3.5 2h11.5a.75.75 0 0 1 .1 1.5H9.75a.75.75 0 0 1-.1-1.5h11.6-11.5Zm-3.5-9C7.2 2 8 2.78 8 3.75v2.5C8 7.2 7.2 8 6.25 8h-2.5C2.78 8 2 7.2 2 6.25v-2.5C2 2.78 2.78 2 3.75 2h2.5Zm3.5 2h11.5a.75.75 0 0 1 .1 1.5H9.75a.75.75 0 0 1-.1-1.5h11.6-11.5Z",
|