@swan-io/lake 4.2.0 → 4.3.1
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
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { NativeSyntheticEvent, TextInput, TextInputFocusEventData, TextInputKeyPressEventData, TextInputProps } from "react-native";
|
|
3
|
+
import { Merge } from "type-fest";
|
|
4
|
+
export type LakeTagInputProps = Merge<TextInputProps, {
|
|
5
|
+
readOnly?: boolean;
|
|
6
|
+
error?: string;
|
|
7
|
+
disabled?: boolean;
|
|
8
|
+
valid?: boolean;
|
|
9
|
+
hideErrors?: boolean;
|
|
10
|
+
help?: string;
|
|
11
|
+
validator?: (value: string) => boolean;
|
|
12
|
+
values: string[];
|
|
13
|
+
onValuesChanged: (values: string[]) => void;
|
|
14
|
+
placeholder?: string;
|
|
15
|
+
}>;
|
|
16
|
+
export declare const LakeTagInput: import("react").ForwardRefExoticComponent<{
|
|
17
|
+
values: string[];
|
|
18
|
+
onValuesChanged: (values: string[]) => void;
|
|
19
|
+
allowFontScaling?: boolean | undefined;
|
|
20
|
+
autoCapitalize?: "none" | "sentences" | "words" | "characters" | undefined;
|
|
21
|
+
autoCorrect?: boolean | undefined;
|
|
22
|
+
autoFocus?: boolean | undefined;
|
|
23
|
+
blurOnSubmit?: boolean | undefined;
|
|
24
|
+
caretHidden?: boolean | undefined;
|
|
25
|
+
contextMenuHidden?: boolean | undefined;
|
|
26
|
+
defaultValue?: string | undefined;
|
|
27
|
+
editable?: boolean | undefined;
|
|
28
|
+
keyboardType?: import("react-native").KeyboardTypeOptions | undefined;
|
|
29
|
+
inputMode?: import("react-native").InputModeOptions | undefined;
|
|
30
|
+
maxLength?: number | undefined;
|
|
31
|
+
multiline?: boolean | undefined;
|
|
32
|
+
onBlur?: ((e: NativeSyntheticEvent<TextInputFocusEventData>) => void) | undefined;
|
|
33
|
+
onChange?: ((e: NativeSyntheticEvent<import("react-native").TextInputChangeEventData>) => void) | undefined;
|
|
34
|
+
onChangeText?: ((text: string) => void) | undefined;
|
|
35
|
+
onContentSizeChange?: ((e: NativeSyntheticEvent<import("react-native").TextInputContentSizeChangeEventData>) => void) | undefined;
|
|
36
|
+
onEndEditing?: ((e: NativeSyntheticEvent<import("react-native").TextInputEndEditingEventData>) => void) | undefined;
|
|
37
|
+
onPressIn?: ((e: NativeSyntheticEvent<import("react-native").NativeTouchEvent>) => void) | undefined;
|
|
38
|
+
onPressOut?: ((e: NativeSyntheticEvent<import("react-native").NativeTouchEvent>) => void) | undefined;
|
|
39
|
+
onFocus?: ((e: NativeSyntheticEvent<TextInputFocusEventData>) => void) | undefined;
|
|
40
|
+
onSelectionChange?: ((e: NativeSyntheticEvent<import("react-native").TextInputSelectionChangeEventData>) => void) | undefined;
|
|
41
|
+
onSubmitEditing?: ((e: NativeSyntheticEvent<import("react-native").TextInputSubmitEditingEventData>) => void) | undefined;
|
|
42
|
+
onTextInput?: ((e: NativeSyntheticEvent<import("react-native").TextInputTextInputEventData>) => void) | undefined;
|
|
43
|
+
onScroll?: ((e: NativeSyntheticEvent<import("react-native").TextInputScrollEventData>) => void) | undefined;
|
|
44
|
+
onKeyPress?: ((e: NativeSyntheticEvent<TextInputKeyPressEventData>) => void) | undefined;
|
|
45
|
+
placeholderTextColor?: import("react-native").ColorValue | undefined;
|
|
46
|
+
returnKeyType?: import("react-native").ReturnKeyTypeOptions | undefined;
|
|
47
|
+
secureTextEntry?: boolean | undefined;
|
|
48
|
+
selectTextOnFocus?: boolean | undefined;
|
|
49
|
+
selection?: {
|
|
50
|
+
start: number;
|
|
51
|
+
end?: number | undefined;
|
|
52
|
+
} | undefined;
|
|
53
|
+
selectionColor?: import("react-native").ColorValue | undefined;
|
|
54
|
+
style?: false | import("react-native").TextStyle | import("react-native").RegisteredStyle<import("react-native").TextStyle> | import("react-native").RecursiveArray<import("react-native").TextStyle | import("react-native").Falsy | import("react-native").RegisteredStyle<import("react-native").TextStyle>> | null | undefined;
|
|
55
|
+
textAlign?: "left" | "right" | "center" | undefined;
|
|
56
|
+
testID?: string | undefined;
|
|
57
|
+
inputAccessoryViewID?: string | undefined;
|
|
58
|
+
value?: string | undefined;
|
|
59
|
+
maxFontSizeMultiplier?: number | null | undefined;
|
|
60
|
+
role?: import("react-native").WebRole | undefined;
|
|
61
|
+
lang?: string | undefined;
|
|
62
|
+
initialValue?: string | undefined;
|
|
63
|
+
autoComplete?: "name" | "email" | "off" | "url" | "tel" | "additional-name" | "address-level1" | "address-level2" | "address-level3" | "address-level4" | "address-line1" | "address-line2" | "address-line3" | "bday" | "bday-day" | "bday-month" | "bday-year" | "cc-additional-name" | "cc-csc" | "cc-exp" | "cc-exp-month" | "cc-exp-year" | "cc-family-name" | "cc-given-name" | "cc-name" | "cc-number" | "cc-type" | "country" | "country-name" | "current-password" | "family-name" | "given-name" | "honorific-prefix" | "honorific-suffix" | "impp" | "language" | "new-password" | "nickname" | "on" | "one-time-code" | "organization" | "organization-title" | "postal-code" | "sex" | "street-address" | "tel-area-code" | "tel-country-code" | "tel-extension" | "tel-local" | "tel-national" | "transaction-amount" | "transaction-currency" | "username" | undefined;
|
|
64
|
+
enterKeyHint?: "enter" | "search" | "done" | "go" | "next" | "send" | "previous" | undefined;
|
|
65
|
+
rows?: number | undefined;
|
|
66
|
+
children?: string | number | boolean | import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>> | Iterable<import("react").ReactNode> | import("react").ReactPortal | null | undefined;
|
|
67
|
+
hitSlop?: import("react-native").Insets | undefined;
|
|
68
|
+
id?: string | undefined;
|
|
69
|
+
onLayout?: ((event: import("react-native").LayoutChangeEvent) => void) | undefined;
|
|
70
|
+
pointerEvents?: "auto" | "none" | "box-none" | "box-only" | undefined;
|
|
71
|
+
removeClippedSubviews?: boolean | undefined;
|
|
72
|
+
nativeID?: string | undefined;
|
|
73
|
+
onKeyDown?: ((event: NativeSyntheticEvent<import("react").KeyboardEvent<Element>>) => void) | undefined;
|
|
74
|
+
onKeyDownCapture?: ((event: NativeSyntheticEvent<import("react").KeyboardEvent<Element>>) => void) | undefined;
|
|
75
|
+
onKeyUp?: ((event: NativeSyntheticEvent<import("react").KeyboardEvent<Element>>) => void) | undefined;
|
|
76
|
+
onKeyUpCapture?: ((event: NativeSyntheticEvent<import("react").KeyboardEvent<Element>>) => void) | undefined;
|
|
77
|
+
collapsable?: boolean | undefined;
|
|
78
|
+
needsOffscreenAlphaCompositing?: boolean | undefined;
|
|
79
|
+
renderToHardwareTextureAndroid?: boolean | undefined;
|
|
80
|
+
focusable?: boolean | undefined;
|
|
81
|
+
shouldRasterizeIOS?: boolean | undefined;
|
|
82
|
+
isTVSelectable?: boolean | undefined;
|
|
83
|
+
hasTVPreferredFocus?: boolean | undefined;
|
|
84
|
+
tvParallaxProperties?: import("react-native").TVParallaxProperties | undefined;
|
|
85
|
+
tvParallaxShiftDistanceX?: number | undefined;
|
|
86
|
+
tvParallaxShiftDistanceY?: number | undefined;
|
|
87
|
+
tvParallaxTiltAngle?: number | undefined;
|
|
88
|
+
tvParallaxMagnification?: number | undefined;
|
|
89
|
+
onStartShouldSetResponder?: ((event: import("react-native").GestureResponderEvent) => boolean) | undefined;
|
|
90
|
+
onMoveShouldSetResponder?: ((event: import("react-native").GestureResponderEvent) => boolean) | undefined;
|
|
91
|
+
onResponderEnd?: ((event: import("react-native").GestureResponderEvent) => void) | undefined;
|
|
92
|
+
onResponderGrant?: ((event: import("react-native").GestureResponderEvent) => void) | undefined;
|
|
93
|
+
onResponderReject?: ((event: import("react-native").GestureResponderEvent) => void) | undefined;
|
|
94
|
+
onResponderMove?: ((event: import("react-native").GestureResponderEvent) => void) | undefined;
|
|
95
|
+
onResponderRelease?: ((event: import("react-native").GestureResponderEvent) => void) | undefined;
|
|
96
|
+
onResponderStart?: ((event: import("react-native").GestureResponderEvent) => void) | undefined;
|
|
97
|
+
onResponderTerminationRequest?: ((event: import("react-native").GestureResponderEvent) => boolean) | undefined;
|
|
98
|
+
onResponderTerminate?: ((event: import("react-native").GestureResponderEvent) => void) | undefined;
|
|
99
|
+
onStartShouldSetResponderCapture?: ((event: import("react-native").GestureResponderEvent) => boolean) | undefined;
|
|
100
|
+
onMoveShouldSetResponderCapture?: ((event: import("react-native").GestureResponderEvent) => boolean) | undefined;
|
|
101
|
+
onTouchStart?: ((event: import("react-native").GestureResponderEvent) => void) | undefined;
|
|
102
|
+
onTouchMove?: ((event: import("react-native").GestureResponderEvent) => void) | undefined;
|
|
103
|
+
onTouchEnd?: ((event: import("react-native").GestureResponderEvent) => void) | undefined;
|
|
104
|
+
onTouchCancel?: ((event: import("react-native").GestureResponderEvent) => void) | undefined;
|
|
105
|
+
onTouchEndCapture?: ((event: import("react-native").GestureResponderEvent) => void) | undefined;
|
|
106
|
+
onPointerEnter?: ((event: import("react-native").PointerEvent) => void) | undefined;
|
|
107
|
+
onPointerEnterCapture?: ((event: import("react-native").PointerEvent) => void) | undefined;
|
|
108
|
+
onPointerLeave?: ((event: import("react-native").PointerEvent) => void) | undefined;
|
|
109
|
+
onPointerLeaveCapture?: ((event: import("react-native").PointerEvent) => void) | undefined;
|
|
110
|
+
onPointerMove?: ((event: import("react-native").PointerEvent) => void) | undefined;
|
|
111
|
+
onPointerMoveCapture?: ((event: import("react-native").PointerEvent) => void) | undefined;
|
|
112
|
+
onPointerCancel?: ((event: import("react-native").PointerEvent) => void) | undefined;
|
|
113
|
+
onPointerCancelCapture?: ((event: import("react-native").PointerEvent) => void) | undefined;
|
|
114
|
+
onPointerDown?: ((event: import("react-native").PointerEvent) => void) | undefined;
|
|
115
|
+
onPointerDownCapture?: ((event: import("react-native").PointerEvent) => void) | undefined;
|
|
116
|
+
onPointerUp?: ((event: import("react-native").PointerEvent) => void) | undefined;
|
|
117
|
+
onPointerUpCapture?: ((event: import("react-native").PointerEvent) => void) | undefined;
|
|
118
|
+
accessible?: boolean | undefined;
|
|
119
|
+
accessibilityActions?: readonly Readonly<{
|
|
120
|
+
name: string;
|
|
121
|
+
label?: string | undefined;
|
|
122
|
+
}>[] | undefined;
|
|
123
|
+
accessibilityLabel?: string | undefined;
|
|
124
|
+
"aria-label"?: string | undefined;
|
|
125
|
+
accessibilityRole?: import("react-native").AccessibilityRole | undefined;
|
|
126
|
+
accessibilityState?: import("react-native").AccessibilityState | undefined;
|
|
127
|
+
"aria-busy"?: boolean | undefined;
|
|
128
|
+
"aria-checked"?: boolean | "mixed" | undefined;
|
|
129
|
+
"aria-disabled"?: boolean | undefined;
|
|
130
|
+
"aria-expanded"?: boolean | undefined;
|
|
131
|
+
"aria-selected"?: boolean | undefined;
|
|
132
|
+
"aria-labelledby"?: string | undefined;
|
|
133
|
+
accessibilityHint?: string | undefined;
|
|
134
|
+
accessibilityValue?: import("react-native").AccessibilityValue | undefined;
|
|
135
|
+
"aria-valuemax"?: number | undefined;
|
|
136
|
+
"aria-valuemin"?: number | undefined;
|
|
137
|
+
"aria-valuenow"?: number | undefined;
|
|
138
|
+
"aria-valuetext"?: string | undefined;
|
|
139
|
+
onAccessibilityAction?: ((event: import("react-native").AccessibilityActionEvent) => void) | undefined;
|
|
140
|
+
importantForAccessibility?: "auto" | "yes" | "no" | "no-hide-descendants" | undefined;
|
|
141
|
+
"aria-hidden"?: boolean | undefined;
|
|
142
|
+
"aria-live"?: "polite" | "assertive" | "off" | undefined;
|
|
143
|
+
"aria-modal"?: boolean | undefined;
|
|
144
|
+
accessibilityLiveRegion?: "none" | "polite" | "assertive" | undefined;
|
|
145
|
+
accessibilityLabelledBy?: string | string[] | undefined;
|
|
146
|
+
accessibilityElementsHidden?: boolean | undefined;
|
|
147
|
+
accessibilityViewIsModal?: boolean | undefined;
|
|
148
|
+
onAccessibilityEscape?: (() => void) | undefined;
|
|
149
|
+
onAccessibilityTap?: (() => void) | undefined;
|
|
150
|
+
onMagicTap?: (() => void) | undefined;
|
|
151
|
+
accessibilityIgnoresInvertColors?: boolean | undefined;
|
|
152
|
+
accessibilityLanguage?: string | undefined;
|
|
153
|
+
tabIndex?: 0 | -1 | undefined;
|
|
154
|
+
"aria-activedescendant"?: string | undefined;
|
|
155
|
+
"aria-atomic"?: boolean | undefined;
|
|
156
|
+
"aria-autocomplete"?: string | undefined;
|
|
157
|
+
"aria-colcount"?: number | undefined;
|
|
158
|
+
"aria-colindex"?: number | undefined;
|
|
159
|
+
"aria-colspan"?: number | undefined;
|
|
160
|
+
"aria-controls"?: string | undefined;
|
|
161
|
+
"aria-current"?: boolean | "time" | "page" | "step" | "location" | "date" | undefined;
|
|
162
|
+
"aria-describedby"?: string | undefined;
|
|
163
|
+
"aria-details"?: string | undefined;
|
|
164
|
+
"aria-errormessage"?: string | undefined;
|
|
165
|
+
"aria-flowto"?: string | undefined;
|
|
166
|
+
"aria-haspopup"?: string | undefined;
|
|
167
|
+
"aria-invalid"?: boolean | undefined;
|
|
168
|
+
"aria-keyshortcuts"?: string | undefined;
|
|
169
|
+
"aria-level"?: number | undefined;
|
|
170
|
+
"aria-multiline"?: boolean | undefined;
|
|
171
|
+
"aria-multiselectable"?: boolean | undefined;
|
|
172
|
+
"aria-orientation"?: "horizontal" | "vertical" | undefined;
|
|
173
|
+
"aria-owns"?: string | undefined;
|
|
174
|
+
"aria-placeholder"?: string | undefined;
|
|
175
|
+
"aria-posinset"?: number | undefined;
|
|
176
|
+
"aria-pressed"?: boolean | undefined;
|
|
177
|
+
"aria-readonly"?: boolean | undefined;
|
|
178
|
+
"aria-required"?: boolean | undefined;
|
|
179
|
+
"aria-roledescription"?: string | undefined;
|
|
180
|
+
"aria-rowcount"?: number | undefined;
|
|
181
|
+
"aria-rowindex"?: number | undefined;
|
|
182
|
+
"aria-rowspan"?: number | undefined;
|
|
183
|
+
"aria-setsize"?: number | undefined;
|
|
184
|
+
"aria-sort"?: "none" | "ascending" | "descending" | "other" | undefined;
|
|
185
|
+
clearButtonMode?: "always" | "never" | "while-editing" | "unless-editing" | undefined;
|
|
186
|
+
clearTextOnFocus?: boolean | undefined;
|
|
187
|
+
dataDetectorTypes?: import("react-native").DataDetectorTypes | import("react-native").DataDetectorTypes[] | undefined;
|
|
188
|
+
enablesReturnKeyAutomatically?: boolean | undefined;
|
|
189
|
+
keyboardAppearance?: "default" | "light" | "dark" | undefined;
|
|
190
|
+
passwordRules?: string | null | undefined;
|
|
191
|
+
rejectResponderTermination?: boolean | null | undefined;
|
|
192
|
+
selectionState?: import("react-native").DocumentSelectionState | undefined;
|
|
193
|
+
spellCheck?: boolean | undefined;
|
|
194
|
+
textContentType?: "none" | "name" | "location" | "nickname" | "username" | "URL" | "addressCity" | "addressCityAndState" | "addressState" | "countryName" | "creditCardNumber" | "emailAddress" | "familyName" | "fullStreetAddress" | "givenName" | "jobTitle" | "middleName" | "namePrefix" | "nameSuffix" | "organizationName" | "postalCode" | "streetAddressLine1" | "streetAddressLine2" | "sublocality" | "telephoneNumber" | "password" | "newPassword" | "oneTimeCode" | undefined;
|
|
195
|
+
scrollEnabled?: boolean | undefined;
|
|
196
|
+
lineBreakStrategyIOS?: "none" | "standard" | "hangul-word" | "push-out" | undefined;
|
|
197
|
+
cursorColor?: import("react-native").ColorValue | null | undefined;
|
|
198
|
+
importantForAutofill?: "auto" | "yes" | "no" | "noExcludeDescendants" | "yesExcludeDescendants" | undefined;
|
|
199
|
+
disableFullscreenUI?: boolean | undefined;
|
|
200
|
+
inlineImageLeft?: string | undefined;
|
|
201
|
+
inlineImagePadding?: number | undefined;
|
|
202
|
+
numberOfLines?: number | undefined;
|
|
203
|
+
returnKeyLabel?: string | undefined;
|
|
204
|
+
textBreakStrategy?: "simple" | "highQuality" | "balanced" | undefined;
|
|
205
|
+
underlineColorAndroid?: import("react-native").ColorValue | undefined;
|
|
206
|
+
textAlignVertical?: "bottom" | "top" | "auto" | "center" | undefined;
|
|
207
|
+
showSoftInputOnFocus?: boolean | undefined;
|
|
208
|
+
verticalAlign?: "bottom" | "top" | "auto" | "middle" | undefined;
|
|
209
|
+
readOnly?: boolean | undefined;
|
|
210
|
+
error?: string | undefined;
|
|
211
|
+
disabled?: boolean | undefined;
|
|
212
|
+
valid?: boolean | undefined;
|
|
213
|
+
hideErrors?: boolean | undefined;
|
|
214
|
+
help?: string | undefined;
|
|
215
|
+
validator?: ((value: string) => boolean) | undefined;
|
|
216
|
+
placeholder?: string | undefined;
|
|
217
|
+
} & import("react").RefAttributes<TextInput | null>>;
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef, useCallback, useRef, useState } from "react";
|
|
3
|
+
import { StyleSheet, TextInput, View, } from "react-native";
|
|
4
|
+
import { P, match } from "ts-pattern";
|
|
5
|
+
import { backgroundColor, colors, radii, shadows, spacings } from "../constants/design";
|
|
6
|
+
import { useHover } from "../hooks/useHover";
|
|
7
|
+
import { useMergeRefs } from "../hooks/useMergeRefs";
|
|
8
|
+
import { isNotNullish, isNotNullishOrEmpty, isNullishOrEmpty } from "../utils/nullish";
|
|
9
|
+
import { Box } from "./Box";
|
|
10
|
+
import { LakeText } from "./LakeText";
|
|
11
|
+
import { Pressable } from "./Pressable";
|
|
12
|
+
import { Tag } from "./Tag";
|
|
13
|
+
const TRANSPARENT = "transparent";
|
|
14
|
+
const styles = StyleSheet.create({
|
|
15
|
+
container: {
|
|
16
|
+
flexGrow: 1,
|
|
17
|
+
flexShrink: 1,
|
|
18
|
+
flexDirection: "row",
|
|
19
|
+
alignItems: "stretch",
|
|
20
|
+
},
|
|
21
|
+
root: {
|
|
22
|
+
flexDirection: "row",
|
|
23
|
+
display: "flex",
|
|
24
|
+
alignItems: "center",
|
|
25
|
+
flexWrap: "wrap",
|
|
26
|
+
borderRadius: radii[6],
|
|
27
|
+
backgroundColor: backgroundColor.accented,
|
|
28
|
+
borderColor: colors.gray[100],
|
|
29
|
+
borderWidth: 1,
|
|
30
|
+
paddingHorizontal: spacings[4],
|
|
31
|
+
paddingTop: spacings[4],
|
|
32
|
+
outlineStyle: "none",
|
|
33
|
+
cursor: "text",
|
|
34
|
+
},
|
|
35
|
+
focused: {
|
|
36
|
+
borderColor: colors.gray[500],
|
|
37
|
+
boxShadow: shadows.tile,
|
|
38
|
+
},
|
|
39
|
+
hovered: {
|
|
40
|
+
boxShadow: shadows.tile,
|
|
41
|
+
},
|
|
42
|
+
disabled: {
|
|
43
|
+
backgroundColor: colors.gray[50],
|
|
44
|
+
borderColor: colors.gray[50],
|
|
45
|
+
color: colors.gray[900],
|
|
46
|
+
cursor: "not-allowed",
|
|
47
|
+
},
|
|
48
|
+
readOnly: {
|
|
49
|
+
backgroundColor: colors.gray[50],
|
|
50
|
+
borderColor: colors.gray[50],
|
|
51
|
+
color: colors.gray[900],
|
|
52
|
+
},
|
|
53
|
+
readOnlyError: {
|
|
54
|
+
borderColor: TRANSPARENT,
|
|
55
|
+
paddingRight: spacings[32],
|
|
56
|
+
},
|
|
57
|
+
error: {
|
|
58
|
+
borderColor: colors.negative[400],
|
|
59
|
+
},
|
|
60
|
+
valid: {
|
|
61
|
+
borderColor: colors.positive[500],
|
|
62
|
+
},
|
|
63
|
+
input: {
|
|
64
|
+
height: 28,
|
|
65
|
+
marginBottom: spacings[4],
|
|
66
|
+
marginLeft: spacings[4],
|
|
67
|
+
outlineStyle: "none",
|
|
68
|
+
flexGrow: 1,
|
|
69
|
+
},
|
|
70
|
+
tag: {
|
|
71
|
+
marginRight: spacings[4],
|
|
72
|
+
marginBottom: spacings[4],
|
|
73
|
+
maxWidth: 350,
|
|
74
|
+
},
|
|
75
|
+
errorContainer: {
|
|
76
|
+
paddingTop: spacings[4],
|
|
77
|
+
},
|
|
78
|
+
});
|
|
79
|
+
const SEPARATORS_REGEX = /,| /;
|
|
80
|
+
export const LakeTagInput = forwardRef(({ validator = () => true, onFocus: originalOnFocus, onBlur: originalOnBlur, values, onValuesChanged, readOnly = false, disabled = false, valid = false, hideErrors = false, placeholder, help, error, }, forwardRef) => {
|
|
81
|
+
const inputRef = useRef(null);
|
|
82
|
+
const containerRef = useRef(null);
|
|
83
|
+
const [isFocused, setIsFocused] = useState(false);
|
|
84
|
+
const [isHovered, setIsHovered] = useState(false);
|
|
85
|
+
useHover(containerRef, {
|
|
86
|
+
onHoverStart: () => setIsHovered(true),
|
|
87
|
+
onHoverEnd: () => setIsHovered(false),
|
|
88
|
+
});
|
|
89
|
+
const pushNewValues = useCallback((vals) => {
|
|
90
|
+
onValuesChanged([...values, ...vals.filter(v => !values.includes(v))]);
|
|
91
|
+
inputRef.current?.clear();
|
|
92
|
+
}, [values, onValuesChanged]);
|
|
93
|
+
const onTextInputChange = useCallback((value) => {
|
|
94
|
+
const input = [...new Set(value.split(SEPARATORS_REGEX).filter(s => s.length))];
|
|
95
|
+
if (input.length > 1 || input[0] !== value) {
|
|
96
|
+
pushNewValues(input);
|
|
97
|
+
}
|
|
98
|
+
}, [pushNewValues]);
|
|
99
|
+
const onTextInputKeyPress = useCallback(({ nativeEvent }) => {
|
|
100
|
+
match({ key: nativeEvent.key, input: inputRef.current })
|
|
101
|
+
.with({ key: "Backspace", input: P.instanceOf(HTMLInputElement) }, ({ input }) => {
|
|
102
|
+
if (isNullishOrEmpty(input.value)) {
|
|
103
|
+
onValuesChanged(values.filter(current => current !== values[values.length - 1]));
|
|
104
|
+
}
|
|
105
|
+
})
|
|
106
|
+
.with({ key: "Enter", input: P.instanceOf(HTMLInputElement) }, ({ input }) => {
|
|
107
|
+
if (isNotNullishOrEmpty(input.value)) {
|
|
108
|
+
pushNewValues([input.value]);
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
}, [onValuesChanged, pushNewValues, values]);
|
|
112
|
+
const autoFocus = useCallback(() => {
|
|
113
|
+
inputRef.current?.focus();
|
|
114
|
+
}, []);
|
|
115
|
+
const onFocus = useCallback((event) => {
|
|
116
|
+
setIsFocused(true);
|
|
117
|
+
originalOnFocus?.(event);
|
|
118
|
+
}, [originalOnFocus]);
|
|
119
|
+
const onBlur = useCallback((event) => {
|
|
120
|
+
setIsFocused(false);
|
|
121
|
+
originalOnBlur?.(event);
|
|
122
|
+
}, [originalOnBlur]);
|
|
123
|
+
const mergedRef = useMergeRefs(inputRef, forwardRef);
|
|
124
|
+
const hasError = isNotNullishOrEmpty(error);
|
|
125
|
+
return (_jsxs(View, { children: [_jsxs(Pressable, { style: [
|
|
126
|
+
styles.root,
|
|
127
|
+
readOnly && hasError && styles.readOnlyError,
|
|
128
|
+
disabled && styles.disabled,
|
|
129
|
+
readOnly && styles.readOnly,
|
|
130
|
+
isFocused && styles.focused,
|
|
131
|
+
hasError && styles.error,
|
|
132
|
+
valid && styles.valid,
|
|
133
|
+
isHovered && styles.hovered,
|
|
134
|
+
], "aria-errormessage": error, onPress: autoFocus, ref: containerRef, children: [values.map((value, i) => (_jsx(Tag, { onPressRemove: !readOnly && !disabled
|
|
135
|
+
? () => onValuesChanged(values.filter(current => current !== value))
|
|
136
|
+
: undefined, style: styles.tag, color: validator(value) ? "gray" : "negative", children: value }, i))), _jsx(TextInput, { ref: mergedRef, style: [styles.input, disabled && styles.disabled], onFocus: onFocus, onBlur: onBlur, "aria-disabled": disabled, onChangeText: onTextInputChange, onKeyPress: onTextInputKeyPress, readOnly: readOnly, placeholder: placeholder })] }), !hideErrors && (_jsx(Box, { direction: "row", style: styles.errorContainer, children: isNotNullish(error) ? (_jsx(LakeText, { variant: "smallRegular", color: colors.negative[500], children: error })) : (_jsx(LakeText, { variant: "smallRegular", color: colors.gray[500], children: help ?? " " })) }))] }));
|
|
137
|
+
});
|
package/src/components/Tag.js
CHANGED
|
@@ -18,20 +18,26 @@ const styles = StyleSheet.create({
|
|
|
18
18
|
padding: 0,
|
|
19
19
|
},
|
|
20
20
|
larger: {
|
|
21
|
-
paddingHorizontal: 4,
|
|
22
21
|
height: 40,
|
|
23
22
|
},
|
|
24
23
|
label: {
|
|
25
24
|
borderTopRightRadius: 0,
|
|
26
25
|
borderBottomRightRadius: 0,
|
|
27
26
|
borderRightWidth: 0,
|
|
27
|
+
paddingHorizontal: 8,
|
|
28
|
+
},
|
|
29
|
+
withLabel: {
|
|
30
|
+
borderLeftWidth: 0,
|
|
31
|
+
borderTopLeftRadius: 0,
|
|
32
|
+
borderBottomLeftRadius: 0,
|
|
33
|
+
},
|
|
34
|
+
center: {
|
|
35
|
+
paddingHorizontal: 8,
|
|
36
|
+
flexGrow: 1,
|
|
37
|
+
flexShrink: 1,
|
|
28
38
|
},
|
|
29
39
|
text: {
|
|
30
40
|
...texts.smallMedium,
|
|
31
|
-
display: "flex",
|
|
32
|
-
alignItems: "center",
|
|
33
|
-
justifyContent: "center",
|
|
34
|
-
paddingHorizontal: 8,
|
|
35
41
|
},
|
|
36
42
|
unselectable: {
|
|
37
43
|
userSelect: "none",
|
|
@@ -60,17 +66,10 @@ export const Tag = ({ children, label, color = "gray", size = "small", icon, ico
|
|
|
60
66
|
styles.base,
|
|
61
67
|
size === "large" && styles.larger,
|
|
62
68
|
hasOnlyIcon && styles.onlyIcon,
|
|
63
|
-
{
|
|
64
|
-
|
|
65
|
-
borderColor: tint200,
|
|
66
|
-
...(hasLabel && {
|
|
67
|
-
borderLeftWidth: 0,
|
|
68
|
-
borderTopLeftRadius: 0,
|
|
69
|
-
borderBottomLeftRadius: 0,
|
|
70
|
-
}),
|
|
71
|
-
},
|
|
69
|
+
{ backgroundColor: tint50, borderColor: tint200 },
|
|
70
|
+
hasLabel && styles.withLabel,
|
|
72
71
|
style,
|
|
73
|
-
], children: [_jsxs(
|
|
72
|
+
], children: [_jsxs(Box, { direction: "row", alignItems: "center", style: styles.center, children: [isNotNullish(icon) && (_jsxs(_Fragment, { children: [_jsx(Icon, { name: icon, color: primary, size: iconSize }), isNotNullish(children) && _jsx(Space, { width: 8 })] })), _jsx(Text, { numberOfLines: 1, style: [styles.text, hasOnlyIcon && styles.onlyIcon, { color: primary }], children: children })] }), hasRemoveButton && (_jsx(Pressable, { role: "button", onPress: onPressRemove, style: ({ hovered, pressed }) => [
|
|
74
73
|
styles.dismiss,
|
|
75
74
|
{ color: primary, borderColor: tint100 },
|
|
76
75
|
hovered && { backgroundColor: tint100 },
|