@swan-io/lake 2.7.24 → 2.7.25
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
|
@@ -27,7 +27,7 @@ export type LakeComboboxRef = {
|
|
|
27
27
|
close: () => void;
|
|
28
28
|
open: () => void;
|
|
29
29
|
};
|
|
30
|
-
declare const LakeComboboxWithRef: <I>({ inputRef, value, items, itemHeight, nbItemsDisplayed, ListFooterComponent, onChange, onValueChange, onSelectItem, renderItem, keyExtractor, icon, placeholder, disabled, emptyResultText, readOnly, id, error, hideErrors, }: LakeComboboxProps<I>,
|
|
30
|
+
declare const LakeComboboxWithRef: <I>({ inputRef, value, items, itemHeight, nbItemsDisplayed, ListFooterComponent, onChange, onValueChange, onSelectItem, renderItem, keyExtractor, icon, placeholder, disabled, emptyResultText, readOnly, id, error, hideErrors, }: LakeComboboxProps<I>, forwardedRef: ForwardedRef<LakeComboboxRef>) => import("react/jsx-runtime").JSX.Element;
|
|
31
31
|
export declare const LakeCombobox: <I>(props: LakeComboboxProps<I> & {
|
|
32
32
|
ref?: RefObject<LakeComboboxRef> | undefined;
|
|
33
33
|
}) => ReturnType<typeof LakeComboboxWithRef>;
|
|
@@ -78,7 +78,7 @@ const getItemLayout = (_data, index) => ({
|
|
|
78
78
|
offset: DEFAULT_ELEMENT_HEIGHT * index,
|
|
79
79
|
index,
|
|
80
80
|
});
|
|
81
|
-
const LakeComboboxWithRef = ({ inputRef, value, items, itemHeight = DEFAULT_ELEMENT_HEIGHT, nbItemsDisplayed = DEFAULT_NB_SUGGESTION_DISPLAYED, ListFooterComponent, onChange, onValueChange, onSelectItem, renderItem, keyExtractor, icon, placeholder, disabled = false, emptyResultText, readOnly, id, error, hideErrors, },
|
|
81
|
+
const LakeComboboxWithRef = ({ inputRef, value, items, itemHeight = DEFAULT_ELEMENT_HEIGHT, nbItemsDisplayed = DEFAULT_NB_SUGGESTION_DISPLAYED, ListFooterComponent, onChange, onValueChange, onSelectItem, renderItem, keyExtractor, icon, placeholder, disabled = false, emptyResultText, readOnly, id, error, hideErrors, }, forwardedRef) => {
|
|
82
82
|
const ref = useRef(null);
|
|
83
83
|
const inputTextRef = useMergeRefs(ref, inputRef);
|
|
84
84
|
const listRef = useRef(null);
|
|
@@ -92,7 +92,7 @@ const LakeComboboxWithRef = ({ inputRef, value, items, itemHeight = DEFAULT_ELEM
|
|
|
92
92
|
const open = useCallback(() => setState("opened"), []);
|
|
93
93
|
const close = useCallback(() => setState("closed"), []);
|
|
94
94
|
const dismiss = useCallback(() => setState("dismissed"), []);
|
|
95
|
-
useImperativeHandle(
|
|
95
|
+
useImperativeHandle(forwardedRef, () => {
|
|
96
96
|
return {
|
|
97
97
|
open,
|
|
98
98
|
close,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ReactElement, ReactNode } from "react";
|
|
2
|
-
import { StyleProp, TextStyle, ViewStyle } from "react-native";
|
|
1
|
+
import { ForwardedRef, ReactElement, ReactNode } from "react";
|
|
2
|
+
import { StyleProp, TextStyle, View, ViewStyle } from "react-native";
|
|
3
3
|
import { ColorVariants } from "../constants/design";
|
|
4
4
|
import { IconName } from "./Icon";
|
|
5
5
|
export type Item<V> = {
|
|
@@ -27,4 +27,8 @@ export type SelectProps<V> = {
|
|
|
27
27
|
readOnly?: boolean;
|
|
28
28
|
style?: StyleProp<ViewStyle>;
|
|
29
29
|
};
|
|
30
|
-
|
|
30
|
+
declare const LakeSelectWithRef: <V>({ title, items, valueStyle, size, color, disabled, mode, placeholder, readOnly, id, matchReferenceWidth, value, error, hideErrors, icon, onValueChange, PopoverFooter, style, }: SelectProps<V>, forwardedRef: ForwardedRef<View>) => import("react/jsx-runtime").JSX.Element;
|
|
31
|
+
export declare const LakeSelect: <I>(props: SelectProps<I> & {
|
|
32
|
+
ref?: ForwardedRef<View> | undefined;
|
|
33
|
+
}) => ReturnType<typeof LakeSelectWithRef>;
|
|
34
|
+
export {};
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { useCallback, useRef } from "react";
|
|
2
|
+
import { forwardRef, useCallback, useRef, } from "react";
|
|
3
3
|
import { FlatList, StyleSheet, View, } from "react-native";
|
|
4
4
|
import { commonStyles } from "../constants/commonStyles";
|
|
5
5
|
import { colors, invariantColors, radii, shadows, spacings, texts, } from "../constants/design";
|
|
6
6
|
import { useDisclosure } from "../hooks/useDisclosure";
|
|
7
|
+
import { useMergeRefs } from "../hooks/useMergeRefs";
|
|
7
8
|
import { getFocusableElements } from "../utils/a11y";
|
|
8
9
|
import { isNotNullish } from "../utils/nullish";
|
|
9
10
|
import { Box } from "./Box";
|
|
@@ -103,12 +104,13 @@ const styles = StyleSheet.create({
|
|
|
103
104
|
borderColor: colors.negative[500],
|
|
104
105
|
},
|
|
105
106
|
});
|
|
106
|
-
|
|
107
|
+
const LakeSelectWithRef = ({ title, items, valueStyle, size, color = "current", disabled = false, mode = "normal", placeholder, readOnly = false, id, matchReferenceWidth = true, value, error, hideErrors = false, icon, onValueChange, PopoverFooter, style, }, forwardedRef) => {
|
|
107
108
|
const inputRef = useRef(null);
|
|
108
109
|
const listRef = useRef(null);
|
|
109
110
|
const typingTimeoutRef = useRef(undefined);
|
|
110
111
|
const currentlyTypedRef = useRef(undefined);
|
|
111
112
|
const listItemRefs = useRef(Array(items.length));
|
|
113
|
+
const mergedRef = useMergeRefs(inputRef, forwardedRef);
|
|
112
114
|
const [visible, { close, open }] = useDisclosure(false);
|
|
113
115
|
const hasValue = isNotNullish(value);
|
|
114
116
|
const isSmall = size === "small";
|
|
@@ -141,7 +143,7 @@ export function LakeSelect({ title, items, valueStyle, size, color = "current",
|
|
|
141
143
|
}, 300);
|
|
142
144
|
}, [items, onValueChange, visible]);
|
|
143
145
|
const name = itemValue?.name ?? value;
|
|
144
|
-
return (_jsxs(View, { style: commonStyles.fill, children: [_jsx(Pressable, { id: id, ref:
|
|
146
|
+
return (_jsxs(View, { style: commonStyles.fill, children: [_jsx(Pressable, { id: id, ref: mergedRef, "aria-haspopup": "listbox", role: "button", "aria-expanded": visible, disabled: readOnly || disabled, style: ({ focused }) => [
|
|
145
147
|
mode === "normal" ? styles.normal : styles.borderless,
|
|
146
148
|
size === "small" && styles.small,
|
|
147
149
|
(disabled || readOnly) && styles.inputDisabled,
|
|
@@ -176,4 +178,5 @@ export function LakeSelect({ title, items, valueStyle, size, color = "current",
|
|
|
176
178
|
close();
|
|
177
179
|
}, 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 }), _jsx(Fill, { minWidth: 12 }), isSelected && (_jsx(Icon, { color: colors.positive[500], name: "checkmark-filled", size: 14 }))] }));
|
|
178
180
|
} }), PopoverFooter] })] }));
|
|
179
|
-
}
|
|
181
|
+
};
|
|
182
|
+
export const LakeSelect = forwardRef(LakeSelectWithRef);
|