@swan-io/lake 11.4.1 → 11.4.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/package.json
CHANGED
|
@@ -5,7 +5,8 @@ type Props = {
|
|
|
5
5
|
onChangeText: (text: string) => void;
|
|
6
6
|
debounceDuration?: number;
|
|
7
7
|
maxWidth?: number;
|
|
8
|
+
children?: ReactNode;
|
|
8
9
|
renderEnd?: () => ReactNode;
|
|
9
10
|
};
|
|
10
|
-
export declare const LakeSearchField: ({ initialValue, placeholder, onChangeText, debounceDuration, maxWidth, renderEnd, }: Props) => import("react/jsx-runtime").JSX.Element;
|
|
11
|
+
export declare const LakeSearchField: ({ initialValue, placeholder, onChangeText, debounceDuration, maxWidth: maxWidthProp, renderEnd, children, }: Props) => import("react/jsx-runtime").JSX.Element;
|
|
11
12
|
export {};
|
|
@@ -5,23 +5,22 @@ import { animations, backgroundColor, colors, radii, spacings } from "../constan
|
|
|
5
5
|
import { useBoolean } from "../hooks/useBoolean";
|
|
6
6
|
import { useDebounce } from "../hooks/useDebounce";
|
|
7
7
|
import { isNotNullishOrEmpty } from "../utils/nullish";
|
|
8
|
+
import { Icon } from "./Icon";
|
|
8
9
|
import { LakeButton } from "./LakeButton";
|
|
9
10
|
import { LakeTextInput } from "./LakeTextInput";
|
|
10
11
|
import { ResponsiveContainer } from "./ResponsiveContainer";
|
|
11
|
-
import { Line, Svg } from "./Svg";
|
|
12
12
|
import { TransitionView } from "./TransitionView";
|
|
13
|
+
const BREAKPOINT = 350;
|
|
13
14
|
const styles = StyleSheet.create({
|
|
14
15
|
container: {
|
|
16
|
+
flexDirection: "row",
|
|
17
|
+
alignItems: "center",
|
|
18
|
+
justifyContent: "flex-end",
|
|
15
19
|
flexGrow: 1,
|
|
16
20
|
flexShrink: 1,
|
|
17
21
|
},
|
|
18
22
|
input: {
|
|
19
23
|
transition: "300ms ease-in-out border-color",
|
|
20
|
-
// ResponsiveContainer uses a 200 breaking,
|
|
21
|
-
// we give the opportunity to the component to grow 2px more
|
|
22
|
-
// to trigger the change
|
|
23
|
-
maxWidth: 202,
|
|
24
|
-
minWidth: 38,
|
|
25
24
|
justifyContent: "flex-end",
|
|
26
25
|
},
|
|
27
26
|
focus: {
|
|
@@ -29,21 +28,8 @@ const styles = StyleSheet.create({
|
|
|
29
28
|
borderColor: colors.current.primary,
|
|
30
29
|
},
|
|
31
30
|
clearButton: {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
clear: {
|
|
35
|
-
width: 8,
|
|
36
|
-
height: 8,
|
|
37
|
-
},
|
|
38
|
-
smallButtonContainer: {
|
|
39
|
-
flexDirection: "row",
|
|
40
|
-
justifyContent: "flex-end",
|
|
41
|
-
flexGrow: 1,
|
|
42
|
-
},
|
|
43
|
-
largeInputContainer: {
|
|
44
|
-
flexDirection: "row",
|
|
45
|
-
justifyContent: "flex-end",
|
|
46
|
-
flexGrow: 1,
|
|
31
|
+
padding: spacings[8],
|
|
32
|
+
borderRadius: radii[4],
|
|
47
33
|
},
|
|
48
34
|
openSearchFieldContainer: {
|
|
49
35
|
position: "absolute",
|
|
@@ -60,19 +46,17 @@ const styles = StyleSheet.create({
|
|
|
60
46
|
borderRadius: radii[6],
|
|
61
47
|
},
|
|
62
48
|
});
|
|
63
|
-
const
|
|
64
|
-
return (_jsxs(View, {
|
|
65
|
-
setFocused.on();
|
|
66
|
-
}, pill: currentValue !== "" }), _jsx(TransitionView, { style: styles.openSearchFieldContainer, ...animations.fadeAndSlideInFromRight, children: hasFocus ? (_jsx(View, { style: styles.openSearchField, children: _jsx(ExpandedSearchField, { inputRef: inputRef, placeholder: placeholder, initialValue: initialValue, onChange: onChange, setFocused: setFocused, hasFocus: hasFocus, clear: clear, currentValue: currentValue, renderEnd: renderEnd }) })) : null })] }));
|
|
49
|
+
const CollapsibleSearchField = ({ inputRef, placeholder, initialValue, onChange, setFocused, hasFocus, clear, currentValue, renderEnd, }) => {
|
|
50
|
+
return (_jsxs(View, { children: [_jsx(LakeButton, { mode: "secondary", size: "small", ariaLabel: placeholder, icon: "search-filled", onPress: setFocused.on, pill: currentValue !== "" }), _jsx(TransitionView, { style: styles.openSearchFieldContainer, ...animations.fadeAndSlideInFromRight, children: hasFocus ? (_jsx(View, { style: styles.openSearchField, children: _jsx(ExpandedSearchField, { inputRef: inputRef, placeholder: placeholder, initialValue: initialValue, onChange: onChange, setFocused: setFocused, hasFocus: hasFocus, clear: clear, currentValue: currentValue, renderEnd: renderEnd }) })) : null })] }));
|
|
67
51
|
};
|
|
68
52
|
const ExpandedSearchField = ({ inputRef, placeholder, initialValue, onChange, setFocused, hasFocus, clear, renderEnd, currentValue, }) => {
|
|
69
53
|
const timeoutRef = useRef(null);
|
|
70
|
-
return (_jsx(LakeTextInput, { ref: inputRef, autoFocus: hasFocus, icon: "search-filled", placeholder: placeholder, defaultValue: initialValue, inputMode: "search", onChangeText: onChange, hideErrors: true, renderEnd: () => (_jsxs(_Fragment, { children: [isNotNullishOrEmpty(currentValue) && (_jsx(Pressable, { onPress: () => {
|
|
54
|
+
return (_jsx(LakeTextInput, { ref: inputRef, autoFocus: hasFocus, icon: "search-filled", placeholder: placeholder, defaultValue: initialValue, inputMode: "search", onChangeText: onChange, hideErrors: true, renderEnd: () => (_jsxs(_Fragment, { children: [isNotNullishOrEmpty(currentValue) && (_jsx(Pressable, { role: "button", style: styles.clearButton, onPress: () => {
|
|
71
55
|
if (timeoutRef.current != null) {
|
|
72
56
|
clearTimeout(timeoutRef.current);
|
|
73
57
|
}
|
|
74
58
|
clear();
|
|
75
|
-
},
|
|
59
|
+
}, children: _jsx(Icon, { name: "dismiss-filled", size: 12, color: colors.gray[500] }) })), renderEnd === null || renderEnd === void 0 ? void 0 : renderEnd()] })), onFocus: () => {
|
|
76
60
|
if (timeoutRef.current != null) {
|
|
77
61
|
clearTimeout(timeoutRef.current);
|
|
78
62
|
}
|
|
@@ -81,9 +65,9 @@ const ExpandedSearchField = ({ inputRef, placeholder, initialValue, onChange, se
|
|
|
81
65
|
timeoutRef.current = window.setTimeout(() => {
|
|
82
66
|
setFocused.off();
|
|
83
67
|
}, 300);
|
|
84
|
-
},
|
|
68
|
+
}, style: [styles.input, hasFocus && styles.focus] }));
|
|
85
69
|
};
|
|
86
|
-
export const LakeSearchField = ({ initialValue, placeholder, onChangeText, debounceDuration = 500, maxWidth, renderEnd, }) => {
|
|
70
|
+
export const LakeSearchField = ({ initialValue, placeholder, onChangeText, debounceDuration = 500, maxWidth: maxWidthProp = 350, renderEnd, children, }) => {
|
|
87
71
|
const [hasFocus, setFocused] = useBoolean(false);
|
|
88
72
|
const inputRef = useRef(null);
|
|
89
73
|
const [currentValue, setCurrentValue] = useState(initialValue);
|
|
@@ -92,7 +76,7 @@ export const LakeSearchField = ({ initialValue, placeholder, onChangeText, debou
|
|
|
92
76
|
setCurrentValue(value.trim());
|
|
93
77
|
}, debounceDuration);
|
|
94
78
|
const clear = useCallback(() => {
|
|
95
|
-
if (inputRef.current
|
|
79
|
+
if (inputRef.current != null) {
|
|
96
80
|
inputRef.current.clear();
|
|
97
81
|
inputRef.current.focus();
|
|
98
82
|
onChangeText("");
|
|
@@ -110,8 +94,9 @@ export const LakeSearchField = ({ initialValue, placeholder, onChangeText, debou
|
|
|
110
94
|
currentValue,
|
|
111
95
|
renderEnd,
|
|
112
96
|
};
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
97
|
+
const maxWidth = Math.max(maxWidthProp, BREAKPOINT);
|
|
98
|
+
return (_jsx(ResponsiveContainer, { breakpoint: BREAKPOINT, style: [styles.container, { maxWidth }], children: ({ large }) => {
|
|
99
|
+
const Component = large ? ExpandedSearchField : CollapsibleSearchField;
|
|
100
|
+
return (_jsxs(_Fragment, { children: [children, _jsx(Component, { ...props })] }));
|
|
116
101
|
} }));
|
|
117
102
|
};
|
package/src/components/Toggle.js
CHANGED