@swan-io/lake 2.7.4 → 2.7.5
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 +1 -1
- package/src/components/LakeAlert.d.ts +1 -1
- package/src/components/LakeAlert.js +8 -2
- package/src/components/LakeCombobox.js +6 -2
- package/src/components/LakeTextInput.d.ts +4 -2
- package/src/components/LakeTextInput.js +3 -3
- package/src/hooks/useDisclosure.d.ts +1 -1
- package/src/hooks/useDisclosure.js +5 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ReactNode } from "react";
|
|
2
2
|
import { StyleProp, ViewStyle } from "react-native";
|
|
3
|
-
type AlertVariant = "info" | "warning" | "error" | "success";
|
|
3
|
+
type AlertVariant = "info" | "warning" | "error" | "success" | "neutral";
|
|
4
4
|
type Props = {
|
|
5
5
|
anchored?: boolean;
|
|
6
6
|
variant: AlertVariant;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { StyleSheet, View } from "react-native";
|
|
3
3
|
import { commonStyles } from "../constants/commonStyles";
|
|
4
4
|
import { colors, shadows } from "../constants/design";
|
|
@@ -38,38 +38,44 @@ const alertIcon = {
|
|
|
38
38
|
warning: "warning-regular",
|
|
39
39
|
error: "dismiss-circle-regular",
|
|
40
40
|
success: "checkmark-circle-regular",
|
|
41
|
+
neutral: undefined,
|
|
41
42
|
};
|
|
42
43
|
const alertColor = {
|
|
43
44
|
info: colors.shakespear[700],
|
|
44
45
|
warning: colors.warning[700],
|
|
45
46
|
error: colors.negative[700],
|
|
46
47
|
success: colors.positive[700],
|
|
48
|
+
neutral: colors.gray[700],
|
|
47
49
|
};
|
|
48
50
|
const alertBackground = {
|
|
49
51
|
info: colors.shakespear[0],
|
|
50
52
|
warning: colors.warning[0],
|
|
51
53
|
error: colors.negative[0],
|
|
52
54
|
success: colors.positive[0],
|
|
55
|
+
neutral: colors.gray[0],
|
|
53
56
|
};
|
|
54
57
|
const alertBorder = {
|
|
55
58
|
info: colors.shakespear[200],
|
|
56
59
|
warning: colors.warning[200],
|
|
57
60
|
error: colors.negative[200],
|
|
58
61
|
success: colors.positive[200],
|
|
62
|
+
neutral: colors.gray[200],
|
|
59
63
|
};
|
|
60
64
|
const alertLeftBorder = {
|
|
61
65
|
info: colors.shakespear[500],
|
|
62
66
|
warning: colors.warning[500],
|
|
63
67
|
error: colors.negative[500],
|
|
64
68
|
success: colors.positive[500],
|
|
69
|
+
neutral: colors.gray[500],
|
|
65
70
|
};
|
|
66
71
|
const isText = (node) => typeof node === "string" || typeof node === "number";
|
|
67
72
|
export const LakeAlert = ({ anchored = false, variant, title, subtitle, children, style, callToAction, }) => {
|
|
68
73
|
const color = alertColor[variant];
|
|
74
|
+
const icon = alertIcon[variant];
|
|
69
75
|
return (_jsxs(View, { style: [
|
|
70
76
|
styles.base,
|
|
71
77
|
{ backgroundColor: alertBackground[variant], borderColor: alertBorder[variant] },
|
|
72
78
|
anchored ? styles.anchored : { borderLeftColor: alertLeftBorder[variant] },
|
|
73
79
|
style,
|
|
74
|
-
], children: [_jsxs(Box, { direction: "row", alignItems: "center", children: [_jsx(Icon, { name:
|
|
80
|
+
], children: [_jsxs(Box, { direction: "row", alignItems: "center", children: [icon != null ? (_jsxs(_Fragment, { children: [_jsx(Icon, { name: icon, color: color, size: 20 }), _jsx(Space, { width: 20 })] })) : null, _jsxs(View, { style: commonStyles.fill, children: [_jsx(LakeText, { color: color, variant: icon != null ? "regular" : "medium", children: title }), isNotNullishOrEmpty(subtitle) && _jsx(LakeText, { color: color, children: subtitle })] }), isNotNullish(callToAction) && _jsx(View, { style: styles.callToAction, children: callToAction })] }), isNotNullish(children) && (_jsxs(View, { style: icon != null ? styles.content : null, children: [_jsx(Space, { height: 12 }), isText(children) ? _jsx(LakeText, { children: children }) : children] }))] }));
|
|
75
81
|
};
|
|
@@ -86,8 +86,9 @@ const LakeComboboxWithRef = ({ inputRef, value, items, itemHeight = DEFAULT_ELEM
|
|
|
86
86
|
const listRef = useRef(null);
|
|
87
87
|
const listContainerRef = useRef(null);
|
|
88
88
|
const blurTimeoutId = useRef(undefined);
|
|
89
|
-
const [isFocused, { open, close }] = useDisclosure(false);
|
|
89
|
+
const [isFocused, { open, close }] = useDisclosure(false, () => setHasChanged(false));
|
|
90
90
|
const [isFetchingAdditionalInfo, setIsFetchingAdditionalInfo] = useState(false);
|
|
91
|
+
const [hasChanged, setHasChanged] = useState(false);
|
|
91
92
|
useImperativeHandle(externalRef, () => {
|
|
92
93
|
return {
|
|
93
94
|
open,
|
|
@@ -141,7 +142,10 @@ const LakeComboboxWithRef = ({ inputRef, value, items, itemHeight = DEFAULT_ELEM
|
|
|
141
142
|
close();
|
|
142
143
|
}, 100);
|
|
143
144
|
}, [close]);
|
|
144
|
-
return (_jsxs(View, { children: [_jsx(LakeTextInput, {
|
|
145
|
+
return (_jsxs(View, { children: [_jsx(LakeTextInput, { containerRef: inputTextRef, style: styles.input, ariaExpanded: isFocused, ariaControls: isFocused ? suggestionsId : "", enterKeyHint: "search", icon: icon, role: "combobox", placeholder: placeholder, value: value, disabled: disabled, error: error, hideErrors: hideErrors, onChangeText: onValueChange, onChange: event => {
|
|
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({
|
|
145
149
|
NotAsked: () => null,
|
|
146
150
|
Loading: () => _jsx(LoadingView, { style: styles.loader }),
|
|
147
151
|
Done: items => items.match({
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ChangeEventHandler, ReactNode } from "react";
|
|
2
|
-
import { NativeSyntheticEvent, TextInput, TextInputFocusEventData, TextInputProps } from "react-native";
|
|
1
|
+
import { ChangeEventHandler, ReactNode, Ref } from "react";
|
|
2
|
+
import { NativeSyntheticEvent, TextInput, TextInputFocusEventData, TextInputProps, View } from "react-native";
|
|
3
3
|
import { Except } from "type-fest";
|
|
4
4
|
import { ColorVariants } from "../constants/design";
|
|
5
5
|
import { IconName } from "./Icon";
|
|
@@ -24,6 +24,7 @@ export type LakeTextInputProps = Except<TextInputProps, "editable" | "keyboardTy
|
|
|
24
24
|
maxCharCount?: number;
|
|
25
25
|
help?: string;
|
|
26
26
|
renderEnd?: () => ReactNode;
|
|
27
|
+
containerRef?: Ref<View>;
|
|
27
28
|
};
|
|
28
29
|
export declare const LakeTextInput: import("react").ForwardRefExoticComponent<{
|
|
29
30
|
allowFontScaling?: boolean | undefined;
|
|
@@ -236,4 +237,5 @@ export declare const LakeTextInput: import("react").ForwardRefExoticComponent<{
|
|
|
236
237
|
maxCharCount?: number | undefined;
|
|
237
238
|
help?: string | undefined;
|
|
238
239
|
renderEnd?: (() => ReactNode) | undefined;
|
|
240
|
+
containerRef?: Ref<View> | undefined;
|
|
239
241
|
} & import("react").RefAttributes<TextInput | null>>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
-
import { forwardRef, useCallback, useRef, useState } from "react";
|
|
2
|
+
import { forwardRef, useCallback, useRef, useState, } from "react";
|
|
3
3
|
import { ActivityIndicator, StyleSheet, TextInput, View, } from "react-native";
|
|
4
4
|
import { commonStyles } from "../constants/commonStyles";
|
|
5
5
|
import { backgroundColor, colors, radii, shadows, spacings, texts, } from "../constants/design";
|
|
@@ -121,7 +121,7 @@ const styles = StyleSheet.create({
|
|
|
121
121
|
paddingTop: spacings[4],
|
|
122
122
|
},
|
|
123
123
|
});
|
|
124
|
-
export const LakeTextInput = forwardRef(({ ariaExpanded, ariaControls, error, disabled = false, validating = false, valid = false, readOnly = false, icon, children, unit, color = "gray", inputMode = "text", hideErrors = false, onChange, pattern, style: stylesFromProps, onFocus: originalOnFocus, onBlur: originalOnBlur, value, defaultValue, multiline = false,
|
|
124
|
+
export const LakeTextInput = forwardRef(({ ariaExpanded, ariaControls, error, disabled = false, validating = false, valid = false, readOnly = false, icon, children, unit, color = "gray", inputMode = "text", hideErrors = false, onChange, pattern, style: stylesFromProps, onFocus: originalOnFocus, onBlur: originalOnBlur, value, defaultValue, multiline = false, containerRef,
|
|
125
125
|
//maxCharCount is different from maxLength(props inherited of TextInput)
|
|
126
126
|
//maxLength truncates the text in the limitation asked,
|
|
127
127
|
//maxCharCount doesn't have limitation but displays a counter of characters
|
|
@@ -158,7 +158,7 @@ maxCharCount, help, renderEnd, ...props }, forwardRef) => {
|
|
|
158
158
|
hasError && styles.error,
|
|
159
159
|
valid && styles.valid,
|
|
160
160
|
stylesFromProps,
|
|
161
|
-
], children: [isNotNullish(icon) && (_jsx(Icon, { name: icon, size: 20, color: colors.current.primary, style: styles.icon })), _jsx(TextInput, { "aria-expanded": ariaExpanded, "aria-controls": ariaControls, inputMode: inputMode,
|
|
161
|
+
], ref: containerRef, children: [isNotNullish(icon) && (_jsx(Icon, { name: icon, size: 20, color: colors.current.primary, style: styles.icon })), _jsx(TextInput, { "aria-expanded": ariaExpanded, "aria-controls": ariaControls, inputMode: inputMode, ...props, defaultValue: defaultValue, value: isNullish(defaultValue) ? value ?? "" : value, onFocus: onFocus, onBlur: onBlur, readOnly: !isInteractive, onChange: onChange, multiline: multiline, ref: mergedRef, style: [
|
|
162
162
|
styles.input,
|
|
163
163
|
multiline && styles.multilineInput,
|
|
164
164
|
readOnly && hasError && styles.readOnlyError,
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import { useMemo, useState } from "react";
|
|
2
|
-
export const useDisclosure = (initialValue) => {
|
|
2
|
+
export const useDisclosure = (initialValue, onClose) => {
|
|
3
3
|
const [value, setValue] = useState(initialValue);
|
|
4
4
|
return [
|
|
5
5
|
value,
|
|
6
6
|
useMemo(() => ({
|
|
7
7
|
open: () => setValue(true),
|
|
8
|
-
close: () =>
|
|
8
|
+
close: () => {
|
|
9
|
+
setValue(false);
|
|
10
|
+
onClose?.();
|
|
11
|
+
},
|
|
9
12
|
toggle: () => setValue(prevValue => !prevValue),
|
|
10
13
|
}), []),
|
|
11
14
|
];
|