@swan-io/lake 13.5.3 → 13.6.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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@swan-io/lake",
3
- "version": "13.5.3",
3
+ "version": "13.6.1",
4
4
  "engines": {
5
5
  "node": ">22.12.0"
6
6
  },
@@ -13,12 +13,12 @@ type Props<T> = {
13
13
  id?: string;
14
14
  placeholder?: string;
15
15
  error?: string;
16
- emptyResultText: string;
16
+ emptyResult: string;
17
17
  ListFooterComponent?: ReactNode;
18
18
  shouldDisplaySuggestions?: boolean;
19
19
  loadSuggestions?: (value: string) => Future<Result<Suggestion<T>[], unknown>>;
20
20
  onSuggestion: (suggestion: Suggestion<T>) => void;
21
21
  onLoadError?: (error: unknown) => void;
22
22
  };
23
- export declare const AutocompleteSearchInput: <T>({ inputRef, value, onValueChange, disabled, id, placeholder, error, emptyResultText, ListFooterComponent, shouldDisplaySuggestions, loadSuggestions, onSuggestion, onLoadError, }: Props<T>) => import("react/jsx-runtime").JSX.Element;
23
+ export declare const AutocompleteSearchInput: <T>({ inputRef, value, onValueChange, disabled, id, placeholder, error, emptyResult, ListFooterComponent, shouldDisplaySuggestions, loadSuggestions, onSuggestion, onLoadError, }: Props<T>) => import("react/jsx-runtime").JSX.Element;
24
24
  export {};
@@ -12,7 +12,7 @@ const styles = StyleSheet.create({
12
12
  userSelect: "none",
13
13
  },
14
14
  });
15
- export const AutocompleteSearchInput = ({ inputRef, value, onValueChange, disabled, id, placeholder, error, emptyResultText, ListFooterComponent, shouldDisplaySuggestions = true, loadSuggestions, onSuggestion, onLoadError, }) => {
15
+ export const AutocompleteSearchInput = ({ inputRef, value, onValueChange, disabled, id, placeholder, error, emptyResult, ListFooterComponent, shouldDisplaySuggestions = true, loadSuggestions, onSuggestion, onLoadError, }) => {
16
16
  const [state, setState] = useState(AsyncData.NotAsked());
17
17
  const lastRequest = useRef(undefined);
18
18
  return (_jsx(LakeCombobox, { inputRef: inputRef, id: id, placeholder: placeholder, value: value !== null && value !== void 0 ? value : "", items: state, icon: loadSuggestions != null ? "search-filled" : undefined, disabled: disabled, error: error, ListFooterComponent: ListFooterComponent != null && (_jsxs(_Fragment, { children: [match(state)
@@ -36,5 +36,5 @@ export const AutocompleteSearchInput = ({ inputRef, value, onValueChange, disabl
36
36
  }
37
37
  request.onResolve(value => setState(AsyncData.Done(value)));
38
38
  }
39
- }, keyExtractor: item => `${item.title} ${item.subtitle}`, emptyResultText: emptyResultText, renderItem: item => (_jsxs(_Fragment, { children: [_jsx(LakeText, { numberOfLines: 1, style: styles.unselectable, color: colors.gray[900], children: item.title }), _jsx(LakeText, { numberOfLines: 1, style: styles.unselectable, variant: "smallRegular", children: item.subtitle })] })) }));
39
+ }, keyExtractor: item => `${item.title} ${item.subtitle}`, emptyResult: emptyResult, renderItem: item => (_jsxs(_Fragment, { children: [_jsx(LakeText, { numberOfLines: 1, style: styles.unselectable, color: colors.gray[900], children: item.title }), _jsx(LakeText, { numberOfLines: 1, style: styles.unselectable, variant: "smallRegular", children: item.subtitle })] })) }));
40
40
  };
@@ -1,5 +1,5 @@
1
1
  import { AsyncData, Result } from "@swan-io/boxed";
2
- import { ReactNode, Ref } from "react";
2
+ import { ReactElement, ReactNode, Ref } from "react";
3
3
  import { IconName } from "./Icon";
4
4
  import { LakeTextInputProps } from "./LakeTextInput";
5
5
  export type LakeComboboxRef = {
@@ -22,10 +22,10 @@ export type LakeComboboxProps<I> = {
22
22
  icon?: IconName;
23
23
  placeholder?: string;
24
24
  disabled?: boolean;
25
- emptyResultText: string;
25
+ emptyResult: string | ReactElement;
26
26
  error?: string;
27
27
  hideErrors?: boolean;
28
28
  id?: string;
29
29
  readOnly?: boolean;
30
30
  };
31
- export declare const LakeCombobox: <I>({ ref, inputRef, value, items, itemHeight, nbItemsDisplayed, ListFooterComponent, onChange, onValueChange, onSelectItem, renderItem, keyExtractor, icon, placeholder, disabled, emptyResultText, readOnly, id, error, hideErrors, }: LakeComboboxProps<I>) => import("react/jsx-runtime").JSX.Element;
31
+ export declare const LakeCombobox: <I>({ ref, inputRef, value, items, itemHeight, nbItemsDisplayed, ListFooterComponent, onChange, onValueChange, onSelectItem, renderItem, keyExtractor, icon, placeholder, disabled, emptyResult, readOnly, id, error, hideErrors, }: LakeComboboxProps<I>) => import("react/jsx-runtime").JSX.Element;
@@ -1,6 +1,7 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { useCallback, useId, useImperativeHandle, useRef, useState } from "react";
3
- import { Pressable, StyleSheet, Text, View, } from "react-native";
2
+ import { useCallback, useId, useImperativeHandle, useRef, useState, } from "react";
3
+ import { Pressable, StyleSheet, View, } from "react-native";
4
+ import { match, P } from "ts-pattern";
4
5
  import { backgroundColor, colors, spacings } from "../constants/design";
5
6
  import { useMergeRefs } from "../hooks/useMergeRefs";
6
7
  import { getFocusableElements } from "../utils/a11y";
@@ -74,7 +75,7 @@ const styles = StyleSheet.create({
74
75
  flexGrow: 1,
75
76
  },
76
77
  });
77
- export const LakeCombobox = ({ ref, 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, }) => {
78
+ export const LakeCombobox = ({ ref, inputRef, value, items, itemHeight = DEFAULT_ELEMENT_HEIGHT, nbItemsDisplayed = DEFAULT_NB_SUGGESTION_DISPLAYED, ListFooterComponent, onChange, onValueChange, onSelectItem, renderItem, keyExtractor, icon, placeholder, disabled = false, emptyResult, readOnly, id, error, hideErrors, }) => {
78
79
  const innerInputRef = useRef(null);
79
80
  const inputTextRef = useMergeRefs(innerInputRef, inputRef);
80
81
  const listContainerRef = useRef(null);
@@ -153,7 +154,10 @@ export const LakeCombobox = ({ ref, inputRef, value, items, itemHeight = DEFAULT
153
154
  Loading: () => _jsx(LoadingView, { style: styles.loader }),
154
155
  Done: items => items.match({
155
156
  Error: _ => (_jsx(Icon, { name: "error-circle-regular", size: 22, color: colors.negative[500] })),
156
- Ok: items => (_jsxs(View, { ref: listContainerRef, style: styles.listContainer, children: [items.length === 0 ? (_jsxs(Box, { justifyContent: "center", alignItems: "center", style: styles.emptyList, children: [_jsx(Icon, { name: "clipboard-search-regular", size: 24, color: colors.gray.primary }), _jsx(Space, { height: 8 }), _jsx(Text, { style: styles.emptyListText, children: emptyResultText })] })) : (_jsx(FlatList, { keyExtractor: keyExtractor, role: "list", data: items, style: styles.flatList, ItemSeparatorComponent: _jsx(Separator, {}), renderItem: ({ item }) => {
157
+ Ok: items => (_jsxs(View, { ref: listContainerRef, style: styles.listContainer, children: [items.length === 0 ? (match(emptyResult)
158
+ .with(P.string, text => (_jsxs(Box, { justifyContent: "center", alignItems: "center", style: styles.emptyList, children: [_jsx(Icon, { name: "clipboard-search-regular", size: 24, color: colors.gray.primary }), _jsx(Space, { height: 8 }), _jsx(LakeText, { style: styles.emptyListText, children: text })] })))
159
+ .when((value) => typeof value === "object" && value != null, element => element)
160
+ .exhaustive()) : (_jsx(FlatList, { keyExtractor: keyExtractor, role: "list", data: items, style: styles.flatList, ItemSeparatorComponent: _jsx(Separator, {}), renderItem: ({ item }) => {
157
161
  const rendered = renderItem(item);
158
162
  return (_jsx(Pressable, { onFocus: handleFocus, onBlur: handleBlur, role: "listitem", onKeyDown: handleListItemKeyPress, style: ({ hovered, pressed, focused }) => [
159
163
  styles.item,
@@ -134,7 +134,7 @@ export const TimePicker = ({ value, onChangeText, suggestionStart = DEFAULT_STAR
134
134
  const suffix = suggestionSuffix === null || suggestionSuffix === void 0 ? void 0 : suggestionSuffix(item);
135
135
  const label = isNotNullishOrEmpty(suffix) ? `${text} ${suffix}` : text;
136
136
  return (_jsxs(Box, { direction: "row", alignItems: "center", children: [_jsx(LakeText, { color: selected ? colors.gray[700] : colors.gray[900], variant: selected ? "smallRegular" : "medium", children: label }), _jsx(Fill, { minWidth: 8 }), selected && (_jsx(Icon, { name: "checkmark-filled", color: colors.positive[500], size: 16 }))] }));
137
- }, readOnly: readOnly, disabled: disabled, error: error, hideErrors: hideErrors, emptyResultText: noSuggestionLabel, onChange: onChange, onValueChange: noop, onSelectItem: item => onChangeText(stringifyTime(item)) })) }));
137
+ }, readOnly: readOnly, disabled: disabled, error: error, hideErrors: hideErrors, emptyResult: noSuggestionLabel, onChange: onChange, onValueChange: noop, onSelectItem: item => onChangeText(stringifyTime(item)) })) }));
138
138
  };
139
139
  export const TimeRangePicker = ({ value, onChange, intervalInMinutes = DEFAULT_INTERVAL_IN_MINUTES, nbMaxSuggestions, readOnly, disabled, error, startLabel, endLabel, minutesLabel, hoursLabel, noSuggestionLabel, }) => {
140
140
  var _a;