@swan-io/lake 1.0.0
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/HISTORY.md +3 -0
- package/LICENSE +21 -0
- package/README.md +49 -0
- package/package.json +60 -0
- package/src/components/Alert.d.ts +10 -0
- package/src/components/Alert.js +36 -0
- package/src/components/AppOpeningAnimation.d.ts +10 -0
- package/src/components/AppOpeningAnimation.js +50 -0
- package/src/components/AutoWidthImage.d.ts +8 -0
- package/src/components/AutoWidthImage.js +26 -0
- package/src/components/Avatar.d.ts +7 -0
- package/src/components/Avatar.js +42 -0
- package/src/components/BorderedButton.d.ts +16 -0
- package/src/components/BorderedButton.js +98 -0
- package/src/components/BorderedIcon.d.ts +12 -0
- package/src/components/BorderedIcon.js +25 -0
- package/src/components/BottomPanel.d.ts +9 -0
- package/src/components/BottomPanel.js +94 -0
- package/src/components/Box.d.ts +65 -0
- package/src/components/Box.js +31 -0
- package/src/components/Breadcrumbs.d.ts +18 -0
- package/src/components/Breadcrumbs.js +362 -0
- package/src/components/Button.d.ts +15 -0
- package/src/components/Button.js +83 -0
- package/src/components/Caption.d.ts +6 -0
- package/src/components/Caption.js +11 -0
- package/src/components/Checkbox.d.ts +12 -0
- package/src/components/Checkbox.js +83 -0
- package/src/components/ChoicePicker.d.ts +11 -0
- package/src/components/ChoicePicker.js +99 -0
- package/src/components/Combobox.d.ts +29 -0
- package/src/components/Combobox.js +182 -0
- package/src/components/FailureIcon.d.ts +8 -0
- package/src/components/FailureIcon.js +4 -0
- package/src/components/FileTile.d.ts +11 -0
- package/src/components/FileTile.js +37 -0
- package/src/components/Fill.d.ts +8 -0
- package/src/components/Fill.js +24 -0
- package/src/components/FilterChooser.d.ts +15 -0
- package/src/components/FilterChooser.js +52 -0
- package/src/components/Filters.d.ts +57 -0
- package/src/components/Filters.js +229 -0
- package/src/components/FixedListView.d.ts +104 -0
- package/src/components/FixedListView.js +821 -0
- package/src/components/FixedListViewCells.d.ts +55 -0
- package/src/components/FixedListViewCells.js +157 -0
- package/src/components/Flag.d.ts +8 -0
- package/src/components/Flag.js +36 -0
- package/src/components/FlowPresentation.d.ts +12 -0
- package/src/components/FlowPresentation.js +70 -0
- package/src/components/FocusTrap.d.ts +16 -0
- package/src/components/FocusTrap.js +90 -0
- package/src/components/Form.d.ts +8 -0
- package/src/components/Form.js +17 -0
- package/src/components/FullViewportLayer.d.ts +7 -0
- package/src/components/FullViewportLayer.js +91 -0
- package/src/components/Grid.d.ts +13 -0
- package/src/components/Grid.js +33 -0
- package/src/components/Heading.d.ts +61 -0
- package/src/components/Heading.js +27 -0
- package/src/components/Icon.d.ts +191 -0
- package/src/components/Icon.js +11 -0
- package/src/components/Input.d.ts +34 -0
- package/src/components/Input.js +115 -0
- package/src/components/InputError.d.ts +8 -0
- package/src/components/InputError.js +16 -0
- package/src/components/Label.d.ts +10 -0
- package/src/components/Label.js +19 -0
- package/src/components/LakeAlert.d.ts +14 -0
- package/src/components/LakeAlert.js +75 -0
- package/src/components/LakeButton.d.ts +36 -0
- package/src/components/LakeButton.js +171 -0
- package/src/components/LakeCheckbox.d.ts +16 -0
- package/src/components/LakeCheckbox.js +54 -0
- package/src/components/LakeCombobox.d.ts +28 -0
- package/src/components/LakeCombobox.js +166 -0
- package/src/components/LakeCopyButton.d.ts +10 -0
- package/src/components/LakeCopyButton.js +16 -0
- package/src/components/LakeDownloadButton.d.ts +8 -0
- package/src/components/LakeDownloadButton.js +6 -0
- package/src/components/LakeHeading.d.ts +10 -0
- package/src/components/LakeHeading.js +19 -0
- package/src/components/LakeLabel.d.ts +19 -0
- package/src/components/LakeLabel.js +43 -0
- package/src/components/LakeModal.d.ts +14 -0
- package/src/components/LakeModal.js +132 -0
- package/src/components/LakeRadio.d.ts +9 -0
- package/src/components/LakeRadio.js +44 -0
- package/src/components/LakeScrollView.d.ts +10 -0
- package/src/components/LakeScrollView.js +35 -0
- package/src/components/LakeSearchField.d.ts +10 -0
- package/src/components/LakeSearchField.js +111 -0
- package/src/components/LakeSelect.d.ts +30 -0
- package/src/components/LakeSelect.js +183 -0
- package/src/components/LakeSlider.d.ts +12 -0
- package/src/components/LakeSlider.js +31 -0
- package/src/components/LakeStepper.d.ts +21 -0
- package/src/components/LakeStepper.js +134 -0
- package/src/components/LakeText.d.ts +19 -0
- package/src/components/LakeText.js +20 -0
- package/src/components/LakeTextInput.d.ts +36 -0
- package/src/components/LakeTextInput.js +154 -0
- package/src/components/LakeTooltip.d.ts +24 -0
- package/src/components/LakeTooltip.js +188 -0
- package/src/components/Link.d.ts +138 -0
- package/src/components/Link.js +23 -0
- package/src/components/ListRightPanel.d.ts +17 -0
- package/src/components/ListRightPanel.js +79 -0
- package/src/components/LoadingView.d.ts +9 -0
- package/src/components/LoadingView.js +24 -0
- package/src/components/Modal.d.ts +12 -0
- package/src/components/Modal.js +80 -0
- package/src/components/MultiSelect.d.ts +27 -0
- package/src/components/MultiSelect.js +223 -0
- package/src/components/MultilineInput.d.ts +15 -0
- package/src/components/MultilineInput.js +55 -0
- package/src/components/Picker.d.ts +26 -0
- package/src/components/Picker.js +116 -0
- package/src/components/PlainListView.d.ts +36 -0
- package/src/components/PlainListView.js +208 -0
- package/src/components/Popover.d.ts +23 -0
- package/src/components/Popover.js +147 -0
- package/src/components/PopoverContent.d.ts +8 -0
- package/src/components/PopoverContent.js +9 -0
- package/src/components/Portal.d.ts +7 -0
- package/src/components/Portal.js +9 -0
- package/src/components/Pressable.d.ts +348 -0
- package/src/components/Pressable.js +91 -0
- package/src/components/ProgressBar.d.ts +11 -0
- package/src/components/ProgressBar.js +46 -0
- package/src/components/ProjectEnvTag.d.ts +7 -0
- package/src/components/ProjectEnvTag.js +12 -0
- package/src/components/QuickActions.d.ts +15 -0
- package/src/components/QuickActions.js +38 -0
- package/src/components/RadioGroup.d.ts +16 -0
- package/src/components/RadioGroup.js +34 -0
- package/src/components/ReadOnlyFieldList.d.ts +6 -0
- package/src/components/ReadOnlyFieldList.js +8 -0
- package/src/components/ResponsiveContainer.d.ts +13 -0
- package/src/components/ResponsiveContainer.js +23 -0
- package/src/components/RightPanel.d.ts +10 -0
- package/src/components/RightPanel.js +102 -0
- package/src/components/SegmentedControl.d.ts +19 -0
- package/src/components/SegmentedControl.js +74 -0
- package/src/components/Separator.d.ts +10 -0
- package/src/components/Separator.js +19 -0
- package/src/components/SidebarNavigationTracker.d.ts +13 -0
- package/src/components/SidebarNavigationTracker.js +93 -0
- package/src/components/Slider.d.ts +11 -0
- package/src/components/Slider.js +119 -0
- package/src/components/SmsOpeningAnimation.d.ts +8 -0
- package/src/components/SmsOpeningAnimation.js +52 -0
- package/src/components/Space.d.ts +10 -0
- package/src/components/Space.js +23 -0
- package/src/components/Stack.d.ts +12 -0
- package/src/components/Stack.js +23 -0
- package/src/components/StepDots.d.ts +7 -0
- package/src/components/StepDots.js +24 -0
- package/src/components/Stepper.d.ts +9 -0
- package/src/components/Stepper.js +67 -0
- package/src/components/SuccessIcon.d.ts +8 -0
- package/src/components/SuccessIcon.js +4 -0
- package/src/components/Svg.d.ts +145 -0
- package/src/components/Svg.js +24 -0
- package/src/components/SwanLogo.d.ts +8 -0
- package/src/components/SwanLogo.js +11 -0
- package/src/components/Switch.d.ts +9 -0
- package/src/components/Switch.js +74 -0
- package/src/components/TabView.d.ts +16 -0
- package/src/components/TabView.js +398 -0
- package/src/components/Table.d.ts +34 -0
- package/src/components/Table.js +79 -0
- package/src/components/Tag.d.ts +17 -0
- package/src/components/Tag.js +76 -0
- package/src/components/Tile.d.ts +34 -0
- package/src/components/Tile.js +130 -0
- package/src/components/TilePlaceholder.d.ts +6 -0
- package/src/components/TilePlaceholder.js +51 -0
- package/src/components/ToastStack.d.ts +2 -0
- package/src/components/ToastStack.js +96 -0
- package/src/components/Tooltip.d.ts +18 -0
- package/src/components/Tooltip.js +162 -0
- package/src/components/TransitionGroupView.d.ts +12 -0
- package/src/components/TransitionGroupView.js +43 -0
- package/src/components/TransitionView.d.ts +12 -0
- package/src/components/TransitionView.js +43 -0
- package/src/components/WithCurrentColor.d.ts +12 -0
- package/src/components/WithCurrentColor.js +65 -0
- package/src/components/WithPartnerAccentColor.d.ts +7 -0
- package/src/components/WithPartnerAccentColor.js +91 -0
- package/src/constants/colors.d.ts +42 -0
- package/src/constants/colors.js +42 -0
- package/src/constants/commonStyles.d.ts +66 -0
- package/src/constants/commonStyles.js +45 -0
- package/src/constants/design.d.ts +168 -0
- package/src/constants/design.js +564 -0
- package/src/constants/insets.d.ts +10 -0
- package/src/constants/insets.js +22 -0
- package/src/constants/typography.d.ts +26 -0
- package/src/constants/typography.js +54 -0
- package/src/hooks/useAnimatedValue.d.ts +2 -0
- package/src/hooks/useAnimatedValue.js +3 -0
- package/src/hooks/useBodyClassName.d.ts +3 -0
- package/src/hooks/useBodyClassName.js +14 -0
- package/src/hooks/useBoolean.d.ts +8 -0
- package/src/hooks/useBoolean.js +12 -0
- package/src/hooks/useComputedColors.d.ts +10 -0
- package/src/hooks/useComputedColors.js +42 -0
- package/src/hooks/useDebounce.d.ts +1 -0
- package/src/hooks/useDebounce.js +12 -0
- package/src/hooks/useDisclosure.d.ts +8 -0
- package/src/hooks/useDisclosure.js +12 -0
- package/src/hooks/useFirstMountState.d.ts +1 -0
- package/src/hooks/useFirstMountState.js +9 -0
- package/src/hooks/useForceableState.d.ts +1 -0
- package/src/hooks/useForceableState.js +6 -0
- package/src/hooks/useHover.d.ts +11 -0
- package/src/hooks/useHover.js +4 -0
- package/src/hooks/useInterval.d.ts +1 -0
- package/src/hooks/useInterval.js +11 -0
- package/src/hooks/useLazyRef.d.ts +2 -0
- package/src/hooks/useLazyRef.js +9 -0
- package/src/hooks/useMergeRefs.d.ts +2 -0
- package/src/hooks/useMergeRefs.js +5 -0
- package/src/hooks/useNativeProp.d.ts +2 -0
- package/src/hooks/useNativeProp.js +9 -0
- package/src/hooks/useOutsideClick.d.ts +8 -0
- package/src/hooks/useOutsideClick.js +54 -0
- package/src/hooks/usePersistedState.d.ts +1 -0
- package/src/hooks/usePersistedState.js +21 -0
- package/src/hooks/usePressEvents.d.ts +31 -0
- package/src/hooks/usePressEvents.js +4 -0
- package/src/hooks/usePreviousValue.d.ts +1 -0
- package/src/hooks/usePreviousValue.js +8 -0
- package/src/hooks/useResponsive.d.ts +7 -0
- package/src/hooks/useResponsive.js +20 -0
- package/src/hooks/useUpdateEffect.d.ts +2 -0
- package/src/hooks/useUpdateEffect.js +10 -0
- package/src/hooks/useUrqlMutation.d.ts +4 -0
- package/src/hooks/useUrqlMutation.js +30 -0
- package/src/hooks/useUrqlQuery.d.ts +19 -0
- package/src/hooks/useUrqlQuery.js +73 -0
- package/src/state/toasts.d.ts +21 -0
- package/src/state/toasts.js +61 -0
- package/src/utils/__tests__/array.test.d.ts +1 -0
- package/src/utils/__tests__/array.test.js +127 -0
- package/src/utils/__tests__/base64.test.d.ts +1 -0
- package/src/utils/__tests__/base64.test.js +27 -0
- package/src/utils/__tests__/function.test.d.ts +1 -0
- package/src/utils/__tests__/function.test.js +36 -0
- package/src/utils/__tests__/object.test.d.ts +1 -0
- package/src/utils/__tests__/object.test.js +17 -0
- package/src/utils/__tests__/rifm.test.d.ts +1 -0
- package/src/utils/__tests__/rifm.test.js +124 -0
- package/src/utils/__tests__/string.test.d.ts +1 -0
- package/src/utils/__tests__/string.test.js +16 -0
- package/src/utils/a11y.d.ts +1 -0
- package/src/utils/a11y.js +18 -0
- package/src/utils/array.d.ts +6 -0
- package/src/utils/array.js +71 -0
- package/src/utils/base64.d.ts +2 -0
- package/src/utils/base64.js +20 -0
- package/src/utils/file.d.ts +2 -0
- package/src/utils/file.js +10 -0
- package/src/utils/flagCountry.d.ts +1 -0
- package/src/utils/flagCountry.js +1 -0
- package/src/utils/function.d.ts +4 -0
- package/src/utils/function.js +19 -0
- package/src/utils/math.d.ts +16 -0
- package/src/utils/math.js +47 -0
- package/src/utils/nullish.d.ts +10 -0
- package/src/utils/nullish.js +8 -0
- package/src/utils/object.d.ts +2 -0
- package/src/utils/object.js +7 -0
- package/src/utils/popper.d.ts +3 -0
- package/src/utils/popper.js +30 -0
- package/src/utils/rifm.d.ts +14 -0
- package/src/utils/rifm.js +53 -0
- package/src/utils/string.d.ts +4 -0
- package/src/utils/string.js +233 -0
- package/src/utils/timer.d.ts +11 -0
- package/src/utils/timer.js +46 -0
- package/src/utils/types.d.ts +8 -0
- package/src/utils/types.js +1 -0
- package/src/utils/userAgent.d.ts +4 -0
- package/src/utils/userAgent.js +9 -0
- package/src/utils/viewport.d.ts +1 -0
- package/src/utils/viewport.js +12 -0
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Children, forwardRef, Fragment, memo } from "react";
|
|
3
|
+
import { ActivityIndicator, StyleSheet, View, } from "react-native";
|
|
4
|
+
import { match } from "ts-pattern";
|
|
5
|
+
import { backgroundColor, colors, invariantColors, radii, spacings, texts, } from "../constants/design";
|
|
6
|
+
import { isNotNullish, isNullish } from "../utils/nullish";
|
|
7
|
+
import { Icon } from "./Icon";
|
|
8
|
+
import { LakeText } from "./LakeText";
|
|
9
|
+
import { Pressable } from "./Pressable";
|
|
10
|
+
import { Space } from "./Space";
|
|
11
|
+
const styles = StyleSheet.create({
|
|
12
|
+
base: {
|
|
13
|
+
alignItems: "center",
|
|
14
|
+
backgroundColor: colors.gray[900],
|
|
15
|
+
borderRadius: radii[6],
|
|
16
|
+
flexDirection: "row",
|
|
17
|
+
flexShrink: 0,
|
|
18
|
+
height: 48,
|
|
19
|
+
minWidth: 90,
|
|
20
|
+
justifyContent: "center",
|
|
21
|
+
paddingHorizontal: 20,
|
|
22
|
+
transitionDuration: "150ms",
|
|
23
|
+
transitionProperty: ["background-color", "color"],
|
|
24
|
+
},
|
|
25
|
+
grow: {
|
|
26
|
+
flexGrow: 1,
|
|
27
|
+
},
|
|
28
|
+
iconOnly: {
|
|
29
|
+
minWidth: 48,
|
|
30
|
+
width: 48,
|
|
31
|
+
paddingRight: 0,
|
|
32
|
+
paddingLeft: 0,
|
|
33
|
+
},
|
|
34
|
+
iconSmallOnly: {
|
|
35
|
+
minWidth: 40,
|
|
36
|
+
width: 40,
|
|
37
|
+
paddingRight: 0,
|
|
38
|
+
paddingLeft: 0,
|
|
39
|
+
},
|
|
40
|
+
hiddenView: {
|
|
41
|
+
position: "absolute",
|
|
42
|
+
width: "100%",
|
|
43
|
+
height: "100%",
|
|
44
|
+
transitionDuration: "150ms",
|
|
45
|
+
transitionProperty: "opacity",
|
|
46
|
+
opacity: 0,
|
|
47
|
+
},
|
|
48
|
+
pressed: {
|
|
49
|
+
opacity: 0.15,
|
|
50
|
+
backgroundColor: colors.gray[900],
|
|
51
|
+
},
|
|
52
|
+
small: {
|
|
53
|
+
height: 40,
|
|
54
|
+
paddingLeft: 16,
|
|
55
|
+
paddingRight: 16,
|
|
56
|
+
},
|
|
57
|
+
withIconStart: {
|
|
58
|
+
paddingRight: 24,
|
|
59
|
+
paddingLeft: 26,
|
|
60
|
+
},
|
|
61
|
+
withIconStartSmall: {
|
|
62
|
+
paddingRight: 19.5,
|
|
63
|
+
paddingLeft: 21.5,
|
|
64
|
+
},
|
|
65
|
+
withIconEnd: {
|
|
66
|
+
paddingRight: 20,
|
|
67
|
+
paddingLeft: 24,
|
|
68
|
+
},
|
|
69
|
+
withIconEndSmall: {
|
|
70
|
+
paddingRight: 20.5,
|
|
71
|
+
paddingLeft: 21.5,
|
|
72
|
+
},
|
|
73
|
+
text: texts.semibold,
|
|
74
|
+
textSmall: texts.smallSemibold,
|
|
75
|
+
disabled: {
|
|
76
|
+
cursor: "not-allowed",
|
|
77
|
+
opacity: 0.3,
|
|
78
|
+
},
|
|
79
|
+
loaderContainer: {
|
|
80
|
+
...StyleSheet.absoluteFillObject,
|
|
81
|
+
alignItems: "center",
|
|
82
|
+
justifyContent: "center",
|
|
83
|
+
transform: [{ translateZ: 0 }],
|
|
84
|
+
borderRadius: radii[6],
|
|
85
|
+
},
|
|
86
|
+
group: {
|
|
87
|
+
flexDirection: "row",
|
|
88
|
+
alignItems: "stretch",
|
|
89
|
+
paddingVertical: spacings[16],
|
|
90
|
+
},
|
|
91
|
+
pill: {
|
|
92
|
+
width: 10,
|
|
93
|
+
height: 10,
|
|
94
|
+
borderRadius: 5,
|
|
95
|
+
borderWidth: 2,
|
|
96
|
+
borderColor: backgroundColor.default,
|
|
97
|
+
backgroundColor: colors.negative[500],
|
|
98
|
+
position: "absolute",
|
|
99
|
+
top: -3,
|
|
100
|
+
right: -3,
|
|
101
|
+
},
|
|
102
|
+
});
|
|
103
|
+
const isReactText = (node) => ["string", "number"].includes(typeof node);
|
|
104
|
+
export const LakeButton = memo(forwardRef(({ accessibilityControls, accessibilityExpanded, accessibilityLabel, children, color = "gray", disabled = false, icon, grow = false, iconPosition = "start", loading = false, mode = "primary", onPress, size = "large", style, forceBackground = false, href, hrefAttrs, pill, }, forwardedRef) => {
|
|
105
|
+
const isSmall = size === "small";
|
|
106
|
+
const iconSize = isSmall ? 18 : 20;
|
|
107
|
+
const hasIconStart = isNotNullish(icon) && iconPosition === "start";
|
|
108
|
+
const hasIconEnd = isNotNullish(icon) && iconPosition === "end";
|
|
109
|
+
const hasOnlyIcon = isNullish(children) && isNotNullish(icon);
|
|
110
|
+
return (_jsx(Pressable, { href: href, hrefAttrs: hrefAttrs, accessibilityRole: href != null ? "link" : "button", accessibilityBusy: loading, accessibilityDisabled: disabled, accessibilityControls: accessibilityControls, accessibilityExpanded: accessibilityExpanded, accessibilityLabel: accessibilityLabel, disabled: loading || disabled, ref: forwardedRef, onPress: onPress, style: ({ hovered, pressed, focused }) => [
|
|
111
|
+
styles.base,
|
|
112
|
+
isSmall && styles.small,
|
|
113
|
+
hasIconStart && isSmall ? styles.withIconStartSmall : styles.withIconStart,
|
|
114
|
+
hasIconEnd && (isSmall ? styles.withIconEndSmall : styles.withIconEnd),
|
|
115
|
+
hasOnlyIcon && (isSmall ? styles.iconSmallOnly : styles.iconOnly),
|
|
116
|
+
disabled && styles.disabled,
|
|
117
|
+
grow && styles.grow,
|
|
118
|
+
typeof style == "function" ? style({ hovered, pressed, focused }) : style,
|
|
119
|
+
match(mode)
|
|
120
|
+
.with("primary", () => ({
|
|
121
|
+
backgroundColor: color === "warning"
|
|
122
|
+
? hovered
|
|
123
|
+
? colors[color][600]
|
|
124
|
+
: colors[color][500]
|
|
125
|
+
: hovered
|
|
126
|
+
? colors[color].secondary
|
|
127
|
+
: colors[color].primary,
|
|
128
|
+
}))
|
|
129
|
+
.with("secondary", () => ({
|
|
130
|
+
backgroundColor: pressed
|
|
131
|
+
? colors[color][100]
|
|
132
|
+
: hovered
|
|
133
|
+
? colors[color][50]
|
|
134
|
+
: forceBackground
|
|
135
|
+
? backgroundColor.accented
|
|
136
|
+
: invariantColors.transparent,
|
|
137
|
+
borderWidth: 1,
|
|
138
|
+
borderColor: hovered ? colors[color][600] : colors[color][300],
|
|
139
|
+
}))
|
|
140
|
+
.with("tertiary", () => ({
|
|
141
|
+
backgroundColor: pressed
|
|
142
|
+
? colors[color][200]
|
|
143
|
+
: hovered
|
|
144
|
+
? colors[color][100]
|
|
145
|
+
: invariantColors.transparent,
|
|
146
|
+
}))
|
|
147
|
+
.exhaustive(),
|
|
148
|
+
], children: ({ pressed, hovered }) => {
|
|
149
|
+
const textColor = mode === "secondary" || mode === "tertiary"
|
|
150
|
+
? hovered || pressed
|
|
151
|
+
? colors[color][700]
|
|
152
|
+
: colors[color][600]
|
|
153
|
+
: colors[color].contrast;
|
|
154
|
+
return (_jsxs(_Fragment, { children: [hasIconStart && (_jsxs(_Fragment, { children: [_jsx(Icon, { color: textColor, name: icon, size: iconSize }), isNotNullish(children) && _jsx(Space, { width: isSmall ? 8 : 12 })] })), isReactText(children) ? (_jsx(LakeText, { numberOfLines: 1, selectable: false, style: [isSmall ? styles.textSmall : styles.text, { color: textColor }], children: children })) : (children), hasIconEnd && (_jsxs(_Fragment, { children: [isNotNullish(children) && _jsx(Space, { width: isSmall ? 8 : 12 }), _jsx(Icon, { color: textColor, name: icon, size: iconSize })] })), loading && (_jsx(View, { accessibilityRole: "none", style: [
|
|
155
|
+
styles.loaderContainer,
|
|
156
|
+
{
|
|
157
|
+
backgroundColor: mode === "secondary" || mode === "tertiary"
|
|
158
|
+
? backgroundColor.accented
|
|
159
|
+
: colors[color].primary,
|
|
160
|
+
},
|
|
161
|
+
], children: _jsx(ActivityIndicator, { color: mode === "secondary" || mode === "tertiary"
|
|
162
|
+
? colors[color].primary
|
|
163
|
+
: colors[color].contrast, size: iconSize }) })), _jsx(View, { style: [styles.hiddenView, pressed && mode === "primary" && styles.pressed] }), pill === true ? _jsx(View, { style: styles.pill }) : null] }));
|
|
164
|
+
} }));
|
|
165
|
+
}));
|
|
166
|
+
LakeButton.displayName = "Button";
|
|
167
|
+
const ZERO = 0;
|
|
168
|
+
export const LakeButtonGroup = ({ children, justifyContent = "flex-start", paddingBottom = 16, }) => (_jsx(View, { style: [
|
|
169
|
+
styles.group,
|
|
170
|
+
{ justifyContent, paddingBottom: paddingBottom === 0 ? ZERO : spacings[paddingBottom] },
|
|
171
|
+
], children: Children.toArray(children).map((item, index) => (_jsxs(Fragment, { children: [index > 0 ? _jsx(Space, { width: 16 }) : null, item] }, index))) }));
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { ColorVariants } from "../constants/design";
|
|
3
|
+
export type CheckboxProps = {
|
|
4
|
+
value: boolean | "mixed";
|
|
5
|
+
color?: ColorVariants;
|
|
6
|
+
disabled?: boolean;
|
|
7
|
+
isError?: boolean;
|
|
8
|
+
};
|
|
9
|
+
export declare const LakeCheckbox: ({ value, color, disabled, isError, }: CheckboxProps) => JSX.Element;
|
|
10
|
+
export type LabelledCheckboxProps = CheckboxProps & {
|
|
11
|
+
onValueChange: (value: boolean) => void;
|
|
12
|
+
label: string;
|
|
13
|
+
disabled?: boolean;
|
|
14
|
+
isError?: boolean;
|
|
15
|
+
};
|
|
16
|
+
export declare const LakeLabelledCheckbox: ({ value, color, label, onValueChange, disabled, isError, }: LabelledCheckboxProps) => JSX.Element;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useRef, useState } from "react";
|
|
3
|
+
import { StyleSheet, View } from "react-native";
|
|
4
|
+
import { colors } from "../constants/design";
|
|
5
|
+
import { LakeText } from "./LakeText";
|
|
6
|
+
import { Pressable } from "./Pressable";
|
|
7
|
+
import { Space } from "./Space";
|
|
8
|
+
import { Animate, Path, Svg } from "./Svg";
|
|
9
|
+
const SIZE = 16;
|
|
10
|
+
const RADIUS = 4;
|
|
11
|
+
const styles = StyleSheet.create({
|
|
12
|
+
container: {
|
|
13
|
+
width: SIZE,
|
|
14
|
+
height: SIZE,
|
|
15
|
+
borderRadius: RADIUS,
|
|
16
|
+
borderWidth: 1,
|
|
17
|
+
borderColor: colors.gray[500],
|
|
18
|
+
alignItems: "center",
|
|
19
|
+
justifyContent: "center",
|
|
20
|
+
},
|
|
21
|
+
mixed: {
|
|
22
|
+
width: SIZE - 8,
|
|
23
|
+
height: 2,
|
|
24
|
+
},
|
|
25
|
+
labelled: {
|
|
26
|
+
flexDirection: "row",
|
|
27
|
+
alignItems: "center",
|
|
28
|
+
},
|
|
29
|
+
disabled: {
|
|
30
|
+
opacity: 0.5,
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
export const LakeCheckbox = ({ value, color = "current", disabled = false, isError = false, }) => {
|
|
34
|
+
const isFirstRender = useRef(true);
|
|
35
|
+
const [shouldAnimate, setShouldAnimate] = useState(false);
|
|
36
|
+
useEffect(() => {
|
|
37
|
+
if (!isFirstRender.current) {
|
|
38
|
+
setShouldAnimate(true);
|
|
39
|
+
}
|
|
40
|
+
isFirstRender.current = false;
|
|
41
|
+
}, [value]);
|
|
42
|
+
return (_jsxs(View, { accessibilityRole: "none", style: [
|
|
43
|
+
styles.container,
|
|
44
|
+
disabled && styles.disabled,
|
|
45
|
+
value !== false && {
|
|
46
|
+
backgroundColor: colors[color].primary,
|
|
47
|
+
borderColor: colors[color].primary,
|
|
48
|
+
},
|
|
49
|
+
isError && { borderColor: colors.negative[500] },
|
|
50
|
+
], children: [value === true && (_jsx(Svg, { viewBox: "0 0 16 16", children: _jsx(Path, { d: "m3.5 7.5 2.8 3.4 5.6-6.7", stroke: colors[color].contrast, strokeWidth: 1.5, fill: "none", strokeLinecap: "round", strokeLinejoin: "round", strokeDasharray: "20", strokeDashoffset: shouldAnimate ? "20" : "0", children: shouldAnimate && (_jsx(Animate, { attributeName: "stroke-dashoffset", values: "20;0", dur: "150ms", begin: "150ms", fill: "freeze" })) }) })), value === "mixed" && (_jsx(View, { style: [styles.mixed, { backgroundColor: colors[color].contrast }] }))] }));
|
|
51
|
+
};
|
|
52
|
+
export const LakeLabelledCheckbox = ({ value, color, label, onValueChange, disabled = false, isError = false, }) => {
|
|
53
|
+
return (_jsxs(Pressable, { accessibilityChecked: value, style: styles.labelled, onPress: () => onValueChange(value === true ? false : true), disabled: disabled, children: [_jsx(LakeCheckbox, { value: value, color: color, disabled: disabled, isError: isError }), _jsx(Space, { width: 8 }), _jsx(LakeText, { color: colors.gray[900], selectable: false, children: label })] }));
|
|
54
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { AsyncData, Result } from "@swan-io/boxed";
|
|
2
|
+
import { ForwardedRef, ReactNode, RefObject } from "react";
|
|
3
|
+
import { IconName } from "./Icon";
|
|
4
|
+
export type LakeComboboxProps<I> = {
|
|
5
|
+
value: string;
|
|
6
|
+
items: AsyncData<Result<I[], unknown>>;
|
|
7
|
+
ListFooterComponent?: ReactNode;
|
|
8
|
+
onValueChange: (value: string) => void;
|
|
9
|
+
onSelectItem: (value: I) => void | Promise<unknown>;
|
|
10
|
+
renderItem: (item: I) => ReactNode | null;
|
|
11
|
+
keyExtractor: (item: I) => string;
|
|
12
|
+
icon?: IconName;
|
|
13
|
+
placeholder?: string;
|
|
14
|
+
disabled?: boolean;
|
|
15
|
+
emptyResultText: string;
|
|
16
|
+
error?: string;
|
|
17
|
+
nativeID?: string;
|
|
18
|
+
readOnly?: boolean;
|
|
19
|
+
};
|
|
20
|
+
export type LakeComboboxRef = {
|
|
21
|
+
close: () => void;
|
|
22
|
+
open: () => void;
|
|
23
|
+
};
|
|
24
|
+
declare const LakeComboboxWithRef: <I>({ value, items, ListFooterComponent, onValueChange, onSelectItem, renderItem, keyExtractor, icon, placeholder, disabled, emptyResultText, readOnly, nativeID, error, }: LakeComboboxProps<I>, externalRef: ForwardedRef<LakeComboboxRef>) => JSX.Element;
|
|
25
|
+
export declare const LakeCombobox: <I>(props: LakeComboboxProps<I> & {
|
|
26
|
+
ref?: RefObject<LakeComboboxRef> | undefined;
|
|
27
|
+
}) => ReturnType<typeof LakeComboboxWithRef>;
|
|
28
|
+
export {};
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef, useCallback, useId, useImperativeHandle, useRef, useState, } from "react";
|
|
3
|
+
import { FlatList, Pressable, StyleSheet, Text, View, } from "react-native";
|
|
4
|
+
import { backgroundColor, colors, spacings } from "../constants/design";
|
|
5
|
+
import { typography } from "../constants/typography";
|
|
6
|
+
import { useDisclosure } from "../hooks/useDisclosure";
|
|
7
|
+
import { getFocusableElements } from "../utils/a11y";
|
|
8
|
+
import { Box } from "./Box";
|
|
9
|
+
import { Icon } from "./Icon";
|
|
10
|
+
import { LakeTextInput } from "./LakeTextInput";
|
|
11
|
+
import { LoadingView } from "./LoadingView";
|
|
12
|
+
import { Popover } from "./Popover";
|
|
13
|
+
import { Space } from "./Space";
|
|
14
|
+
const ELEMENT_HEIGHT = 64;
|
|
15
|
+
const NB_SUGGESTION_DISPLAYED = 3.5;
|
|
16
|
+
const styles = StyleSheet.create({
|
|
17
|
+
list: {
|
|
18
|
+
maxHeight: ELEMENT_HEIGHT * NB_SUGGESTION_DISPLAYED,
|
|
19
|
+
marginVertical: spacings[8],
|
|
20
|
+
},
|
|
21
|
+
flatList: { scrollBehavior: "smooth" },
|
|
22
|
+
item: {
|
|
23
|
+
flexShrink: 1,
|
|
24
|
+
flexGrow: 1,
|
|
25
|
+
height: ELEMENT_HEIGHT,
|
|
26
|
+
justifyContent: "center",
|
|
27
|
+
paddingHorizontal: spacings[24],
|
|
28
|
+
paddingVertical: 0,
|
|
29
|
+
transitionProperty: "background-color",
|
|
30
|
+
transitionDuration: "200ms",
|
|
31
|
+
outlineStyle: "none",
|
|
32
|
+
borderColor: colors.gray[100],
|
|
33
|
+
borderStyle: "solid",
|
|
34
|
+
borderBottomWidth: 1,
|
|
35
|
+
justifyContents: "center",
|
|
36
|
+
},
|
|
37
|
+
hoveredItem: {
|
|
38
|
+
backgroundColor: colors.gray[0],
|
|
39
|
+
},
|
|
40
|
+
focusedItem: {
|
|
41
|
+
backgroundColor: colors.gray[0],
|
|
42
|
+
},
|
|
43
|
+
pressedItem: {
|
|
44
|
+
backgroundColor: colors.gray[100],
|
|
45
|
+
},
|
|
46
|
+
itemText: {
|
|
47
|
+
...typography.bodyLarge,
|
|
48
|
+
},
|
|
49
|
+
loader: {
|
|
50
|
+
padding: spacings[24],
|
|
51
|
+
},
|
|
52
|
+
listContainer: {
|
|
53
|
+
flexGrow: 1,
|
|
54
|
+
flexShrink: 1,
|
|
55
|
+
},
|
|
56
|
+
loaderAdditional: {
|
|
57
|
+
...StyleSheet.absoluteFillObject,
|
|
58
|
+
alignItems: "center",
|
|
59
|
+
justifyContent: "center",
|
|
60
|
+
},
|
|
61
|
+
loaderAdditionalUnderlay: {
|
|
62
|
+
...StyleSheet.absoluteFillObject,
|
|
63
|
+
backgroundColor: backgroundColor.accented,
|
|
64
|
+
opacity: 0.8,
|
|
65
|
+
},
|
|
66
|
+
emptyList: {
|
|
67
|
+
height: 136,
|
|
68
|
+
},
|
|
69
|
+
emptyListText: {
|
|
70
|
+
color: colors.gray.primary,
|
|
71
|
+
},
|
|
72
|
+
input: {
|
|
73
|
+
width: 1,
|
|
74
|
+
flexGrow: 1,
|
|
75
|
+
},
|
|
76
|
+
});
|
|
77
|
+
const isReactText = (node) => ["string", "number"].includes(typeof node);
|
|
78
|
+
const getItemLayout = (_data, index) => ({
|
|
79
|
+
length: ELEMENT_HEIGHT,
|
|
80
|
+
offset: ELEMENT_HEIGHT * index,
|
|
81
|
+
index,
|
|
82
|
+
});
|
|
83
|
+
const LakeComboboxWithRef = ({ value, items, ListFooterComponent, onValueChange, onSelectItem, renderItem, keyExtractor, icon, placeholder, disabled = false, emptyResultText, readOnly, nativeID, error, }, externalRef) => {
|
|
84
|
+
const ref = useRef(null);
|
|
85
|
+
const listRef = useRef(null);
|
|
86
|
+
const listContainerRef = useRef(null);
|
|
87
|
+
const blurTimeoutId = useRef(undefined);
|
|
88
|
+
const [isFocused, { open, close }] = useDisclosure(false);
|
|
89
|
+
const [isFetchingAdditionalInfo, setIsFetchingAdditionalInfo] = useState(false);
|
|
90
|
+
useImperativeHandle(externalRef, () => {
|
|
91
|
+
return {
|
|
92
|
+
open,
|
|
93
|
+
close,
|
|
94
|
+
};
|
|
95
|
+
});
|
|
96
|
+
const suggestionsId = useId();
|
|
97
|
+
const handleKeyPress = useCallback((event) => {
|
|
98
|
+
if (event.nativeEvent.key === "ArrowDown") {
|
|
99
|
+
const listElement = listContainerRef.current;
|
|
100
|
+
if (listElement != null) {
|
|
101
|
+
const element = listElement;
|
|
102
|
+
const focusableElements = getFocusableElements(element, false);
|
|
103
|
+
focusableElements[0]?.focus();
|
|
104
|
+
event.preventDefault();
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}, []);
|
|
108
|
+
const handleListItemKeyPress = useCallback((event) => {
|
|
109
|
+
if (event.nativeEvent.key === "ArrowDown" || event.nativeEvent.key === "ArrowUp") {
|
|
110
|
+
const listElement = listContainerRef.current;
|
|
111
|
+
if (listElement != null) {
|
|
112
|
+
const element = listElement;
|
|
113
|
+
const target = event.currentTarget;
|
|
114
|
+
const focusableElements = getFocusableElements(element, false);
|
|
115
|
+
const index = focusableElements.indexOf(target);
|
|
116
|
+
const direction = event.nativeEvent.key === "ArrowDown" ? 1 : -1;
|
|
117
|
+
if (index === -1) {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
const nextIndex = index + direction;
|
|
121
|
+
event.preventDefault();
|
|
122
|
+
if (nextIndex === 0) {
|
|
123
|
+
ref.current?.focus();
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
focusableElements[nextIndex === focusableElements.length ? 0 : nextIndex]?.focus();
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}, []);
|
|
131
|
+
const handleFocus = useCallback(() => {
|
|
132
|
+
window.clearTimeout(blurTimeoutId.current);
|
|
133
|
+
blurTimeoutId.current = window.setTimeout(() => {
|
|
134
|
+
open();
|
|
135
|
+
}, 100);
|
|
136
|
+
}, [open]);
|
|
137
|
+
const handleBlur = useCallback(() => {
|
|
138
|
+
window.clearTimeout(blurTimeoutId.current);
|
|
139
|
+
blurTimeoutId.current = window.setTimeout(() => {
|
|
140
|
+
close();
|
|
141
|
+
}, 100);
|
|
142
|
+
}, [close]);
|
|
143
|
+
return (_jsxs(View, { children: [_jsx(LakeTextInput, { ref: ref, style: styles.input, accessibilityExpanded: isFocused, accessibilityControls: isFocused ? suggestionsId : "", returnKeyType: "search", icon: icon, accessibilityRole: "combobox", placeholder: placeholder, value: value, disabled: disabled, error: error, onChangeText: onValueChange, onFocus: handleFocus, onBlur: handleBlur, onKeyPress: handleKeyPress, nativeID: nativeID, readOnly: readOnly }), _jsx(Popover, { id: suggestionsId, role: "listbox", matchReferenceWidth: true, onDismiss: close, referenceRef: ref, autoFocus: true, returnFocus: false, visible: isFocused && !items.isNotAsked(), underlay: false, forcedMode: "Dropdown", children: _jsx(View, { style: styles.list, children: items.match({
|
|
144
|
+
NotAsked: () => null,
|
|
145
|
+
Loading: () => _jsx(LoadingView, { style: styles.loader }),
|
|
146
|
+
Done: items => items.match({
|
|
147
|
+
Error: _ => (_jsx(Icon, { name: "error-circle-regular", size: 22, color: colors.negative[500] })),
|
|
148
|
+
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, { ref: listRef, keyExtractor: keyExtractor, getItemLayout: getItemLayout, accessibilityRole: "list", data: items, style: styles.flatList, renderItem: ({ item }) => {
|
|
149
|
+
const rendered = renderItem(item);
|
|
150
|
+
return (_jsx(Pressable, { onFocus: handleFocus, onBlur: handleBlur, accessibilityRole: "listitem", onKeyDown: handleListItemKeyPress, style: ({ hovered, pressed, focused }) => [
|
|
151
|
+
styles.item,
|
|
152
|
+
hovered && styles.hoveredItem,
|
|
153
|
+
focused && styles.focusedItem,
|
|
154
|
+
pressed && styles.pressedItem,
|
|
155
|
+
], onPress: () => {
|
|
156
|
+
setIsFetchingAdditionalInfo(true);
|
|
157
|
+
Promise.resolve(onSelectItem(item)).finally(() => {
|
|
158
|
+
setIsFetchingAdditionalInfo(false);
|
|
159
|
+
close();
|
|
160
|
+
});
|
|
161
|
+
}, children: isReactText(rendered) ? (_jsx(Text, { numberOfLines: 1, selectable: false, style: styles.itemText, children: rendered })) : (rendered) }));
|
|
162
|
+
} })), ListFooterComponent, isFetchingAdditionalInfo ? (_jsxs(View, { style: styles.loaderAdditional, children: [_jsx(View, { style: styles.loaderAdditionalUnderlay }), _jsx(LoadingView, {})] })) : null] })),
|
|
163
|
+
}),
|
|
164
|
+
}) }) })] }));
|
|
165
|
+
};
|
|
166
|
+
export const LakeCombobox = forwardRef(LakeComboboxWithRef);
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
type Props = {
|
|
3
|
+
valueToCopy: string;
|
|
4
|
+
copyText: string;
|
|
5
|
+
copiedText: string;
|
|
6
|
+
size?: number;
|
|
7
|
+
};
|
|
8
|
+
export declare const copyButtondefaultSize = 21;
|
|
9
|
+
export declare const LakeCopyButton: ({ valueToCopy, size, copyText, copiedText, }: Props) => JSX.Element;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useState } from "react";
|
|
3
|
+
import { Clipboard } from "react-native";
|
|
4
|
+
import { Icon } from "./Icon";
|
|
5
|
+
import { LakeTooltip } from "./LakeTooltip";
|
|
6
|
+
import { Pressable } from "./Pressable";
|
|
7
|
+
export const copyButtondefaultSize = 21;
|
|
8
|
+
export const LakeCopyButton = ({ valueToCopy, size = copyButtondefaultSize, copyText, copiedText, }) => {
|
|
9
|
+
const [visibleState, setVisibleState] = useState("copy");
|
|
10
|
+
return (_jsx(LakeTooltip, { describedBy: "copy", placement: "top", onHide: () => setVisibleState("copy"), togglableOnFocus: true, content: visibleState === "copy" ? copyText : copiedText, children: _jsx(Pressable, { onPress: event => {
|
|
11
|
+
event.stopPropagation();
|
|
12
|
+
event.preventDefault();
|
|
13
|
+
Clipboard.setString(valueToCopy);
|
|
14
|
+
setVisibleState("copied");
|
|
15
|
+
}, children: _jsx(Icon, { size: size, name: "copy-regular" }) }) }));
|
|
16
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Text } from "react-native";
|
|
3
|
+
import { Icon } from "./Icon";
|
|
4
|
+
export const LakeDownloadButton = ({ url, filename }) => {
|
|
5
|
+
return (_jsx(Text, { href: url, hrefAttrs: { download: filename, target: "blank" }, accessibilityHint: "download", children: _jsx(Icon, { size: 18, name: "arrow-download-filled" }) }));
|
|
6
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ReactNode } from "react";
|
|
2
|
+
import { Text, TextProps } from "react-native";
|
|
3
|
+
import { Except } from "type-fest";
|
|
4
|
+
export declare const LakeHeading: import("react").ForwardRefExoticComponent<Except<TextProps, "accessibilityRole"> & {
|
|
5
|
+
align?: "center" | "left" | "right" | undefined;
|
|
6
|
+
children: ReactNode;
|
|
7
|
+
color?: string | undefined;
|
|
8
|
+
level: 1 | 2 | 3 | 4 | 5 | 6 | "none";
|
|
9
|
+
variant?: "h1" | "h2" | "h3" | "h4" | "h5" | "h6" | undefined;
|
|
10
|
+
} & import("react").RefAttributes<Text>>;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef } from "react";
|
|
3
|
+
import { StyleSheet, Text } from "react-native";
|
|
4
|
+
import { texts } from "../constants/design";
|
|
5
|
+
import { isNotNullish } from "../utils/nullish";
|
|
6
|
+
const alignments = StyleSheet.create({
|
|
7
|
+
center: { textAlign: "center" },
|
|
8
|
+
left: { textAlign: "left" },
|
|
9
|
+
right: { textAlign: "right" },
|
|
10
|
+
});
|
|
11
|
+
const variants = StyleSheet.create({
|
|
12
|
+
h1: texts.h1,
|
|
13
|
+
h2: texts.h2,
|
|
14
|
+
h3: texts.h3,
|
|
15
|
+
h4: texts.h4,
|
|
16
|
+
h5: texts.h5,
|
|
17
|
+
h6: texts.h6,
|
|
18
|
+
});
|
|
19
|
+
export const LakeHeading = forwardRef(({ align = "left", children, color, level, style, variant = "h1", ...props }, forwardedRef) => (_jsx(Text, { ref: forwardedRef, accessibilityRole: level === "none" ? undefined : "header", accessibilityLevel: level === "none" ? undefined : level, style: [variants[variant], alignments[align], isNotNullish(color) && { color }, style], ...props, children: children })));
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ReactNode } from "react";
|
|
2
|
+
import { StyleProp, ViewStyle } from "react-native";
|
|
3
|
+
import { ColorVariants } from "../constants/design";
|
|
4
|
+
type Props = {
|
|
5
|
+
label: string;
|
|
6
|
+
optionalLabel?: string;
|
|
7
|
+
readOnlyColor?: string;
|
|
8
|
+
color?: ColorVariants;
|
|
9
|
+
type?: "form" | "formSmall" | "view" | "viewSmall";
|
|
10
|
+
extra?: () => ReactNode;
|
|
11
|
+
help?: ReactNode;
|
|
12
|
+
render: (id: string) => ReactNode;
|
|
13
|
+
actions?: ReactNode;
|
|
14
|
+
readOnly?: boolean;
|
|
15
|
+
style?: StyleProp<ViewStyle>;
|
|
16
|
+
};
|
|
17
|
+
export declare const defaultLabelType: NonNullable<Props["type"]>;
|
|
18
|
+
export declare const LakeLabel: ({ label, optionalLabel, extra, readOnly, color, readOnlyColor, type, help, render, actions, style, }: Props) => JSX.Element;
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useCallback, useRef, useState } from "react";
|
|
3
|
+
import { StyleSheet, unstable_createElement, View, } from "react-native";
|
|
4
|
+
import { v4 as uuid } from "uuid";
|
|
5
|
+
import { commonStyles } from "../constants/commonStyles";
|
|
6
|
+
import { colors, fonts, spacings, texts } from "../constants/design";
|
|
7
|
+
import { isNotNullish } from "../utils/nullish";
|
|
8
|
+
import { Box } from "./Box";
|
|
9
|
+
import { LakeText } from "./LakeText";
|
|
10
|
+
import { Space } from "./Space";
|
|
11
|
+
const styles = StyleSheet.create({
|
|
12
|
+
container: {
|
|
13
|
+
paddingTop: spacings[4],
|
|
14
|
+
},
|
|
15
|
+
label: {
|
|
16
|
+
...texts.medium,
|
|
17
|
+
fontFamily: fonts.primary,
|
|
18
|
+
color: colors.gray[700],
|
|
19
|
+
},
|
|
20
|
+
shrink: {
|
|
21
|
+
flexShrink: 1,
|
|
22
|
+
},
|
|
23
|
+
optionalLabel: {
|
|
24
|
+
fontStyle: "italic",
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
const Label = (props) => {
|
|
28
|
+
return unstable_createElement("label", props);
|
|
29
|
+
};
|
|
30
|
+
export const defaultLabelType = "formSmall";
|
|
31
|
+
export const LakeLabel = ({ label, optionalLabel, extra, readOnly = false, color = "current", readOnlyColor = colors[color].primary, type = defaultLabelType, help, render, actions, style, }) => {
|
|
32
|
+
const [id] = useState(() => uuid());
|
|
33
|
+
const containerRef = useRef(null);
|
|
34
|
+
const onClick = useCallback((event) => {
|
|
35
|
+
event.preventDefault();
|
|
36
|
+
if (containerRef.current != null) {
|
|
37
|
+
const container = containerRef.current;
|
|
38
|
+
const target = container.querySelector(`[id="${id}"]`);
|
|
39
|
+
target?.focus();
|
|
40
|
+
}
|
|
41
|
+
}, [id]);
|
|
42
|
+
return (_jsxs(Box, { style: [styles.container, style], direction: "row", alignItems: "center", justifyContent: "spaceBetween", children: [_jsxs(View, { style: commonStyles.fill, ref: containerRef, children: [_jsxs(Box, { direction: "row", justifyContent: "spaceBetween", alignItems: "center", children: [_jsxs(Box, { direction: "row", style: styles.shrink, children: [type === "form" || type === "formSmall" ? (_jsxs(Label, { onClick: onClick, htmlFor: id, style: [styles.label, readOnly && { color: readOnlyColor }], children: [label, optionalLabel != null ? (_jsxs(_Fragment, { children: [" - ", _jsx(LakeText, { color: colors.gray[400], style: styles.optionalLabel, children: optionalLabel })] })) : null] })) : (_jsxs(LakeText, { variant: "medium", color: readOnlyColor, nativeID: id, children: [label, optionalLabel != null ? (_jsxs(_Fragment, { children: [" - ", _jsx(LakeText, { color: colors.gray[400], style: styles.optionalLabel, children: optionalLabel })] })) : null] })), isNotNullish(extra) && extra()] }), isNotNullish(help) && (_jsxs(_Fragment, { children: [_jsx(Space, { width: 16 }), help] }))] }), _jsx(Space, { height: type === "formSmall" || type === "viewSmall" ? 4 : 8 }), _jsx(View, { accessibilityLabelledBy: type === "view" || type === "viewSmall" ? id : undefined, children: render(id) })] }), isNotNullish(actions) && (_jsxs(_Fragment, { children: [_jsx(Space, { width: 16 }), actions] }))] }));
|
|
43
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ReactNode } from "react";
|
|
2
|
+
import { ColorVariants } from "../constants/design";
|
|
3
|
+
import { IconName } from "./Icon";
|
|
4
|
+
import { Context } from "./ResponsiveContainer";
|
|
5
|
+
export type LakeModalProps = {
|
|
6
|
+
visible: boolean;
|
|
7
|
+
title?: string;
|
|
8
|
+
icon?: IconName;
|
|
9
|
+
color?: ColorVariants;
|
|
10
|
+
children: ReactNode | ((context: Context) => ReactNode);
|
|
11
|
+
maxWidth?: number;
|
|
12
|
+
onPressClose?: () => void;
|
|
13
|
+
};
|
|
14
|
+
export declare const LakeModal: ({ visible, icon, title, color, children, maxWidth, onPressClose, }: LakeModalProps) => JSX.Element | null;
|