@draftbit/core 42.1.5 → 42.1.7-71d4c6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (127) hide show
  1. package/LICENSE +21 -0
  2. package/lib/commonjs/components/DatePicker/DatePicker.js +6 -1
  3. package/lib/commonjs/components/DatePicker/DatePicker.js.map +1 -1
  4. package/lib/commonjs/components/DatePicker/DatePickerComponentType.js +2 -0
  5. package/lib/commonjs/components/Divider.js +18 -5
  6. package/lib/commonjs/components/Divider.js.map +1 -1
  7. package/lib/commonjs/components/Elevation.js +14 -3
  8. package/lib/commonjs/components/Elevation.js.map +1 -1
  9. package/lib/commonjs/components/Justification.js +3 -0
  10. package/lib/commonjs/components/Picker/PickerComponent.android.js +4 -1
  11. package/lib/commonjs/components/Picker/PickerComponent.android.js.map +1 -1
  12. package/lib/commonjs/components/Picker/PickerComponent.web.js +4 -1
  13. package/lib/commonjs/components/Picker/PickerComponent.web.js.map +1 -1
  14. package/lib/commonjs/components/Picker/PickerTypes.js +3 -0
  15. package/lib/commonjs/components/Portal/PortalHost.js.map +1 -1
  16. package/lib/commonjs/components/ResizeMode.js +3 -0
  17. package/lib/module/components/DatePicker/DatePicker.js +6 -1
  18. package/lib/module/components/DatePicker/DatePicker.js.map +1 -1
  19. package/lib/module/components/DatePicker/DatePickerComponentType.js +1 -1
  20. package/lib/module/components/Justification.js +1 -1
  21. package/lib/module/components/Picker/PickerComponent.android.js +4 -1
  22. package/lib/module/components/Picker/PickerComponent.android.js.map +1 -1
  23. package/lib/module/components/Picker/PickerComponent.web.js +4 -1
  24. package/lib/module/components/Picker/PickerComponent.web.js.map +1 -1
  25. package/lib/module/components/Picker/PickerTypes.js +1 -1
  26. package/lib/module/components/ResizeMode.js +1 -1
  27. package/package.json +3 -2
  28. package/src/Provider.js +9 -0
  29. package/src/components/Accordion/AccordionGroup.js +94 -0
  30. package/src/components/Accordion/AccordionItem.js +48 -0
  31. package/src/components/Accordion/index.js +2 -0
  32. package/src/components/ActionSheet/ActionSheet.js +57 -0
  33. package/src/components/ActionSheet/ActionSheetCancel.js +28 -0
  34. package/src/components/ActionSheet/ActionSheetItem.js +49 -0
  35. package/src/components/ActionSheet/index.js +3 -0
  36. package/src/components/AnimatedCircularProgress.js +43 -0
  37. package/src/components/AspectRatio.js +18 -0
  38. package/src/components/AvatarEdit.js +67 -0
  39. package/src/components/Button.js +187 -0
  40. package/src/components/Card.js +109 -0
  41. package/src/components/CardBlock.js +176 -0
  42. package/src/components/CardContainer.js +171 -0
  43. package/src/components/CardContainerRating.js +203 -0
  44. package/src/components/CardContainerShortImage.js +151 -0
  45. package/src/components/CardInline.js +87 -0
  46. package/src/components/Carousel.js +85 -0
  47. package/src/components/Checkbox/Checkbox.js +114 -0
  48. package/src/components/Checkbox/CheckboxGroup.js +46 -0
  49. package/src/components/Checkbox/CheckboxRow.js +109 -0
  50. package/src/components/Checkbox/context.js +14 -0
  51. package/src/components/Checkbox/index.js +3 -0
  52. package/src/components/CircleImage.js +32 -0
  53. package/src/components/CircularProgress.js +78 -0
  54. package/src/components/Config.js +63 -0
  55. package/src/components/Container.js +73 -0
  56. package/src/components/DatePicker/DatePicker.js +379 -0
  57. package/src/components/DatePicker/DatePicker.tsx +7 -1
  58. package/src/components/DatePicker/DatePickerComponent.js +13 -0
  59. package/src/components/DatePicker/DatePickerComponent.web.js +30 -0
  60. package/src/components/DatePicker/DatePickerComponentType.js +1 -0
  61. package/src/components/DeprecatedButton.js +201 -0
  62. package/src/components/DeprecatedCardWrapper.js +18 -0
  63. package/src/components/DeprecatedFAB.js +261 -0
  64. package/src/components/Divider.js +39 -0
  65. package/src/components/Elevation.js +20 -0
  66. package/src/components/FAB.js +82 -0
  67. package/src/components/FieldSearchBarFull.js +92 -0
  68. package/src/components/FormRow.js +19 -0
  69. package/src/components/Header.js +44 -0
  70. package/src/components/HeaderLarge.js +35 -0
  71. package/src/components/HeaderMedium.js +61 -0
  72. package/src/components/HeaderOverline.js +61 -0
  73. package/src/components/IconButton.js +65 -0
  74. package/src/components/Image.js +62 -0
  75. package/src/components/Justification.js +1 -0
  76. package/src/components/Layout.js +245 -0
  77. package/src/components/Picker/Picker.js +204 -0
  78. package/src/components/Picker/PickerComponent.android.js +68 -0
  79. package/src/components/Picker/PickerComponent.android.tsx +6 -1
  80. package/src/components/Picker/PickerComponent.ios.js +72 -0
  81. package/src/components/Picker/PickerComponent.web.js +68 -0
  82. package/src/components/Picker/PickerComponent.web.tsx +6 -1
  83. package/src/components/Picker/PickerTypes.js +1 -0
  84. package/src/components/Portal/Portal.js +35 -0
  85. package/src/components/Portal/PortalConsumer.js +28 -0
  86. package/src/components/Portal/PortalHost.js +105 -0
  87. package/src/components/Portal/PortalManager.js +29 -0
  88. package/src/components/ProgressBar.js +218 -0
  89. package/src/components/ProgressCircle.js +121 -0
  90. package/src/components/ProgressIndicator.js +207 -0
  91. package/src/components/RadioButton/RadioButton.js +66 -0
  92. package/src/components/RadioButton/RadioButtonFieldGroup.js +17 -0
  93. package/src/components/RadioButton/RadioButtonGroup.js +43 -0
  94. package/src/components/RadioButton/RadioButtonRow.js +111 -0
  95. package/src/components/RadioButton/context.js +14 -0
  96. package/src/components/RadioButton/index.js +4 -0
  97. package/src/components/ResizeMode.js +1 -0
  98. package/src/components/Row.js +48 -0
  99. package/src/components/RowBodyIcon.js +83 -0
  100. package/src/components/RowHeadlineImageCaption.js +179 -0
  101. package/src/components/RowHeadlineImageIcon.js +113 -0
  102. package/src/components/ScreenContainer.js +35 -0
  103. package/src/components/Slider.js +114 -0
  104. package/src/components/StarRating.js +80 -0
  105. package/src/components/StepIndicator.js +346 -0
  106. package/src/components/Stepper.js +69 -0
  107. package/src/components/Surface.js +36 -0
  108. package/src/components/Switch.js +59 -0
  109. package/src/components/Text.js +232 -0
  110. package/src/components/TextField.js +552 -0
  111. package/src/components/TextInput.js +13 -0
  112. package/src/components/ToggleButton.js +75 -0
  113. package/src/components/Touchable.js +24 -0
  114. package/src/components/Touchable.web.js +2 -0
  115. package/src/components/Typography.js +36 -0
  116. package/src/components/useAuthState.js +31 -0
  117. package/src/constants.js +10 -0
  118. package/src/hooks.js +12 -0
  119. package/src/index.js +48 -0
  120. package/src/interfaces/Icon.js +8 -0
  121. package/src/styles/DarkTheme.js +26 -0
  122. package/src/styles/DefaultTheme.js +111 -0
  123. package/src/styles/fonts.js +62 -0
  124. package/src/styles/overlay.js +60 -0
  125. package/src/styles/shadow.js +51 -0
  126. package/src/theming.js +3 -0
  127. package/src/utilities.js +42 -0
@@ -0,0 +1,379 @@
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
+ import { usePrevious } from "../../hooks";
11
+ const AnimatedText = Animated.createAnimatedComponent(Text);
12
+ const FOCUS_ANIMATION_DURATION = 150;
13
+ const BLUR_ANIMATION_DURATION = 180;
14
+ const ICON_SIZE = 24;
15
+ const MONTHS = [
16
+ "January",
17
+ "February",
18
+ "March",
19
+ "April",
20
+ "May",
21
+ "June",
22
+ "July",
23
+ "August",
24
+ "September",
25
+ "October",
26
+ "November",
27
+ "December",
28
+ ];
29
+ const DatePicker = ({ Icon, style, theme: { colors, typography, roundness, disabledOpacity }, date, onDateChange = () => { }, initialValue, disabled = false, mode = "date", format, type = "underline", leftIconName, rightIconName, leftIconMode = "inset", label, placeholder, ...props }) => {
30
+ const [value, setValue] = React.useState(date);
31
+ const [pickerVisible, setPickerVisible] = React.useState(false);
32
+ const [labeled] = React.useState(new Animated.Value(date ? 0 : 1));
33
+ const [placeholder1, setPlaceholder1] = React.useState("");
34
+ const [focused, setFocused] = React.useState(false);
35
+ const [labelLayout, setLabelLayout] = React.useState({ measured: false, width: 0 });
36
+ const previousInitialValue = usePrevious(initialValue);
37
+ React.useEffect(() => {
38
+ const initialValueStr = initialValue ? initialValue.toString() : "";
39
+ const previousInitialValueStr = previousInitialValue
40
+ ? // This weirdly complains about being possibly undefined despite being inside a ternary
41
+ // @ts-ignore
42
+ previousInitialValue.toString()
43
+ : "";
44
+ if (initialValueStr !== previousInitialValueStr) {
45
+ setValue(initialValue);
46
+ onDateChange(initialValue);
47
+ }
48
+ }, [initialValue, previousInitialValue, setValue, onDateChange]);
49
+ const getValidDate = () => {
50
+ if (!value) {
51
+ return new Date();
52
+ }
53
+ return typeof value?.getMonth === "function" ? value : new Date();
54
+ };
55
+ const formatDate = () => {
56
+ if (!value)
57
+ return "";
58
+ let newDate = getValidDate();
59
+ if (format)
60
+ return dateFormat(newDate, format);
61
+ if (mode === "time") {
62
+ return `${newDate.toLocaleTimeString()}`;
63
+ }
64
+ if (mode === "datetime") {
65
+ return `${newDate.toLocaleString()}`;
66
+ }
67
+ return `${MONTHS[newDate.getMonth()]} ${newDate.getDate()}, ${newDate.getFullYear()}`;
68
+ };
69
+ const toggleVisibility = async () => {
70
+ setPickerVisible(!pickerVisible);
71
+ focused ? _handleBlur() : _handleFocus();
72
+ };
73
+ const insets = useSafeAreaInsets();
74
+ // const _restoreLabel = () =>
75
+ // Animated.timing(labeled, {
76
+ // toValue: 1,
77
+ // duration: FOCUS_ANIMATION_DURATION,
78
+ // useNativeDriver: true,
79
+ // }).start();
80
+ // const _minmizeLabel = () =>
81
+ // Animated.timing(labeled, {
82
+ // toValue: 0,
83
+ // duration: BLUR_ANIMATION_DURATION,
84
+ // useNativeDriver: true,
85
+ // }).start();
86
+ // const _showPlaceholder = () =>
87
+ // setTimeout(() => setPlaceholder1(placeholder || ""), 50);
88
+ const _hidePlaceholder = () => {
89
+ setPlaceholder1("");
90
+ };
91
+ React.useEffect(() => {
92
+ setValue(date);
93
+ }, [date]);
94
+ React.useEffect(() => {
95
+ if (value || focused || placeholder1) {
96
+ // _minmizeLabel();
97
+ Animated.timing(labeled, {
98
+ toValue: 0,
99
+ duration: BLUR_ANIMATION_DURATION,
100
+ useNativeDriver: true,
101
+ }).start();
102
+ }
103
+ else {
104
+ // _restoreLabel();
105
+ Animated.timing(labeled, {
106
+ toValue: 1,
107
+ duration: FOCUS_ANIMATION_DURATION,
108
+ useNativeDriver: true,
109
+ }).start();
110
+ }
111
+ }, [value, focused, placeholder1, labeled]);
112
+ React.useEffect(() => {
113
+ const _showPlaceholder = () => setTimeout(() => setPlaceholder1(placeholder || ""), 50);
114
+ if (focused || !label) {
115
+ _showPlaceholder();
116
+ }
117
+ else {
118
+ _hidePlaceholder();
119
+ }
120
+ return () => {
121
+ clearTimeout(_showPlaceholder());
122
+ };
123
+ }, [focused, label, placeholder]);
124
+ const _handleFocus = () => {
125
+ if (disabled) {
126
+ return;
127
+ }
128
+ setFocused(true);
129
+ };
130
+ const _handleBlur = () => {
131
+ if (disabled) {
132
+ return;
133
+ }
134
+ setFocused(false);
135
+ };
136
+ const MINIMIZED_LABEL_Y_OFFSET = -(typography.caption.lineHeight + 4);
137
+ const OUTLINE_MINIMIZED_LABEL_Y_OFFSET = -(16 * 0.5 + 4);
138
+ const MAXIMIZED_LABEL_FONT_SIZE = typography.subtitle1.fontSize;
139
+ const MINIMIZED_LABEL_FONT_SIZE = typography.caption.fontSize;
140
+ const hasActiveOutline = focused;
141
+ let inputTextColor, activeColor, underlineColor, borderColor, placeholderColor, containerStyle, backgroundColor, inputStyle;
142
+ inputTextColor = colors.strong;
143
+ if (disabled) {
144
+ activeColor = colors.light;
145
+ placeholderColor = colors.light;
146
+ borderColor = "transparent";
147
+ underlineColor = "transparent";
148
+ backgroundColor = colors.divider;
149
+ }
150
+ else {
151
+ activeColor = colors.primary;
152
+ placeholderColor = borderColor = colors.light;
153
+ underlineColor = colors.light;
154
+ backgroundColor = colors.background;
155
+ }
156
+ const { lineHeight, ...subtitle1 } = typography.subtitle1;
157
+ inputStyle = {
158
+ paddingVertical: 0,
159
+ color: inputTextColor,
160
+ paddingLeft: leftIconName && leftIconMode === "inset"
161
+ ? ICON_SIZE + (type === "solid" ? 16 : 12)
162
+ : 0,
163
+ paddingRight: rightIconName ? ICON_SIZE + 16 + 4 : 12,
164
+ ...subtitle1,
165
+ height: lineHeight,
166
+ };
167
+ if (type === "underline") {
168
+ containerStyle = {
169
+ borderTopLeftRadius: roundness,
170
+ borderTopRightRadius: roundness,
171
+ paddingBottom: 12,
172
+ marginTop: 16,
173
+ };
174
+ }
175
+ else {
176
+ containerStyle = {
177
+ borderRadius: roundness,
178
+ borderColor: hasActiveOutline ? activeColor : borderColor,
179
+ borderWidth: 1,
180
+ paddingTop: labeled ? 16 * 1.5 : 16,
181
+ paddingBottom: labeled ? 16 * 0.5 : 16,
182
+ opacity: disabled ? disabledOpacity : 1,
183
+ backgroundColor,
184
+ };
185
+ inputStyle.paddingHorizontal = 12;
186
+ }
187
+ if (leftIconName && leftIconMode === "outset") {
188
+ containerStyle.marginLeft = ICON_SIZE + 8;
189
+ }
190
+ let leftIconColor;
191
+ if (focused) {
192
+ leftIconColor = colors.primary;
193
+ }
194
+ else {
195
+ leftIconColor = colors.light;
196
+ }
197
+ const leftIconProps = {
198
+ size: 24,
199
+ color: leftIconColor,
200
+ name: leftIconName || "",
201
+ };
202
+ const leftIconStyle = {
203
+ position: "absolute",
204
+ marginTop: type === "solid"
205
+ ? leftIconMode === "inset"
206
+ ? MINIMIZED_LABEL_FONT_SIZE + 4
207
+ : 16
208
+ : leftIconMode === "outset"
209
+ ? 16
210
+ : 0,
211
+ };
212
+ const labelStyle = {
213
+ ...typography.subtitle1,
214
+ top: type === "solid" ? 16 : 0,
215
+ left: leftIconName && leftIconMode === "inset"
216
+ ? ICON_SIZE + (type === "solid" ? 16 : 12)
217
+ : 0,
218
+ transform: [
219
+ {
220
+ // Move label to top
221
+ translateY: labeled.interpolate({
222
+ inputRange: [0, 1],
223
+ outputRange: [
224
+ type === "solid"
225
+ ? OUTLINE_MINIMIZED_LABEL_Y_OFFSET
226
+ : MINIMIZED_LABEL_Y_OFFSET,
227
+ 0,
228
+ ],
229
+ }),
230
+ },
231
+ {
232
+ // Make label smaller
233
+ scale: labeled.interpolate({
234
+ inputRange: [0, 1],
235
+ outputRange: [
236
+ MINIMIZED_LABEL_FONT_SIZE / MAXIMIZED_LABEL_FONT_SIZE,
237
+ 1,
238
+ ],
239
+ }),
240
+ },
241
+ {
242
+ // Offset label scale since RN doesn't support transform origin
243
+ translateX: labeled.interpolate({
244
+ inputRange: [0, 1],
245
+ outputRange: [
246
+ -(1 - MINIMIZED_LABEL_FONT_SIZE / MAXIMIZED_LABEL_FONT_SIZE) *
247
+ (labelLayout.width / 2),
248
+ 0,
249
+ ],
250
+ }),
251
+ },
252
+ ],
253
+ };
254
+ const inputStyles = [
255
+ styles.input,
256
+ inputStyle,
257
+ type === "solid" ? { marginHorizontal: 12 } : {},
258
+ ];
259
+ // const render = (props) => <NativeTextInput {...props} />;
260
+ return (React.createElement(View, { style: [styles.container, style] },
261
+ React.createElement(Touchable, { disabled: disabled, onPress: toggleVisibility },
262
+ React.createElement(View, { pointerEvents: "none" },
263
+ React.createElement(View, { style: [styles.container, style] },
264
+ leftIconName && leftIconMode === "outset" ? (React.createElement(Icon, { ...leftIconProps, style: leftIconStyle })) : null,
265
+ React.createElement(View, { style: [containerStyle, style ? { height: style.height } : {}] },
266
+ type === "underline" ? (
267
+ // When type === 'flat', render an underline
268
+ React.createElement(Animated.View, { style: [
269
+ styles.underline,
270
+ {
271
+ backgroundColor: focused ? activeColor : underlineColor,
272
+ // Underlines is thinner when input is not focused
273
+ transform: [{ scaleY: focused ? 1 : 0.5 }],
274
+ },
275
+ ] })) : null,
276
+ label ? (
277
+ // Position colored placeholder and gray placeholder on top of each other and crossfade them
278
+ // This gives the effect of animating the color, but allows us to use native driver
279
+ React.createElement(View, { pointerEvents: "none", style: [
280
+ StyleSheet.absoluteFill,
281
+ {
282
+ opacity:
283
+ // Hide the label in minimized state until we measure its width
284
+ date || focused ? (labelLayout.measured ? 1 : 0) : 1,
285
+ },
286
+ ] },
287
+ React.createElement(AnimatedText, { onLayout: (e) => setLabelLayout({
288
+ width: e.nativeEvent.layout.width,
289
+ measured: true,
290
+ }), style: [
291
+ styles.placeholder,
292
+ type === "solid" ? { paddingHorizontal: 12 } : {},
293
+ labelStyle,
294
+ {
295
+ color: colors.light,
296
+ opacity: labeled.interpolate({
297
+ inputRange: [0, 1],
298
+ outputRange: [hasActiveOutline ? 1 : 0, 0],
299
+ }),
300
+ },
301
+ ], numberOfLines: 1 }, label),
302
+ React.createElement(AnimatedText, { style: [
303
+ styles.placeholder,
304
+ type === "solid" ? { paddingHorizontal: 12 } : {},
305
+ labelStyle,
306
+ {
307
+ color: placeholderColor,
308
+ opacity: hasActiveOutline ? labeled : 1,
309
+ },
310
+ ], numberOfLines: 1 }, label))) : null,
311
+ leftIconName && leftIconMode === "inset" ? (React.createElement(Icon, { ...leftIconProps, style: {
312
+ ...leftIconStyle,
313
+ marginLeft: type === "solid" ? 16 : 0,
314
+ } })) : null,
315
+ React.createElement(NativeTextInput, { value: formatDate(), placeholder: label ? placeholder1 : placeholder, editable: !disabled, placeholderTextColor: placeholderColor, selectionColor: activeColor, onFocus: _handleFocus, onBlur: _handleBlur, underlineColorAndroid: "transparent", style: inputStyles, ...props })),
316
+ rightIconName ? (React.createElement(Icon, { name: rightIconName, size: ICON_SIZE, color: colors.light, style: {
317
+ position: "absolute",
318
+ right: 16,
319
+ marginTop: type === "solid" ? MINIMIZED_LABEL_FONT_SIZE + 4 : 16,
320
+ } })) : null))),
321
+ pickerVisible && (React.createElement(Portal, null,
322
+ React.createElement(View, { style: [
323
+ styles.picker,
324
+ {
325
+ backgroundColor: colors.divider,
326
+ },
327
+ ] },
328
+ React.createElement(View, { style: [
329
+ styles.pickerContainer,
330
+ {
331
+ paddingTop: insets.top,
332
+ paddingBottom: insets.bottom,
333
+ paddingLeft: insets.left,
334
+ paddingRight: insets.right,
335
+ },
336
+ ] },
337
+ Platform.OS === "ios" && (React.createElement(Button, { Icon: Icon, type: "text", onPress: toggleVisibility, style: styles.closeButton }, "Close")),
338
+ React.createElement(DateTimePicker, { value: getValidDate(), mode: mode, isVisible: pickerVisible, toggleVisibility: toggleVisibility, onChange: (_event, data) => {
339
+ Platform.OS === "ios" ? null : toggleVisibility();
340
+ setValue(data);
341
+ onDateChange(data);
342
+ } })))))));
343
+ };
344
+ const styles = StyleSheet.create({
345
+ container: {
346
+ alignSelf: "stretch",
347
+ },
348
+ picker: {
349
+ position: "absolute",
350
+ bottom: 0,
351
+ left: 0,
352
+ right: 0,
353
+ flexDirection: "row",
354
+ justifyContent: "center",
355
+ },
356
+ underline: {
357
+ position: "absolute",
358
+ left: 0,
359
+ right: 0,
360
+ bottom: 0,
361
+ height: 2,
362
+ },
363
+ input: {
364
+ flexGrow: 1,
365
+ justifyContent: "center",
366
+ textAlignVertical: "center",
367
+ margin: 0,
368
+ textAlign: I18nManager.isRTL ? "right" : "left",
369
+ },
370
+ placeholder: {
371
+ position: "absolute",
372
+ left: 0,
373
+ },
374
+ pickerContainer: { flexDirection: "column", width: "100%" },
375
+ closeButton: {
376
+ alignSelf: "flex-end",
377
+ },
378
+ });
379
+ export default withTheme(DatePicker);
@@ -104,7 +104,13 @@ const DatePicker: React.FC<Props> = ({
104
104
 
105
105
  const previousInitialValue = usePrevious(initialValue);
106
106
  React.useEffect(() => {
107
- if (initialValue !== previousInitialValue) {
107
+ const initialValueStr = initialValue ? initialValue.toString() : "";
108
+ const previousInitialValueStr = previousInitialValue
109
+ ? // This weirdly complains about being possibly undefined despite being inside a ternary
110
+ // @ts-ignore
111
+ previousInitialValue.toString()
112
+ : "";
113
+ if (initialValueStr !== previousInitialValueStr) {
108
114
  setValue(initialValue);
109
115
  onDateChange(initialValue);
110
116
  }
@@ -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;
@@ -0,0 +1,30 @@
1
+ import React from "react";
2
+ import DateFnsUtils from "@date-io/date-fns";
3
+ import { MuiPickersUtilsProvider, DatePicker, TimePicker, DateTimePicker, } from "@material-ui/pickers";
4
+ import { createMuiTheme, ThemeProvider } from "@material-ui/core/styles";
5
+ import { withTheme } from "../../theming";
6
+ import Theme from "../../styles/DefaultTheme";
7
+ const DatePickerComponent = ({ value, onChange, mode, toggleVisibility, isVisible, theme, }) => {
8
+ const internalTheme = createMuiTheme({
9
+ palette: {
10
+ primary: {
11
+ main: theme?.colors?.primary ?? Theme.colors.primary,
12
+ },
13
+ secondary: {
14
+ main: theme?.colors?.secondary ?? Theme.colors.secondary,
15
+ },
16
+ },
17
+ });
18
+ const Picker = mode === "date"
19
+ ? DatePicker
20
+ : mode === "time"
21
+ ? TimePicker
22
+ : DateTimePicker;
23
+ return (React.createElement(MuiPickersUtilsProvider, { utils: DateFnsUtils },
24
+ React.createElement(ThemeProvider, { theme: internalTheme },
25
+ React.createElement(Picker, { value: value, open: isVisible, onChange: (d) => {
26
+ toggleVisibility();
27
+ onChange(null, d);
28
+ }, onClose: () => toggleVisibility(), variant: "dialog", TextFieldComponent: () => null }))));
29
+ };
30
+ export default withTheme(DatePickerComponent);
@@ -0,0 +1,201 @@
1
+ import * as React from "react";
2
+ import { ActivityIndicator, View, Text, StyleSheet, } from "react-native";
3
+ import color from "color";
4
+ import Config from "./Config";
5
+ import Touchable from "./Touchable";
6
+ import Elevation from "./Elevation";
7
+ import { withTheme } from "../theming";
8
+ import { GROUPS, FORM_TYPES, PROP_TYPES, COMPONENT_TYPES, createActionProp, Triggers, } from "@draftbit/types";
9
+ const Button = ({ Icon, icon, disabled = false, type = "solid", loading = false, labelColor, color: colorOverride, children, onPress, elevation = 0, style, theme: { colors, disabledOpacity, roundness, typography }, ...rest }) => {
10
+ let backgroundColor, borderColor, textColor, borderWidth;
11
+ const buttonColor = colorOverride || colors.primary;
12
+ if (type === "solid") {
13
+ backgroundColor = buttonColor;
14
+ if (disabled) {
15
+ textColor = color(colors.surface).alpha(disabledOpacity).rgb().string();
16
+ }
17
+ else {
18
+ textColor = labelColor || colors.surface;
19
+ }
20
+ }
21
+ else {
22
+ backgroundColor = "transparent";
23
+ if (disabled) {
24
+ textColor = color(buttonColor).alpha(disabledOpacity).rgb().string();
25
+ }
26
+ else {
27
+ textColor = labelColor || buttonColor;
28
+ }
29
+ }
30
+ if (type === "outline") {
31
+ if (disabled) {
32
+ borderColor = color(buttonColor).alpha(disabledOpacity).rgb().string();
33
+ }
34
+ else {
35
+ borderColor = buttonColor;
36
+ }
37
+ borderWidth = StyleSheet.hairlineWidth;
38
+ }
39
+ else {
40
+ borderColor = "transparent";
41
+ borderWidth = 0;
42
+ }
43
+ const buttonStyle = {
44
+ backgroundColor,
45
+ borderColor,
46
+ borderWidth,
47
+ borderRadius: roundness,
48
+ };
49
+ const textStyle = {
50
+ textAlign: "center",
51
+ color: textColor,
52
+ marginVertical: 16,
53
+ marginHorizontal: 16,
54
+ };
55
+ const iconStyle = [
56
+ styles.icon,
57
+ {
58
+ marginLeft: 16,
59
+ marginRight: -8,
60
+ width: Config.buttonIconSize,
61
+ },
62
+ ];
63
+ const { margin, marginEnd, marginTop, marginLeft, marginRight, marginBottom, marginHorizontal, marginVertical, ...innerStyles } = StyleSheet.flatten(style || {});
64
+ const margins = {
65
+ margin,
66
+ marginEnd,
67
+ marginTop,
68
+ marginLeft,
69
+ marginRight,
70
+ marginBottom,
71
+ marginHorizontal,
72
+ marginVertical,
73
+ };
74
+ return (React.createElement(Elevation, { style: { elevation, alignSelf: "stretch", ...margins } },
75
+ React.createElement(Touchable, { ...rest, onPress: onPress, accessibilityState: { disabled }, accessibilityRole: "button", disabled: disabled || loading, style: [styles.button, buttonStyle, innerStyles] },
76
+ React.createElement(View, { style: styles.content },
77
+ icon && loading !== true ? (React.createElement(View, { style: iconStyle },
78
+ React.createElement(Icon, { name: icon, size: Config.buttonIconSize, color: textColor }))) : null,
79
+ loading ? (React.createElement(ActivityIndicator, { size: "small", color: textColor, style: iconStyle })) : null,
80
+ React.createElement(Text, { numberOfLines: 1, style: [textStyle, typography.button] }, children)))));
81
+ };
82
+ const styles = StyleSheet.create({
83
+ button: {
84
+ minWidth: 64,
85
+ borderStyle: "solid",
86
+ },
87
+ content: {
88
+ flexDirection: "row",
89
+ alignItems: "center",
90
+ justifyContent: "center",
91
+ },
92
+ icon: {
93
+ width: Config.buttonIconSize,
94
+ },
95
+ });
96
+ export default withTheme(Button);
97
+ const SEED_DATA_PROPS = {
98
+ onPress: createActionProp(),
99
+ icon: {
100
+ group: GROUPS.basic,
101
+ label: "Icon Name",
102
+ description: "Name of the icon",
103
+ editable: true,
104
+ required: true,
105
+ formType: FORM_TYPES.icon,
106
+ propType: PROP_TYPES.STRING,
107
+ defaultValue: null,
108
+ },
109
+ children: {
110
+ group: GROUPS.data,
111
+ label: "Label",
112
+ description: "Button label",
113
+ required: true,
114
+ editable: true,
115
+ formType: FORM_TYPES.string,
116
+ propType: PROP_TYPES.STRING,
117
+ defaultValue: "Get Started",
118
+ },
119
+ color: {
120
+ group: GROUPS.basic,
121
+ label: "Color Override",
122
+ description: "Override the background color of the button",
123
+ editable: true,
124
+ required: false,
125
+ formType: FORM_TYPES.color,
126
+ propType: PROP_TYPES.THEME,
127
+ defaultValue: null,
128
+ },
129
+ labelColor: {
130
+ group: GROUPS.basic,
131
+ label: "Label Color Override",
132
+ description: "Override the label color of the button",
133
+ editable: true,
134
+ required: false,
135
+ formType: FORM_TYPES.color,
136
+ propType: PROP_TYPES.THEME,
137
+ defaultValue: null,
138
+ },
139
+ disabled: {
140
+ group: GROUPS.basic,
141
+ label: "Disabled",
142
+ description: "Whether the button should be disabled",
143
+ editable: true,
144
+ required: false,
145
+ formType: FORM_TYPES.boolean,
146
+ propType: PROP_TYPES.BOOLEAN,
147
+ defaultValue: null,
148
+ },
149
+ loading: {
150
+ group: GROUPS.data,
151
+ label: "Loading",
152
+ description: "Whether to show a loading indicator",
153
+ editable: true,
154
+ required: false,
155
+ formType: FORM_TYPES.boolean,
156
+ propType: PROP_TYPES.BOOLEAN,
157
+ defaultValue: null,
158
+ },
159
+ };
160
+ export const SEED_DATA = [
161
+ {
162
+ name: "Button Outline",
163
+ tag: "Button",
164
+ category: COMPONENT_TYPES.deprecated,
165
+ triggers: [Triggers.OnPress],
166
+ props: {
167
+ ...SEED_DATA_PROPS,
168
+ type: {
169
+ group: GROUPS.uncategorized,
170
+ label: "Type",
171
+ description: "Button type",
172
+ editable: false,
173
+ required: true,
174
+ formType: FORM_TYPES.string,
175
+ propType: PROP_TYPES.STRING,
176
+ defaultValue: "outline",
177
+ },
178
+ },
179
+ layout: {},
180
+ },
181
+ {
182
+ name: "Button Solid",
183
+ tag: "Button",
184
+ category: COMPONENT_TYPES.deprecated,
185
+ triggers: [Triggers.OnPress],
186
+ props: {
187
+ ...SEED_DATA_PROPS,
188
+ type: {
189
+ group: GROUPS.uncategorized,
190
+ label: "Type",
191
+ description: "Button type",
192
+ editable: false,
193
+ required: true,
194
+ formType: FORM_TYPES.string,
195
+ propType: PROP_TYPES.STRING,
196
+ defaultValue: "solid",
197
+ },
198
+ },
199
+ layout: {},
200
+ },
201
+ ];
@@ -0,0 +1,18 @@
1
+ import React from "react";
2
+ import { withTheme } from "../theming";
3
+ import Touchable from "./Touchable";
4
+ const getWidth = (numColumns) => {
5
+ switch (numColumns) {
6
+ case 1:
7
+ return "33%";
8
+ case 2:
9
+ return "50%";
10
+ default:
11
+ return "100%";
12
+ }
13
+ };
14
+ const Card = ({ numColumns = 3, children, onPress, style, ...rest }) => {
15
+ const width = getWidth(numColumns);
16
+ return (React.createElement(Touchable, { disabled: !onPress, onPress: onPress, style: [style, { width }], ...rest }, children));
17
+ };
18
+ export default withTheme(Card);