@swan-io/lake 13.9.2 → 13.10.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/package.json
CHANGED
|
@@ -119,8 +119,7 @@ const styles = StyleSheet.create({
|
|
|
119
119
|
flexGrow: 1,
|
|
120
120
|
flexShrink: 1,
|
|
121
121
|
marginHorizontal: 16,
|
|
122
|
-
|
|
123
|
-
marginTop: 4,
|
|
122
|
+
marginTop: 16,
|
|
124
123
|
},
|
|
125
124
|
filterInput: {
|
|
126
125
|
...texts.regular,
|
|
@@ -235,32 +234,32 @@ export const LakeSelect = ({ ref, title, items, valueStyle, size, color = "curre
|
|
|
235
234
|
styles.itemText,
|
|
236
235
|
styles.selectPlaceholder,
|
|
237
236
|
isSmall && styles.selectSmallPlaceholder,
|
|
238
|
-
], children: placeholder !== null && placeholder !== void 0 ? placeholder : " " }))] }), _jsx(Fill, { minWidth: 8 }), !disabled && (_jsx(Icon, { color: colors.gray[900], name: visible ? "chevron-up-filled" : "chevron-down-filled", size: 16 }))] })] })) }), !hideErrors && (_jsx(LakeText, { variant: "smallRegular", color: colors.negative[500], style: styles.errorText, children: error !== null && error !== void 0 ? error : " " })),
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
237
|
+
], children: placeholder !== null && placeholder !== void 0 ? placeholder : " " }))] }), _jsx(Fill, { minWidth: 8 }), !disabled && (_jsx(Icon, { color: colors.gray[900], name: visible ? "chevron-up-filled" : "chevron-down-filled", size: 16 }))] })] })) }), !hideErrors && (_jsx(LakeText, { variant: "smallRegular", color: colors.negative[500], style: styles.errorText, children: error !== null && error !== void 0 ? error : " " })), _jsxs(Popover, { role: "listbox", matchReferenceWidth: matchReferenceWidth, matchReferenceMinWidth: matchReferenceMinWidth, onDismiss: close, referenceRef: inputRef, returnFocus: true, visible: visible, children: [hasSearch ? ListHeaderComponent : undefined, _jsxs(View, { style: styles.list, children: [isNotNullish(title) && (_jsxs(_Fragment, { children: [_jsx(LakeText, { variant: "semibold", color: colors.gray[900], style: styles.selectListTitle, children: title }), _jsx(Separator, {})] })), _jsx(FlatList, { role: "list", data: filteredItems, ref: listRef, contentContainerStyle: styles.listContent, onKeyDown: (event) => {
|
|
238
|
+
var _a;
|
|
239
|
+
const { key } = event.nativeEvent;
|
|
240
|
+
if (key === "ArrowDown" || key === "ArrowUp") {
|
|
241
|
+
event.preventDefault();
|
|
242
|
+
if (isNotNullish(event.currentTarget)) {
|
|
243
|
+
const focusableElements = getFocusableElements(event.currentTarget);
|
|
244
|
+
const current = focusableElements.indexOf(event.target);
|
|
245
|
+
const nextIndex = key === "ArrowDown" ? current + 1 : current - 1;
|
|
246
|
+
(_a = focusableElements[nextIndex]) === null || _a === void 0 ? void 0 : _a.focus();
|
|
247
|
+
}
|
|
248
248
|
}
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
} }), typeof PopoverFooter === "function" ? PopoverFooter({ close }) : PopoverFooter] }) })] }));
|
|
249
|
+
}, keyExtractor: (_, index) => `select-item-${index}`, renderItem: ({ item, index }) => {
|
|
250
|
+
const isSelected = value === item.value;
|
|
251
|
+
const disablement = disabledItems.find(({ value }) => value === item.value);
|
|
252
|
+
const content = renderItem != null ? (renderItem(item, isSelected)) : (_jsxs(_Fragment, { children: [isNotNullish(item.icon) && (_jsxs(_Fragment, { children: [item.icon, _jsx(Space, { width: 12 })] })), _jsx(LakeText, { color: colors.gray[900], numberOfLines: 1, style: [styles.itemText, isSelected && styles.selected], children: item.name })] }));
|
|
253
|
+
return (_jsx(LakeTooltip, { placement: "right", content: disablement === null || disablement === void 0 ? void 0 : disablement.message, disabled: isNullishOrEmpty(disablement === null || disablement === void 0 ? void 0 : disablement.message), children: _jsxs(Pressable, { ref: element => {
|
|
254
|
+
listItemRefs.current[index] = element;
|
|
255
|
+
}, onKeyDown: onKeyDown, disabled: isNotNullish(disablement), style: ({ hovered, focused }) => [
|
|
256
|
+
styles.item,
|
|
257
|
+
(hovered || isSelected) && styles.itemHighlighted,
|
|
258
|
+
focused && styles.itemFocused,
|
|
259
|
+
isNotNullish(disablement) && styles.itemDisabled,
|
|
260
|
+
], role: "option", "aria-selected": true, onPress: () => {
|
|
261
|
+
onValueChange(item.value);
|
|
262
|
+
close();
|
|
263
|
+
}, children: [content, _jsx(Fill, { minWidth: 12 }), isSelected && (_jsx(Icon, { color: colors.positive[500], name: "checkmark-filled", size: 14 }))] }) }));
|
|
264
|
+
} }), typeof PopoverFooter === "function" ? PopoverFooter({ close }) : PopoverFooter] })] })] }));
|
|
266
265
|
};
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { ReactNode, Ref } from "react";
|
|
2
|
-
export type PhoneCountry = {
|
|
3
|
-
cca2: string;
|
|
4
|
-
idd: string;
|
|
5
|
-
};
|
|
6
|
-
export type InputPhoneNumberRef = {
|
|
7
|
-
focus: () => void;
|
|
8
|
-
blur: () => void;
|
|
9
|
-
};
|
|
10
|
-
type Props = {
|
|
11
|
-
ref?: Ref<InputPhoneNumberRef>;
|
|
12
|
-
id?: string;
|
|
13
|
-
country: PhoneCountry;
|
|
14
|
-
value: string;
|
|
15
|
-
error?: string;
|
|
16
|
-
valid?: boolean;
|
|
17
|
-
autofocus?: boolean;
|
|
18
|
-
disabled?: boolean;
|
|
19
|
-
readOnly?: boolean;
|
|
20
|
-
flag?: ReactNode;
|
|
21
|
-
countryList: (close: () => void) => ReactNode;
|
|
22
|
-
countryButtonAriaLabel?: string;
|
|
23
|
-
onChangeText?: (text: string) => void;
|
|
24
|
-
onSubmitEditing?: () => void;
|
|
25
|
-
onBlur?: () => void;
|
|
26
|
-
};
|
|
27
|
-
export declare const InputPhoneNumber: ({ ref, id, country, value, error, valid, autofocus, disabled, readOnly, flag, countryList, countryButtonAriaLabel, onChangeText, onSubmitEditing, onBlur, }: Props) => import("react/jsx-runtime").JSX.Element;
|
|
28
|
-
export {};
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
-
import { useEffect, useImperativeHandle, useRef } from "react";
|
|
3
|
-
import { Pressable, StyleSheet } from "react-native";
|
|
4
|
-
import { colors, radii, spacings } from "../constants/design";
|
|
5
|
-
import { useDisclosure } from "../hooks/useDisclosure";
|
|
6
|
-
import { isNotNullishOrEmpty } from "../utils/nullish";
|
|
7
|
-
import { Box } from "./Box";
|
|
8
|
-
import { Icon } from "./Icon";
|
|
9
|
-
import { LakeText } from "./LakeText";
|
|
10
|
-
import { LakeTextInput } from "./LakeTextInput";
|
|
11
|
-
import { Popover } from "./Popover";
|
|
12
|
-
import { Space } from "./Space";
|
|
13
|
-
const styles = StyleSheet.create({
|
|
14
|
-
idd: {
|
|
15
|
-
alignItems: "center",
|
|
16
|
-
backgroundColor: colors.gray[50],
|
|
17
|
-
borderColor: colors.gray[100],
|
|
18
|
-
borderTopLeftRadius: radii[4],
|
|
19
|
-
borderBottomLeftRadius: radii[4],
|
|
20
|
-
borderWidth: 1,
|
|
21
|
-
borderRightWidth: 0,
|
|
22
|
-
flexDirection: "row",
|
|
23
|
-
justifyContent: "center",
|
|
24
|
-
paddingLeft: spacings[16],
|
|
25
|
-
paddingRight: spacings[12],
|
|
26
|
-
transitionDuration: "150ms",
|
|
27
|
-
transitionProperty: "background-color",
|
|
28
|
-
},
|
|
29
|
-
iddPressed: { backgroundColor: colors.gray[100] },
|
|
30
|
-
iddErrored: { borderColor: colors.negative[500] },
|
|
31
|
-
iddDisabled: {
|
|
32
|
-
borderColor: colors.gray[50],
|
|
33
|
-
borderRightWidth: 1,
|
|
34
|
-
borderRightColor: colors.gray[100],
|
|
35
|
-
},
|
|
36
|
-
input: { borderTopLeftRadius: 0, borderBottomLeftRadius: 0 },
|
|
37
|
-
});
|
|
38
|
-
export const InputPhoneNumber = ({ ref, id, country, value, error, valid = false, autofocus = false, disabled = false, readOnly = false, flag, countryList, countryButtonAriaLabel = "Select country", onChangeText, onSubmitEditing, onBlur, }) => {
|
|
39
|
-
const referenceRef = useRef(null);
|
|
40
|
-
const inputRef = useRef(null);
|
|
41
|
-
const [visible, { open, close }] = useDisclosure(false);
|
|
42
|
-
const handleChangeText = (text) => {
|
|
43
|
-
const clean = text.replace(/[^ +0-9-()]/g, "");
|
|
44
|
-
if (text === clean) {
|
|
45
|
-
onChangeText === null || onChangeText === void 0 ? void 0 : onChangeText(text);
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
useEffect(() => {
|
|
49
|
-
if (autofocus && inputRef.current) {
|
|
50
|
-
setTimeout(() => { var _a; return (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus(); }, 250);
|
|
51
|
-
}
|
|
52
|
-
}, [autofocus]);
|
|
53
|
-
useImperativeHandle(ref, () => ({ focus: () => { var _a; return (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus(); }, blur: () => { var _a; return (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.blur(); } }), []);
|
|
54
|
-
return (_jsxs(_Fragment, { children: [_jsx(Popover, { referenceRef: referenceRef, visible: visible, matchReferenceWidth: true, onDismiss: close, children: countryList(close) }), _jsxs(Box, { ref: referenceRef, direction: "row", children: [_jsxs(Pressable, { role: "button", disabled: visible || disabled || readOnly, onPress: open, "aria-label": countryButtonAriaLabel, style: ({ pressed }) => [
|
|
55
|
-
styles.idd,
|
|
56
|
-
!visible && pressed && styles.iddPressed,
|
|
57
|
-
(disabled || readOnly) && styles.iddDisabled,
|
|
58
|
-
isNotNullishOrEmpty(error) && styles.iddErrored,
|
|
59
|
-
], children: [flag, flag != null && _jsx(Space, { width: 8 }), _jsxs(LakeText, { color: colors.gray[600], numberOfLines: 1, userSelect: "none", variant: "smallSemibold", children: ["+", country.idd] }), _jsx(Space, { width: 8 }), _jsx(Icon, { name: "chevron-down-filled", color: colors.gray[600], size: 16 })] }), _jsx(LakeTextInput, { id: id, ref: inputRef, autoComplete: "tel", inputMode: "tel", rows: 1, hideErrors: true, value: value, valid: valid, error: error, disabled: disabled, readOnly: readOnly, onChangeText: handleChangeText, onSubmitEditing: onSubmitEditing, onBlur: onBlur, style: styles.input })] })] }));
|
|
60
|
-
};
|