@swan-io/lake 2.7.6 → 2.7.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 +11 -11
- package/src/components/FixedListViewCells.d.ts +1 -1
- package/src/components/FixedListViewCells.js +3 -2
- package/src/components/LakeCombobox.js +25 -19
- package/src/components/LakeText.js +10 -1
- package/src/components/Popover.d.ts +2 -1
- package/src/components/Popover.js +3 -2
- package/src/hooks/useDisclosure.d.ts +1 -1
- package/src/hooks/useDisclosure.js +2 -5
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@swan-io/lake",
|
|
3
|
-
"version": "2.7.
|
|
3
|
+
"version": "2.7.8",
|
|
4
4
|
"engines": {
|
|
5
5
|
"node": ">=18.0.0",
|
|
6
6
|
"yarn": "^1.22.0"
|
|
@@ -27,9 +27,9 @@
|
|
|
27
27
|
"license": "MIT",
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"@popperjs/core": "^2.11.8",
|
|
30
|
-
"@react-three/drei": "^9.
|
|
31
|
-
"@react-three/fiber": "^8.13.
|
|
32
|
-
"@swan-io/boxed": "^1.0
|
|
30
|
+
"@react-three/drei": "^9.80.1",
|
|
31
|
+
"@react-three/fiber": "^8.13.6",
|
|
32
|
+
"@swan-io/boxed": "^1.1.0",
|
|
33
33
|
"@swan-io/chicane": "^1.4.1",
|
|
34
34
|
"dayjs": "^1.11.9",
|
|
35
35
|
"polished": "^4.2.2",
|
|
@@ -39,21 +39,21 @@
|
|
|
39
39
|
"react-dom": "^18.2.0",
|
|
40
40
|
"react-native-web": "^0.19.7",
|
|
41
41
|
"react-popper": "^2.3.0",
|
|
42
|
-
"react-ux-form": "^1.
|
|
42
|
+
"react-ux-form": "^1.5.0",
|
|
43
43
|
"rifm": "^0.12.1",
|
|
44
|
-
"three": "^0.
|
|
44
|
+
"three": "^0.155.0",
|
|
45
45
|
"ts-dedent": "^2.2.0",
|
|
46
|
-
"ts-pattern": "^5.0.
|
|
47
|
-
"urql": "^4.0.
|
|
46
|
+
"ts-pattern": "^5.0.5",
|
|
47
|
+
"urql": "^4.0.5",
|
|
48
48
|
"uuid": "^9.0.0"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
|
-
"@types/react": "^18.2.
|
|
51
|
+
"@types/react": "^18.2.19",
|
|
52
52
|
"@types/react-dom": "^18.2.7",
|
|
53
53
|
"@types/react-native": "^0.72.2",
|
|
54
|
-
"@types/three": "^0.
|
|
54
|
+
"@types/three": "^0.155.0",
|
|
55
55
|
"@types/uuid": "^9.0.2",
|
|
56
56
|
"jsdom": "^22.1.0",
|
|
57
|
-
"type-fest": "^4.
|
|
57
|
+
"type-fest": "^4.2.0"
|
|
58
58
|
}
|
|
59
59
|
}
|
|
@@ -115,11 +115,12 @@ export const SimpleRegularTextCell = ({ variant = "regular", text, textAlign = "
|
|
|
115
115
|
};
|
|
116
116
|
export const CopyableRegularTextCell = ({ variant = "regular", text, textToCopy, copyWording, copiedWording, tooltip, }) => {
|
|
117
117
|
const [visibleState, setVisibleState] = useState("copy");
|
|
118
|
+
const clipboardText = textToCopy ?? text;
|
|
118
119
|
const onPress = useCallback((event) => {
|
|
119
120
|
event.preventDefault();
|
|
120
|
-
Clipboard.setString(
|
|
121
|
+
Clipboard.setString(clipboardText);
|
|
121
122
|
setVisibleState("copied");
|
|
122
|
-
}, [
|
|
123
|
+
}, [clipboardText]);
|
|
123
124
|
return (_jsxs(View, { style: styles.cell, children: [_jsx(LakeTooltip, { placement: "top", onHide: () => setVisibleState("copy"), togglableOnFocus: true, content: visibleState === "copy" ? copyWording : copiedWording, containerStyle: styles.iconContainer, children: _jsx(Pressable, { role: "button", "aria-label": copyWording, onPress: onPress, style: ({ hovered }) => [styles.icon, hovered && styles.underline], children: ({ hovered }) => (_jsx(Icon, { name: hovered ? "copy-filled" : "copy-regular", color: "currentColor", size: 14 })) }) }), _jsx(Space, { width: 4 }), _jsx(LakeText, { tooltip: tooltip, color: colors.gray[900], style: styles.regularText, variant: variant, children: text })] }));
|
|
124
125
|
};
|
|
125
126
|
// TODO: handle `+` sign properly
|
|
@@ -3,14 +3,15 @@ import { forwardRef, useCallback, useId, useImperativeHandle, useRef, useState,
|
|
|
3
3
|
import { FlatList, Pressable, StyleSheet, Text, View, } from "react-native";
|
|
4
4
|
import { backgroundColor, colors, spacings } from "../constants/design";
|
|
5
5
|
import { typography } from "../constants/typography";
|
|
6
|
-
import { useDisclosure } from "../hooks/useDisclosure";
|
|
7
6
|
import { useMergeRefs } from "../hooks/useMergeRefs";
|
|
8
7
|
import { getFocusableElements } from "../utils/a11y";
|
|
8
|
+
import { isNotEmpty } from "../utils/nullish";
|
|
9
9
|
import { Box } from "./Box";
|
|
10
10
|
import { Icon } from "./Icon";
|
|
11
11
|
import { LakeTextInput } from "./LakeTextInput";
|
|
12
12
|
import { LoadingView } from "./LoadingView";
|
|
13
13
|
import { Popover } from "./Popover";
|
|
14
|
+
import { Separator } from "./Separator";
|
|
14
15
|
import { Space } from "./Space";
|
|
15
16
|
const DEFAULT_ELEMENT_HEIGHT = 64;
|
|
16
17
|
const DEFAULT_NB_SUGGESTION_DISPLAYED = 3.5;
|
|
@@ -28,9 +29,6 @@ const styles = StyleSheet.create({
|
|
|
28
29
|
transitionProperty: "background-color",
|
|
29
30
|
transitionDuration: "200ms",
|
|
30
31
|
outlineStyle: "none",
|
|
31
|
-
borderColor: colors.gray[100],
|
|
32
|
-
borderStyle: "solid",
|
|
33
|
-
borderBottomWidth: 1,
|
|
34
32
|
justifyContents: "center",
|
|
35
33
|
},
|
|
36
34
|
hoveredItem: {
|
|
@@ -86,9 +84,14 @@ const LakeComboboxWithRef = ({ inputRef, value, items, itemHeight = DEFAULT_ELEM
|
|
|
86
84
|
const listRef = useRef(null);
|
|
87
85
|
const listContainerRef = useRef(null);
|
|
88
86
|
const blurTimeoutId = useRef(undefined);
|
|
89
|
-
const [isFocused, { open, close }] = useDisclosure(false, () => setHasChanged(false));
|
|
90
87
|
const [isFetchingAdditionalInfo, setIsFetchingAdditionalInfo] = useState(false);
|
|
91
|
-
|
|
88
|
+
// The Combobox has two distinct closed states: "closed" and "dismissed"
|
|
89
|
+
// When it's "closed", it will open on input focus or text change
|
|
90
|
+
// When it's "dismissed", it will NOT open on input focus, but will on text change
|
|
91
|
+
const [state, setState] = useState("closed");
|
|
92
|
+
const open = useCallback(() => setState("opened"), []);
|
|
93
|
+
const close = useCallback(() => setState("closed"), []);
|
|
94
|
+
const dismiss = useCallback(() => setState("dismissed"), []);
|
|
92
95
|
useImperativeHandle(externalRef, () => {
|
|
93
96
|
return {
|
|
94
97
|
open,
|
|
@@ -130,27 +133,30 @@ const LakeComboboxWithRef = ({ inputRef, value, items, itemHeight = DEFAULT_ELEM
|
|
|
130
133
|
}
|
|
131
134
|
}
|
|
132
135
|
}, []);
|
|
136
|
+
const handleChangeText = useCallback((value) => {
|
|
137
|
+
onValueChange(value);
|
|
138
|
+
setState(isNotEmpty(value) ? "opened" : "closed");
|
|
139
|
+
}, [onValueChange]);
|
|
133
140
|
const handleFocus = useCallback(() => {
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
141
|
+
if (isNotEmpty(value)) {
|
|
142
|
+
window.clearTimeout(blurTimeoutId.current);
|
|
143
|
+
blurTimeoutId.current = window.setTimeout(() => {
|
|
144
|
+
setState(prevState => (prevState === "closed" ? "opened" : prevState));
|
|
145
|
+
}, 100);
|
|
146
|
+
}
|
|
147
|
+
}, [value]);
|
|
139
148
|
const handleBlur = useCallback(() => {
|
|
140
149
|
window.clearTimeout(blurTimeoutId.current);
|
|
141
150
|
blurTimeoutId.current = window.setTimeout(() => {
|
|
142
|
-
|
|
151
|
+
setState("dismissed");
|
|
143
152
|
}, 100);
|
|
144
|
-
}, [
|
|
145
|
-
return (_jsxs(View, { children: [_jsx(LakeTextInput, { containerRef: inputTextRef, style: styles.input, ariaExpanded:
|
|
146
|
-
setHasChanged(true);
|
|
147
|
-
onChange?.(event);
|
|
148
|
-
}, onFocus: handleFocus, onBlur: handleBlur, onKeyPress: handleKeyPress, id: id, readOnly: readOnly }), _jsx(Popover, { id: suggestionsId, role: "listbox", matchReferenceWidth: true, onDismiss: close, referenceRef: ref, autoFocus: false, returnFocus: true, visible: isFocused && !items.isNotAsked() && hasChanged, underlay: false, forcedMode: "Dropdown", children: _jsx(View, { style: [styles.list, { maxHeight: itemHeight * nbItemsDisplayed }], children: items.match({
|
|
153
|
+
}, []);
|
|
154
|
+
return (_jsxs(View, { children: [_jsx(LakeTextInput, { containerRef: inputTextRef, style: styles.input, ariaExpanded: state === "opened", ariaControls: state === "opened" ? suggestionsId : "", enterKeyHint: "search", icon: icon, role: "combobox", placeholder: placeholder, value: value, disabled: disabled, error: error, hideErrors: hideErrors, onChangeText: handleChangeText, onChange: onChange, onFocus: handleFocus, onBlur: handleBlur, onKeyPress: handleKeyPress, id: id, readOnly: readOnly }), _jsx(Popover, { id: suggestionsId, role: "listbox", matchReferenceWidth: true, onEscapeKey: dismiss, referenceRef: ref, autoFocus: false, returnFocus: true, visible: state === "opened" && !items.isNotAsked(), underlay: false, forcedMode: "Dropdown", children: _jsx(View, { style: [styles.list, { maxHeight: itemHeight * nbItemsDisplayed }], children: items.match({
|
|
149
155
|
NotAsked: () => null,
|
|
150
156
|
Loading: () => _jsx(LoadingView, { style: styles.loader }),
|
|
151
157
|
Done: items => items.match({
|
|
152
158
|
Error: _ => (_jsx(Icon, { name: "error-circle-regular", size: 22, color: colors.negative[500] })),
|
|
153
|
-
Ok: items => (_jsxs(View, { ref: listContainerRef, style: styles.listContainer, children: [items.length === 0 ? (_jsxs(Box, { justifyContent: "center", alignItems: "center", style: styles.emptyList, children: [_jsx(Icon, { name: "clipboard-search-regular", size: 24, color: colors.gray.primary }), _jsx(Space, { height: 8 }), _jsx(Text, { style: styles.emptyListText, children: emptyResultText })] })) : (_jsx(FlatList, { ref: listRef, keyExtractor: keyExtractor, getItemLayout: getItemLayout, role: "list", data: items, style: styles.flatList, renderItem: ({ item }) => {
|
|
159
|
+
Ok: items => (_jsxs(View, { ref: listContainerRef, style: styles.listContainer, children: [items.length === 0 ? (_jsxs(Box, { justifyContent: "center", alignItems: "center", style: styles.emptyList, children: [_jsx(Icon, { name: "clipboard-search-regular", size: 24, color: colors.gray.primary }), _jsx(Space, { height: 8 }), _jsx(Text, { style: styles.emptyListText, children: emptyResultText })] })) : (_jsx(FlatList, { ref: listRef, keyExtractor: keyExtractor, getItemLayout: getItemLayout, role: "list", data: items, style: styles.flatList, ItemSeparatorComponent: Separator, renderItem: ({ item }) => {
|
|
154
160
|
const rendered = renderItem(item);
|
|
155
161
|
return (_jsx(Pressable, { onFocus: handleFocus, onBlur: handleBlur, role: "listitem", onKeyDown: handleListItemKeyPress, style: ({ hovered, pressed, focused }) => [
|
|
156
162
|
styles.item,
|
|
@@ -163,7 +169,7 @@ const LakeComboboxWithRef = ({ inputRef, value, items, itemHeight = DEFAULT_ELEM
|
|
|
163
169
|
setIsFetchingAdditionalInfo(true);
|
|
164
170
|
void Promise.resolve(onSelectItem(item)).finally(() => {
|
|
165
171
|
setIsFetchingAdditionalInfo(false);
|
|
166
|
-
|
|
172
|
+
dismiss();
|
|
167
173
|
});
|
|
168
174
|
}, children: isReactText(rendered) ? (_jsx(Text, { numberOfLines: 1, style: styles.itemText, children: rendered })) : (rendered) }));
|
|
169
175
|
} })), ListFooterComponent, isFetchingAdditionalInfo ? (_jsxs(View, { style: styles.loaderAdditional, children: [_jsx(View, { style: styles.loaderAdditionalUnderlay }), _jsx(LoadingView, {})] })) : null] })),
|
|
@@ -18,10 +18,19 @@ const variants = StyleSheet.create({
|
|
|
18
18
|
smallMedium: texts.smallMedium,
|
|
19
19
|
smallRegular: texts.smallRegular,
|
|
20
20
|
});
|
|
21
|
+
const styles = StyleSheet.create({
|
|
22
|
+
tooltip: {
|
|
23
|
+
width: "100%",
|
|
24
|
+
},
|
|
25
|
+
ellipsis: {
|
|
26
|
+
overflow: "hidden",
|
|
27
|
+
textOverflow: "ellipsis",
|
|
28
|
+
},
|
|
29
|
+
});
|
|
21
30
|
export const LakeText = forwardRef(({ align = "left", children, color, style, userSelect, variant = "regular", tooltip, ...props }, forwardedRef) => (_jsx(Text, { ref: forwardedRef, style: [
|
|
22
31
|
variants[variant],
|
|
23
32
|
alignments[align],
|
|
24
33
|
isNotNullish(color) && { color },
|
|
25
34
|
isNotNullish(userSelect) && { userSelect },
|
|
26
35
|
style,
|
|
27
|
-
], ...props, children: tooltip ? (_jsx(LakeTooltip, { ...tooltip, children: _jsx(Text, { children: children }) })) : (children) })));
|
|
36
|
+
], ...props, children: tooltip ? (_jsx(LakeTooltip, { containerStyle: styles.tooltip, ...tooltip, children: _jsx(Text, { style: styles.ellipsis, children: children }) })) : (children) })));
|
|
@@ -9,7 +9,8 @@ type Props = {
|
|
|
9
9
|
describedBy?: string;
|
|
10
10
|
matchReferenceWidth?: boolean;
|
|
11
11
|
matchReferenceMinWidth?: boolean;
|
|
12
|
-
onDismiss
|
|
12
|
+
onDismiss?: () => void;
|
|
13
|
+
onEscapeKey?: () => void;
|
|
13
14
|
referenceRef: RefObject<unknown>;
|
|
14
15
|
returnFocus?: boolean;
|
|
15
16
|
autoFocus?: boolean;
|
|
@@ -4,6 +4,7 @@ import { Pressable, ScrollView, StyleSheet, View, } from "react-native";
|
|
|
4
4
|
import { match, P } from "ts-pattern";
|
|
5
5
|
import { animations, backgroundColor, radii, shadows } from "../constants/design";
|
|
6
6
|
import { useResponsive } from "../hooks/useResponsive";
|
|
7
|
+
import { noop } from "../utils/function";
|
|
7
8
|
import { BottomPanel } from "./BottomPanel";
|
|
8
9
|
import { FocusTrap } from "./FocusTrap";
|
|
9
10
|
import { Portal } from "./Portal";
|
|
@@ -65,7 +66,7 @@ const animation = {
|
|
|
65
66
|
],
|
|
66
67
|
};
|
|
67
68
|
export const VIEWPORT_WIDTH_THRESHOLD = 600;
|
|
68
|
-
export const Popover = memo(({ children, id, label, role = "dialog", describedBy, matchReferenceWidth = false, matchReferenceMinWidth = false, onDismiss, referenceRef, returnFocus = true, autoFocus = true, visible, underlay = true, safetyMargin = 8, forcedMode, }) => {
|
|
69
|
+
export const Popover = memo(({ children, id, label, role = "dialog", describedBy, matchReferenceWidth = false, matchReferenceMinWidth = false, onDismiss = noop, onEscapeKey = onDismiss, referenceRef, returnFocus = true, autoFocus = true, visible, underlay = true, safetyMargin = 8, forcedMode, }) => {
|
|
69
70
|
const [rootElement, setRootElement] = useState(null);
|
|
70
71
|
const underlayRef = useRef(null);
|
|
71
72
|
const { desktop } = useResponsive(VIEWPORT_WIDTH_THRESHOLD);
|
|
@@ -147,5 +148,5 @@ export const Popover = memo(({ children, id, label, role = "dialog", describedBy
|
|
|
147
148
|
{
|
|
148
149
|
justifyContent: availableSpaceAbove > availableSpaceBelow ? FLEX_END : FLEX_START,
|
|
149
150
|
},
|
|
150
|
-
], id: id, role: role, "aria-describedby": describedBy, "aria-label": label, children: _jsx(FocusTrap, { focusLock: true, returnFocus: returnFocus, autoFocus: autoFocus, onEscapeKey:
|
|
151
|
+
], id: id, role: role, "aria-describedby": describedBy, "aria-label": label, children: _jsx(FocusTrap, { focusLock: true, returnFocus: returnFocus, autoFocus: autoFocus, onEscapeKey: onEscapeKey, onClickOutside: underlay ? undefined : onClickOutside, children: _jsx(Pressable, { tabIndex: -1, onPress: onPress, style: styles.defaultCursor, children: typeof children == "function" ? children({ mode: "dropdown" }) : children }) }) })) : null] })) : null }) }));
|
|
151
152
|
});
|
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
import { useMemo, useState } from "react";
|
|
2
|
-
export const useDisclosure = (initialValue
|
|
2
|
+
export const useDisclosure = (initialValue) => {
|
|
3
3
|
const [value, setValue] = useState(initialValue);
|
|
4
4
|
return [
|
|
5
5
|
value,
|
|
6
6
|
useMemo(() => ({
|
|
7
7
|
open: () => setValue(true),
|
|
8
|
-
close: () =>
|
|
9
|
-
setValue(false);
|
|
10
|
-
onClose?.();
|
|
11
|
-
},
|
|
8
|
+
close: () => setValue(false),
|
|
12
9
|
toggle: () => setValue(prevValue => !prevValue),
|
|
13
10
|
}), []),
|
|
14
11
|
];
|