@swan-io/lake 1.4.4 → 1.5.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.
Files changed (108) hide show
  1. package/package.json +4 -5
  2. package/src/components/AppOpeningAnimation.js +13 -13
  3. package/src/components/AutoWidthImage.d.ts +1 -0
  4. package/src/components/AutoWidthImage.js +3 -4
  5. package/src/components/Avatar.js +3 -2
  6. package/src/components/BorderedButton.d.ts +1 -1
  7. package/src/components/BorderedButton.js +6 -4
  8. package/src/components/BottomPanel.js +2 -2
  9. package/src/components/Box.js +1 -1
  10. package/src/components/Breadcrumbs.js +7 -7
  11. package/src/components/ChoicePicker.js +6 -6
  12. package/src/components/Fill.js +2 -1
  13. package/src/components/FilterChooser.js +2 -2
  14. package/src/components/Filters.js +9 -9
  15. package/src/components/FixedListView.js +15 -12
  16. package/src/components/FixedListViewCells.js +2 -2
  17. package/src/components/Form.d.ts +1 -1
  18. package/src/components/FullViewportLayer.js +10 -7
  19. package/src/components/Heading.d.ts +1 -1
  20. package/src/components/Heading.js +1 -1
  21. package/src/components/Icon.d.ts +2 -4
  22. package/src/components/Icon.js +7 -1
  23. package/src/components/Input.d.ts +6 -6
  24. package/src/components/Input.js +6 -11
  25. package/src/components/Label.d.ts +1 -1
  26. package/src/components/Label.js +1 -1
  27. package/src/components/LakeButton.d.ts +3 -3
  28. package/src/components/LakeButton.js +5 -5
  29. package/src/components/LakeCheckbox.js +2 -2
  30. package/src/components/LakeCombobox.d.ts +2 -2
  31. package/src/components/LakeCombobox.js +6 -10
  32. package/src/components/LakeDownloadButton.js +1 -1
  33. package/src/components/LakeHeading.d.ts +3 -2
  34. package/src/components/LakeHeading.js +7 -1
  35. package/src/components/LakeLabel.d.ts +0 -1
  36. package/src/components/LakeLabel.js +3 -3
  37. package/src/components/LakeModal.js +6 -3
  38. package/src/components/LakeRadio.js +3 -3
  39. package/src/components/LakeScrollView.js +2 -1
  40. package/src/components/LakeSearchField.js +3 -3
  41. package/src/components/LakeSelect.d.ts +2 -2
  42. package/src/components/LakeSelect.js +14 -23
  43. package/src/components/LakeSlider.js +1 -1
  44. package/src/components/LakeStepper.js +4 -4
  45. package/src/components/LakeText.d.ts +9 -8
  46. package/src/components/LakeText.js +7 -1
  47. package/src/components/LakeTextInput.d.ts +10 -5
  48. package/src/components/LakeTextInput.js +4 -4
  49. package/src/components/LakeTooltip.js +7 -12
  50. package/src/components/Link.d.ts +52 -49
  51. package/src/components/Link.js +2 -2
  52. package/src/components/ListRightPanel.js +2 -2
  53. package/src/components/Modal.js +15 -5
  54. package/src/components/MultiSelect.d.ts +1 -1
  55. package/src/components/MultiSelect.js +10 -7
  56. package/src/components/PlainListView.js +4 -3
  57. package/src/components/Popover.js +9 -5
  58. package/src/components/Portal.js +2 -2
  59. package/src/components/Pressable.d.ts +112 -101
  60. package/src/components/Pressable.js +16 -6
  61. package/src/components/RightPanel.js +10 -7
  62. package/src/components/Separator.js +1 -1
  63. package/src/components/SidebarNavigationTracker.js +5 -4
  64. package/src/components/Slider.js +28 -12
  65. package/src/components/SmsOpeningAnimation.js +15 -15
  66. package/src/components/Stack.d.ts +4 -4
  67. package/src/components/Stack.js +1 -1
  68. package/src/components/Stepper.js +1 -1
  69. package/src/components/Svg.d.ts +6 -7
  70. package/src/components/Switch.js +18 -6
  71. package/src/components/TabView.js +8 -7
  72. package/src/components/Tag.d.ts +2 -2
  73. package/src/components/Tag.js +6 -3
  74. package/src/components/Tile.js +2 -2
  75. package/src/components/ToastStack.js +16 -7
  76. package/src/components/Tooltip.js +3 -6
  77. package/src/components/TransitionGroupView.d.ts +2 -3
  78. package/src/components/TransitionGroupView.js +2 -2
  79. package/src/components/TransitionView.d.ts +2 -3
  80. package/src/components/TransitionView.js +2 -2
  81. package/src/components/WithCurrentColor.d.ts +1 -1
  82. package/src/constants/design.d.ts +4 -12
  83. package/src/constants/design.js +12 -12
  84. package/src/hooks/useAnimatedValue.js +9 -2
  85. package/src/hooks/useForceableState.js +1 -1
  86. package/src/hooks/useHover.js +1 -1
  87. package/src/hooks/useMergeRefs.js +1 -1
  88. package/src/hooks/usePressEvents.js +1 -1
  89. package/src/components/Alert.d.ts +0 -10
  90. package/src/components/Alert.js +0 -36
  91. package/src/components/Button.d.ts +0 -15
  92. package/src/components/Button.js +0 -83
  93. package/src/components/Checkbox.d.ts +0 -12
  94. package/src/components/Checkbox.js +0 -83
  95. package/src/components/Combobox.d.ts +0 -29
  96. package/src/components/Combobox.js +0 -182
  97. package/src/components/MultilineInput.d.ts +0 -15
  98. package/src/components/MultilineInput.js +0 -55
  99. package/src/components/Picker.d.ts +0 -26
  100. package/src/components/Picker.js +0 -116
  101. package/src/components/ProgressBar.d.ts +0 -11
  102. package/src/components/ProgressBar.js +0 -46
  103. package/src/components/SegmentedControl.d.ts +0 -19
  104. package/src/components/SegmentedControl.js +0 -74
  105. package/src/components/Table.d.ts +0 -34
  106. package/src/components/Table.js +0 -79
  107. package/src/hooks/useLazyRef.d.ts +0 -2
  108. package/src/hooks/useLazyRef.js +0 -9
@@ -1,55 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { forwardRef, memo, useId } from "react";
3
- import { StyleSheet, View } from "react-native";
4
- import { colors } from "../constants/colors";
5
- import { typography } from "../constants/typography";
6
- import { isNotNullish } from "../utils/nullish";
7
- import { InputError } from "./InputError";
8
- import { Label } from "./Label";
9
- import { PressableTextInput } from "./Pressable";
10
- import { Space } from "./Space";
11
- const styles = StyleSheet.create({
12
- base: {
13
- ...typography.bodyLarge,
14
- backgroundColor: colors.white,
15
- borderColor: colors.gray[10],
16
- borderRadius: 4,
17
- borderWidth: 1,
18
- flexGrow: 1,
19
- flexShrink: 1,
20
- maxWidth: "100%",
21
- minHeight: 128,
22
- outlineStyle: "none",
23
- padding: 16,
24
- placeholderTextColor: colors.gray[30],
25
- resize: "vertical",
26
- transitionProperty: ["border-color", "box-shadow"],
27
- transitionDuration: "150ms",
28
- },
29
- focused: {
30
- borderColor: colors.gray[30],
31
- shadowColor: colors.gray[100],
32
- shadowOpacity: 0.12,
33
- shadowOffset: { height: 0, width: 0 },
34
- shadowRadius: 2,
35
- },
36
- hovered: {
37
- shadowColor: colors.gray[100],
38
- shadowOpacity: 0.06,
39
- shadowOffset: { height: 4, width: 0 },
40
- shadowRadius: 8,
41
- },
42
- errored: {
43
- borderColor: colors.red[100],
44
- paddingRight: 48,
45
- },
46
- });
47
- export const MultilineInput = memo(forwardRef(({ disabled = false, error, label, onBlur, onSubmitEditing, onValueChange, placeholder, readOnly = false, value = "", }, forwardedRef) => {
48
- const id = `input-${useId()}`;
49
- return (_jsxs(View, { children: [_jsx(Label, { htmlFor: id, children: label }), _jsx(Space, { height: 8 }), _jsx(PressableTextInput, { nativeID: id, ref: forwardedRef, allowFontScaling: false, autoComplete: "off", editable: !readOnly && !disabled, multiline: true, onBlur: onBlur, onChangeText: onValueChange, onSubmitEditing: onSubmitEditing, placeholder: placeholder, value: value, style: ({ hovered, focused }) => [
50
- styles.base,
51
- focused ? styles.focused : hovered && styles.hovered,
52
- isNotNullish(error) && styles.errored,
53
- ] }), _jsx(InputError, { message: error })] }));
54
- }));
55
- MultilineInput.displayName = "MultilineInput";
@@ -1,26 +0,0 @@
1
- import { ReactNode } from "react";
2
- import { StyleProp, ViewStyle } from "react-native";
3
- type Props<V, I extends {
4
- value: V;
5
- }> = {
6
- value: V;
7
- items: I[];
8
- onValueChange: (item: V) => void;
9
- renderItem: (item: I) => ReactNode | null;
10
- renderValue?: (item: I) => ReactNode | null;
11
- itemHeight?: number;
12
- describedBy?: string;
13
- size?: "large" | "small";
14
- label?: string | (() => ReactNode);
15
- info?: ReactNode;
16
- disabled?: boolean;
17
- style?: StyleProp<ViewStyle>;
18
- pickerStyle?: StyleProp<ViewStyle>;
19
- hideErrorMessage?: boolean;
20
- };
21
- export declare const Picker: (<V, I extends {
22
- value: V;
23
- }>(props: Props<V, I>) => JSX.Element | null) & {
24
- displayName?: string | undefined;
25
- };
26
- export {};
@@ -1,116 +0,0 @@
1
- import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { memo as reactMemo, useMemo, useRef } from "react";
3
- import isEqual from "react-fast-compare";
4
- import { FlatList, Pressable, StyleSheet, Text, View } from "react-native";
5
- import { colors } from "../constants/colors";
6
- import { commonStyles } from "../constants/commonStyles";
7
- import { typography } from "../constants/typography";
8
- import { useBoolean } from "../hooks/useBoolean";
9
- import { Fill } from "./Fill";
10
- import { Icon } from "./Icon";
11
- import { InputError } from "./InputError";
12
- import { Label } from "./Label";
13
- import { Popover } from "./Popover";
14
- import { Space } from "./Space";
15
- const ELEMENT_HEIGHT = 48;
16
- const styles = StyleSheet.create({
17
- base: {
18
- alignItems: "center",
19
- backgroundColor: colors.white,
20
- borderColor: colors.gray[10],
21
- borderRadius: 4,
22
- borderWidth: 1,
23
- flexDirection: "row",
24
- flexGrow: 1,
25
- flexShrink: 1,
26
- height: 48,
27
- outlineStyle: "none",
28
- paddingHorizontal: 16,
29
- transitionDuration: "150ms",
30
- transitionProperty: ["border-color", "box-shadow"],
31
- },
32
- small: {
33
- height: 40,
34
- },
35
- focused: {
36
- borderColor: colors.gray[20],
37
- shadowColor: colors.gray[100],
38
- shadowOpacity: 0.12,
39
- shadowOffset: { height: 0, width: 0 },
40
- shadowRadius: 2,
41
- },
42
- hovered: {
43
- shadowColor: colors.gray[100],
44
- shadowOpacity: 0.06,
45
- shadowOffset: { height: 4, width: 0 },
46
- shadowRadius: 8,
47
- },
48
- disabled: {
49
- backgroundColor: colors.gray[3],
50
- borderColor: colors.gray[3],
51
- cursor: "not-allowed",
52
- },
53
- list: {
54
- maxHeight: ELEMENT_HEIGHT * 4.5,
55
- backgroundColor: colors.white,
56
- borderRadius: 4,
57
- shadowColor: colors.gray[100],
58
- shadowOpacity: 0.12,
59
- shadowOffset: { height: 6, width: 0 },
60
- shadowRadius: 24,
61
- },
62
- item: {
63
- alignItems: "center",
64
- flexDirection: "row",
65
- flexGrow: 1,
66
- flexShrink: 1,
67
- paddingHorizontal: 16,
68
- paddingVertical: 0,
69
- transitionProperty: "background-color",
70
- transitionDuration: "200ms",
71
- },
72
- hoveredItem: {
73
- backgroundColor: colors.gray[3],
74
- },
75
- pressedItem: {
76
- backgroundColor: colors.gray[10],
77
- },
78
- itemText: {
79
- ...typography.bodyLarge,
80
- },
81
- });
82
- const isReactText = (node) => ["string", "number"].includes(typeof node);
83
- const memo = reactMemo;
84
- export const Picker = memo(({ value, items, onValueChange, renderItem, renderValue = renderItem, itemHeight = ELEMENT_HEIGHT, describedBy, size = "large", label = "", info = "", disabled = false, style, pickerStyle, hideErrorMessage = false, }) => {
85
- const buttonRef = useRef(null);
86
- const [visible, setVisible] = useBoolean(false);
87
- const selectedItem = items.find(item => item.value === value);
88
- const selectedRendered = selectedItem ? renderValue(selectedItem) : undefined;
89
- const getItemLayout = useMemo(() => (data, index) => ({
90
- length: itemHeight,
91
- offset: itemHeight * index,
92
- index,
93
- }), [itemHeight]);
94
- return (_jsxs(View, { style: style, children: [typeof label === "function"
95
- ? label()
96
- : label !== "" && (_jsxs(_Fragment, { children: [_jsx(Label, { children: label }), _jsx(Space, { height: 8 })] })), _jsxs(Pressable, { ref: buttonRef, accessibilityRole: "button", disabled: disabled, onPress: setVisible.toggle, style: ({ hovered, focused }) => [
97
- styles.base,
98
- size === "small" && styles.small,
99
- pickerStyle,
100
- focused || visible ? styles.focused : hovered && styles.hovered,
101
- disabled && styles.disabled,
102
- ], children: [selectedItem ? (_jsx(View, { style: commonStyles.fill, children: isReactText(selectedRendered) ? (_jsx(Text, { numberOfLines: 1, style: styles.itemText, children: selectedRendered })) : (selectedRendered) })) : (_jsx(Fill, {})), !disabled && (_jsxs(_Fragment, { children: [_jsx(Space, { height: 8 }), _jsx(Icon, { name: visible ? "chevron-up-filled" : "chevron-down-filled", color: colors.gray[30], size: 18 })] }))] }), info !== "" && (_jsxs(_Fragment, { children: [_jsx(Space, { height: 8 }), _jsx(View, { children: info })] })), !hideErrorMessage && _jsx(InputError, {}), _jsx(Popover, { referenceRef: buttonRef, matchReferenceWidth: true, describedBy: describedBy, visible: visible, onDismiss: setVisible.toggle, children: _jsx(FlatList, { getItemLayout: getItemLayout, accessibilityRole: "list", data: items, style: styles.list, keyExtractor: item => `option-${item.value}`, renderItem: ({ item }) => {
103
- const selected = item.value === value;
104
- const rendered = renderItem(item);
105
- return (_jsxs(Pressable, { accessibilityRole: "listitem", accessibilitySelected: selected, style: ({ hovered, pressed }) => [
106
- styles.item,
107
- (hovered || selected) && styles.hoveredItem,
108
- pressed && styles.pressedItem,
109
- { height: itemHeight },
110
- ], onPress: () => {
111
- onValueChange(item.value);
112
- setVisible.toggle();
113
- }, children: [isReactText(rendered) ? (_jsx(Text, { numberOfLines: 1, style: styles.itemText, children: rendered })) : (rendered), selected && (_jsxs(_Fragment, { children: [_jsx(Fill, { minWidth: 16 }), _jsx(Icon, { name: "checkmark-filled", color: colors.green[100], size: 20 })] }))] }));
114
- } }) })] }));
115
- }, isEqual);
116
- Picker.displayName = "Picker";
@@ -1,11 +0,0 @@
1
- /// <reference types="react" />
2
- type Props = {
3
- color: string;
4
- label: string;
5
- progressLabel: string;
6
- minValue: number;
7
- maxValue: number;
8
- value: number;
9
- };
10
- export declare const ProgressBar: ({ color, label, progressLabel, minValue, maxValue, value }: Props) => JSX.Element;
11
- export {};
@@ -1,46 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { useId } from "react";
3
- import { StyleSheet, Text, View } from "react-native";
4
- import { colors } from "../constants/colors";
5
- import { typography } from "../constants/typography";
6
- import { useComputedColors } from "../hooks/useComputedColors";
7
- import { interpolate } from "../utils/math";
8
- import { Box } from "./Box";
9
- import { Fill } from "./Fill";
10
- import { Space } from "./Space";
11
- const styles = StyleSheet.create({
12
- label: {
13
- ...typography.bodySmall,
14
- lineHeight: typography.lineHeights.title,
15
- color: colors.gray[50],
16
- },
17
- progressLabel: {
18
- ...typography.bodySmall,
19
- fontWeight: typography.fontWeights.demi,
20
- color: colors.gray[100],
21
- whiteSpace: "nowrap",
22
- },
23
- bar: {
24
- height: 8,
25
- borderRadius: 4,
26
- backgroundColor: colors.gray[10],
27
- },
28
- progressBar: {
29
- height: "100%",
30
- borderRadius: 4,
31
- },
32
- });
33
- export const ProgressBar = ({ color, label, progressLabel, minValue, maxValue, value }) => {
34
- const computedColors = useComputedColors(color);
35
- const labelId = `label-${useId()}`;
36
- const percentage = interpolate({
37
- inputRange: [minValue, maxValue],
38
- outputRange: [0, 100],
39
- clamp: true,
40
- })(value);
41
- const fillWidth = `${Math.round(percentage)}%`;
42
- return (_jsxs(View, { accessibilityRole: "progressbar", accessibilityLabelledBy: labelId, accessibilityValueMin: minValue, accessibilityValueMax: maxValue, accessibilityValueNow: value, accessibilityValueText: progressLabel, children: [_jsxs(Box, { direction: "row", alignItems: "center", children: [_jsx(Text, { nativeID: labelId, style: styles.label, children: label }), _jsx(Fill, { minWidth: 16 }), _jsx(Text, { style: styles.progressLabel, children: progressLabel })] }), _jsx(Space, { height: 8 }), _jsx(View, { style: styles.bar, children: _jsx(View, { style: [
43
- styles.progressBar,
44
- { backgroundColor: computedColors.progress, width: fillWidth },
45
- ] }) })] }));
46
- };
@@ -1,19 +0,0 @@
1
- import { ReactNode } from "react";
2
- import { StyleProp, ViewStyle } from "react-native";
3
- type Props<V, I extends {
4
- value: V;
5
- }> = {
6
- value: V;
7
- items: I[];
8
- onValueChange: (value: V) => void;
9
- renderItem: (item: I) => ReactNode | null;
10
- horizontal?: boolean;
11
- label: string;
12
- style?: StyleProp<ViewStyle>;
13
- };
14
- export declare const SegmentedControl: (<V, I extends {
15
- value: V;
16
- }>(props: Props<V, I>) => JSX.Element | null) & {
17
- displayName?: string | undefined;
18
- };
19
- export {};
@@ -1,74 +0,0 @@
1
- import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { memo as reactMemo } from "react";
3
- import isEqual from "react-fast-compare";
4
- import { Pressable, StyleSheet, Text, View } from "react-native";
5
- import { colors } from "../constants/colors";
6
- import { typography } from "../constants/typography";
7
- import { Fill } from "./Fill";
8
- import { Icon } from "./Icon";
9
- import { Label } from "./Label";
10
- import { Space } from "./Space";
11
- const styles = StyleSheet.create({
12
- base: {
13
- backgroundColor: colors.white,
14
- borderWidth: 1,
15
- borderColor: colors.gray[10],
16
- borderRadius: 4,
17
- overflow: "hidden",
18
- },
19
- horizontalBase: {
20
- flexDirection: "row",
21
- },
22
- item: {
23
- alignItems: "center",
24
- flexDirection: "row",
25
- flexGrow: 1,
26
- flexShrink: 1,
27
- minHeight: 48,
28
- overflow: "hidden",
29
- paddingHorizontal: 16,
30
- transitionProperty: "background-color",
31
- transitionDuration: "200ms",
32
- },
33
- horizontalItem: {
34
- flexBasis: "0%",
35
- flexDirection: "column",
36
- flexGrow: 1,
37
- flexShrink: 1,
38
- justifyContent: "center",
39
- },
40
- hoveredItem: {
41
- backgroundColor: colors.gray[3],
42
- },
43
- pressedItem: {
44
- backgroundColor: colors.gray[10],
45
- },
46
- rightBorder: {
47
- borderRightColor: colors.gray[10],
48
- borderRightWidth: 1,
49
- },
50
- bottomBorder: {
51
- borderBottomColor: colors.gray[10],
52
- borderBottomWidth: 1,
53
- },
54
- itemText: {
55
- ...typography.bodyLarge,
56
- },
57
- });
58
- const isReactText = (node) => ["string", "number"].includes(typeof node);
59
- const memo = reactMemo;
60
- export const SegmentedControl = memo(({ items, horizontal = false, label, onValueChange, renderItem, style, value }) => {
61
- const lastIndex = items.length - 1;
62
- return (_jsxs(View, { children: [_jsx(Label, { children: label }), _jsx(Space, { height: 8 }), _jsx(View, { accessibilityRole: "radiogroup", style: [styles.base, horizontal && styles.horizontalBase, style], children: items.map((item, index) => {
63
- const selected = item.value === value;
64
- const rendered = renderItem(item);
65
- return (_jsx(Pressable, { accessibilitySelected: selected, accessibilityRole: "radio", onPress: () => onValueChange(item.value), style: ({ hovered, pressed }) => [
66
- styles.item,
67
- horizontal && styles.horizontalItem,
68
- (hovered || selected) && styles.hoveredItem,
69
- pressed && styles.pressedItem,
70
- index !== lastIndex && (horizontal ? styles.rightBorder : styles.bottomBorder),
71
- ], children: _jsxs(_Fragment, { children: [isReactText(rendered) ? (_jsx(Text, { style: styles.itemText, children: rendered })) : (rendered), !horizontal && selected ? (_jsxs(_Fragment, { children: [_jsx(Fill, { minWidth: 16 }), _jsx(Icon, { name: "checkmark-filled", color: colors.green[100], size: 20 })] })) : null] }) }, `option-${item.value}`));
72
- }) })] }));
73
- }, isEqual);
74
- SegmentedControl.displayName = "SegmentedControl";
@@ -1,34 +0,0 @@
1
- import { ComponentProps, ComponentType, ReactElement, ReactNode } from "react";
2
- import { FlatList, StyleProp, ViewStyle } from "react-native";
3
- /**
4
- * `fixed` set the column width in px
5
- * `percentage` set the column with in remaining percentage (by using flex-basis)
6
- */
7
- type ColumnWidth = {
8
- type: "fixed";
9
- value: number;
10
- } | {
11
- type: "remainingPercent";
12
- value: number;
13
- };
14
- export type TableColumn<T> = {
15
- key: string;
16
- width: ColumnWidth;
17
- label: string;
18
- render: (item: T) => ReactNode;
19
- };
20
- type Props<T> = {
21
- keyExtractor?: (item: T, index: number) => string;
22
- columns: TableColumn<T>[];
23
- data: T[];
24
- hideColumns?: boolean;
25
- ListEmptyComponent?: ComponentType<unknown> | ReactElement | null;
26
- ListFooterComponent?: ComponentType<unknown> | ReactElement | null;
27
- ListHeaderComponent?: ComponentType<unknown> | ReactElement | null;
28
- onPressLine?: (item: T) => void;
29
- isDisabledLine?: (item: T) => boolean;
30
- onEndReached?: ComponentProps<typeof FlatList>["onEndReached"];
31
- contentContainerStyle?: StyleProp<ViewStyle>;
32
- };
33
- export declare function Table<T>({ keyExtractor, columns, data, ListEmptyComponent, ListFooterComponent, ListHeaderComponent, onPressLine, isDisabledLine, onEndReached, contentContainerStyle, hideColumns, }: Props<T>): JSX.Element;
34
- export {};
@@ -1,79 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { Fragment, useEffect, } from "react";
3
- import { FlatList, Pressable, StyleSheet, Text, View } from "react-native";
4
- import { match } from "ts-pattern";
5
- import { colors } from "../constants/colors";
6
- import { commonStyles } from "../constants/commonStyles";
7
- import { typography } from "../constants/typography";
8
- import { Box } from "./Box";
9
- import { Separator } from "./Separator";
10
- import { Space } from "./Space";
11
- const styles = StyleSheet.create({
12
- content: {
13
- flexGrow: 1,
14
- },
15
- header: {
16
- height: 44,
17
- paddingHorizontal: 16,
18
- },
19
- head: {
20
- ...typography.bodySmall,
21
- fontWeight: typography.fontWeights.demi,
22
- color: colors.gray[100],
23
- },
24
- row: {
25
- flexDirection: "row",
26
- alignItems: "center",
27
- height: 56,
28
- paddingHorizontal: 16,
29
- transitionDuration: "300ms",
30
- transitionProperty: "background-color",
31
- },
32
- rowHover: {
33
- backgroundColor: colors.gray[3],
34
- },
35
- rowPressed: {
36
- opacity: 0.75,
37
- },
38
- text: {
39
- ...typography.bodySmall,
40
- color: colors.gray[80],
41
- },
42
- });
43
- const getColumnStyle = (width) => {
44
- return match(width.type)
45
- .with("remainingPercent", () => ({
46
- flexBasis: `${width.value}%`,
47
- flexShrink: 1,
48
- }))
49
- .with("fixed", () => ({
50
- width: width.value,
51
- flexShrink: 0,
52
- }))
53
- .exhaustive();
54
- };
55
- const isText = (node) => ["string", "number"].includes(typeof node);
56
- export function Table({ keyExtractor, columns, data, ListEmptyComponent, ListFooterComponent, ListHeaderComponent, onPressLine, isDisabledLine, onEndReached, contentContainerStyle, hideColumns = false, }) {
57
- // Add width checker which run only during development
58
- if (process.env.NODE_ENV === "development") {
59
- // We use useEffect to avoid spaming development console with warning message
60
- // eslint-disable-next-line react-hooks/rules-of-hooks
61
- useEffect(() => {
62
- const columnsInPercent = columns.filter(({ width }) => width.type === "remainingPercent");
63
- const percentWidth = columnsInPercent.reduce((acc, { width }) => acc + width.value, 0);
64
- if (process.env.NODE_ENV === "development" && percentWidth !== 100) {
65
- console.warn(`Invalid Table width: total remaining width is ${percentWidth}, please check columns config where 'width.type' is 'remainingPercent'`);
66
- }
67
- }, [columns]);
68
- }
69
- return (_jsxs(View, { style: commonStyles.fill, children: [!hideColumns && (_jsx(Box, { direction: "row", alignItems: "center", style: styles.header, children: columns.map(({ key, width, label }, index) => (_jsxs(Fragment, { children: [index > 0 && _jsx(Space, { width: 4 }), _jsx(Text, { numberOfLines: 1, style: [styles.head, getColumnStyle(width)], children: label })] }, key))) })), _jsx(FlatList, { keyExtractor: keyExtractor, contentContainerStyle: StyleSheet.flatten([styles.content, contentContainerStyle]), accessibilityRole: "list", data: data, ListHeaderComponent: ListHeaderComponent, ListFooterComponent: ListFooterComponent, onEndReached: onEndReached, onEndReachedThreshold: 0.5, ItemSeparatorComponent: Separator, renderItem: ({ item }) => {
70
- return (_jsx(Pressable, { style: ({ hovered, pressed }) => [
71
- styles.row,
72
- hovered && styles.rowHover,
73
- pressed && styles.rowPressed,
74
- ], disabled: !onPressLine || isDisabledLine?.(item) === true, onPress: () => onPressLine?.(item), children: columns.map(({ key, width, render }, index) => {
75
- const content = render(item);
76
- return (_jsxs(Fragment, { children: [index > 0 && _jsx(Space, { width: 4 }), _jsx(View, { style: getColumnStyle(width), children: isText(content) ? (_jsx(Text, { numberOfLines: 1, style: styles.text, children: content })) : (content) })] }, key));
77
- }) }));
78
- }, ListEmptyComponent: ListEmptyComponent })] }));
79
- }
@@ -1,2 +0,0 @@
1
- import { MutableRefObject } from "react";
2
- export declare const useLazyRef: <T>(getInitialValue: () => T) => MutableRefObject<T>;
@@ -1,9 +0,0 @@
1
- import { useRef } from "react";
2
- const UNSET = Symbol("unset");
3
- export const useLazyRef = (getInitialValue) => {
4
- const ref = useRef(UNSET);
5
- if (ref.current === UNSET) {
6
- ref.current = getInitialValue();
7
- }
8
- return ref;
9
- };