@swan-io/lake 13.5.0 → 13.5.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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@swan-io/lake",
3
- "version": "13.5.0",
3
+ "version": "13.5.2",
4
4
  "engines": {
5
5
  "node": ">22.12.0"
6
6
  },
@@ -7,15 +7,17 @@ export type Item<V> = {
7
7
  value: V;
8
8
  icon?: ReactNode;
9
9
  };
10
- export type SelectProps<V> = {
10
+ export type SelectProps<V, T extends Item<V> = Item<V>> = {
11
11
  ref?: Ref<View>;
12
12
  placeholder?: string;
13
- items: Item<V>[];
13
+ items: T[];
14
14
  matchReferenceWidth?: boolean;
15
15
  mode?: "normal" | "borderless";
16
16
  title?: string;
17
17
  valueStyle?: StyleProp<TextStyle>;
18
- PopoverFooter?: ReactElement;
18
+ PopoverFooter?: ReactElement | ((helpers: {
19
+ close: () => void;
20
+ }) => ReactElement);
19
21
  size?: "small" | "large";
20
22
  icon?: IconName;
21
23
  color?: ColorVariants;
@@ -26,10 +28,11 @@ export type SelectProps<V> = {
26
28
  value: V;
27
29
  message?: string;
28
30
  }[];
31
+ renderItem?: (item: T, isSelected: boolean) => ReactElement;
29
32
  hideErrors?: boolean;
30
33
  id?: string;
31
34
  error?: string;
32
35
  readOnly?: boolean;
33
36
  style?: StyleProp<ViewStyle>;
34
37
  };
35
- export declare const LakeSelect: <V>({ ref, title, items, valueStyle, size, color, disabled, mode, placeholder, readOnly, id, matchReferenceWidth, value, error, hideErrors, icon, onValueChange, disabledItems, PopoverFooter, style, }: SelectProps<V>) => import("react/jsx-runtime").JSX.Element;
38
+ 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, }: SelectProps<V, T>) => import("react/jsx-runtime").JSX.Element;
@@ -112,7 +112,7 @@ const styles = StyleSheet.create({
112
112
  borderColor: colors.negative[500],
113
113
  },
114
114
  });
115
- export const LakeSelect = ({ ref, title, items, valueStyle, size, color = "current", disabled = false, mode = "normal", placeholder, readOnly = false, id, matchReferenceWidth = true, value, error, hideErrors = false, icon, onValueChange, disabledItems = [], PopoverFooter, style, }) => {
115
+ export const LakeSelect = ({ ref, title, items, valueStyle, size, color = "current", disabled = false, mode = "normal", placeholder, readOnly = false, id, matchReferenceWidth = true, value, error, hideErrors = false, icon, onValueChange, disabledItems = [], renderItem, PopoverFooter, style, }) => {
116
116
  var _a;
117
117
  const inputRef = useRef(null);
118
118
  const listRef = useRef(null);
@@ -189,6 +189,7 @@ export const LakeSelect = ({ ref, title, items, valueStyle, size, color = "curre
189
189
  }, keyExtractor: (_, index) => `select-item-${index}`, renderItem: ({ item, index }) => {
190
190
  const isSelected = value === item.value;
191
191
  const disablement = disabledItems.find(({ value }) => value === item.value);
192
+ const content = renderItem != null ? (renderItem(item, isSelected)) : (_jsxs(_Fragment, { 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 })] }));
192
193
  return (_jsx(LakeTooltip, { placement: "right", content: disablement === null || disablement === void 0 ? void 0 : disablement.message, disabled: isNullishOrEmpty(disablement === null || disablement === void 0 ? void 0 : disablement.message), children: _jsxs(Pressable, { ref: element => {
193
194
  listItemRefs.current[index] = element;
194
195
  }, onKeyDown: onKeyDown, disabled: isNotNullish(disablement), style: ({ hovered, focused }) => [
@@ -199,6 +200,6 @@ export const LakeSelect = ({ ref, title, items, valueStyle, size, color = "curre
199
200
  ], role: "option", "aria-selected": true, onPress: () => {
200
201
  onValueChange(item.value);
201
202
  close();
202
- }, 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 }))] }) }));
203
- } }), PopoverFooter] })] }));
203
+ }, children: [content, _jsx(Fill, { minWidth: 12 }), isSelected && (_jsx(Icon, { color: colors.positive[500], name: "checkmark-filled", size: 14 }))] }) }));
204
+ } }), typeof PopoverFooter === "function" ? PopoverFooter({ close }) : PopoverFooter] })] }));
204
205
  };