@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,31 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef } from "react";
|
|
3
|
+
import { StyleSheet, View } from "react-native";
|
|
4
|
+
/* eslint-disable react-native/no-unused-styles */
|
|
5
|
+
const directionStyles = StyleSheet.create({
|
|
6
|
+
columnReverse: { flexDirection: "column-reverse" },
|
|
7
|
+
row: { flexDirection: "row" },
|
|
8
|
+
rowReverse: { flexDirection: "row-reverse" },
|
|
9
|
+
});
|
|
10
|
+
const alignItemsStyles = StyleSheet.create({
|
|
11
|
+
baseline: { alignItems: "baseline" },
|
|
12
|
+
center: { alignItems: "center" },
|
|
13
|
+
end: { alignItems: "flex-end" },
|
|
14
|
+
start: { alignItems: "flex-start" },
|
|
15
|
+
});
|
|
16
|
+
const justifyContentStyles = StyleSheet.create({
|
|
17
|
+
center: { justifyContent: "center" },
|
|
18
|
+
end: { justifyContent: "flex-end" },
|
|
19
|
+
start: { justifyContent: "flex-start" },
|
|
20
|
+
spaceBetween: { justifyContent: "space-between" },
|
|
21
|
+
spaceAround: { justifyContent: "space-around" },
|
|
22
|
+
spaceEvenly: { justifyContent: "space-evenly" },
|
|
23
|
+
});
|
|
24
|
+
export const Box = forwardRef((
|
|
25
|
+
// Default <View /> styles https://github.com/necolas/react-native-web/blob/0.17.5/packages/react-native-web/src/exports/View/index.js#L133
|
|
26
|
+
{ alignItems = "stretch", direction = "column", justifyContent = "normal", style, ...props }, forwardedRef) => (_jsx(View, { ref: forwardedRef, ...props, style: [
|
|
27
|
+
alignItems !== "stretch" && alignItemsStyles[alignItems],
|
|
28
|
+
direction !== "column" && directionStyles[direction],
|
|
29
|
+
justifyContent !== "normal" && justifyContentStyles[justifyContent],
|
|
30
|
+
style,
|
|
31
|
+
] })));
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ReactNode } from "react";
|
|
2
|
+
export type Crumb = {
|
|
3
|
+
label: string;
|
|
4
|
+
link: string;
|
|
5
|
+
siblings?: {
|
|
6
|
+
label: string;
|
|
7
|
+
url: string;
|
|
8
|
+
isMatching: boolean;
|
|
9
|
+
}[];
|
|
10
|
+
};
|
|
11
|
+
type Props = {
|
|
12
|
+
rootLevelCrumbs?: readonly Crumb[];
|
|
13
|
+
children: ReactNode;
|
|
14
|
+
};
|
|
15
|
+
export declare const BreadcrumbsRoot: ({ rootLevelCrumbs, children }: Props) => JSX.Element;
|
|
16
|
+
export declare const useCrumb: (crumb?: Crumb) => void;
|
|
17
|
+
export declare const Breadcrumbs: () => JSX.Element;
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,362 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { FocusTrap } from "@swan-io/lake/src/components/FocusTrap";
|
|
3
|
+
import { Icon } from "@swan-io/lake/src/components/Icon";
|
|
4
|
+
import { LakeText } from "@swan-io/lake/src/components/LakeText";
|
|
5
|
+
import { Link } from "@swan-io/lake/src/components/Link";
|
|
6
|
+
import { Space } from "@swan-io/lake/src/components/Space";
|
|
7
|
+
import { TransitionView } from "@swan-io/lake/src/components/TransitionView";
|
|
8
|
+
import { animations, backgroundColor, colors, gray75, radii, shadows, spacings, texts, } from "@swan-io/lake/src/constants/design";
|
|
9
|
+
import { useHover } from "@swan-io/lake/src/hooks/useHover";
|
|
10
|
+
import { usePreviousValue } from "@swan-io/lake/src/hooks/usePreviousValue";
|
|
11
|
+
import { isNotNullish, isNullish } from "@swan-io/lake/src/utils/nullish";
|
|
12
|
+
import { createContext, useCallback, useContext, useEffect, useMemo, useReducer, useRef, useState, } from "react";
|
|
13
|
+
import { Pressable, StyleSheet, Text, View, } from "react-native";
|
|
14
|
+
import { match, P } from "ts-pattern";
|
|
15
|
+
import { v4 as uuid } from "uuid";
|
|
16
|
+
import { noop } from "../utils/function";
|
|
17
|
+
import { Box } from "./Box";
|
|
18
|
+
const styles = StyleSheet.create({
|
|
19
|
+
container: {
|
|
20
|
+
flexDirection: "row",
|
|
21
|
+
alignItems: "center",
|
|
22
|
+
zIndex: 10,
|
|
23
|
+
transform: [{ translateZ: 0 }],
|
|
24
|
+
},
|
|
25
|
+
item: {
|
|
26
|
+
flexDirection: "row",
|
|
27
|
+
alignItems: "center",
|
|
28
|
+
borderRadius: radii[6],
|
|
29
|
+
transitionProperty: "opacity",
|
|
30
|
+
transitionDuration: "0.15s",
|
|
31
|
+
},
|
|
32
|
+
itemPressed: {
|
|
33
|
+
opacity: 0.2,
|
|
34
|
+
},
|
|
35
|
+
itemForcedOpen: {
|
|
36
|
+
backgroundColor: colors.gray[50],
|
|
37
|
+
},
|
|
38
|
+
chevron: {
|
|
39
|
+
padding: spacings[8],
|
|
40
|
+
},
|
|
41
|
+
horizontalLink: {
|
|
42
|
+
paddingVertical: spacings[8],
|
|
43
|
+
},
|
|
44
|
+
horizontalLinkText: {
|
|
45
|
+
paddingHorizontal: spacings[8],
|
|
46
|
+
alignItems: "center",
|
|
47
|
+
display: "inline-flex",
|
|
48
|
+
},
|
|
49
|
+
horizontalLinkTextHovered: {
|
|
50
|
+
color: colors.gray[900],
|
|
51
|
+
boxShadow: `0 1px currentColor`,
|
|
52
|
+
},
|
|
53
|
+
activeHorizontalLinkText: {
|
|
54
|
+
color: colors.gray[800],
|
|
55
|
+
backgroundColor: gray75,
|
|
56
|
+
borderRadius: radii[4],
|
|
57
|
+
boxShadow: "none",
|
|
58
|
+
},
|
|
59
|
+
dropdown: {
|
|
60
|
+
position: "absolute",
|
|
61
|
+
left: "50%",
|
|
62
|
+
transform: [{ translateX: "-50%" }],
|
|
63
|
+
top: "100%",
|
|
64
|
+
backgroundColor: backgroundColor.accented,
|
|
65
|
+
borderRadius: radii[8],
|
|
66
|
+
boxShadow: shadows.modal,
|
|
67
|
+
paddingVertical: spacings[8],
|
|
68
|
+
},
|
|
69
|
+
siblingsDropdown: {
|
|
70
|
+
position: "absolute",
|
|
71
|
+
left: "50%",
|
|
72
|
+
transform: [{ translateX: "-50%" }],
|
|
73
|
+
top: "100%",
|
|
74
|
+
backgroundColor: backgroundColor.accented,
|
|
75
|
+
borderRadius: radii[8],
|
|
76
|
+
boxShadow: shadows.modal,
|
|
77
|
+
paddingVertical: spacings[8],
|
|
78
|
+
alignItems: "stretch",
|
|
79
|
+
},
|
|
80
|
+
dropdownLink: {
|
|
81
|
+
paddingHorizontal: spacings[16],
|
|
82
|
+
paddingVertical: spacings[8],
|
|
83
|
+
flexDirection: "row",
|
|
84
|
+
alignItems: "center",
|
|
85
|
+
},
|
|
86
|
+
dropdownLinkText: {
|
|
87
|
+
...texts.regular,
|
|
88
|
+
whiteSpace: "nowrap",
|
|
89
|
+
},
|
|
90
|
+
dropdownLinkTextHovered: {
|
|
91
|
+
color: colors.gray[500],
|
|
92
|
+
},
|
|
93
|
+
dropdownLinkActive: {
|
|
94
|
+
backgroundColor: colors.gray[50],
|
|
95
|
+
},
|
|
96
|
+
dropdownContainer: {
|
|
97
|
+
position: "absolute",
|
|
98
|
+
left: "50%",
|
|
99
|
+
top: "100%",
|
|
100
|
+
},
|
|
101
|
+
dropdownLinkContainer: {
|
|
102
|
+
display: "flex",
|
|
103
|
+
flexDirection: "column",
|
|
104
|
+
alignItems: "stretch",
|
|
105
|
+
},
|
|
106
|
+
tick: {
|
|
107
|
+
position: "absolute",
|
|
108
|
+
top: "50%",
|
|
109
|
+
right: spacings[16],
|
|
110
|
+
transform: [{ translateY: "-50%" }],
|
|
111
|
+
},
|
|
112
|
+
});
|
|
113
|
+
const emptyCrumbWithIdArray = [];
|
|
114
|
+
const emptyCrumbArray = [];
|
|
115
|
+
const defaultContext = [emptyCrumbWithIdArray, emptyCrumbWithIdArray, noop, { current: -1 }];
|
|
116
|
+
const BreadcrumbsContext = createContext(defaultContext);
|
|
117
|
+
export const BreadcrumbsRoot = ({ rootLevelCrumbs = emptyCrumbArray, children }) => {
|
|
118
|
+
const [crumbs, setCrumbs] = useState(emptyCrumbWithIdArray);
|
|
119
|
+
const isFirstRenderRef = useRef(true);
|
|
120
|
+
const currentIndexRef = useRef(-1);
|
|
121
|
+
const [rootCrumbs, setRootCrumbs] = useState(() => rootLevelCrumbs.map(crumb => ({ id: uuid(), crumb, isRootCrumb: true })));
|
|
122
|
+
useEffect(() => {
|
|
123
|
+
if (isFirstRenderRef.current) {
|
|
124
|
+
isFirstRenderRef.current = false;
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
setRootCrumbs(rootLevelCrumbs.map(crumb => ({ id: uuid(), crumb, isRootCrumb: true })));
|
|
128
|
+
}, [rootLevelCrumbs]);
|
|
129
|
+
const orderedCrumbs = useMemo(() => [...crumbs].sort((a, b) => ((b.index ?? -1) > (a.index ?? -1) ? -1 : 1)), [crumbs]);
|
|
130
|
+
const value = useMemo(() => [rootCrumbs, orderedCrumbs, setCrumbs, currentIndexRef], [rootCrumbs, orderedCrumbs, setCrumbs, currentIndexRef]);
|
|
131
|
+
return _jsx(BreadcrumbsContext.Provider, { value: value, children: children });
|
|
132
|
+
};
|
|
133
|
+
const useBreadcrumbs = () => {
|
|
134
|
+
const [initialCrumbs, crumbs] = useContext(BreadcrumbsContext);
|
|
135
|
+
return useMemo(() => [...initialCrumbs, ...crumbs], [initialCrumbs, crumbs]);
|
|
136
|
+
};
|
|
137
|
+
export const useCrumb = (crumb) => {
|
|
138
|
+
const [, , setValue, currentIndex] = useContext(BreadcrumbsContext);
|
|
139
|
+
const [id] = useState(() => uuid());
|
|
140
|
+
const initialCrumb = useRef(crumb);
|
|
141
|
+
const [index] = useState(() => ++currentIndex.current);
|
|
142
|
+
useEffect(() => {
|
|
143
|
+
setValue(existingCrumbs => {
|
|
144
|
+
const nextCrumbs = existingCrumbs.concat([
|
|
145
|
+
{ id, crumb: initialCrumb.current, isRootCrumb: false, index },
|
|
146
|
+
]);
|
|
147
|
+
return nextCrumbs;
|
|
148
|
+
});
|
|
149
|
+
return () => {
|
|
150
|
+
setValue(existingCrumbs => existingCrumbs.filter(existingCrumb => existingCrumb.id !== id));
|
|
151
|
+
};
|
|
152
|
+
}, [id, setValue, index]);
|
|
153
|
+
useEffect(() => {
|
|
154
|
+
setValue(existingCrumbs => {
|
|
155
|
+
const exisitingCrumb = existingCrumbs.find(existingCrumb => existingCrumb.id === id);
|
|
156
|
+
if (isNotNullish(exisitingCrumb) && exisitingCrumb.crumb !== crumb) {
|
|
157
|
+
return existingCrumbs.map(existingCrumb => {
|
|
158
|
+
return existingCrumb.id === id
|
|
159
|
+
? { id, crumb, isRootCrumb: exisitingCrumb.isRootCrumb, index }
|
|
160
|
+
: existingCrumb;
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
return existingCrumbs;
|
|
164
|
+
});
|
|
165
|
+
}, [id, crumb, setValue, index]);
|
|
166
|
+
};
|
|
167
|
+
const CHEVRON = (_jsx(View, { style: styles.chevron, children: _jsx(Icon, { name: "chevron-right-filled", color: colors.gray[500], size: 16 }) }));
|
|
168
|
+
const BreadcrumbsSiblingsDropdown = ({ siblings, onPress, }) => {
|
|
169
|
+
return (_jsx(View, { style: styles.siblingsDropdown, children: siblings.map(({ url, label, isMatching }) => {
|
|
170
|
+
return (_jsx(Link, { to: url, ariaCurrentValue: "location", onPress: (event) => {
|
|
171
|
+
if (isMatching) {
|
|
172
|
+
event.preventDefault();
|
|
173
|
+
}
|
|
174
|
+
onPress();
|
|
175
|
+
}, style: styles.dropdownLinkContainer, children: ({ hovered }) => (_jsxs(View, { style: [styles.dropdownLink, isMatching && styles.dropdownLinkActive], children: [_jsx(LakeText, { style: [styles.dropdownLinkText, hovered && styles.dropdownLinkTextHovered], children: label }), isMatching && (_jsxs(_Fragment, { children: [_jsx(Space, { width: 32 }), _jsx(Icon, { color: colors.positive[500], name: "checkmark-filled", size: 14, style: styles.tick })] }))] })) }, url));
|
|
176
|
+
}) }));
|
|
177
|
+
};
|
|
178
|
+
const BreadcrumbsItem = ({ crumb, isFirstItem = false, isLastItem = false, shouldAnimate, }) => {
|
|
179
|
+
const [isHovered, setIsHovered] = useState(() => false);
|
|
180
|
+
const hoverRef = useRef(null);
|
|
181
|
+
const [siblings, setSiblings] = useState(null);
|
|
182
|
+
useHover(hoverRef, {
|
|
183
|
+
onHoverStart: () => setIsHovered(true),
|
|
184
|
+
onHoverEnd: () => setIsHovered(false),
|
|
185
|
+
});
|
|
186
|
+
const handlePress = useCallback((event) => {
|
|
187
|
+
if (crumb.siblings != null) {
|
|
188
|
+
event.preventDefault();
|
|
189
|
+
setSiblings(crumb.siblings);
|
|
190
|
+
}
|
|
191
|
+
}, [crumb.siblings]);
|
|
192
|
+
return (_jsxs(View, { style: [styles.item, shouldAnimate ? animations.fadeAndSlideInFromRight.enter : null], children: [!isFirstItem ? CHEVRON : null, _jsxs(View, { children: [_jsx(Link, { to: crumb.link, ariaCurrentValue: "location", onPress: handlePress, children: _jsx(View, { ref: hoverRef, style: [
|
|
193
|
+
styles.horizontalLink,
|
|
194
|
+
shouldAnimate && animations.fadeAndSlideInFromRight.enter,
|
|
195
|
+
], children: _jsxs(LakeText, { color: colors.gray[800], style: [styles.horizontalLinkText, isLastItem && styles.activeHorizontalLinkText], children: [_jsx(Text, { style: isHovered && !isLastItem ? styles.horizontalLinkTextHovered : undefined, children: crumb.label }), crumb.siblings != null ? (_jsxs(_Fragment, { children: [_jsx(Space, { width: 4 }), _jsx(Icon, { name: "chevron-down-filled", color: colors.gray[500], size: 16 })] })) : null] }) }) }), _jsx(View, { style: styles.dropdownContainer, children: _jsx(TransitionView, { ...animations.fadeAndSlideInFromBottom, children: siblings ? (_jsx(FocusTrap, { autoFocus: true, focusLock: true, returnFocus: true, onClickOutside: () => setSiblings(null), onEscapeKey: () => setSiblings(null), children: _jsx(BreadcrumbsSiblingsDropdown, { siblings: siblings, onPress: () => setSiblings(null) }) })) : null }) })] })] }));
|
|
196
|
+
};
|
|
197
|
+
const BreadcrumbsDropdown = ({ crumbs, onHoverStart, onHoverEnd, onLinkFocus, onLinkBlur, onLinkPress, }) => {
|
|
198
|
+
const containerRef = useRef(null);
|
|
199
|
+
useHover(containerRef, {
|
|
200
|
+
onHoverStart,
|
|
201
|
+
onHoverEnd,
|
|
202
|
+
});
|
|
203
|
+
return (_jsx(View, { style: styles.dropdown, ref: containerRef, children: crumbs.map(({ id, crumb }) => {
|
|
204
|
+
return (_jsx(Link, { to: crumb.link, onFocus: onLinkFocus, onBlur: onLinkBlur, onPress: onLinkPress, ariaCurrentValue: "location", children: ({ hovered }) => (_jsx(View, { style: styles.dropdownLink, children: _jsx(LakeText, { style: [styles.dropdownLinkText, hovered && styles.dropdownLinkTextHovered], children: crumb.label }) })) }, id));
|
|
205
|
+
}) }));
|
|
206
|
+
};
|
|
207
|
+
const SHOULD_AUTOFOCUS = new Set(["ForcedOpen", "OpenFromFocus"]);
|
|
208
|
+
const SHOULD_OPEN = new Set(["Open", "ForcedOpen", "OpenFromFocus"]);
|
|
209
|
+
const SHOULD_LOCK_FOCUS = new Set(["ForcedOpen"]);
|
|
210
|
+
const BreadcrumbsDropdownItems = ({ crumbs }) => {
|
|
211
|
+
const [openingStatus, dispatch] = useReducer((state, action) => {
|
|
212
|
+
const input = [action, state];
|
|
213
|
+
return match(input)
|
|
214
|
+
.with(["ForceToggle", "Closed"], ["ForceToggle", "Open"], ["ForceToggle", "ForcedClosed"], () => "ForcedOpen")
|
|
215
|
+
.with(["ForceToggle", "OpenFromFocus"], ["ForceToggle", "ForcedOpen"], () => "ForcedClosed")
|
|
216
|
+
.with(["ForceClose", P._], () => "ForcedClosed")
|
|
217
|
+
.with(["FocusHandle", "ForcedClosed"], () => "Closed")
|
|
218
|
+
.with(["Open", "ForcedOpen"], ["FocusHandle", "ForcedOpen"], ["Close", "ForcedOpen"], () => "ForcedOpen")
|
|
219
|
+
.with(["Open", P._], () => "Open")
|
|
220
|
+
.with(["FocusHandle", P._], () => "OpenFromFocus")
|
|
221
|
+
.with(["Close", P._], () => "Closed")
|
|
222
|
+
.exhaustive();
|
|
223
|
+
}, "Closed");
|
|
224
|
+
const timeoutRef = useRef(undefined);
|
|
225
|
+
const handleRef = useRef(null);
|
|
226
|
+
const containerRef = useRef(null);
|
|
227
|
+
const { onHandleFocus, onLinkFocus, onAnyBlur, onHoverStart, onHoverEnd, onPress, onPressOutside, onEscapeKey, } = useMemo(() => ({
|
|
228
|
+
onHandleFocus: (event) => {
|
|
229
|
+
if (isNullish(containerRef.current)) {
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
const container = containerRef.current;
|
|
233
|
+
const focusEvent = event;
|
|
234
|
+
// Don't reopen if leaving
|
|
235
|
+
if (!container.contains(focusEvent.relatedTarget)) {
|
|
236
|
+
if (isNotNullish(timeoutRef.current)) {
|
|
237
|
+
clearTimeout(timeoutRef.current);
|
|
238
|
+
}
|
|
239
|
+
dispatch("FocusHandle");
|
|
240
|
+
}
|
|
241
|
+
},
|
|
242
|
+
onLinkFocus: () => {
|
|
243
|
+
if (isNotNullish(timeoutRef.current)) {
|
|
244
|
+
clearTimeout(timeoutRef.current);
|
|
245
|
+
}
|
|
246
|
+
dispatch("Open");
|
|
247
|
+
},
|
|
248
|
+
onAnyBlur: () => {
|
|
249
|
+
if (isNotNullish(timeoutRef.current)) {
|
|
250
|
+
clearTimeout(timeoutRef.current);
|
|
251
|
+
}
|
|
252
|
+
timeoutRef.current = window.setTimeout(() => {
|
|
253
|
+
dispatch("Close");
|
|
254
|
+
}, 300);
|
|
255
|
+
},
|
|
256
|
+
onHoverStart: () => {
|
|
257
|
+
if (isNotNullish(timeoutRef.current)) {
|
|
258
|
+
clearTimeout(timeoutRef.current);
|
|
259
|
+
}
|
|
260
|
+
dispatch("Open");
|
|
261
|
+
},
|
|
262
|
+
onHoverEnd: () => {
|
|
263
|
+
if (isNotNullish(timeoutRef.current)) {
|
|
264
|
+
clearTimeout(timeoutRef.current);
|
|
265
|
+
}
|
|
266
|
+
timeoutRef.current = window.setTimeout(() => {
|
|
267
|
+
dispatch("Close");
|
|
268
|
+
}, 300);
|
|
269
|
+
},
|
|
270
|
+
onPress: () => {
|
|
271
|
+
if (isNotNullish(timeoutRef.current)) {
|
|
272
|
+
clearTimeout(timeoutRef.current);
|
|
273
|
+
}
|
|
274
|
+
dispatch("ForceToggle");
|
|
275
|
+
},
|
|
276
|
+
onPressOutside: (event) => {
|
|
277
|
+
if (isNotNullish(handleRef.current)) {
|
|
278
|
+
const handle = handleRef.current;
|
|
279
|
+
if (handle.contains(event.target)) {
|
|
280
|
+
return;
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
if (isNotNullish(timeoutRef.current)) {
|
|
284
|
+
clearTimeout(timeoutRef.current);
|
|
285
|
+
}
|
|
286
|
+
// Only force closing in case the focus comes directly to the handle
|
|
287
|
+
// Then put it back to a regular closed state
|
|
288
|
+
dispatch("ForceClose");
|
|
289
|
+
timeoutRef.current = window.setTimeout(() => {
|
|
290
|
+
dispatch("Close");
|
|
291
|
+
}, 300);
|
|
292
|
+
},
|
|
293
|
+
onEscapeKey: () => {
|
|
294
|
+
if (isNotNullish(timeoutRef.current)) {
|
|
295
|
+
clearTimeout(timeoutRef.current);
|
|
296
|
+
}
|
|
297
|
+
dispatch("ForceClose");
|
|
298
|
+
timeoutRef.current = window.setTimeout(() => {
|
|
299
|
+
dispatch("Close");
|
|
300
|
+
}, 300);
|
|
301
|
+
},
|
|
302
|
+
}), []);
|
|
303
|
+
useEffect(() => {
|
|
304
|
+
return () => {
|
|
305
|
+
if (isNotNullish(timeoutRef.current)) {
|
|
306
|
+
clearTimeout(timeoutRef.current);
|
|
307
|
+
}
|
|
308
|
+
};
|
|
309
|
+
}, []);
|
|
310
|
+
const shouldOpen = SHOULD_OPEN.has(openingStatus);
|
|
311
|
+
const shouldAutoFocus = SHOULD_AUTOFOCUS.has(openingStatus);
|
|
312
|
+
const shouldLockFocus = SHOULD_LOCK_FOCUS.has(openingStatus);
|
|
313
|
+
useHover(handleRef, {
|
|
314
|
+
onHoverStart,
|
|
315
|
+
onHoverEnd,
|
|
316
|
+
});
|
|
317
|
+
return (_jsxs(Box, { direction: "row", alignItems: "center", children: [CHEVRON, _jsxs(View, { ref: containerRef, children: [_jsx(Pressable, { ref: handleRef, style: ({ pressed }) => [
|
|
318
|
+
styles.item,
|
|
319
|
+
pressed && styles.itemPressed,
|
|
320
|
+
openingStatus === "ForcedOpen" && styles.itemForcedOpen,
|
|
321
|
+
], focusable: true, onFocus: onHandleFocus, onBlur: onAnyBlur, onPress: onPress, children: _jsx(View, { style: styles.horizontalLink, children: _jsx(LakeText, { style: [styles.horizontalLinkText, styles.activeHorizontalLinkText], children: "…" }) }) }), _jsx(TransitionView, { ...animations.fadeAndSlideInFromBottom, children: shouldOpen ? (_jsx(FocusTrap, { autoFocus: shouldAutoFocus, focusLock: shouldLockFocus, returnFocus: shouldLockFocus, onClickOutside: onPressOutside, onEscapeKey: shouldLockFocus ? onEscapeKey : undefined, children: _jsx(BreadcrumbsDropdown, { crumbs: crumbs, onHoverStart: onHoverStart, onHoverEnd: onHoverEnd, onLinkFocus: onLinkFocus, onLinkBlur: onAnyBlur, onLinkPress: onEscapeKey }) })) : null })] })] }));
|
|
322
|
+
};
|
|
323
|
+
// In order to preserve the horizontal space, we collapse the breadcrumbs once
|
|
324
|
+
// there's strictly more than three crumbs. In that case, the expected behavior
|
|
325
|
+
// is as follows:
|
|
326
|
+
// - Display the root crumb (the first one) inline
|
|
327
|
+
// - Collapse any crumb between the first and the penultimate item in a dropdown
|
|
328
|
+
// - Display the last two crumbs inline
|
|
329
|
+
const arrangeArray = (array) => {
|
|
330
|
+
if (array.length <= 3) {
|
|
331
|
+
return {
|
|
332
|
+
start: array,
|
|
333
|
+
collapsed: [],
|
|
334
|
+
end: [],
|
|
335
|
+
};
|
|
336
|
+
}
|
|
337
|
+
return {
|
|
338
|
+
start: array.slice(0, 1),
|
|
339
|
+
collapsed: array.slice(1, -2),
|
|
340
|
+
end: array.slice(-2),
|
|
341
|
+
};
|
|
342
|
+
};
|
|
343
|
+
export const Breadcrumbs = () => {
|
|
344
|
+
const crumbs = useBreadcrumbs();
|
|
345
|
+
const cleanCrumbs = useMemo(() => {
|
|
346
|
+
const hasCrumb = (value) => isNotNullish(value.crumb);
|
|
347
|
+
return crumbs.filter(hasCrumb);
|
|
348
|
+
}, [crumbs]);
|
|
349
|
+
const previousCrumbs = usePreviousValue(useMemo(() => {
|
|
350
|
+
return new Set(cleanCrumbs.map(crumb => crumb.id));
|
|
351
|
+
}, [cleanCrumbs]));
|
|
352
|
+
const { start, collapsed, end } = useMemo(() => {
|
|
353
|
+
return arrangeArray(cleanCrumbs.map(({ id, crumb, isRootCrumb }, index) => ({
|
|
354
|
+
id,
|
|
355
|
+
crumb,
|
|
356
|
+
isFirst: index === 0,
|
|
357
|
+
isLast: index === cleanCrumbs.length - 1,
|
|
358
|
+
isRootCrumb,
|
|
359
|
+
})));
|
|
360
|
+
}, [cleanCrumbs]);
|
|
361
|
+
return (_jsxs(View, { accessibilityRole: "navigation", style: styles.container, children: [start.map(({ id, crumb, isFirst, isLast, isRootCrumb }) => (_jsx(BreadcrumbsItem, { crumb: crumb, isFirstItem: isFirst, isLastItem: isLast, shouldAnimate: !previousCrumbs.has(id) && !isRootCrumb }, id))), collapsed.length > 0 ? _jsx(BreadcrumbsDropdownItems, { crumbs: collapsed }) : null, end.map(({ id, crumb, isLast, isRootCrumb }) => (_jsx(BreadcrumbsItem, { crumb: crumb, isLastItem: isLast, shouldAnimate: !previousCrumbs.has(id) && !isRootCrumb }, id)))] }));
|
|
362
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ReactText } from "react";
|
|
2
|
+
import { GestureResponderEvent, StyleProp, View, ViewStyle } from "react-native";
|
|
3
|
+
import { IconName } from "./Icon";
|
|
4
|
+
type Props = {
|
|
5
|
+
children?: ReactText;
|
|
6
|
+
color?: string;
|
|
7
|
+
disabled?: boolean;
|
|
8
|
+
loading?: boolean;
|
|
9
|
+
icon?: IconName;
|
|
10
|
+
onPress?: (event: GestureResponderEvent) => void;
|
|
11
|
+
size?: "large" | "small";
|
|
12
|
+
style?: StyleProp<ViewStyle>;
|
|
13
|
+
};
|
|
14
|
+
export declare const Button: import("react").MemoExoticComponent<import("react").ForwardRefExoticComponent<Props & import("react").RefAttributes<View>>>;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef, memo } from "react";
|
|
3
|
+
import { ActivityIndicator, Pressable, 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 { isNotNullish, isNullish } from "../utils/nullish";
|
|
8
|
+
import { Icon } from "./Icon";
|
|
9
|
+
import { Space } from "./Space";
|
|
10
|
+
const styles = StyleSheet.create({
|
|
11
|
+
base: {
|
|
12
|
+
alignItems: "center",
|
|
13
|
+
backgroundColor: colors.black,
|
|
14
|
+
borderRadius: 4,
|
|
15
|
+
flexDirection: "row",
|
|
16
|
+
flexShrink: 1,
|
|
17
|
+
height: 48,
|
|
18
|
+
justifyContent: "center",
|
|
19
|
+
overflow: "hidden",
|
|
20
|
+
paddingLeft: 20,
|
|
21
|
+
paddingRight: 20,
|
|
22
|
+
transitionDuration: "150ms",
|
|
23
|
+
transitionProperty: "background-color",
|
|
24
|
+
},
|
|
25
|
+
small: {
|
|
26
|
+
height: 40,
|
|
27
|
+
paddingLeft: 16,
|
|
28
|
+
paddingRight: 16,
|
|
29
|
+
},
|
|
30
|
+
withIcon: {
|
|
31
|
+
paddingLeft: 18,
|
|
32
|
+
},
|
|
33
|
+
withIconSmall: {
|
|
34
|
+
paddingLeft: 14,
|
|
35
|
+
},
|
|
36
|
+
iconOnly: {
|
|
37
|
+
paddingLeft: 13,
|
|
38
|
+
paddingRight: 13,
|
|
39
|
+
},
|
|
40
|
+
iconOnlySmall: {
|
|
41
|
+
paddingLeft: 10,
|
|
42
|
+
paddingRight: 10,
|
|
43
|
+
},
|
|
44
|
+
text: {
|
|
45
|
+
...typography.bodyLarge,
|
|
46
|
+
fontWeight: typography.fontWeights.demi,
|
|
47
|
+
},
|
|
48
|
+
textSmall: {
|
|
49
|
+
...typography.bodySmall,
|
|
50
|
+
fontWeight: typography.fontWeights.demi,
|
|
51
|
+
},
|
|
52
|
+
disabled: {
|
|
53
|
+
cursor: "not-allowed",
|
|
54
|
+
},
|
|
55
|
+
loaderContainer: {
|
|
56
|
+
...StyleSheet.absoluteFillObject,
|
|
57
|
+
alignItems: "center",
|
|
58
|
+
justifyContent: "center",
|
|
59
|
+
},
|
|
60
|
+
});
|
|
61
|
+
export const Button = memo(forwardRef(({ children, color = colors.gray[100], disabled = false, loading = false, icon, onPress, size = "large", style, }, forwardedRef) => {
|
|
62
|
+
const computedColors = useComputedColors(color);
|
|
63
|
+
const isSmall = size === "small";
|
|
64
|
+
const iconSize = isSmall ? 18 : 20;
|
|
65
|
+
return (_jsxs(Pressable, { accessibilityRole: "button", accessibilityBusy: loading, accessibilityDisabled: disabled, disabled: loading || disabled, ref: forwardedRef, onPress: onPress, style: ({ hovered, pressed }) => [
|
|
66
|
+
styles.base,
|
|
67
|
+
isSmall && styles.small,
|
|
68
|
+
isNotNullish(icon) && (isSmall ? styles.withIconSmall : styles.withIcon),
|
|
69
|
+
isNullish(children) && (isSmall ? styles.iconOnlySmall : styles.iconOnly),
|
|
70
|
+
disabled && styles.disabled,
|
|
71
|
+
style,
|
|
72
|
+
{
|
|
73
|
+
backgroundColor: disabled
|
|
74
|
+
? computedColors.disabled
|
|
75
|
+
: pressed
|
|
76
|
+
? computedColors.pressed
|
|
77
|
+
: hovered
|
|
78
|
+
? computedColors.hovered
|
|
79
|
+
: computedColors.original,
|
|
80
|
+
},
|
|
81
|
+
], children: [icon && _jsx(Icon, { color: computedColors.text, name: icon, size: iconSize }), isNotNullish(icon) && isNotNullish(children) && _jsx(Space, { width: isSmall ? 8 : 12 }), _jsx(Text, { numberOfLines: 1, selectable: false, style: [isSmall ? styles.textSmall : styles.text, { color: computedColors.text }], children: children }), loading && (_jsx(View, { accessibilityRole: "none", style: [styles.loaderContainer, { backgroundColor: computedColors.original }], children: _jsx(ActivityIndicator, { color: computedColors.text, size: iconSize }) }))] }));
|
|
82
|
+
}));
|
|
83
|
+
Button.displayName = "Button";
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ReactText } from "react";
|
|
2
|
+
import { Text, TextProps } from "react-native";
|
|
3
|
+
export declare const Caption: import("react").ForwardRefExoticComponent<TextProps & {
|
|
4
|
+
align?: "center" | "left" | "right" | undefined;
|
|
5
|
+
children: ReactText;
|
|
6
|
+
} & import("react").RefAttributes<Text>>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef } from "react";
|
|
3
|
+
import { StyleSheet, Text } from "react-native";
|
|
4
|
+
import { typography } from "../constants/typography";
|
|
5
|
+
/* eslint-disable react-native/no-unused-styles */
|
|
6
|
+
const styles = StyleSheet.create({
|
|
7
|
+
center: { ...typography.caption, textAlign: "center" },
|
|
8
|
+
left: { ...typography.caption, textAlign: "left" },
|
|
9
|
+
right: { ...typography.caption, textAlign: "right" },
|
|
10
|
+
});
|
|
11
|
+
export const Caption = forwardRef(({ children, align = "left", style, ...props }, forwardedRef) => (_jsx(Text, { ref: forwardedRef, style: [styles[align], style], ...props, children: children })));
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ReactNode } from "react";
|
|
2
|
+
import { StyleProp, View, ViewStyle } from "react-native";
|
|
3
|
+
type Props = {
|
|
4
|
+
children?: ReactNode;
|
|
5
|
+
disabled?: boolean;
|
|
6
|
+
error?: string;
|
|
7
|
+
style?: StyleProp<ViewStyle>;
|
|
8
|
+
value: boolean;
|
|
9
|
+
onValueChange?: (value: boolean) => void;
|
|
10
|
+
};
|
|
11
|
+
export declare const CheckBox: import("react").MemoExoticComponent<import("react").ForwardRefExoticComponent<Props & import("react").RefAttributes<View>>>;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef, memo, useId, useRef } from "react";
|
|
3
|
+
import { StyleSheet, Text, unstable_createElement as createElement, View, } from "react-native";
|
|
4
|
+
import { colors } from "../constants/colors";
|
|
5
|
+
import { typography } from "../constants/typography";
|
|
6
|
+
import { useNativeProp } from "../hooks/useNativeProp";
|
|
7
|
+
import { isNotNullish } from "../utils/nullish";
|
|
8
|
+
import { Icon } from "./Icon";
|
|
9
|
+
import { Pressable } from "./Pressable";
|
|
10
|
+
import { Space } from "./Space";
|
|
11
|
+
const styles = StyleSheet.create({
|
|
12
|
+
base: {
|
|
13
|
+
flexDirection: "row",
|
|
14
|
+
flexShrink: 1,
|
|
15
|
+
},
|
|
16
|
+
box: {
|
|
17
|
+
alignItems: "center",
|
|
18
|
+
borderColor: colors.gray[10],
|
|
19
|
+
borderRadius: 4,
|
|
20
|
+
borderWidth: 1,
|
|
21
|
+
height: 20,
|
|
22
|
+
justifyContent: "center",
|
|
23
|
+
padding: 4,
|
|
24
|
+
transitionDuration: "150ms",
|
|
25
|
+
transitionProperty: "border-color",
|
|
26
|
+
width: 20,
|
|
27
|
+
},
|
|
28
|
+
native: {
|
|
29
|
+
...StyleSheet.absoluteFillObject,
|
|
30
|
+
appearance: "none",
|
|
31
|
+
borderColor: colors.transparent,
|
|
32
|
+
cursor: "inherit",
|
|
33
|
+
height: "100%",
|
|
34
|
+
margin: 0,
|
|
35
|
+
padding: 0,
|
|
36
|
+
width: "100%",
|
|
37
|
+
},
|
|
38
|
+
icon: {
|
|
39
|
+
opacity: 0,
|
|
40
|
+
animationKeyframes: {
|
|
41
|
+
from: { opacity: 0 },
|
|
42
|
+
to: { opacity: 1 },
|
|
43
|
+
},
|
|
44
|
+
animationDuration: "0.25s",
|
|
45
|
+
animationFillMode: "forwards",
|
|
46
|
+
animationTimingFunction: "ease",
|
|
47
|
+
},
|
|
48
|
+
hovered: {
|
|
49
|
+
borderColor: colors.gray[30],
|
|
50
|
+
},
|
|
51
|
+
disabled: {
|
|
52
|
+
cursor: "not-allowed",
|
|
53
|
+
backgroundColor: colors.gray[3],
|
|
54
|
+
},
|
|
55
|
+
errored: {
|
|
56
|
+
borderColor: colors.red[100],
|
|
57
|
+
},
|
|
58
|
+
label: {
|
|
59
|
+
...typography.bodyLarge,
|
|
60
|
+
lineHeight: typography.lineHeights.title,
|
|
61
|
+
},
|
|
62
|
+
});
|
|
63
|
+
export const CheckBox = memo(forwardRef(({ children, disabled = false, error = "", style, value, onValueChange }, forwardedRef) => {
|
|
64
|
+
const ref = useRef(null);
|
|
65
|
+
const id = useId();
|
|
66
|
+
useNativeProp(ref, "for", id);
|
|
67
|
+
return (_jsxs(View, { style: [styles.base, style], children: [_jsxs(Pressable, { ref: forwardedRef, accessibilityRole: "checkbox", focusable: false, accessibilityChecked: value, accessibilityDisabled: disabled, style: ({ hovered }) => [
|
|
68
|
+
styles.box,
|
|
69
|
+
disabled && styles.disabled,
|
|
70
|
+
!disabled && error !== "" && styles.errored,
|
|
71
|
+
!disabled && error === "" && hovered && styles.hovered,
|
|
72
|
+
], children: [createElement("input", {
|
|
73
|
+
checked: value,
|
|
74
|
+
disabled,
|
|
75
|
+
id,
|
|
76
|
+
style: styles.native,
|
|
77
|
+
type: "checkbox",
|
|
78
|
+
onChange: () => {
|
|
79
|
+
!disabled && onValueChange?.(!value);
|
|
80
|
+
},
|
|
81
|
+
}), value && (_jsx(Icon, { name: "checkmark-filled", color: disabled ? colors.gray[50] : colors.green[100], size: 16, style: styles.icon }))] }), isNotNullish(children) && (_jsxs(_Fragment, { children: [_jsx(Space, { width: 12 }), _jsx(Text, { accessibilityRole: "label", ref: ref, style: styles.label, children: children })] }))] }));
|
|
82
|
+
}));
|
|
83
|
+
CheckBox.displayName = "CheckBox";
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ReactNode } from "react";
|
|
2
|
+
type Props<T> = {
|
|
3
|
+
items: T[];
|
|
4
|
+
large?: boolean;
|
|
5
|
+
renderItem: (value: T) => ReactNode;
|
|
6
|
+
value?: T;
|
|
7
|
+
getId?: (item: T) => unknown;
|
|
8
|
+
onChange: (value: T) => void;
|
|
9
|
+
};
|
|
10
|
+
export declare const ChoicePicker: <T>({ items, getId, large, renderItem, value, onChange, }: Props<T>) => JSX.Element;
|
|
11
|
+
export {};
|