@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.
Files changed (288) hide show
  1. package/HISTORY.md +3 -0
  2. package/LICENSE +21 -0
  3. package/README.md +49 -0
  4. package/package.json +60 -0
  5. package/src/components/Alert.d.ts +10 -0
  6. package/src/components/Alert.js +36 -0
  7. package/src/components/AppOpeningAnimation.d.ts +10 -0
  8. package/src/components/AppOpeningAnimation.js +50 -0
  9. package/src/components/AutoWidthImage.d.ts +8 -0
  10. package/src/components/AutoWidthImage.js +26 -0
  11. package/src/components/Avatar.d.ts +7 -0
  12. package/src/components/Avatar.js +42 -0
  13. package/src/components/BorderedButton.d.ts +16 -0
  14. package/src/components/BorderedButton.js +98 -0
  15. package/src/components/BorderedIcon.d.ts +12 -0
  16. package/src/components/BorderedIcon.js +25 -0
  17. package/src/components/BottomPanel.d.ts +9 -0
  18. package/src/components/BottomPanel.js +94 -0
  19. package/src/components/Box.d.ts +65 -0
  20. package/src/components/Box.js +31 -0
  21. package/src/components/Breadcrumbs.d.ts +18 -0
  22. package/src/components/Breadcrumbs.js +362 -0
  23. package/src/components/Button.d.ts +15 -0
  24. package/src/components/Button.js +83 -0
  25. package/src/components/Caption.d.ts +6 -0
  26. package/src/components/Caption.js +11 -0
  27. package/src/components/Checkbox.d.ts +12 -0
  28. package/src/components/Checkbox.js +83 -0
  29. package/src/components/ChoicePicker.d.ts +11 -0
  30. package/src/components/ChoicePicker.js +99 -0
  31. package/src/components/Combobox.d.ts +29 -0
  32. package/src/components/Combobox.js +182 -0
  33. package/src/components/FailureIcon.d.ts +8 -0
  34. package/src/components/FailureIcon.js +4 -0
  35. package/src/components/FileTile.d.ts +11 -0
  36. package/src/components/FileTile.js +37 -0
  37. package/src/components/Fill.d.ts +8 -0
  38. package/src/components/Fill.js +24 -0
  39. package/src/components/FilterChooser.d.ts +15 -0
  40. package/src/components/FilterChooser.js +52 -0
  41. package/src/components/Filters.d.ts +57 -0
  42. package/src/components/Filters.js +229 -0
  43. package/src/components/FixedListView.d.ts +104 -0
  44. package/src/components/FixedListView.js +821 -0
  45. package/src/components/FixedListViewCells.d.ts +55 -0
  46. package/src/components/FixedListViewCells.js +157 -0
  47. package/src/components/Flag.d.ts +8 -0
  48. package/src/components/Flag.js +36 -0
  49. package/src/components/FlowPresentation.d.ts +12 -0
  50. package/src/components/FlowPresentation.js +70 -0
  51. package/src/components/FocusTrap.d.ts +16 -0
  52. package/src/components/FocusTrap.js +90 -0
  53. package/src/components/Form.d.ts +8 -0
  54. package/src/components/Form.js +17 -0
  55. package/src/components/FullViewportLayer.d.ts +7 -0
  56. package/src/components/FullViewportLayer.js +91 -0
  57. package/src/components/Grid.d.ts +13 -0
  58. package/src/components/Grid.js +33 -0
  59. package/src/components/Heading.d.ts +61 -0
  60. package/src/components/Heading.js +27 -0
  61. package/src/components/Icon.d.ts +191 -0
  62. package/src/components/Icon.js +11 -0
  63. package/src/components/Input.d.ts +34 -0
  64. package/src/components/Input.js +115 -0
  65. package/src/components/InputError.d.ts +8 -0
  66. package/src/components/InputError.js +16 -0
  67. package/src/components/Label.d.ts +10 -0
  68. package/src/components/Label.js +19 -0
  69. package/src/components/LakeAlert.d.ts +14 -0
  70. package/src/components/LakeAlert.js +75 -0
  71. package/src/components/LakeButton.d.ts +36 -0
  72. package/src/components/LakeButton.js +171 -0
  73. package/src/components/LakeCheckbox.d.ts +16 -0
  74. package/src/components/LakeCheckbox.js +54 -0
  75. package/src/components/LakeCombobox.d.ts +28 -0
  76. package/src/components/LakeCombobox.js +166 -0
  77. package/src/components/LakeCopyButton.d.ts +10 -0
  78. package/src/components/LakeCopyButton.js +16 -0
  79. package/src/components/LakeDownloadButton.d.ts +8 -0
  80. package/src/components/LakeDownloadButton.js +6 -0
  81. package/src/components/LakeHeading.d.ts +10 -0
  82. package/src/components/LakeHeading.js +19 -0
  83. package/src/components/LakeLabel.d.ts +19 -0
  84. package/src/components/LakeLabel.js +43 -0
  85. package/src/components/LakeModal.d.ts +14 -0
  86. package/src/components/LakeModal.js +132 -0
  87. package/src/components/LakeRadio.d.ts +9 -0
  88. package/src/components/LakeRadio.js +44 -0
  89. package/src/components/LakeScrollView.d.ts +10 -0
  90. package/src/components/LakeScrollView.js +35 -0
  91. package/src/components/LakeSearchField.d.ts +10 -0
  92. package/src/components/LakeSearchField.js +111 -0
  93. package/src/components/LakeSelect.d.ts +30 -0
  94. package/src/components/LakeSelect.js +183 -0
  95. package/src/components/LakeSlider.d.ts +12 -0
  96. package/src/components/LakeSlider.js +31 -0
  97. package/src/components/LakeStepper.d.ts +21 -0
  98. package/src/components/LakeStepper.js +134 -0
  99. package/src/components/LakeText.d.ts +19 -0
  100. package/src/components/LakeText.js +20 -0
  101. package/src/components/LakeTextInput.d.ts +36 -0
  102. package/src/components/LakeTextInput.js +154 -0
  103. package/src/components/LakeTooltip.d.ts +24 -0
  104. package/src/components/LakeTooltip.js +188 -0
  105. package/src/components/Link.d.ts +138 -0
  106. package/src/components/Link.js +23 -0
  107. package/src/components/ListRightPanel.d.ts +17 -0
  108. package/src/components/ListRightPanel.js +79 -0
  109. package/src/components/LoadingView.d.ts +9 -0
  110. package/src/components/LoadingView.js +24 -0
  111. package/src/components/Modal.d.ts +12 -0
  112. package/src/components/Modal.js +80 -0
  113. package/src/components/MultiSelect.d.ts +27 -0
  114. package/src/components/MultiSelect.js +223 -0
  115. package/src/components/MultilineInput.d.ts +15 -0
  116. package/src/components/MultilineInput.js +55 -0
  117. package/src/components/Picker.d.ts +26 -0
  118. package/src/components/Picker.js +116 -0
  119. package/src/components/PlainListView.d.ts +36 -0
  120. package/src/components/PlainListView.js +208 -0
  121. package/src/components/Popover.d.ts +23 -0
  122. package/src/components/Popover.js +147 -0
  123. package/src/components/PopoverContent.d.ts +8 -0
  124. package/src/components/PopoverContent.js +9 -0
  125. package/src/components/Portal.d.ts +7 -0
  126. package/src/components/Portal.js +9 -0
  127. package/src/components/Pressable.d.ts +348 -0
  128. package/src/components/Pressable.js +91 -0
  129. package/src/components/ProgressBar.d.ts +11 -0
  130. package/src/components/ProgressBar.js +46 -0
  131. package/src/components/ProjectEnvTag.d.ts +7 -0
  132. package/src/components/ProjectEnvTag.js +12 -0
  133. package/src/components/QuickActions.d.ts +15 -0
  134. package/src/components/QuickActions.js +38 -0
  135. package/src/components/RadioGroup.d.ts +16 -0
  136. package/src/components/RadioGroup.js +34 -0
  137. package/src/components/ReadOnlyFieldList.d.ts +6 -0
  138. package/src/components/ReadOnlyFieldList.js +8 -0
  139. package/src/components/ResponsiveContainer.d.ts +13 -0
  140. package/src/components/ResponsiveContainer.js +23 -0
  141. package/src/components/RightPanel.d.ts +10 -0
  142. package/src/components/RightPanel.js +102 -0
  143. package/src/components/SegmentedControl.d.ts +19 -0
  144. package/src/components/SegmentedControl.js +74 -0
  145. package/src/components/Separator.d.ts +10 -0
  146. package/src/components/Separator.js +19 -0
  147. package/src/components/SidebarNavigationTracker.d.ts +13 -0
  148. package/src/components/SidebarNavigationTracker.js +93 -0
  149. package/src/components/Slider.d.ts +11 -0
  150. package/src/components/Slider.js +119 -0
  151. package/src/components/SmsOpeningAnimation.d.ts +8 -0
  152. package/src/components/SmsOpeningAnimation.js +52 -0
  153. package/src/components/Space.d.ts +10 -0
  154. package/src/components/Space.js +23 -0
  155. package/src/components/Stack.d.ts +12 -0
  156. package/src/components/Stack.js +23 -0
  157. package/src/components/StepDots.d.ts +7 -0
  158. package/src/components/StepDots.js +24 -0
  159. package/src/components/Stepper.d.ts +9 -0
  160. package/src/components/Stepper.js +67 -0
  161. package/src/components/SuccessIcon.d.ts +8 -0
  162. package/src/components/SuccessIcon.js +4 -0
  163. package/src/components/Svg.d.ts +145 -0
  164. package/src/components/Svg.js +24 -0
  165. package/src/components/SwanLogo.d.ts +8 -0
  166. package/src/components/SwanLogo.js +11 -0
  167. package/src/components/Switch.d.ts +9 -0
  168. package/src/components/Switch.js +74 -0
  169. package/src/components/TabView.d.ts +16 -0
  170. package/src/components/TabView.js +398 -0
  171. package/src/components/Table.d.ts +34 -0
  172. package/src/components/Table.js +79 -0
  173. package/src/components/Tag.d.ts +17 -0
  174. package/src/components/Tag.js +76 -0
  175. package/src/components/Tile.d.ts +34 -0
  176. package/src/components/Tile.js +130 -0
  177. package/src/components/TilePlaceholder.d.ts +6 -0
  178. package/src/components/TilePlaceholder.js +51 -0
  179. package/src/components/ToastStack.d.ts +2 -0
  180. package/src/components/ToastStack.js +96 -0
  181. package/src/components/Tooltip.d.ts +18 -0
  182. package/src/components/Tooltip.js +162 -0
  183. package/src/components/TransitionGroupView.d.ts +12 -0
  184. package/src/components/TransitionGroupView.js +43 -0
  185. package/src/components/TransitionView.d.ts +12 -0
  186. package/src/components/TransitionView.js +43 -0
  187. package/src/components/WithCurrentColor.d.ts +12 -0
  188. package/src/components/WithCurrentColor.js +65 -0
  189. package/src/components/WithPartnerAccentColor.d.ts +7 -0
  190. package/src/components/WithPartnerAccentColor.js +91 -0
  191. package/src/constants/colors.d.ts +42 -0
  192. package/src/constants/colors.js +42 -0
  193. package/src/constants/commonStyles.d.ts +66 -0
  194. package/src/constants/commonStyles.js +45 -0
  195. package/src/constants/design.d.ts +168 -0
  196. package/src/constants/design.js +564 -0
  197. package/src/constants/insets.d.ts +10 -0
  198. package/src/constants/insets.js +22 -0
  199. package/src/constants/typography.d.ts +26 -0
  200. package/src/constants/typography.js +54 -0
  201. package/src/hooks/useAnimatedValue.d.ts +2 -0
  202. package/src/hooks/useAnimatedValue.js +3 -0
  203. package/src/hooks/useBodyClassName.d.ts +3 -0
  204. package/src/hooks/useBodyClassName.js +14 -0
  205. package/src/hooks/useBoolean.d.ts +8 -0
  206. package/src/hooks/useBoolean.js +12 -0
  207. package/src/hooks/useComputedColors.d.ts +10 -0
  208. package/src/hooks/useComputedColors.js +42 -0
  209. package/src/hooks/useDebounce.d.ts +1 -0
  210. package/src/hooks/useDebounce.js +12 -0
  211. package/src/hooks/useDisclosure.d.ts +8 -0
  212. package/src/hooks/useDisclosure.js +12 -0
  213. package/src/hooks/useFirstMountState.d.ts +1 -0
  214. package/src/hooks/useFirstMountState.js +9 -0
  215. package/src/hooks/useForceableState.d.ts +1 -0
  216. package/src/hooks/useForceableState.js +6 -0
  217. package/src/hooks/useHover.d.ts +11 -0
  218. package/src/hooks/useHover.js +4 -0
  219. package/src/hooks/useInterval.d.ts +1 -0
  220. package/src/hooks/useInterval.js +11 -0
  221. package/src/hooks/useLazyRef.d.ts +2 -0
  222. package/src/hooks/useLazyRef.js +9 -0
  223. package/src/hooks/useMergeRefs.d.ts +2 -0
  224. package/src/hooks/useMergeRefs.js +5 -0
  225. package/src/hooks/useNativeProp.d.ts +2 -0
  226. package/src/hooks/useNativeProp.js +9 -0
  227. package/src/hooks/useOutsideClick.d.ts +8 -0
  228. package/src/hooks/useOutsideClick.js +54 -0
  229. package/src/hooks/usePersistedState.d.ts +1 -0
  230. package/src/hooks/usePersistedState.js +21 -0
  231. package/src/hooks/usePressEvents.d.ts +31 -0
  232. package/src/hooks/usePressEvents.js +4 -0
  233. package/src/hooks/usePreviousValue.d.ts +1 -0
  234. package/src/hooks/usePreviousValue.js +8 -0
  235. package/src/hooks/useResponsive.d.ts +7 -0
  236. package/src/hooks/useResponsive.js +20 -0
  237. package/src/hooks/useUpdateEffect.d.ts +2 -0
  238. package/src/hooks/useUpdateEffect.js +10 -0
  239. package/src/hooks/useUrqlMutation.d.ts +4 -0
  240. package/src/hooks/useUrqlMutation.js +30 -0
  241. package/src/hooks/useUrqlQuery.d.ts +19 -0
  242. package/src/hooks/useUrqlQuery.js +73 -0
  243. package/src/state/toasts.d.ts +21 -0
  244. package/src/state/toasts.js +61 -0
  245. package/src/utils/__tests__/array.test.d.ts +1 -0
  246. package/src/utils/__tests__/array.test.js +127 -0
  247. package/src/utils/__tests__/base64.test.d.ts +1 -0
  248. package/src/utils/__tests__/base64.test.js +27 -0
  249. package/src/utils/__tests__/function.test.d.ts +1 -0
  250. package/src/utils/__tests__/function.test.js +36 -0
  251. package/src/utils/__tests__/object.test.d.ts +1 -0
  252. package/src/utils/__tests__/object.test.js +17 -0
  253. package/src/utils/__tests__/rifm.test.d.ts +1 -0
  254. package/src/utils/__tests__/rifm.test.js +124 -0
  255. package/src/utils/__tests__/string.test.d.ts +1 -0
  256. package/src/utils/__tests__/string.test.js +16 -0
  257. package/src/utils/a11y.d.ts +1 -0
  258. package/src/utils/a11y.js +18 -0
  259. package/src/utils/array.d.ts +6 -0
  260. package/src/utils/array.js +71 -0
  261. package/src/utils/base64.d.ts +2 -0
  262. package/src/utils/base64.js +20 -0
  263. package/src/utils/file.d.ts +2 -0
  264. package/src/utils/file.js +10 -0
  265. package/src/utils/flagCountry.d.ts +1 -0
  266. package/src/utils/flagCountry.js +1 -0
  267. package/src/utils/function.d.ts +4 -0
  268. package/src/utils/function.js +19 -0
  269. package/src/utils/math.d.ts +16 -0
  270. package/src/utils/math.js +47 -0
  271. package/src/utils/nullish.d.ts +10 -0
  272. package/src/utils/nullish.js +8 -0
  273. package/src/utils/object.d.ts +2 -0
  274. package/src/utils/object.js +7 -0
  275. package/src/utils/popper.d.ts +3 -0
  276. package/src/utils/popper.js +30 -0
  277. package/src/utils/rifm.d.ts +14 -0
  278. package/src/utils/rifm.js +53 -0
  279. package/src/utils/string.d.ts +4 -0
  280. package/src/utils/string.js +233 -0
  281. package/src/utils/timer.d.ts +11 -0
  282. package/src/utils/timer.js +46 -0
  283. package/src/utils/types.d.ts +8 -0
  284. package/src/utils/types.js +1 -0
  285. package/src/utils/userAgent.d.ts +4 -0
  286. package/src/utils/userAgent.js +9 -0
  287. package/src/utils/viewport.d.ts +1 -0
  288. 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,8 @@
1
+ /// <reference types="react" />
2
+ type Props = {
3
+ url: string;
4
+ filename: string;
5
+ onError: () => void;
6
+ };
7
+ export declare const LakeDownloadButton: ({ url, filename }: Props) => JSX.Element;
8
+ export {};
@@ -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;