@swan-io/lake 13.7.0 → 13.7.2
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
|
@@ -12,6 +12,7 @@ export type SelectProps<V, T extends Item<V> = Item<V>> = {
|
|
|
12
12
|
ref?: Ref<View>;
|
|
13
13
|
placeholder?: string;
|
|
14
14
|
items: T[];
|
|
15
|
+
matchReferenceMinWidth?: boolean;
|
|
15
16
|
matchReferenceWidth?: boolean;
|
|
16
17
|
mode?: "normal" | "borderless";
|
|
17
18
|
title?: string;
|
|
@@ -38,4 +39,4 @@ export type SelectProps<V, T extends Item<V> = Item<V>> = {
|
|
|
38
39
|
hasSearch?: boolean;
|
|
39
40
|
searchPlaceholder?: string;
|
|
40
41
|
};
|
|
41
|
-
export declare const LakeSelect: <V, T extends Item<V> = Item<V>>({ ref, title, items, valueStyle, size, color, disabled, mode, placeholder, readOnly, id, matchReferenceWidth, value, error, hideErrors, icon, onValueChange, disabledItems, renderItem, PopoverFooter, style, hasSearch, searchPlaceholder, }: SelectProps<V, T>) => import("react/jsx-runtime").JSX.Element;
|
|
42
|
+
export declare const LakeSelect: <V, T extends Item<V> = Item<V>>({ ref, title, items, valueStyle, size, color, disabled, mode, placeholder, readOnly, id, matchReferenceMinWidth, matchReferenceWidth, value, error, hideErrors, icon, onValueChange, disabledItems, renderItem, PopoverFooter, style, hasSearch, searchPlaceholder, }: SelectProps<V, T>) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -140,7 +140,7 @@ const styles = StyleSheet.create({
|
|
|
140
140
|
left: 14,
|
|
141
141
|
},
|
|
142
142
|
});
|
|
143
|
-
export const LakeSelect = ({ ref, title, items, valueStyle, size, color = "current", disabled = false, mode = "normal", placeholder, readOnly = false, id,
|
|
143
|
+
export const LakeSelect = ({ ref, title, items, valueStyle, size, color = "current", disabled = false, mode = "normal", placeholder, readOnly = false, id, matchReferenceMinWidth = true, matchReferenceWidth = false, value, error, hideErrors = false, icon, onValueChange, disabledItems = [], renderItem, PopoverFooter, style, hasSearch = false, searchPlaceholder, }) => {
|
|
144
144
|
var _a;
|
|
145
145
|
const [filter, setFilter] = useState("");
|
|
146
146
|
const [filterFocused, setFilterFocused] = useBoolean(false);
|
|
@@ -228,7 +228,7 @@ export const LakeSelect = ({ ref, title, items, valueStyle, size, color = "curre
|
|
|
228
228
|
styles.itemText,
|
|
229
229
|
styles.selectPlaceholder,
|
|
230
230
|
isSmall && styles.selectSmallPlaceholder,
|
|
231
|
-
], 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",
|
|
231
|
+
], 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: [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) => {
|
|
232
232
|
var _a;
|
|
233
233
|
const { key } = event.nativeEvent;
|
|
234
234
|
if (key === "ArrowDown" || key === "ArrowUp") {
|
|
@@ -2,6 +2,7 @@ import { Option } from "@swan-io/boxed";
|
|
|
2
2
|
import { useCallback, useEffect, useRef, useState } from "react";
|
|
3
3
|
import { match } from "ts-pattern";
|
|
4
4
|
const MAX_OFFSET_FOR_CENTER_PLACEMENT = 100;
|
|
5
|
+
const HORIZONTAL_SAFETY_MARGIN = 16;
|
|
5
6
|
export const useContextualLayer = ({ placement, visible, matchReferenceWidth = false, matchReferenceMinWidth = false, referenceRef: externalReferenceRef, }) => {
|
|
6
7
|
const referenceRef = useRef(null);
|
|
7
8
|
const usedRef = externalReferenceRef !== null && externalReferenceRef !== void 0 ? externalReferenceRef : referenceRef;
|
|
@@ -51,10 +52,16 @@ export const useContextualLayer = ({ placement, visible, matchReferenceWidth = f
|
|
|
51
52
|
height: "100vh",
|
|
52
53
|
pointerEvents: "none",
|
|
53
54
|
};
|
|
55
|
+
const maxWidth = match(inferedPlacement)
|
|
56
|
+
.with("left", () => viewportWidth - rect.left - HORIZONTAL_SAFETY_MARGIN)
|
|
57
|
+
.with("right", () => rect.right - HORIZONTAL_SAFETY_MARGIN)
|
|
58
|
+
.with("center", () => Math.min(availableSpaceBefore + width / 2, availableSpaceAfter + width / 2) * 2 - HORIZONTAL_SAFETY_MARGIN)
|
|
59
|
+
.exhaustive();
|
|
54
60
|
const style = {
|
|
55
61
|
...verticalPosition,
|
|
56
62
|
...horizontalPosition,
|
|
57
63
|
maxHeight,
|
|
64
|
+
maxWidth,
|
|
58
65
|
...(matchReferenceWidth === true ? { width } : undefined),
|
|
59
66
|
...(matchReferenceMinWidth === true ? { minWidth: width } : undefined),
|
|
60
67
|
pointerEvents: "auto",
|