@draftbit/core 43.4.10 → 43.4.11-776ef8.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 (186) hide show
  1. package/lib/commonjs/components/FAB.js +19 -5
  2. package/lib/commonjs/components/FAB.js.map +1 -1
  3. package/lib/commonjs/components/FieldSearchBarFull.js.map +1 -1
  4. package/lib/commonjs/components/Justification.js +3 -0
  5. package/lib/commonjs/components/ResizeMode.js +3 -0
  6. package/lib/commonjs/mappings/Icon.js +3 -1
  7. package/lib/commonjs/mappings/Icon.js.map +1 -1
  8. package/lib/commonjs/mappings/RowHeadlineImageCaption.js.map +1 -1
  9. package/lib/commonjs/mappings/RowHeadlineImageIcon.js.map +1 -1
  10. package/lib/module/components/Justification.js +1 -1
  11. package/lib/module/components/ResizeMode.js +1 -1
  12. package/lib/module/mappings/Icon.js +3 -1
  13. package/lib/module/mappings/Icon.js.map +1 -1
  14. package/lib/typescript/src/mappings/Icon.d.ts +1 -1
  15. package/package.json +2 -2
  16. package/src/Provider.js +9 -0
  17. package/src/components/Accordion/AccordionGroup.js +44 -0
  18. package/src/components/Accordion/AccordionItem.js +32 -0
  19. package/src/components/Accordion/index.js +2 -0
  20. package/src/components/ActionSheet/ActionSheet.js +45 -0
  21. package/src/components/ActionSheet/ActionSheetCancel.js +6 -0
  22. package/src/components/ActionSheet/ActionSheetItem.js +30 -0
  23. package/src/components/ActionSheet/index.js +3 -0
  24. package/src/components/AnimatedCircularProgress.js +43 -0
  25. package/src/components/AspectRatio.js +18 -0
  26. package/src/components/AvatarEdit.js +30 -0
  27. package/src/components/Button.js +112 -0
  28. package/src/components/Card.js +57 -0
  29. package/src/components/CardBlock.js +54 -0
  30. package/src/components/CardContainer.js +69 -0
  31. package/src/components/CardContainerRating.js +79 -0
  32. package/src/components/CardContainerShortImage.js +33 -0
  33. package/src/components/CardInline.js +36 -0
  34. package/src/components/Carousel.js +66 -0
  35. package/src/components/Checkbox/Checkbox.js +63 -0
  36. package/src/components/Checkbox/CheckboxGroup.js +21 -0
  37. package/src/components/Checkbox/CheckboxRow.js +77 -0
  38. package/src/components/Checkbox/context.js +14 -0
  39. package/src/components/Checkbox/index.js +3 -0
  40. package/src/components/CircleImage.js +8 -0
  41. package/src/components/CircularProgress.js +78 -0
  42. package/src/components/Config.js +63 -0
  43. package/src/components/Container.js +44 -0
  44. package/src/components/DatePicker/DatePicker.js +370 -0
  45. package/src/components/DatePicker/DatePickerComponent.js +13 -0
  46. package/src/components/DatePicker/DatePickerComponent.web.js +30 -0
  47. package/src/components/DatePicker/DatePickerComponentType.js +1 -0
  48. package/src/components/DeprecatedButton.js +95 -0
  49. package/src/components/DeprecatedCardWrapper.js +18 -0
  50. package/src/components/DeprecatedFAB.js +115 -0
  51. package/src/components/Divider.js +13 -0
  52. package/src/components/Elevation.js +20 -0
  53. package/src/components/FAB.js +46 -0
  54. package/src/components/FieldSearchBarFull.js +53 -0
  55. package/src/components/FormRow.js +19 -0
  56. package/src/components/Header.js +44 -0
  57. package/src/components/HeaderLarge.js +7 -0
  58. package/src/components/HeaderMedium.js +7 -0
  59. package/src/components/HeaderOverline.js +7 -0
  60. package/src/components/IconButton.js +35 -0
  61. package/src/components/Image.js +47 -0
  62. package/src/components/Justification.js +1 -0
  63. package/src/components/Layout.js +50 -0
  64. package/src/components/NumberInput.js +50 -0
  65. package/src/components/Picker/Picker.js +56 -0
  66. package/src/components/Picker/PickerComponent.android.js +68 -0
  67. package/src/components/Picker/PickerComponent.ios.js +78 -0
  68. package/src/components/Picker/PickerComponent.web.js +69 -0
  69. package/src/components/Picker/PickerTypes.js +1 -0
  70. package/src/components/Portal/Portal.js +35 -0
  71. package/src/components/Portal/PortalConsumer.js +28 -0
  72. package/src/components/Portal/PortalHost.js +105 -0
  73. package/src/components/Portal/PortalManager.js +29 -0
  74. package/src/components/ProgressBar.js +118 -0
  75. package/src/components/ProgressCircle.js +13 -0
  76. package/src/components/ProgressIndicator.js +27 -0
  77. package/src/components/RadioButton/RadioButton.js +17 -0
  78. package/src/components/RadioButton/RadioButtonFieldGroup.js +17 -0
  79. package/src/components/RadioButton/RadioButtonGroup.js +39 -0
  80. package/src/components/RadioButton/RadioButtonRow.js +76 -0
  81. package/src/components/RadioButton/context.js +14 -0
  82. package/src/components/RadioButton/index.js +4 -0
  83. package/src/components/ResizeMode.js +1 -0
  84. package/src/components/Row.js +48 -0
  85. package/src/components/RowBodyIcon.js +8 -0
  86. package/src/components/RowHeadlineImageCaption.js +12 -0
  87. package/src/components/RowHeadlineImageIcon.js +14 -0
  88. package/src/components/ScreenContainer.js +35 -0
  89. package/src/components/Slider.js +63 -0
  90. package/src/components/StarRating.js +50 -0
  91. package/src/components/StepIndicator.js +346 -0
  92. package/src/components/Stepper.js +53 -0
  93. package/src/components/Surface.js +23 -0
  94. package/src/components/Swiper/Swiper.js +18 -0
  95. package/src/components/Swiper/SwiperItem.js +9 -0
  96. package/src/components/Swiper/index.js +2 -0
  97. package/src/components/Switch.js +56 -0
  98. package/src/components/Text.js +28 -0
  99. package/src/components/TextField.js +419 -0
  100. package/src/components/ToggleButton.js +39 -0
  101. package/src/components/Touchable.js +12 -0
  102. package/src/components/Touchable.web.js +2 -0
  103. package/src/components/Typography.js +36 -0
  104. package/src/components/useAuthState.js +31 -0
  105. package/src/constants.js +10 -0
  106. package/src/hooks.js +12 -0
  107. package/src/index.js +50 -0
  108. package/src/interfaces/Icon.js +8 -0
  109. package/src/mappings/Accordion.js +37 -0
  110. package/src/mappings/AccordionItem.js +16 -0
  111. package/src/mappings/ActionSheet.js +13 -0
  112. package/src/mappings/ActionSheetCancel.js +19 -0
  113. package/src/mappings/ActionSheetItem.js +22 -0
  114. package/src/mappings/ActivityIndicator.js +53 -0
  115. package/src/mappings/AudioPlayer.js +20 -0
  116. package/src/mappings/AvatarEdit.js +37 -0
  117. package/src/mappings/BlurView.js +41 -0
  118. package/src/mappings/Button.js +56 -0
  119. package/src/mappings/Card.js +52 -0
  120. package/src/mappings/CardBlock.js +122 -0
  121. package/src/mappings/CardContainer.js +102 -0
  122. package/src/mappings/CardContainerRating.js +124 -0
  123. package/src/mappings/CardContainerShortImage.js +118 -0
  124. package/src/mappings/CardInline.js +51 -0
  125. package/src/mappings/Carousel.js +18 -0
  126. package/src/mappings/Checkbox.js +45 -0
  127. package/src/mappings/CheckboxGroup.js +25 -0
  128. package/src/mappings/CheckboxRow.js +37 -0
  129. package/src/mappings/CircleImage.js +24 -0
  130. package/src/mappings/Container.js +29 -0
  131. package/src/mappings/CustomCode.js +8 -0
  132. package/src/mappings/DatePicker.js +146 -0
  133. package/src/mappings/Divider.js +26 -0
  134. package/src/mappings/FAB.js +36 -0
  135. package/src/mappings/Fetch.js +12 -0
  136. package/src/mappings/FieldSearchBarFull.js +49 -0
  137. package/src/mappings/FlatList.js +19 -0
  138. package/src/mappings/HeaderLarge.js +28 -0
  139. package/src/mappings/HeaderMedium.js +54 -0
  140. package/src/mappings/HeaderOverline.js +54 -0
  141. package/src/mappings/Icon.js +25 -0
  142. package/src/mappings/Icon.ts +4 -1
  143. package/src/mappings/IconButton.js +30 -0
  144. package/src/mappings/Image.js +15 -0
  145. package/src/mappings/ImageBackground.js +28 -0
  146. package/src/mappings/KeyboardAvoidingView.js +40 -0
  147. package/src/mappings/Layout.js +195 -0
  148. package/src/mappings/LinearGradient.js +77 -0
  149. package/src/mappings/MapCallout.js +19 -0
  150. package/src/mappings/MapMarker.js +46 -0
  151. package/src/mappings/Modal.js +41 -0
  152. package/src/mappings/Picker.js +137 -0
  153. package/src/mappings/ProgressBar.js +100 -0
  154. package/src/mappings/ProgressCircle.js +108 -0
  155. package/src/mappings/ProgressIndicator.js +180 -0
  156. package/src/mappings/RadioButton.js +50 -0
  157. package/src/mappings/RadioButtonGroup.js +16 -0
  158. package/src/mappings/RadioButtonRow.js +37 -0
  159. package/src/mappings/RowBodyIcon.js +75 -0
  160. package/src/mappings/RowHeadlineImageCaption.js +167 -0
  161. package/src/mappings/RowHeadlineImageIcon.js +99 -0
  162. package/src/mappings/SafeAreaView.js +33 -0
  163. package/src/mappings/ScrollView.js +30 -0
  164. package/src/mappings/Slider.js +59 -0
  165. package/src/mappings/StarRating.js +46 -0
  166. package/src/mappings/Stepper.js +28 -0
  167. package/src/mappings/Surface.js +13 -0
  168. package/src/mappings/Swiper.js +60 -0
  169. package/src/mappings/SwiperItem.js +8 -0
  170. package/src/mappings/Switch.js +75 -0
  171. package/src/mappings/Text.js +227 -0
  172. package/src/mappings/TextArea.js +52 -0
  173. package/src/mappings/TextField.js +158 -0
  174. package/src/mappings/TextInput.js +208 -0
  175. package/src/mappings/ToggleButton.js +50 -0
  176. package/src/mappings/Touchable.js +12 -0
  177. package/src/mappings/Video.js +74 -0
  178. package/src/mappings/View.js +206 -0
  179. package/src/mappings/WebView.js +13 -0
  180. package/src/styles/DarkTheme.js +26 -0
  181. package/src/styles/DefaultTheme.js +111 -0
  182. package/src/styles/fonts.js +62 -0
  183. package/src/styles/overlay.js +60 -0
  184. package/src/styles/shadow.js +51 -0
  185. package/src/theming.js +3 -0
  186. package/src/utilities.js +54 -0
@@ -0,0 +1,77 @@
1
+ import * as React from "react";
2
+ import { StyleSheet, View, Platform, } from "react-native";
3
+ import Checkbox from "./Checkbox";
4
+ import Text from "../Text";
5
+ import { useCheckboxGroupContext } from "./context";
6
+ import { Direction as GroupDirection } from "./context";
7
+ import Touchable from "../Touchable";
8
+ import { extractStyles } from "../../utilities";
9
+ export var Direction;
10
+ (function (Direction) {
11
+ Direction["Row"] = "row";
12
+ Direction["RowReverse"] = "row-reverse";
13
+ })(Direction || (Direction = {}));
14
+ const getCheckboxAlignment = (parentDirection, direction) => {
15
+ if (parentDirection === GroupDirection.Horizontal) {
16
+ return direction === Direction.Row ? "flex-start" : "flex-end";
17
+ }
18
+ else if (direction === Direction.RowReverse) {
19
+ return "flex-start";
20
+ }
21
+ else {
22
+ return "flex-end";
23
+ }
24
+ };
25
+ const renderLabel = (value, labelStyle, textStyle) => {
26
+ if (typeof value === "string") {
27
+ return React.createElement(Text, { style: [labelStyle, textStyle] }, value);
28
+ }
29
+ else {
30
+ return React.createElement(React.Fragment, null, value);
31
+ }
32
+ };
33
+ const CheckboxRow = ({ Icon, label = "Label", status, value, onPress = () => { }, labelContainerStyle, labelStyle, checkboxStyle, direction = Direction.Row, disabled, style, color, uncheckedColor, ...rest }) => {
34
+ const { values: selectedValues, onValueChange, direction: parentDirection, } = useCheckboxGroupContext();
35
+ const values = Array.isArray(selectedValues) ? selectedValues : [];
36
+ const isChecked = status || values.includes(value);
37
+ const handlePress = () => {
38
+ if (!disabled) {
39
+ onPress(!isChecked);
40
+ onValueChange && onValueChange(value, !isChecked);
41
+ }
42
+ };
43
+ const { textStyles, viewStyles } = extractStyles(style);
44
+ return (React.createElement(Touchable, { onPress: handlePress, style: [styles.mainParent, { flexDirection: direction }, viewStyles], disabled: disabled, ...rest },
45
+ React.createElement(View, { style: [
46
+ styles.label,
47
+ {
48
+ alignItems: direction === Direction.Row ? "flex-start" : "flex-end",
49
+ },
50
+ labelContainerStyle,
51
+ ] }, renderLabel(label, labelStyle, textStyles)),
52
+ React.createElement(View, { style: {
53
+ flex: 1,
54
+ alignItems: getCheckboxAlignment(parentDirection, direction),
55
+ } },
56
+ React.createElement(Checkbox, { Icon: Icon, status: isChecked, onPress: handlePress, style: checkboxStyle, disabled: disabled, color: color, uncheckedColor: uncheckedColor }))));
57
+ };
58
+ const styles = StyleSheet.create({
59
+ mainParent: {
60
+ alignItems: "center",
61
+ justifyContent: "space-around",
62
+ paddingStart: 20,
63
+ minHeight: 50,
64
+ paddingEnd: 20,
65
+ flex: 1,
66
+ ...Platform.select({
67
+ web: {
68
+ cursor: "pointer",
69
+ userSelect: "none",
70
+ },
71
+ }),
72
+ },
73
+ label: {
74
+ flex: 3,
75
+ },
76
+ });
77
+ export default CheckboxRow;
@@ -0,0 +1,14 @@
1
+ import { createContext, useContext } from "react";
2
+ export var Direction;
3
+ (function (Direction) {
4
+ Direction["Horizontal"] = "horizontal";
5
+ Direction["Vertical"] = "vertical";
6
+ })(Direction || (Direction = {}));
7
+ export const checkboxGroupContext = createContext({
8
+ onValueChange: () => { },
9
+ values: [],
10
+ direction: undefined,
11
+ });
12
+ export function useCheckboxGroupContext() {
13
+ return useContext(checkboxGroupContext);
14
+ }
@@ -0,0 +1,3 @@
1
+ export { default as Checkbox } from "./Checkbox";
2
+ export { default as CheckboxGroup } from "./CheckboxGroup";
3
+ export { default as CheckboxRow } from "./CheckboxRow";
@@ -0,0 +1,8 @@
1
+ import * as React from "react";
2
+ import { Image, } from "react-native";
3
+ import Config from "./Config";
4
+ const CircleImage = ({ source = Config.placeholderImageURL, size = 60, style, ...props }) => {
5
+ const borderRadius = size / 2;
6
+ return (React.createElement(Image, { style: [{ width: size, height: size, borderRadius }, style], source: typeof source === "string" ? { uri: source } : source, resizeMode: "cover", ...props }));
7
+ };
8
+ export default CircleImage;
@@ -0,0 +1,78 @@
1
+ import React from "react";
2
+ import { View } from "react-native";
3
+ import { Svg, Path, G } from "react-native-svg";
4
+ class CircularProgress extends React.Component {
5
+ polarToCartesian = (centerX, centerY, radius, angleInDegrees) => {
6
+ var angleInRadians = ((angleInDegrees - 90) * Math.PI) / 180.0;
7
+ return {
8
+ x: centerX + radius * Math.cos(angleInRadians),
9
+ y: centerY + radius * Math.sin(angleInRadians),
10
+ };
11
+ };
12
+ circlePath = (x, y, radius, startAngle, endAngle) => {
13
+ var start = this.polarToCartesian(x, y, radius, endAngle * 0.9999);
14
+ var end = this.polarToCartesian(x, y, radius, startAngle);
15
+ var largeArcFlag = endAngle - startAngle <= 180 ? "0" : "1";
16
+ var d = [
17
+ "M",
18
+ start.x,
19
+ start.y,
20
+ "A",
21
+ radius,
22
+ radius,
23
+ 0,
24
+ largeArcFlag,
25
+ 0,
26
+ end.x,
27
+ end.y,
28
+ ];
29
+ return d.join(" ");
30
+ };
31
+ clampFill = (fill) => Math.min(100, Math.max(0, fill));
32
+ render() {
33
+ const { size, width, backgroundWidth, tintColor = "black", tintTransparency = true, backgroundColor, style, rotation = 90, lineCap = "butt", arcSweepAngle = 360, fill, children, childrenContainerStyle, padding = 0, renderCap, dashedBackground = { width: 0, gap: 0 }, dashedTint = { width: 0, gap: 0 }, } = this.props;
34
+ const maxWidthCircle = backgroundWidth
35
+ ? Math.max(width, backgroundWidth)
36
+ : width;
37
+ const sizeWithPadding = size / 2 + padding / 2;
38
+ const radius = size / 2 - maxWidthCircle / 2 - padding / 2;
39
+ const currentFillAngle = (arcSweepAngle * this.clampFill(fill)) / 100;
40
+ const backgroundPath = this.circlePath(sizeWithPadding, sizeWithPadding, radius, tintTransparency ? 0 : currentFillAngle, arcSweepAngle);
41
+ const circlePathItem = this.circlePath(sizeWithPadding, sizeWithPadding, radius, 0, currentFillAngle);
42
+ const coordinate = this.polarToCartesian(sizeWithPadding, sizeWithPadding, radius, currentFillAngle);
43
+ const cap = renderCap ? renderCap({ center: coordinate }) : null;
44
+ const offset = size - maxWidthCircle * 2;
45
+ const localChildrenContainerStyle = [
46
+ {
47
+ position: "absolute",
48
+ left: maxWidthCircle + padding / 2,
49
+ top: maxWidthCircle + padding / 2,
50
+ width: offset,
51
+ height: offset,
52
+ borderRadius: offset / 2,
53
+ alignItems: "center",
54
+ justifyContent: "center",
55
+ overflow: "hidden",
56
+ },
57
+ childrenContainerStyle,
58
+ ];
59
+ const strokeDasharrayTint = dashedTint.gap > 0
60
+ ? Object.values(dashedTint)
61
+ .map((value) => value.toString())
62
+ .join(" ")
63
+ : "";
64
+ const strokeDasharrayBackground = dashedBackground.gap > 0
65
+ ? Object.values(dashedBackground)
66
+ .map((value) => value.toString())
67
+ .join(" ")
68
+ : "";
69
+ return (React.createElement(View, { style: style },
70
+ React.createElement(Svg, { width: size + padding, height: size + padding },
71
+ React.createElement(G, { rotation: rotation, originX: (size + padding) / 2, originY: (size + padding) / 2 },
72
+ backgroundColor && (React.createElement(Path, { d: backgroundPath, stroke: backgroundColor, strokeWidth: backgroundWidth || width, strokeLinecap: lineCap, strokeDasharray: strokeDasharrayBackground, fill: "transparent" })),
73
+ fill > 0 && (React.createElement(Path, { d: circlePathItem, stroke: tintColor, strokeWidth: width, strokeLinecap: lineCap, strokeDasharray: strokeDasharrayTint, fill: "transparent" })),
74
+ cap)),
75
+ children && (React.createElement(View, { style: localChildrenContainerStyle }, children(fill)))));
76
+ }
77
+ }
78
+ export default CircularProgress;
@@ -0,0 +1,63 @@
1
+ import { Dimensions, Platform } from "react-native";
2
+ const getWindowDimensions = () => {
3
+ const { width, height } = Dimensions.get("window");
4
+ return {
5
+ windowWidth: width,
6
+ windowHeight: height,
7
+ };
8
+ };
9
+ const { windowWidth, windowHeight } = getWindowDimensions();
10
+ const getFilters = (options) => {
11
+ const { width, height } = options;
12
+ const filters = ["c_scale", "q_auto", "dpr_auto"];
13
+ if (width)
14
+ filters.push(`w_${width}`);
15
+ if (height)
16
+ filters.push(`h_${height}`);
17
+ return filters.join(",");
18
+ };
19
+ const buildImageUrl = (options, name) => {
20
+ const filters = getFilters(options);
21
+ return [
22
+ "https://res.cloudinary.com/altos/image/upload",
23
+ filters,
24
+ `${name}.png`,
25
+ ].join("/");
26
+ };
27
+ const getExtension = () => {
28
+ return Platform.OS === "web" ? ".svg" : ".png";
29
+ };
30
+ export default {
31
+ windowWidth,
32
+ windowHeight,
33
+ avatarImageUrl: buildImageUrl({
34
+ width: 60,
35
+ height: 60,
36
+ }, "Avatar"),
37
+ avatarImageSize: 60,
38
+ cardImageSize: 200,
39
+ cardImageUrl: "https://static.draftbit.com/images/placeholder-image" + getExtension(),
40
+ cardIconSize: 16,
41
+ cardIconBackgroundOpacity: 0.24,
42
+ cardIconElevation: 1,
43
+ placeholderImageURL: "https://static.draftbit.com/images/placeholder-image" + getExtension(),
44
+ getPlaceholderImageUrl: (size) => buildImageUrl({ width: size.width, height: size.height }, "image-placeholder_1"),
45
+ squareImageUrl: buildImageUrl({ width: 100, height: 100 }, "Avatar"),
46
+ FABSize: 40,
47
+ FABBorderRadius: 20,
48
+ FABFixedHeight: 64,
49
+ cardContainerShortImageAspectRatio: 1,
50
+ rowSingleLineImageSize: 24,
51
+ rowMultiLineImageSize: 48,
52
+ rowSingleLineIconSize: 24,
53
+ rowMultiLineIconSize: 16,
54
+ headerIconSize: 24,
55
+ buttonIconSize: 24,
56
+ swiperInactiveDotSize: 6,
57
+ swiperActiveDotSize: 10,
58
+ fieldSearchBarFullIconSize: 24,
59
+ stepperButtonSize: 40,
60
+ radioButtonSize: 24,
61
+ topSafeAreaViewHeight: 0,
62
+ // topSafeAreaViewHeight: Platform.OS === "android" ? Constants.statusBarHeight : 0
63
+ };
@@ -0,0 +1,44 @@
1
+ import * as React from "react";
2
+ import { View, ImageBackground, StyleSheet, } from "react-native";
3
+ import { withTheme } from "../theming";
4
+ import Elevation from "./Elevation";
5
+ const Container = ({ useThemeGutterPadding, borderColor, borderWidth, backgroundColor, backgroundImage, backgroundImageResizeMode, elevation, style, children, theme, // eslint-disable-line @typescript-eslint/no-unused-vars
6
+ ...rest }) => {
7
+ const { flex, flexGrow, flexWrap, flexBasis, flexShrink, flexDirection, alignContent, justifyContent, alignItems, padding, paddingTop, paddingBottom, paddingLeft, paddingRight, paddingVertical, paddingHorizontal, ...styleProp } = StyleSheet.flatten(style) || {};
8
+ const containerStyle = {
9
+ backgroundColor,
10
+ borderColor,
11
+ borderWidth,
12
+ width: "100%",
13
+ ...styleProp,
14
+ };
15
+ const innerStyle = {
16
+ flex,
17
+ flexGrow,
18
+ flexWrap,
19
+ flexBasis,
20
+ flexShrink,
21
+ flexDirection,
22
+ alignContent,
23
+ justifyContent,
24
+ alignItems,
25
+ padding,
26
+ paddingTop,
27
+ paddingBottom,
28
+ paddingLeft,
29
+ paddingRight,
30
+ paddingVertical,
31
+ paddingHorizontal: paddingHorizontal || useThemeGutterPadding ? 16 : 0,
32
+ };
33
+ const Wrap = elevation ? Elevation : View;
34
+ if (elevation) {
35
+ containerStyle.elevation = elevation;
36
+ }
37
+ return (React.createElement(Wrap, { style: [containerStyle, style], ...rest }, backgroundImage ? (React.createElement(ImageBackground, { source: typeof backgroundImage === "string"
38
+ ? { uri: backgroundImage }
39
+ : backgroundImage, resizeMode: backgroundImageResizeMode, style: {
40
+ flex: 1,
41
+ } },
42
+ React.createElement(View, { style: innerStyle }, children))) : (React.createElement(View, { style: innerStyle }, children))));
43
+ };
44
+ export default withTheme(Container);
@@ -0,0 +1,370 @@
1
+ import * as React from "react";
2
+ import { View, Animated, Text, StyleSheet, Platform, I18nManager, TextInput as NativeTextInput, } from "react-native";
3
+ import { useSafeAreaInsets } from "react-native-safe-area-context";
4
+ import dateFormat from "dateformat";
5
+ import { withTheme } from "../../theming";
6
+ import Portal from "../Portal/Portal";
7
+ import Button from "../DeprecatedButton";
8
+ import Touchable from "../Touchable";
9
+ import DateTimePicker from "./DatePickerComponent";
10
+ const AnimatedText = Animated.createAnimatedComponent(Text);
11
+ const FOCUS_ANIMATION_DURATION = 150;
12
+ const BLUR_ANIMATION_DURATION = 180;
13
+ const ICON_SIZE = 24;
14
+ const MONTHS = [
15
+ "January",
16
+ "February",
17
+ "March",
18
+ "April",
19
+ "May",
20
+ "June",
21
+ "July",
22
+ "August",
23
+ "September",
24
+ "October",
25
+ "November",
26
+ "December",
27
+ ];
28
+ const DatePicker = ({ Icon, style, theme: { colors, typography, roundness, disabledOpacity }, date, onDateChange = () => { }, defaultValue, disabled = false, mode = "date", format, type = "underline", leftIconName, rightIconName, leftIconMode = "inset", label, placeholder, ...props }) => {
29
+ const [value, setValue] = React.useState(date || defaultValue);
30
+ React.useEffect(() => {
31
+ if (defaultValue != null) {
32
+ setValue(defaultValue);
33
+ }
34
+ }, [defaultValue]);
35
+ const [pickerVisible, setPickerVisible] = React.useState(false);
36
+ const [labeled] = React.useState(new Animated.Value(date ? 0 : 1));
37
+ const [placeholder1, setPlaceholder1] = React.useState("");
38
+ const [focused, setFocused] = React.useState(false);
39
+ const [labelLayout, setLabelLayout] = React.useState({ measured: false, width: 0 });
40
+ const getValidDate = () => {
41
+ if (!value) {
42
+ return new Date();
43
+ }
44
+ return typeof value?.getMonth === "function" ? value : new Date();
45
+ };
46
+ const formatDate = () => {
47
+ if (!value)
48
+ return "";
49
+ let newDate = getValidDate();
50
+ if (format)
51
+ return dateFormat(newDate, format);
52
+ if (mode === "time") {
53
+ return `${newDate.toLocaleTimeString()}`;
54
+ }
55
+ if (mode === "datetime") {
56
+ return `${newDate.toLocaleString()}`;
57
+ }
58
+ return `${MONTHS[newDate.getMonth()]} ${newDate.getDate()}, ${newDate.getFullYear()}`;
59
+ };
60
+ const toggleVisibility = async () => {
61
+ setPickerVisible(!pickerVisible);
62
+ focused ? _handleBlur() : _handleFocus();
63
+ };
64
+ const insets = useSafeAreaInsets();
65
+ // const _restoreLabel = () =>
66
+ // Animated.timing(labeled, {
67
+ // toValue: 1,
68
+ // duration: FOCUS_ANIMATION_DURATION,
69
+ // useNativeDriver: true,
70
+ // }).start();
71
+ // const _minmizeLabel = () =>
72
+ // Animated.timing(labeled, {
73
+ // toValue: 0,
74
+ // duration: BLUR_ANIMATION_DURATION,
75
+ // useNativeDriver: true,
76
+ // }).start();
77
+ // const _showPlaceholder = () =>
78
+ // setTimeout(() => setPlaceholder1(placeholder || ""), 50);
79
+ const _hidePlaceholder = () => {
80
+ setPlaceholder1("");
81
+ };
82
+ React.useEffect(() => {
83
+ setValue(date);
84
+ }, [date]);
85
+ React.useEffect(() => {
86
+ if (value || focused || placeholder1) {
87
+ // _minmizeLabel();
88
+ Animated.timing(labeled, {
89
+ toValue: 0,
90
+ duration: BLUR_ANIMATION_DURATION,
91
+ useNativeDriver: true,
92
+ }).start();
93
+ }
94
+ else {
95
+ // _restoreLabel();
96
+ Animated.timing(labeled, {
97
+ toValue: 1,
98
+ duration: FOCUS_ANIMATION_DURATION,
99
+ useNativeDriver: true,
100
+ }).start();
101
+ }
102
+ }, [value, focused, placeholder1, labeled]);
103
+ React.useEffect(() => {
104
+ const _showPlaceholder = () => setTimeout(() => setPlaceholder1(placeholder || ""), 50);
105
+ if (focused || !label) {
106
+ _showPlaceholder();
107
+ }
108
+ else {
109
+ _hidePlaceholder();
110
+ }
111
+ return () => {
112
+ clearTimeout(_showPlaceholder());
113
+ };
114
+ }, [focused, label, placeholder]);
115
+ const _handleFocus = () => {
116
+ if (disabled) {
117
+ return;
118
+ }
119
+ setFocused(true);
120
+ };
121
+ const _handleBlur = () => {
122
+ if (disabled) {
123
+ return;
124
+ }
125
+ setFocused(false);
126
+ };
127
+ const MINIMIZED_LABEL_Y_OFFSET = -(typography.caption.lineHeight + 4);
128
+ const OUTLINE_MINIMIZED_LABEL_Y_OFFSET = -(16 * 0.5 + 4);
129
+ const MAXIMIZED_LABEL_FONT_SIZE = typography.subtitle1.fontSize;
130
+ const MINIMIZED_LABEL_FONT_SIZE = typography.caption.fontSize;
131
+ const hasActiveOutline = focused;
132
+ let inputTextColor, activeColor, underlineColor, borderColor, placeholderColor, containerStyle, backgroundColor, inputStyle;
133
+ inputTextColor = colors.strong;
134
+ if (disabled) {
135
+ activeColor = colors.light;
136
+ placeholderColor = colors.light;
137
+ borderColor = "transparent";
138
+ underlineColor = "transparent";
139
+ backgroundColor = colors.divider;
140
+ }
141
+ else {
142
+ activeColor = colors.primary;
143
+ placeholderColor = borderColor = colors.light;
144
+ underlineColor = colors.light;
145
+ backgroundColor = colors.background;
146
+ }
147
+ const { lineHeight, ...subtitle1 } = typography.subtitle1;
148
+ inputStyle = {
149
+ paddingVertical: 0,
150
+ color: inputTextColor,
151
+ paddingLeft: leftIconName && leftIconMode === "inset"
152
+ ? ICON_SIZE + (type === "solid" ? 16 : 12)
153
+ : 0,
154
+ paddingRight: rightIconName ? ICON_SIZE + 16 + 4 : 12,
155
+ ...subtitle1,
156
+ height: lineHeight,
157
+ };
158
+ if (type === "underline") {
159
+ containerStyle = {
160
+ borderTopLeftRadius: roundness,
161
+ borderTopRightRadius: roundness,
162
+ paddingBottom: 12,
163
+ marginTop: 16,
164
+ };
165
+ }
166
+ else {
167
+ containerStyle = {
168
+ borderRadius: roundness,
169
+ borderColor: hasActiveOutline ? activeColor : borderColor,
170
+ borderWidth: 1,
171
+ paddingTop: labeled ? 16 * 1.5 : 16,
172
+ paddingBottom: labeled ? 16 * 0.5 : 16,
173
+ opacity: disabled ? disabledOpacity : 1,
174
+ backgroundColor,
175
+ };
176
+ inputStyle.paddingHorizontal = 12;
177
+ }
178
+ if (leftIconName && leftIconMode === "outset") {
179
+ containerStyle.marginLeft = ICON_SIZE + 8;
180
+ }
181
+ let leftIconColor;
182
+ if (focused) {
183
+ leftIconColor = colors.primary;
184
+ }
185
+ else {
186
+ leftIconColor = colors.light;
187
+ }
188
+ const leftIconProps = {
189
+ size: 24,
190
+ color: leftIconColor,
191
+ name: leftIconName || "",
192
+ };
193
+ const leftIconStyle = {
194
+ position: "absolute",
195
+ marginTop: type === "solid"
196
+ ? leftIconMode === "inset"
197
+ ? MINIMIZED_LABEL_FONT_SIZE + 4
198
+ : 16
199
+ : leftIconMode === "outset"
200
+ ? 16
201
+ : 0,
202
+ };
203
+ const labelStyle = {
204
+ ...typography.subtitle1,
205
+ top: type === "solid" ? 16 : 0,
206
+ left: leftIconName && leftIconMode === "inset"
207
+ ? ICON_SIZE + (type === "solid" ? 16 : 12)
208
+ : 0,
209
+ transform: [
210
+ {
211
+ // Move label to top
212
+ translateY: labeled.interpolate({
213
+ inputRange: [0, 1],
214
+ outputRange: [
215
+ type === "solid"
216
+ ? OUTLINE_MINIMIZED_LABEL_Y_OFFSET
217
+ : MINIMIZED_LABEL_Y_OFFSET,
218
+ 0,
219
+ ],
220
+ }),
221
+ },
222
+ {
223
+ // Make label smaller
224
+ scale: labeled.interpolate({
225
+ inputRange: [0, 1],
226
+ outputRange: [
227
+ MINIMIZED_LABEL_FONT_SIZE / MAXIMIZED_LABEL_FONT_SIZE,
228
+ 1,
229
+ ],
230
+ }),
231
+ },
232
+ {
233
+ // Offset label scale since RN doesn't support transform origin
234
+ translateX: labeled.interpolate({
235
+ inputRange: [0, 1],
236
+ outputRange: [
237
+ -(1 - MINIMIZED_LABEL_FONT_SIZE / MAXIMIZED_LABEL_FONT_SIZE) *
238
+ (labelLayout.width / 2),
239
+ 0,
240
+ ],
241
+ }),
242
+ },
243
+ ],
244
+ };
245
+ const inputStyles = [
246
+ styles.input,
247
+ inputStyle,
248
+ type === "solid" ? { marginHorizontal: 12 } : {},
249
+ ];
250
+ // const render = (props) => <NativeTextInput {...props} />;
251
+ return (React.createElement(View, { style: [styles.container, style] },
252
+ React.createElement(Touchable, { disabled: disabled, onPress: toggleVisibility },
253
+ React.createElement(View, { pointerEvents: "none" },
254
+ React.createElement(View, { style: [styles.container, style] },
255
+ leftIconName && leftIconMode === "outset" ? (React.createElement(Icon, { ...leftIconProps, style: leftIconStyle })) : null,
256
+ React.createElement(View, { style: [containerStyle, style ? { height: style.height } : {}] },
257
+ type === "underline" ? (
258
+ // When type === 'flat', render an underline
259
+ React.createElement(Animated.View, { style: [
260
+ styles.underline,
261
+ {
262
+ backgroundColor: focused ? activeColor : underlineColor,
263
+ // Underlines is thinner when input is not focused
264
+ transform: [{ scaleY: focused ? 1 : 0.5 }],
265
+ },
266
+ ] })) : null,
267
+ label ? (
268
+ // Position colored placeholder and gray placeholder on top of each other and crossfade them
269
+ // This gives the effect of animating the color, but allows us to use native driver
270
+ React.createElement(View, { pointerEvents: "none", style: [
271
+ StyleSheet.absoluteFill,
272
+ {
273
+ opacity:
274
+ // Hide the label in minimized state until we measure its width
275
+ date || focused ? (labelLayout.measured ? 1 : 0) : 1,
276
+ },
277
+ ] },
278
+ React.createElement(AnimatedText, { onLayout: (e) => setLabelLayout({
279
+ width: e.nativeEvent.layout.width,
280
+ measured: true,
281
+ }), style: [
282
+ styles.placeholder,
283
+ type === "solid" ? { paddingHorizontal: 12 } : {},
284
+ labelStyle,
285
+ {
286
+ color: colors.light,
287
+ opacity: labeled.interpolate({
288
+ inputRange: [0, 1],
289
+ outputRange: [hasActiveOutline ? 1 : 0, 0],
290
+ }),
291
+ },
292
+ ], numberOfLines: 1 }, label),
293
+ React.createElement(AnimatedText, { style: [
294
+ styles.placeholder,
295
+ type === "solid" ? { paddingHorizontal: 12 } : {},
296
+ labelStyle,
297
+ {
298
+ color: placeholderColor,
299
+ opacity: hasActiveOutline ? labeled : 1,
300
+ },
301
+ ], numberOfLines: 1 }, label))) : null,
302
+ leftIconName && leftIconMode === "inset" ? (React.createElement(Icon, { ...leftIconProps, style: {
303
+ ...leftIconStyle,
304
+ marginLeft: type === "solid" ? 16 : 0,
305
+ } })) : null,
306
+ React.createElement(NativeTextInput, { value: formatDate(), placeholder: label ? placeholder1 : placeholder, editable: !disabled, placeholderTextColor: placeholderColor, selectionColor: activeColor, onFocus: _handleFocus, onBlur: _handleBlur, underlineColorAndroid: "transparent", style: inputStyles, ...props })),
307
+ rightIconName ? (React.createElement(Icon, { name: rightIconName, size: ICON_SIZE, color: colors.light, style: {
308
+ position: "absolute",
309
+ right: 16,
310
+ marginTop: type === "solid" ? MINIMIZED_LABEL_FONT_SIZE + 4 : 16,
311
+ } })) : null))),
312
+ pickerVisible && (React.createElement(Portal, null,
313
+ React.createElement(View, { style: [
314
+ styles.picker,
315
+ {
316
+ backgroundColor: colors.divider,
317
+ },
318
+ ] },
319
+ React.createElement(View, { style: [
320
+ styles.pickerContainer,
321
+ {
322
+ paddingTop: insets.top,
323
+ paddingBottom: insets.bottom,
324
+ paddingLeft: insets.left,
325
+ paddingRight: insets.right,
326
+ },
327
+ ] },
328
+ Platform.OS === "ios" && (React.createElement(Button, { Icon: Icon, type: "text", onPress: toggleVisibility, style: styles.closeButton }, "Close")),
329
+ React.createElement(DateTimePicker, { value: getValidDate(), mode: mode, isVisible: pickerVisible, toggleVisibility: toggleVisibility, onChange: (_event, data) => {
330
+ Platform.OS === "ios" ? null : toggleVisibility();
331
+ setValue(data);
332
+ onDateChange(data);
333
+ } })))))));
334
+ };
335
+ const styles = StyleSheet.create({
336
+ container: {
337
+ alignSelf: "stretch",
338
+ },
339
+ picker: {
340
+ position: "absolute",
341
+ bottom: 0,
342
+ left: 0,
343
+ right: 0,
344
+ flexDirection: "row",
345
+ justifyContent: "center",
346
+ },
347
+ underline: {
348
+ position: "absolute",
349
+ left: 0,
350
+ right: 0,
351
+ bottom: 0,
352
+ height: 2,
353
+ },
354
+ input: {
355
+ flexGrow: 1,
356
+ justifyContent: "center",
357
+ textAlignVertical: "center",
358
+ margin: 0,
359
+ textAlign: I18nManager.isRTL ? "right" : "left",
360
+ },
361
+ placeholder: {
362
+ position: "absolute",
363
+ left: 0,
364
+ },
365
+ pickerContainer: { flexDirection: "column", width: "100%" },
366
+ closeButton: {
367
+ alignSelf: "flex-end",
368
+ },
369
+ });
370
+ export default withTheme(DatePicker);
@@ -0,0 +1,13 @@
1
+ import React from "react";
2
+ import { Platform } from "react-native";
3
+ import DateTimePicker from "@react-native-community/datetimepicker";
4
+ import DateTimePickerModal from "react-native-modal-datetime-picker";
5
+ const DatePickerComponent = ({ value, onChange, mode, toggleVisibility, }) => {
6
+ return Platform.OS === "ios" || Platform.OS === "android" ? (React.createElement(DateTimePickerModal, { date: value, mode: mode, isVisible: true, display: Platform.OS === "ios" ? "spinner" : "default", onCancel: () => {
7
+ console.log("Picker cancelled before selecting anything.");
8
+ toggleVisibility();
9
+ }, onConfirm: (data) => {
10
+ onChange(null, data);
11
+ } })) : (React.createElement(DateTimePicker, { value: value, mode: mode, onChange: onChange, display: "default" }));
12
+ };
13
+ export default DatePickerComponent;