@draftbit/core 46.0.2 → 46.1.2

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 (191) hide show
  1. package/lib/commonjs/components/DeprecatedButton.js +20 -4
  2. package/lib/commonjs/components/DeprecatedButton.js.map +1 -1
  3. package/lib/commonjs/components/DeprecatedCardWrapper.js +14 -2
  4. package/lib/commonjs/components/DeprecatedCardWrapper.js.map +1 -1
  5. package/lib/commonjs/components/Justification.js +3 -0
  6. package/lib/commonjs/components/Picker/Picker.js +5 -4
  7. package/lib/commonjs/components/Picker/Picker.js.map +1 -1
  8. package/lib/commonjs/components/ResizeMode.js +3 -0
  9. package/lib/commonjs/mappings/RadioButtonGroup.js.map +1 -1
  10. package/lib/commonjs/mappings/RadioButtonRow.js.map +1 -1
  11. package/lib/module/components/Justification.js +1 -1
  12. package/lib/module/components/Picker/Picker.js +5 -4
  13. package/lib/module/components/Picker/Picker.js.map +1 -1
  14. package/lib/module/components/ResizeMode.js +1 -1
  15. package/package.json +6 -5
  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/Banner.js +109 -0
  28. package/src/components/Button.js +112 -0
  29. package/src/components/Card.js +57 -0
  30. package/src/components/CardBlock.js +54 -0
  31. package/src/components/CardContainer.js +69 -0
  32. package/src/components/CardContainerRating.js +79 -0
  33. package/src/components/CardContainerShortImage.js +33 -0
  34. package/src/components/CardInline.js +36 -0
  35. package/src/components/Carousel.js +66 -0
  36. package/src/components/Checkbox/Checkbox.js +63 -0
  37. package/src/components/Checkbox/CheckboxGroup.js +21 -0
  38. package/src/components/Checkbox/CheckboxGroupRow.js +77 -0
  39. package/src/components/Checkbox/CheckboxRow.js +78 -0
  40. package/src/components/Checkbox/context.js +14 -0
  41. package/src/components/Checkbox/index.js +3 -0
  42. package/src/components/CircleImage.js +8 -0
  43. package/src/components/CircularProgress.js +78 -0
  44. package/src/components/Config.js +63 -0
  45. package/src/components/Container.js +43 -0
  46. package/src/components/DatePicker/DatePicker.js +368 -0
  47. package/src/components/DatePicker/DatePickerComponent.js +13 -0
  48. package/src/components/DatePicker/DatePickerComponent.web.js +30 -0
  49. package/src/components/DatePicker/DatePickerComponentType.js +1 -0
  50. package/src/components/DeprecatedButton.js +95 -0
  51. package/src/components/DeprecatedCardWrapper.js +18 -0
  52. package/src/components/DeprecatedFAB.js +115 -0
  53. package/src/components/Divider.js +13 -0
  54. package/src/components/Elevation.js +20 -0
  55. package/src/components/FAB.js +46 -0
  56. package/src/components/FieldSearchBarFull.js +53 -0
  57. package/src/components/FormRow.js +19 -0
  58. package/src/components/Header.js +44 -0
  59. package/src/components/HeaderLarge.js +7 -0
  60. package/src/components/HeaderMedium.js +7 -0
  61. package/src/components/HeaderOverline.js +7 -0
  62. package/src/components/IconButton.js +35 -0
  63. package/src/components/Image.js +47 -0
  64. package/src/components/Justification.js +1 -0
  65. package/src/components/Layout.js +50 -0
  66. package/src/components/NumberInput.js +49 -0
  67. package/src/components/Picker/Picker.js +267 -0
  68. package/src/components/Picker/Picker.tsx +6 -8
  69. package/src/components/Picker/PickerComponent.android.js +68 -0
  70. package/src/components/Picker/PickerComponent.ios.js +78 -0
  71. package/src/components/Picker/PickerComponent.web.js +69 -0
  72. package/src/components/Picker/PickerTypes.js +1 -0
  73. package/src/components/Portal/Portal.js +35 -0
  74. package/src/components/Portal/PortalConsumer.js +28 -0
  75. package/src/components/Portal/PortalHost.js +105 -0
  76. package/src/components/Portal/PortalManager.js +29 -0
  77. package/src/components/ProgressBar.js +118 -0
  78. package/src/components/ProgressCircle.js +13 -0
  79. package/src/components/ProgressIndicator.js +27 -0
  80. package/src/components/RadioButton/RadioButton.js +17 -0
  81. package/src/components/RadioButton/RadioButtonFieldGroup.js +17 -0
  82. package/src/components/RadioButton/RadioButtonGroup.js +43 -0
  83. package/src/components/RadioButton/RadioButtonRow.js +76 -0
  84. package/src/components/RadioButton/context.js +14 -0
  85. package/src/components/RadioButton/index.js +4 -0
  86. package/src/components/ResizeMode.js +1 -0
  87. package/src/components/Row.js +48 -0
  88. package/src/components/RowBodyIcon.js +8 -0
  89. package/src/components/RowHeadlineImageCaption.js +12 -0
  90. package/src/components/RowHeadlineImageIcon.js +14 -0
  91. package/src/components/ScreenContainer.js +34 -0
  92. package/src/components/Slider.js +63 -0
  93. package/src/components/StarRating.js +50 -0
  94. package/src/components/StepIndicator.js +346 -0
  95. package/src/components/Stepper.js +39 -0
  96. package/src/components/Surface.js +32 -0
  97. package/src/components/Swiper/Swiper.js +29 -0
  98. package/src/components/Swiper/SwiperItem.js +9 -0
  99. package/src/components/Swiper/index.js +2 -0
  100. package/src/components/Switch.js +56 -0
  101. package/src/components/Text.js +28 -0
  102. package/src/components/TextField.js +420 -0
  103. package/src/components/ToggleButton.js +39 -0
  104. package/src/components/Touchable.js +12 -0
  105. package/src/components/Touchable.web.js +2 -0
  106. package/src/components/Typography.js +36 -0
  107. package/src/components/useAuthState.js +31 -0
  108. package/src/constants.js +10 -0
  109. package/src/hooks.js +12 -0
  110. package/src/index.js +52 -0
  111. package/src/interfaces/Icon.js +8 -0
  112. package/src/mappings/Accordion.js +41 -0
  113. package/src/mappings/AccordionItem.js +16 -0
  114. package/src/mappings/ActionSheet.js +13 -0
  115. package/src/mappings/ActionSheetCancel.js +19 -0
  116. package/src/mappings/ActionSheetItem.js +23 -0
  117. package/src/mappings/ActivityIndicator.js +53 -0
  118. package/src/mappings/AudioPlayer.js +20 -0
  119. package/src/mappings/AvatarEdit.js +37 -0
  120. package/src/mappings/Banner.js +32 -0
  121. package/src/mappings/BlurView.js +41 -0
  122. package/src/mappings/Button.js +56 -0
  123. package/src/mappings/Card.js +52 -0
  124. package/src/mappings/CardBlock.js +122 -0
  125. package/src/mappings/CardContainer.js +102 -0
  126. package/src/mappings/CardContainerRating.js +124 -0
  127. package/src/mappings/CardContainerShortImage.js +118 -0
  128. package/src/mappings/CardInline.js +51 -0
  129. package/src/mappings/Carousel.js +18 -0
  130. package/src/mappings/Checkbox.js +45 -0
  131. package/src/mappings/CheckboxGroup.js +25 -0
  132. package/src/mappings/CheckboxRow.js +56 -0
  133. package/src/mappings/CircleImage.js +24 -0
  134. package/src/mappings/Container.js +29 -0
  135. package/src/mappings/CustomCode.js +8 -0
  136. package/src/mappings/DatePicker.js +147 -0
  137. package/src/mappings/Divider.js +26 -0
  138. package/src/mappings/FAB.js +36 -0
  139. package/src/mappings/Fetch.js +12 -0
  140. package/src/mappings/FieldSearchBarFull.js +49 -0
  141. package/src/mappings/FlatList.js +19 -0
  142. package/src/mappings/HeaderLarge.js +28 -0
  143. package/src/mappings/HeaderMedium.js +54 -0
  144. package/src/mappings/HeaderOverline.js +54 -0
  145. package/src/mappings/Icon.js +25 -0
  146. package/src/mappings/IconButton.js +30 -0
  147. package/src/mappings/Image.js +15 -0
  148. package/src/mappings/ImageBackground.js +28 -0
  149. package/src/mappings/KeyboardAvoidingView.js +40 -0
  150. package/src/mappings/KeyboardAwareScrollView.js +49 -0
  151. package/src/mappings/Layout.js +195 -0
  152. package/src/mappings/LinearGradient.js +77 -0
  153. package/src/mappings/MapCallout.js +21 -0
  154. package/src/mappings/MapMarker.js +47 -0
  155. package/src/mappings/MapView.js +138 -0
  156. package/src/mappings/Modal.js +41 -0
  157. package/src/mappings/Picker.js +139 -0
  158. package/src/mappings/ProgressBar.js +100 -0
  159. package/src/mappings/ProgressCircle.js +108 -0
  160. package/src/mappings/ProgressIndicator.js +180 -0
  161. package/src/mappings/RadioButton.js +50 -0
  162. package/src/mappings/RadioButtonGroup.js +16 -0
  163. package/src/mappings/RadioButtonRow.js +37 -0
  164. package/src/mappings/RowBodyIcon.js +75 -0
  165. package/src/mappings/RowHeadlineImageCaption.js +167 -0
  166. package/src/mappings/RowHeadlineImageIcon.js +99 -0
  167. package/src/mappings/SafeAreaView.js +33 -0
  168. package/src/mappings/ScrollView.js +30 -0
  169. package/src/mappings/Slider.js +59 -0
  170. package/src/mappings/StarRating.js +42 -0
  171. package/src/mappings/Stepper.js +28 -0
  172. package/src/mappings/Surface.js +13 -0
  173. package/src/mappings/Swiper.js +60 -0
  174. package/src/mappings/SwiperItem.js +8 -0
  175. package/src/mappings/Switch.js +75 -0
  176. package/src/mappings/Text.js +232 -0
  177. package/src/mappings/TextArea.js +52 -0
  178. package/src/mappings/TextField.js +158 -0
  179. package/src/mappings/TextInput.js +208 -0
  180. package/src/mappings/ToggleButton.js +45 -0
  181. package/src/mappings/Touchable.js +12 -0
  182. package/src/mappings/Video.js +74 -0
  183. package/src/mappings/View.js +206 -0
  184. package/src/mappings/WebView.js +18 -0
  185. package/src/styles/DarkTheme.js +26 -0
  186. package/src/styles/DefaultTheme.js +111 -0
  187. package/src/styles/fonts.js +62 -0
  188. package/src/styles/overlay.js +60 -0
  189. package/src/styles/shadow.js +51 -0
  190. package/src/theming.js +3 -0
  191. package/src/utilities.js +102 -0
@@ -0,0 +1,50 @@
1
+ import * as React from "react";
2
+ import { View, StyleSheet, Pressable, } from "react-native";
3
+ import { withTheme } from "../theming";
4
+ const StarRating = ({ Icon, starSize = 16, maxStars = 5, rating = 0, defaultValue, isEditable = false, activeColor, inactiveColor, style, onPress, ...rest }) => {
5
+ const [localRating, setLocalRating] = React.useState(rating || defaultValue || 0);
6
+ React.useEffect(() => {
7
+ if (rating != null) {
8
+ setLocalRating(rating);
9
+ }
10
+ }, [rating]);
11
+ React.useEffect(() => {
12
+ if (defaultValue != null) {
13
+ setLocalRating(defaultValue);
14
+ }
15
+ }, [defaultValue]);
16
+ const ratingHandler = React.useCallback((r) => {
17
+ setLocalRating(r);
18
+ !!onPress && onPress(r);
19
+ }, [onPress]);
20
+ const ratingRounded = Math.round(localRating * 2) / 2;
21
+ return (React.createElement(View, { style: [styles.container, style], ...rest }, [...Array(maxStars)].map((_, i) => (React.createElement(View, { key: i, style: { display: "flex" } },
22
+ React.createElement(Icon, { name: ratingRounded - i === 0.5
23
+ ? "MaterialIcons/star-half"
24
+ : "MaterialIcons/star", size: starSize, color: ratingRounded > i ? activeColor : inactiveColor }),
25
+ isEditable && (React.createElement(View, { style: styles.touchContainer },
26
+ React.createElement(Pressable, { style: styles.pressable, onPress: () => ratingHandler(i + 0.5) }),
27
+ React.createElement(Pressable, { style: styles.pressable, onPress: () => ratingHandler(i + 1) }))))))));
28
+ };
29
+ const styles = StyleSheet.create({
30
+ container: {
31
+ flexDirection: "row",
32
+ alignItems: "center",
33
+ },
34
+ touchContainer: {
35
+ display: "flex",
36
+ flexDirection: "row",
37
+ position: "absolute",
38
+ top: 0,
39
+ right: 0,
40
+ left: 0,
41
+ bottom: 0,
42
+ zIndex: 1,
43
+ },
44
+ pressable: {
45
+ flex: 1,
46
+ height: "100%",
47
+ width: "50%",
48
+ },
49
+ });
50
+ export default withTheme(StarRating);
@@ -0,0 +1,346 @@
1
+ // @ts-nocheck
2
+ import React, { Component } from "react";
3
+ import { View, Text, StyleSheet, Animated, TouchableWithoutFeedback, } from "react-native";
4
+ const STEP_STATUS = {
5
+ CURRENT: "current",
6
+ FINISHED: "finished",
7
+ UNFINISHED: "unfinished",
8
+ };
9
+ export default class StepIndicator extends Component {
10
+ constructor(props) {
11
+ super(props);
12
+ const defaultStyles = {
13
+ stepIndicatorSize: 30,
14
+ currentStepIndicatorSize: 40,
15
+ separatorStrokeWidth: 3,
16
+ separatorStrokeUnfinishedWidth: 0,
17
+ separatorStrokeFinishedWidth: 0,
18
+ currentStepStrokeWidth: 5,
19
+ stepStrokeWidth: 0,
20
+ stepStrokeCurrentColor: "#4aae4f",
21
+ stepStrokeFinishedColor: "#4aae4f",
22
+ stepStrokeUnFinishedColor: "#4aae4f",
23
+ separatorFinishedColor: "#4aae4f",
24
+ separatorUnFinishedColor: "#a4d4a5",
25
+ stepIndicatorFinishedColor: "#4aae4f",
26
+ stepIndicatorUnFinishedColor: "#a4d4a5",
27
+ stepIndicatorCurrentColor: "#ffffff",
28
+ stepIndicatorLabelFontSize: 15,
29
+ currentStepIndicatorLabelFontSize: 15,
30
+ stepIndicatorLabelCurrentColor: "#000000",
31
+ stepIndicatorLabelFinishedColor: "#ffffff",
32
+ stepIndicatorLabelUnFinishedColor: "rgba(255,255,255,0.5)",
33
+ labelColor: "#000000",
34
+ labelSize: 13,
35
+ labelAlign: "center",
36
+ currentStepLabelColor: "#4aae4f",
37
+ };
38
+ const customStyles = Object.assign(defaultStyles, props.customStyles);
39
+ this.state = {
40
+ width: 0,
41
+ height: 1,
42
+ progressBarSize: -2,
43
+ customStyles,
44
+ };
45
+ this.progressAnim = new Animated.Value(0);
46
+ this.sizeAnim = new Animated.Value(this.state.customStyles.stepIndicatorSize);
47
+ this.borderRadiusAnim = new Animated.Value(this.state.customStyles.stepIndicatorSize / 2);
48
+ }
49
+ stepPressed(position) {
50
+ if (this.props.onPress) {
51
+ this.props.onPress(position);
52
+ }
53
+ }
54
+ render() {
55
+ const { labels, direction } = this.props;
56
+ return (React.createElement(View, { style: [
57
+ styles.container,
58
+ direction === "vertical"
59
+ ? { flexDirection: "row", flex: 1 }
60
+ : { flexDirection: "column" },
61
+ ] },
62
+ this.state.width !== 0 && this.renderProgressBarBackground(),
63
+ this.state.width !== 0 && this.renderProgressBar(),
64
+ this.renderStepIndicator(),
65
+ labels && this.renderStepLabels()));
66
+ }
67
+ componentDidUpdate(prevProps) {
68
+ // if (prevProps.customStyles !== this.props.customStyles) {
69
+ // this.setState((state) => ({
70
+ // customStyles: Object.assign(
71
+ // state.customStyles,
72
+ // this.props.customStyles
73
+ // ),
74
+ // }));
75
+ // }
76
+ if (prevProps.currentPosition !== this.props.currentPosition) {
77
+ this.onCurrentPositionChanged(this.props.currentPosition);
78
+ }
79
+ }
80
+ renderProgressBarBackground = () => {
81
+ const { stepCount, direction } = this.props;
82
+ let progressBarBackgroundStyle;
83
+ if (direction === "vertical") {
84
+ progressBarBackgroundStyle = {
85
+ backgroundColor: this.state.customStyles.separatorUnFinishedColor,
86
+ position: "absolute",
87
+ left: (this.state.width - this.state.customStyles.separatorStrokeWidth) / 2,
88
+ top: this.state.height / (2 * stepCount),
89
+ bottom: this.state.height / (2 * stepCount),
90
+ width: this.state.customStyles.separatorStrokeUnfinishedWidth === 0
91
+ ? this.state.customStyles.separatorStrokeWidth
92
+ : this.state.customStyles.separatorStrokeUnfinishedWidth,
93
+ };
94
+ }
95
+ else {
96
+ progressBarBackgroundStyle = {
97
+ backgroundColor: this.state.customStyles.separatorUnFinishedColor,
98
+ position: "absolute",
99
+ top: (this.state.height - this.state.customStyles.separatorStrokeWidth) /
100
+ 2,
101
+ left: this.state.width / (2 * stepCount),
102
+ right: this.state.width / (2 * stepCount),
103
+ height: this.state.customStyles.separatorStrokeUnfinishedWidth === 0
104
+ ? this.state.customStyles.separatorStrokeWidth
105
+ : this.state.customStyles.separatorStrokeUnfinishedWidth,
106
+ };
107
+ }
108
+ return (React.createElement(View, { onLayout: (event) => {
109
+ if (direction === "vertical") {
110
+ this.setState({ progressBarSize: event.nativeEvent.layout.height }, () => {
111
+ this.onCurrentPositionChanged(this.props.currentPosition);
112
+ });
113
+ }
114
+ else {
115
+ this.setState({ progressBarSize: event.nativeEvent.layout.width }, () => {
116
+ this.onCurrentPositionChanged(this.props.currentPosition);
117
+ });
118
+ }
119
+ }, style: progressBarBackgroundStyle }));
120
+ };
121
+ renderProgressBar = () => {
122
+ const { stepCount, direction } = this.props;
123
+ let progressBarStyle;
124
+ if (direction === "vertical") {
125
+ progressBarStyle = {
126
+ backgroundColor: this.state.customStyles.separatorFinishedColor,
127
+ position: "absolute",
128
+ left: (this.state.width - this.state.customStyles.separatorStrokeWidth) / 2,
129
+ top: this.state.height / (2 * stepCount),
130
+ bottom: this.state.height / (2 * stepCount),
131
+ width: this.state.customStyles.separatorStrokeFinishedWidth === 0
132
+ ? this.state.customStyles.separatorStrokeWidth
133
+ : this.state.customStyles.separatorStrokeFinishedWidth,
134
+ height: this.progressAnim,
135
+ };
136
+ }
137
+ else {
138
+ progressBarStyle = {
139
+ backgroundColor: this.state.customStyles.separatorFinishedColor,
140
+ position: "absolute",
141
+ top: (this.state.height - this.state.customStyles.separatorStrokeWidth) /
142
+ 2,
143
+ left: this.state.width / (2 * stepCount),
144
+ right: this.state.width / (2 * stepCount),
145
+ height: this.state.customStyles.separatorStrokeFinishedWidth === 0
146
+ ? this.state.customStyles.separatorStrokeWidth
147
+ : this.state.customStyles.separatorStrokeFinishedWidth,
148
+ width: this.progressAnim,
149
+ };
150
+ }
151
+ return React.createElement(Animated.View, { style: progressBarStyle });
152
+ };
153
+ renderStepIndicator = () => {
154
+ let steps = [];
155
+ const { stepCount, direction } = this.props;
156
+ for (let position = 0; position < stepCount; position++) {
157
+ steps.push(React.createElement(TouchableWithoutFeedback, { key: position, onPress: () => this.stepPressed(position) },
158
+ React.createElement(View, { style: [
159
+ styles.stepContainer,
160
+ direction === "vertical"
161
+ ? { flexDirection: "column" }
162
+ : { flexDirection: "row" },
163
+ ] }, this.renderStep(position))));
164
+ }
165
+ return (React.createElement(View, { onLayout: (event) => this.setState({
166
+ width: event.nativeEvent.layout.width,
167
+ height: event.nativeEvent.layout.height,
168
+ }), style: [
169
+ styles.stepIndicatorContainer,
170
+ direction === "vertical"
171
+ ? {
172
+ flexDirection: "column",
173
+ width: this.state.customStyles.currentStepIndicatorSize,
174
+ }
175
+ : {
176
+ flexDirection: "row",
177
+ height: this.state.customStyles.currentStepIndicatorSize,
178
+ },
179
+ ] }, steps));
180
+ };
181
+ renderStepLabels = () => {
182
+ const { labels, direction, currentPosition, renderLabel } = this.props;
183
+ var labelViews = labels.map((label, index) => {
184
+ const selectedStepLabelStyle = index === currentPosition
185
+ ? { color: this.state.customStyles.currentStepLabelColor }
186
+ : { color: this.state.customStyles.labelColor };
187
+ return (React.createElement(TouchableWithoutFeedback, { style: styles.stepLabelItem, key: index, onPress: () => this.stepPressed(index) },
188
+ React.createElement(View, { style: styles.stepLabelItem }, renderLabel ? (renderLabel({
189
+ position: index,
190
+ stepStatus: this.getStepStatus(index),
191
+ label,
192
+ currentPosition,
193
+ })) : (React.createElement(Text, { style: [
194
+ styles.stepLabel,
195
+ selectedStepLabelStyle,
196
+ {
197
+ fontSize: this.state.customStyles.labelSize,
198
+ fontFamily: this.state.customStyles.labelFontFamily,
199
+ },
200
+ ] }, label)))));
201
+ });
202
+ return (React.createElement(View, { style: [
203
+ styles.stepLabelsContainer,
204
+ direction === "vertical"
205
+ ? { flexDirection: "column", paddingHorizontal: 4 }
206
+ : { flexDirection: "row", paddingVertical: 4 },
207
+ { alignItems: this.state.customStyles.labelAlign },
208
+ ] }, labelViews));
209
+ };
210
+ renderStep = (position) => {
211
+ const { renderStepIndicator } = this.props;
212
+ let stepStyle;
213
+ let indicatorLabelStyle;
214
+ switch (this.getStepStatus(position)) {
215
+ case STEP_STATUS.CURRENT: {
216
+ stepStyle = {
217
+ backgroundColor: this.state.customStyles.stepIndicatorCurrentColor,
218
+ borderWidth: this.state.customStyles.currentStepStrokeWidth,
219
+ borderColor: this.state.customStyles.stepStrokeCurrentColor,
220
+ height: this.sizeAnim,
221
+ width: this.sizeAnim,
222
+ borderRadius: this.borderRadiusAnim,
223
+ };
224
+ indicatorLabelStyle = {
225
+ fontSize: this.state.customStyles.currentStepIndicatorLabelFontSize,
226
+ color: this.state.customStyles.stepIndicatorLabelCurrentColor,
227
+ };
228
+ break;
229
+ }
230
+ case STEP_STATUS.FINISHED: {
231
+ stepStyle = {
232
+ backgroundColor: this.state.customStyles.stepIndicatorFinishedColor,
233
+ borderWidth: this.state.customStyles.stepStrokeWidth,
234
+ borderColor: this.state.customStyles.stepStrokeFinishedColor,
235
+ height: this.state.customStyles.stepIndicatorSize,
236
+ width: this.state.customStyles.stepIndicatorSize,
237
+ borderRadius: this.state.customStyles.stepIndicatorSize / 2,
238
+ };
239
+ indicatorLabelStyle = {
240
+ fontSize: this.state.customStyles.stepIndicatorLabelFontSize,
241
+ color: this.state.customStyles.stepIndicatorLabelFinishedColor,
242
+ };
243
+ break;
244
+ }
245
+ case STEP_STATUS.UNFINISHED: {
246
+ stepStyle = {
247
+ backgroundColor: this.state.customStyles.stepIndicatorUnFinishedColor,
248
+ borderWidth: this.state.customStyles.stepStrokeWidth,
249
+ borderColor: this.state.customStyles.stepStrokeUnFinishedColor,
250
+ height: this.state.customStyles.stepIndicatorSize,
251
+ width: this.state.customStyles.stepIndicatorSize,
252
+ borderRadius: this.state.customStyles.stepIndicatorSize / 2,
253
+ };
254
+ indicatorLabelStyle = {
255
+ overflow: "hidden",
256
+ fontSize: this.state.customStyles.stepIndicatorLabelFontSize,
257
+ color: this.state.customStyles.stepIndicatorLabelUnFinishedColor,
258
+ };
259
+ break;
260
+ }
261
+ default:
262
+ }
263
+ return (React.createElement(Animated.View, { key: "step-indicator", style: [styles.step, stepStyle] }, renderStepIndicator ? (renderStepIndicator({
264
+ position,
265
+ stepStatus: this.getStepStatus(position),
266
+ })) : (React.createElement(Text, { style: indicatorLabelStyle }, `${position + 1}`))));
267
+ };
268
+ getStepStatus = (stepPosition) => {
269
+ const { currentPosition } = this.props;
270
+ if (stepPosition === currentPosition) {
271
+ return STEP_STATUS.CURRENT;
272
+ }
273
+ else if (stepPosition < currentPosition) {
274
+ return STEP_STATUS.FINISHED;
275
+ }
276
+ else {
277
+ return STEP_STATUS.UNFINISHED;
278
+ }
279
+ };
280
+ onCurrentPositionChanged = (position) => {
281
+ let { stepCount } = this.props;
282
+ if (position > stepCount - 1) {
283
+ position = stepCount - 1;
284
+ }
285
+ const animateToPosition = (this.state.progressBarSize / (stepCount - 1)) * position;
286
+ this.sizeAnim.setValue(this.state.customStyles.stepIndicatorSize);
287
+ this.borderRadiusAnim.setValue(this.state.customStyles.stepIndicatorSize / 2);
288
+ Animated.sequence([
289
+ Animated.timing(this.progressAnim, {
290
+ toValue: animateToPosition,
291
+ duration: 200,
292
+ }),
293
+ Animated.parallel([
294
+ Animated.timing(this.sizeAnim, {
295
+ toValue: this.state.customStyles.currentStepIndicatorSize,
296
+ duration: 100,
297
+ }),
298
+ Animated.timing(this.borderRadiusAnim, {
299
+ toValue: this.state.customStyles.currentStepIndicatorSize / 2,
300
+ duration: 100,
301
+ }),
302
+ ]),
303
+ ]).start();
304
+ };
305
+ }
306
+ const styles = StyleSheet.create({
307
+ container: {
308
+ backgroundColor: "transparent",
309
+ },
310
+ stepIndicatorContainer: {
311
+ flexDirection: "row",
312
+ alignItems: "center",
313
+ justifyContent: "space-around",
314
+ backgroundColor: "transparent",
315
+ },
316
+ stepLabelsContainer: {
317
+ justifyContent: "space-around",
318
+ },
319
+ step: {
320
+ alignItems: "center",
321
+ justifyContent: "center",
322
+ zIndex: 2,
323
+ },
324
+ stepContainer: {
325
+ flex: 1,
326
+ flexDirection: "row",
327
+ alignItems: "center",
328
+ justifyContent: "center",
329
+ },
330
+ stepLabel: {
331
+ fontSize: 12,
332
+ textAlign: "center",
333
+ fontWeight: "500",
334
+ },
335
+ stepLabelItem: {
336
+ flex: 1,
337
+ alignItems: "center",
338
+ justifyContent: "center",
339
+ },
340
+ });
341
+ StepIndicator.defaultProps = {
342
+ currentPosition: 0,
343
+ stepCount: 5,
344
+ customStyles: {},
345
+ direction: "horizontal",
346
+ };
@@ -0,0 +1,39 @@
1
+ import React, { useEffect, useState } from "react";
2
+ import { View, Text } from "react-native";
3
+ import { isNumber } from "lodash";
4
+ import { withTheme } from "../theming";
5
+ import IconButton from "./IconButton";
6
+ const Stepper = ({ min = -Infinity, max = Infinity, value: valueProp, defaultValue, style, typeStyle, iconSize = 24, iconColor, onChange, theme: { colors, typography }, Icon, }) => {
7
+ const [value, setValue] = useState(defaultValue ?? 0);
8
+ const isValidValue = (valueArg) => valueArg >= min && valueArg <= max;
9
+ const handlePlusOrMinus = (type) => {
10
+ const newValue = type === "plus" ? value + 1 : value - 1;
11
+ if (isValidValue(newValue)) {
12
+ setValue(newValue);
13
+ onChange?.(newValue);
14
+ }
15
+ };
16
+ useEffect(() => {
17
+ if (valueProp != null &&
18
+ isNumber(valueProp) &&
19
+ valueProp !== value &&
20
+ isValidValue(valueProp)) {
21
+ setValue(valueProp);
22
+ }
23
+ // eslint-disable-next-line react-hooks/exhaustive-deps
24
+ }, [valueProp]);
25
+ return (React.createElement(View, { style: [{ flexDirection: "row" }, style] },
26
+ React.createElement(IconButton, { Icon: Icon, icon: "MaterialIcons/remove", onPress: () => handlePlusOrMinus("minus"), size: iconSize, color: iconColor, disabled: value === min, style: { opacity: value === min ? 0.5 : 1 } }),
27
+ React.createElement(Text, { style: [
28
+ typography.body1,
29
+ {
30
+ textAlign: "center",
31
+ alignSelf: "center",
32
+ color: colors.medium,
33
+ marginHorizontal: 8,
34
+ },
35
+ typeStyle,
36
+ ] }, value),
37
+ React.createElement(IconButton, { Icon: Icon, icon: "MaterialIcons/add", onPress: () => handlePlusOrMinus("plus"), size: iconSize, color: iconColor, disabled: value === max, style: { opacity: value === max ? 0.5 : 1 } })));
38
+ };
39
+ export default withTheme(Stepper);
@@ -0,0 +1,32 @@
1
+ /* Copied from https://github.com/callstack/react-native-paper/blob/main/src/components/Surface.tsx */
2
+ import * as React from "react";
3
+ import { Animated, StyleSheet, } from "react-native";
4
+ import shadow from "../styles/shadow";
5
+ import overlay from "../styles/overlay";
6
+ import { withTheme } from "../theming";
7
+ const Surface = ({ elevation: propElevation, style, theme, children, ...rest }) => {
8
+ const { elevation: styleElevation = 3, backgroundColor, ...restStyle } = (StyleSheet.flatten(style) || {});
9
+ const { dark: isDarkTheme, mode, colors } = theme;
10
+ const elevation = propElevation || styleElevation;
11
+ const evalationStyles = elevation ? shadow(elevation) : {};
12
+ const getBackgroundColor = () => {
13
+ if (backgroundColor) {
14
+ return backgroundColor;
15
+ }
16
+ else if (isDarkTheme && mode === "adaptive") {
17
+ return overlay(elevation, colors.surface);
18
+ }
19
+ else {
20
+ return colors.surface;
21
+ }
22
+ };
23
+ return (React.createElement(Animated.View, { ...rest, style: [
24
+ {
25
+ backgroundColor: getBackgroundColor(),
26
+ elevation,
27
+ ...evalationStyles,
28
+ ...restStyle,
29
+ },
30
+ ] }, children));
31
+ };
32
+ export default withTheme(Surface);
@@ -0,0 +1,29 @@
1
+ import React from "react";
2
+ import { View } from "react-native";
3
+ import SwiperComponent from "react-native-web-swiper";
4
+ const Swiper = ({ vertical = false, loop = false, timeout = 0, from = 0, prevTitle = "", nextTitle = "", prevTitleColor, nextTitleColor, dotsTouchable = true, dotColor, dotActiveColor, data, keyExtractor, renderItem, children, style, }) => (React.createElement(View, { style: style },
5
+ React.createElement(SwiperComponent, { from: from, loop: loop, timeout: timeout, vertical: vertical, controlsProps: {
6
+ prevTitle,
7
+ nextTitle,
8
+ prevTitleStyle: { color: prevTitleColor },
9
+ nextTitleStyle: { color: nextTitleColor },
10
+ dotsTouchable,
11
+ ...(dotColor
12
+ ? { dotProps: { badgeStyle: { backgroundColor: dotColor } } }
13
+ : {}),
14
+ ...(dotActiveColor
15
+ ? { dotActiveStyle: { backgroundColor: dotActiveColor } }
16
+ : {}),
17
+ } }, data && renderItem
18
+ ? data.map((item, index) => {
19
+ const component = renderItem({ item, index });
20
+ if (!component) {
21
+ return null;
22
+ }
23
+ const key = keyExtractor ? keyExtractor(item, index) : index;
24
+ return React.cloneElement(component, {
25
+ key,
26
+ });
27
+ })
28
+ : children)));
29
+ export default Swiper;
@@ -0,0 +1,9 @@
1
+ import React from "react";
2
+ import { View, StyleSheet } from "react-native";
3
+ const styles = StyleSheet.create({
4
+ wrapper: {
5
+ flex: 1,
6
+ },
7
+ });
8
+ const SwiperItem = ({ children, style }) => (React.createElement(View, { style: [styles.wrapper, style] }, children));
9
+ export default SwiperItem;
@@ -0,0 +1,2 @@
1
+ export { default as Swiper } from "./Swiper";
2
+ export { default as SwiperItem } from "./SwiperItem";
@@ -0,0 +1,56 @@
1
+ import * as React from "react";
2
+ import { Switch as NativeSwitch, } from "react-native";
3
+ import { withTheme } from "../theming";
4
+ import FormRow from "./FormRow";
5
+ import { RowDirection } from "@draftbit/types";
6
+ import { usePrevious } from "../hooks";
7
+ function Switch({ value, defaultValue, disabled, onValueChange, activeTrackColor, inactiveTrackColor, activeThumbColor, inactiveThumbColor, theme, style, ...rest }) {
8
+ const activeTrackThemeColor = activeTrackColor || theme.colors.primary;
9
+ const inactiveTrackThemeColor = inactiveTrackColor || "#EEE";
10
+ const activeThumbThemeColor = activeThumbColor || "#FFF";
11
+ const inactiveThumbThemeColor = inactiveThumbColor || "#FFF";
12
+ const [checked, setChecked] = React.useState(value || defaultValue);
13
+ React.useEffect(() => {
14
+ if (value != null && value !== checked) {
15
+ setChecked(value);
16
+ }
17
+ }, [value, checked]);
18
+ // This special logic is to handle weird APIs like Airtable that return
19
+ // true or undefined for a boolean
20
+ const previousDefaultValue = usePrevious(defaultValue);
21
+ React.useEffect(() => {
22
+ if (defaultValue !== previousDefaultValue) {
23
+ setChecked(Boolean(defaultValue));
24
+ }
25
+ }, [defaultValue, previousDefaultValue]);
26
+ return (React.createElement(NativeSwitch, { value: checked, disabled: disabled, trackColor: {
27
+ false: inactiveTrackThemeColor,
28
+ true: activeTrackThemeColor,
29
+ }, thumbColor: value ? activeThumbThemeColor : inactiveThumbThemeColor,
30
+ // @ts-ignore react-native-web only
31
+ activeThumbColor: activeThumbThemeColor, ios_backgroundColor: inactiveTrackThemeColor, style: style, onValueChange: (bool) => {
32
+ setChecked(bool);
33
+ onValueChange && onValueChange(bool);
34
+ }, ...rest }));
35
+ }
36
+ function Row({ label = "Label", direction = RowDirection.Row, style, value, defaultValue, disabled, onValueChange, activeTrackColor, inactiveTrackColor, activeThumbColor, inactiveThumbColor, theme, ...rest }) {
37
+ const [checked, setChecked] = React.useState(value != null ? value : defaultValue);
38
+ React.useEffect(() => {
39
+ if (value != null) {
40
+ setChecked(value);
41
+ }
42
+ }, [value]);
43
+ React.useEffect(() => {
44
+ if (defaultValue != null) {
45
+ setChecked(defaultValue);
46
+ }
47
+ }, [defaultValue]);
48
+ return (React.createElement(FormRow, { disabled: disabled, onPress: () => {
49
+ setChecked(!checked);
50
+ onValueChange && onValueChange(!checked);
51
+ }, label: label, direction: direction, style: style, ...rest },
52
+ React.createElement(Switch, { theme: theme, value: checked, disabled: disabled, onValueChange: onValueChange, activeTrackColor: activeTrackColor, inactiveTrackColor: inactiveTrackColor, activeThumbColor: activeThumbColor, inactiveThumbColor: inactiveThumbColor })));
53
+ }
54
+ const SwitchRow = withTheme(Row);
55
+ export { SwitchRow };
56
+ export default withTheme(Switch);
@@ -0,0 +1,28 @@
1
+ import * as React from "react";
2
+ import { Text as NativeText, I18nManager } from "react-native";
3
+ import { withTheme } from "../theming";
4
+ class Text extends React.Component {
5
+ _root;
6
+ setNativeProps(args) {
7
+ return this._root && this._root.setNativeProps(args);
8
+ }
9
+ render() {
10
+ const { style, ...rest } = this.props;
11
+ const writingDirection = I18nManager.isRTL ? "rtl" : "ltr";
12
+ return (React.createElement(NativeText, { ...rest, ref: (c) => {
13
+ this._root = c;
14
+ }, style: [
15
+ {
16
+ textAlign: "left",
17
+ writingDirection,
18
+ },
19
+ style,
20
+ ] }));
21
+ }
22
+ }
23
+ export const BaseLink = ({ style, theme, title, ...props }) => {
24
+ return (React.createElement(Text, { hitSlop: 8, style: [{ color: theme.colors.primary }, style], theme: theme, ...props }, title));
25
+ };
26
+ const Link = withTheme(BaseLink);
27
+ export { Link };
28
+ export default withTheme(Text);