@draftbit/core 44.1.15 → 44.2.1-ada448.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 (215) hide show
  1. package/lib/commonjs/components/Accordion/index.js.map +1 -1
  2. package/lib/commonjs/components/ActionSheet/index.js.map +1 -1
  3. package/lib/commonjs/components/CircularProgress.js.map +1 -1
  4. package/lib/commonjs/components/Container.js +16 -5
  5. package/lib/commonjs/components/Container.js.map +1 -1
  6. package/lib/commonjs/components/DeprecatedButton.js +19 -4
  7. package/lib/commonjs/components/DeprecatedButton.js.map +1 -1
  8. package/lib/commonjs/components/DeprecatedCardWrapper.js +14 -2
  9. package/lib/commonjs/components/DeprecatedCardWrapper.js.map +1 -1
  10. package/lib/commonjs/components/Divider.js +13 -3
  11. package/lib/commonjs/components/Divider.js.map +1 -1
  12. package/lib/commonjs/components/FAB.js +19 -5
  13. package/lib/commonjs/components/FAB.js.map +1 -1
  14. package/lib/commonjs/components/FormRow.js +18 -5
  15. package/lib/commonjs/components/FormRow.js.map +1 -1
  16. package/lib/commonjs/components/Justification.js +3 -0
  17. package/lib/commonjs/components/ResizeMode.js +3 -0
  18. package/lib/commonjs/index.js.map +1 -1
  19. package/lib/commonjs/mappings/Card.js.map +1 -1
  20. package/lib/commonjs/mappings/Picker.js +1 -7
  21. package/lib/commonjs/mappings/Picker.js.map +1 -1
  22. package/lib/commonjs/mappings/RadioButtonGroup.js.map +1 -1
  23. package/lib/commonjs/mappings/RadioButtonRow.js.map +1 -1
  24. package/lib/commonjs/mappings/RowHeadlineImageIcon.js.map +1 -1
  25. package/lib/commonjs/mappings/TextArea.js.map +1 -1
  26. package/lib/commonjs/utilities.js +0 -19
  27. package/lib/commonjs/utilities.js.map +1 -1
  28. package/lib/module/components/Justification.js +1 -1
  29. package/lib/module/components/Layout.js +26 -24
  30. package/lib/module/components/Layout.js.map +1 -1
  31. package/lib/module/components/ResizeMode.js +1 -1
  32. package/lib/module/mappings/Picker.js +2 -8
  33. package/lib/module/mappings/Picker.js.map +1 -1
  34. package/lib/module/utilities.js +1 -12
  35. package/lib/module/utilities.js.map +1 -1
  36. package/lib/typescript/src/mappings/Picker.d.ts +0 -21
  37. package/lib/typescript/src/utilities.d.ts +0 -7
  38. package/package.json +5 -5
  39. package/src/Provider.js +9 -0
  40. package/src/components/Accordion/AccordionGroup.js +44 -0
  41. package/src/components/Accordion/AccordionItem.js +32 -0
  42. package/src/components/Accordion/index.js +2 -0
  43. package/src/components/ActionSheet/ActionSheet.js +45 -0
  44. package/src/components/ActionSheet/ActionSheetCancel.js +6 -0
  45. package/src/components/ActionSheet/ActionSheetItem.js +30 -0
  46. package/src/components/ActionSheet/index.js +3 -0
  47. package/src/components/AnimatedCircularProgress.js +43 -0
  48. package/src/components/AspectRatio.js +18 -0
  49. package/src/components/AvatarEdit.js +30 -0
  50. package/src/components/Banner.js +109 -0
  51. package/src/components/Button.js +112 -0
  52. package/src/components/Card.js +57 -0
  53. package/src/components/CardBlock.js +54 -0
  54. package/src/components/CardContainer.js +69 -0
  55. package/src/components/CardContainerRating.js +79 -0
  56. package/src/components/CardContainerShortImage.js +33 -0
  57. package/src/components/CardInline.js +36 -0
  58. package/src/components/Carousel.js +66 -0
  59. package/src/components/Checkbox/Checkbox.js +63 -0
  60. package/src/components/Checkbox/CheckboxGroup.js +21 -0
  61. package/src/components/Checkbox/CheckboxGroupRow.js +77 -0
  62. package/src/components/Checkbox/CheckboxRow.js +78 -0
  63. package/src/components/Checkbox/context.js +14 -0
  64. package/src/components/Checkbox/index.js +3 -0
  65. package/src/components/CircleImage.js +8 -0
  66. package/src/components/CircularProgress.js +78 -0
  67. package/src/components/Config.js +63 -0
  68. package/src/components/Container.js +43 -0
  69. package/src/components/DatePicker/DatePicker.js +368 -0
  70. package/src/components/DatePicker/DatePickerComponent.js +13 -0
  71. package/src/components/DatePicker/DatePickerComponent.web.js +30 -0
  72. package/src/components/DatePicker/DatePickerComponentType.js +1 -0
  73. package/src/components/DeprecatedButton.js +95 -0
  74. package/src/components/DeprecatedCardWrapper.js +18 -0
  75. package/src/components/DeprecatedFAB.js +115 -0
  76. package/src/components/Divider.js +13 -0
  77. package/src/components/Elevation.js +20 -0
  78. package/src/components/FAB.js +46 -0
  79. package/src/components/FieldSearchBarFull.js +53 -0
  80. package/src/components/FormRow.js +19 -0
  81. package/src/components/Header.js +44 -0
  82. package/src/components/HeaderLarge.js +7 -0
  83. package/src/components/HeaderMedium.js +7 -0
  84. package/src/components/HeaderOverline.js +7 -0
  85. package/src/components/IconButton.js +35 -0
  86. package/src/components/Image.js +47 -0
  87. package/src/components/Justification.js +1 -0
  88. package/src/components/Layout.js +50 -0
  89. package/src/components/NumberInput.js +49 -0
  90. package/src/components/Picker/Picker.js +56 -0
  91. package/src/components/Picker/PickerComponent.android.js +68 -0
  92. package/src/components/Picker/PickerComponent.ios.js +78 -0
  93. package/src/components/Picker/PickerComponent.web.js +69 -0
  94. package/src/components/Picker/PickerTypes.js +1 -0
  95. package/src/components/Portal/Portal.js +35 -0
  96. package/src/components/Portal/PortalConsumer.js +28 -0
  97. package/src/components/Portal/PortalHost.js +105 -0
  98. package/src/components/Portal/PortalManager.js +29 -0
  99. package/src/components/ProgressBar.js +118 -0
  100. package/src/components/ProgressCircle.js +13 -0
  101. package/src/components/ProgressIndicator.js +27 -0
  102. package/src/components/RadioButton/RadioButton.js +17 -0
  103. package/src/components/RadioButton/RadioButtonFieldGroup.js +17 -0
  104. package/src/components/RadioButton/RadioButtonGroup.js +43 -0
  105. package/src/components/RadioButton/RadioButtonRow.js +76 -0
  106. package/src/components/RadioButton/context.js +14 -0
  107. package/src/components/RadioButton/index.js +4 -0
  108. package/src/components/ResizeMode.js +1 -0
  109. package/src/components/Row.js +48 -0
  110. package/src/components/RowBodyIcon.js +8 -0
  111. package/src/components/RowHeadlineImageCaption.js +12 -0
  112. package/src/components/RowHeadlineImageIcon.js +14 -0
  113. package/src/components/ScreenContainer.js +34 -0
  114. package/src/components/Slider.js +63 -0
  115. package/src/components/StarRating.js +50 -0
  116. package/src/components/StepIndicator.js +346 -0
  117. package/src/components/Stepper.js +39 -0
  118. package/src/components/Surface.js +32 -0
  119. package/src/components/Swiper/Swiper.js +29 -0
  120. package/src/components/Swiper/SwiperItem.js +9 -0
  121. package/src/components/Swiper/index.js +2 -0
  122. package/src/components/Switch.js +56 -0
  123. package/src/components/Text.js +28 -0
  124. package/src/components/TextField.js +420 -0
  125. package/src/components/ToggleButton.js +39 -0
  126. package/src/components/Touchable.js +12 -0
  127. package/src/components/Touchable.web.js +2 -0
  128. package/src/components/Typography.js +36 -0
  129. package/src/components/useAuthState.js +31 -0
  130. package/src/constants.js +10 -0
  131. package/src/hooks.js +12 -0
  132. package/src/index.js +52 -0
  133. package/src/interfaces/Icon.js +8 -0
  134. package/src/mappings/Accordion.js +41 -0
  135. package/src/mappings/AccordionItem.js +16 -0
  136. package/src/mappings/ActionSheet.js +13 -0
  137. package/src/mappings/ActionSheetCancel.js +19 -0
  138. package/src/mappings/ActionSheetItem.js +23 -0
  139. package/src/mappings/ActivityIndicator.js +53 -0
  140. package/src/mappings/AudioPlayer.js +20 -0
  141. package/src/mappings/AvatarEdit.js +37 -0
  142. package/src/mappings/Banner.js +32 -0
  143. package/src/mappings/BlurView.js +41 -0
  144. package/src/mappings/Button.js +56 -0
  145. package/src/mappings/Card.js +52 -0
  146. package/src/mappings/CardBlock.js +122 -0
  147. package/src/mappings/CardContainer.js +102 -0
  148. package/src/mappings/CardContainerRating.js +124 -0
  149. package/src/mappings/CardContainerShortImage.js +118 -0
  150. package/src/mappings/CardInline.js +51 -0
  151. package/src/mappings/Carousel.js +18 -0
  152. package/src/mappings/Checkbox.js +45 -0
  153. package/src/mappings/CheckboxGroup.js +25 -0
  154. package/src/mappings/CheckboxRow.js +56 -0
  155. package/src/mappings/CircleImage.js +24 -0
  156. package/src/mappings/Container.js +29 -0
  157. package/src/mappings/CustomCode.js +8 -0
  158. package/src/mappings/DatePicker.js +146 -0
  159. package/src/mappings/Divider.js +26 -0
  160. package/src/mappings/FAB.js +36 -0
  161. package/src/mappings/Fetch.js +12 -0
  162. package/src/mappings/FieldSearchBarFull.js +49 -0
  163. package/src/mappings/FlatList.js +19 -0
  164. package/src/mappings/HeaderLarge.js +28 -0
  165. package/src/mappings/HeaderMedium.js +54 -0
  166. package/src/mappings/HeaderOverline.js +54 -0
  167. package/src/mappings/Icon.js +25 -0
  168. package/src/mappings/IconButton.js +30 -0
  169. package/src/mappings/Image.js +15 -0
  170. package/src/mappings/ImageBackground.js +28 -0
  171. package/src/mappings/KeyboardAvoidingView.js +40 -0
  172. package/src/mappings/KeyboardAwareScrollView.js +49 -0
  173. package/src/mappings/Layout.js +195 -0
  174. package/src/mappings/LinearGradient.js +77 -0
  175. package/src/mappings/MapCallout.js +21 -0
  176. package/src/mappings/MapMarker.js +47 -0
  177. package/src/mappings/MapView.js +138 -0
  178. package/src/mappings/Modal.js +41 -0
  179. package/src/mappings/Picker.js +137 -0
  180. package/src/mappings/Picker.ts +0 -4
  181. package/src/mappings/ProgressBar.js +100 -0
  182. package/src/mappings/ProgressCircle.js +108 -0
  183. package/src/mappings/ProgressIndicator.js +180 -0
  184. package/src/mappings/RadioButton.js +50 -0
  185. package/src/mappings/RadioButtonGroup.js +16 -0
  186. package/src/mappings/RadioButtonRow.js +37 -0
  187. package/src/mappings/RowBodyIcon.js +75 -0
  188. package/src/mappings/RowHeadlineImageCaption.js +167 -0
  189. package/src/mappings/RowHeadlineImageIcon.js +99 -0
  190. package/src/mappings/SafeAreaView.js +33 -0
  191. package/src/mappings/ScrollView.js +30 -0
  192. package/src/mappings/Slider.js +59 -0
  193. package/src/mappings/StarRating.js +42 -0
  194. package/src/mappings/Stepper.js +28 -0
  195. package/src/mappings/Surface.js +13 -0
  196. package/src/mappings/Swiper.js +60 -0
  197. package/src/mappings/SwiperItem.js +8 -0
  198. package/src/mappings/Switch.js +75 -0
  199. package/src/mappings/Text.js +232 -0
  200. package/src/mappings/TextArea.js +52 -0
  201. package/src/mappings/TextField.js +158 -0
  202. package/src/mappings/TextInput.js +208 -0
  203. package/src/mappings/ToggleButton.js +45 -0
  204. package/src/mappings/Touchable.js +12 -0
  205. package/src/mappings/Video.js +74 -0
  206. package/src/mappings/View.js +206 -0
  207. package/src/mappings/WebView.js +18 -0
  208. package/src/styles/DarkTheme.js +26 -0
  209. package/src/styles/DefaultTheme.js +111 -0
  210. package/src/styles/fonts.js +62 -0
  211. package/src/styles/overlay.js +60 -0
  212. package/src/styles/shadow.js +51 -0
  213. package/src/theming.js +3 -0
  214. package/src/utilities.js +54 -0
  215. package/src/utilities.ts +1 -65
@@ -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 radioButtonGroupContext = createContext({
8
+ onValueChange: () => { },
9
+ value: "",
10
+ direction: undefined,
11
+ });
12
+ export function useRadioButtonGroupContext() {
13
+ return useContext(radioButtonGroupContext);
14
+ }
@@ -0,0 +1,4 @@
1
+ export { default as RadioButton } from "./RadioButton";
2
+ export { default as RadioButtonGroup } from "./RadioButtonGroup";
3
+ export { default as RadioButtonRow } from "./RadioButtonRow";
4
+ export { default as RadioButtonFieldGroup } from "./RadioButtonFieldGroup";
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,48 @@
1
+ import * as React from "react";
2
+ import { View, Text, Image, StyleSheet, } from "react-native";
3
+ import { withTheme } from "../theming";
4
+ import Config from "./Config";
5
+ const Row = ({ titleTypeStyle, titleColor, subtitleTypeStyle, subtitleColor, title, subtitle, multilineSubtitle, image, right, style, }) => {
6
+ return (React.createElement(View, { style: [styles.container, { padding: 16 }, style] },
7
+ React.createElement(View, { style: styles.leftContainer },
8
+ image && (React.createElement(Image, { source: typeof image === "string" ? { uri: image } : image, style: {
9
+ marginRight: 12,
10
+ width: subtitle
11
+ ? Config.rowMultiLineImageSize
12
+ : Config.rowSingleLineImageSize,
13
+ height: subtitle
14
+ ? Config.rowMultiLineImageSize
15
+ : Config.rowSingleLineImageSize,
16
+ } })),
17
+ React.createElement(View, { style: styles.textContainer },
18
+ React.createElement(Text, { style: [
19
+ titleTypeStyle,
20
+ {
21
+ color: titleColor,
22
+ },
23
+ ], numberOfLines: 1 }, title),
24
+ subtitle ? (React.createElement(Text, { style: [
25
+ subtitleTypeStyle,
26
+ {
27
+ color: subtitleColor,
28
+ marginTop: 4,
29
+ },
30
+ ], numberOfLines: multilineSubtitle ? undefined : 1 }, subtitle)) : null)),
31
+ right && right()));
32
+ };
33
+ const styles = StyleSheet.create({
34
+ leftContainer: {
35
+ flexDirection: "row",
36
+ flex: 1,
37
+ },
38
+ container: {
39
+ flexDirection: "row",
40
+ justifyContent: "space-between",
41
+ alignItems: "center",
42
+ },
43
+ textContainer: {
44
+ flex: 1,
45
+ justifyContent: "center",
46
+ },
47
+ });
48
+ export default withTheme(Row);
@@ -0,0 +1,8 @@
1
+ import * as React from "react";
2
+ import { withTheme } from "../theming";
3
+ import Row from "./Row";
4
+ import Config from "./Config";
5
+ const RowBodyIcon = ({ Icon, title, subtitle, icon, style, theme: { colors, typography }, }) => {
6
+ return (React.createElement(Row, { titleTypeStyle: typography.body1, titleColor: colors.medium, subtitleTypeStyle: typography.subtitle2, subtitleColor: colors.light, title: title, subtitle: subtitle, right: () => (React.createElement(Icon, { name: icon, size: Config.rowSingleLineIconSize, color: colors.light, style: { marginLeft: 16 } })), style: style }));
7
+ };
8
+ export default withTheme(RowBodyIcon);
@@ -0,0 +1,12 @@
1
+ import * as React from "react";
2
+ import { Text } from "react-native";
3
+ import { withTheme } from "../theming";
4
+ import Row from "./Row";
5
+ const RowHeadlineImageCaption = ({ title, subtitle, caption, image, style, theme: { colors, typography }, }) => {
6
+ return (React.createElement(Row, { titleTypeStyle: typography.headline6, titleColor: colors.strong, subtitleTypeStyle: typography.body2, subtitleColor: colors.medium, title: title, subtitle: subtitle, image: image, right: () => (React.createElement(Text, { style: {
7
+ ...typography.caption,
8
+ color: colors.strong,
9
+ marginLeft: 16,
10
+ } }, caption)), style: style }));
11
+ };
12
+ export default withTheme(RowHeadlineImageCaption);
@@ -0,0 +1,14 @@
1
+ import * as React from "react";
2
+ import { withTheme } from "../theming";
3
+ import Row from "./Row";
4
+ import Config from "./Config";
5
+ const RowHeadlineImageIcon = ({ Icon, icon, title, image, subtitle, multilineSubtitle = false, style, theme: { colors, typography }, }) => {
6
+ return (React.createElement(Row, { titleTypeStyle: typography.headline6, titleColor: colors.strong, subtitleTypeStyle: typography.body2, subtitleColor: colors.medium, title: title, subtitle: subtitle, multilineSubtitle: multilineSubtitle, image: image, right: () => (React.createElement(Icon, { name: icon, size: multilineSubtitle
7
+ ? Config.rowMultiLineIconSize
8
+ : Config.rowSingleLineIconSize, color: colors.light, style: {
9
+ marginLeft: 16,
10
+ alignSelf: multilineSubtitle ? "flex-start" : "center",
11
+ marginTop: multilineSubtitle ? 4 : 0,
12
+ } })), style: style }));
13
+ };
14
+ export default withTheme(RowHeadlineImageIcon);
@@ -0,0 +1,34 @@
1
+ import * as React from "react";
2
+ import { StyleSheet, ScrollView, View, } from "react-native";
3
+ import { SafeAreaView } from "react-native-safe-area-context";
4
+ import { withTheme } from "../theming";
5
+ function ScreenContainer({ scrollable = false, hasSafeArea = false, hasBottomSafeArea = false, hasTopSafeArea = false, theme, style, children, ...rest }) {
6
+ const backgroundColor = theme.colors.background;
7
+ const edges = ["left", "right"];
8
+ if (hasSafeArea || hasTopSafeArea) {
9
+ edges.push("top");
10
+ }
11
+ if (hasSafeArea || hasBottomSafeArea) {
12
+ edges.push("bottom");
13
+ }
14
+ return (React.createElement(SafeAreaView, { edges: edges, style: [
15
+ styles.container,
16
+ {
17
+ backgroundColor,
18
+ },
19
+ ], ...rest }, scrollable ? (React.createElement(ScrollView, { contentContainerStyle: [
20
+ styles.scrollViewContainer,
21
+ { backgroundColor },
22
+ style,
23
+ ] }, children)) : (React.createElement(View, { style: [styles.container, { backgroundColor }, style] }, children))));
24
+ }
25
+ const styles = StyleSheet.create({
26
+ container: {
27
+ flex: 1,
28
+ },
29
+ scrollViewContainer: {
30
+ flexGrow: 1,
31
+ flex: undefined,
32
+ },
33
+ });
34
+ export default withTheme(ScreenContainer);
@@ -0,0 +1,63 @@
1
+ import * as React from "react";
2
+ import { View, StyleSheet } from "react-native";
3
+ import NativeSlider from "@react-native-community/slider";
4
+ import isNumber from "lodash.isnumber";
5
+ import toNumber from "lodash.tonumber";
6
+ import { withTheme } from "../theming";
7
+ function maybeParseValue(value) {
8
+ if (value === undefined) {
9
+ return undefined;
10
+ }
11
+ if (isNumber(value)) {
12
+ return value;
13
+ }
14
+ try {
15
+ const maybe = toNumber(value);
16
+ if (isNumber(maybe)) {
17
+ return maybe;
18
+ }
19
+ }
20
+ catch {
21
+ return undefined;
22
+ }
23
+ return undefined;
24
+ }
25
+ function Slider({ Icon, leftIcon, rightIcon, leftIconColor, rightIconColor, value, defaultValue, minimumTrackTintColor, maximumTrackTintColor, thumbTintColor, minimumValue = 0, maximumValue = 100, tapToSeek, step = 1, onValueChange = () => { }, style, theme, ...rest }) {
26
+ const [internalValue, setInternalValue] = React.useState(value || defaultValue);
27
+ React.useEffect(() => {
28
+ if (value != null) {
29
+ setInternalValue(value);
30
+ }
31
+ }, [value]);
32
+ React.useEffect(() => {
33
+ if (defaultValue != null) {
34
+ setInternalValue(defaultValue);
35
+ }
36
+ }, [defaultValue]);
37
+ const minTrackColor = minimumTrackTintColor || theme.colors.primary;
38
+ const maxTrackColor = maximumTrackTintColor || theme.colors.light;
39
+ const thumbColor = thumbTintColor || theme.colors.primary;
40
+ const leftIconThemeColor = leftIconColor || theme.colors.light;
41
+ const rightIconThemeColor = rightIconColor || theme.colors.light;
42
+ const parsedValue = maybeParseValue(internalValue);
43
+ const handleSlidingComplete = (newValue) => {
44
+ setInternalValue(newValue);
45
+ onValueChange(newValue);
46
+ };
47
+ return (React.createElement(View, { style: [styles.container, style], ...rest },
48
+ leftIcon ? (React.createElement(Icon, { color: leftIconThemeColor, name: leftIcon, size: 24 })) : null,
49
+ React.createElement(NativeSlider, { value: parsedValue, step: step, minimumValue: minimumValue, maximumValue: maximumValue, tapToSeek: tapToSeek, minimumTrackTintColor: minTrackColor, maximumTrackTintColor: maxTrackColor, thumbTintColor: thumbColor, onSlidingComplete: handleSlidingComplete, style: styles.slider }),
50
+ rightIcon ? (React.createElement(Icon, { color: rightIconThemeColor, name: rightIcon, size: 24 })) : null));
51
+ }
52
+ const styles = StyleSheet.create({
53
+ container: {
54
+ height: 40,
55
+ flexDirection: "row",
56
+ alignItems: "center",
57
+ },
58
+ slider: {
59
+ flex: 1,
60
+ marginHorizontal: 12,
61
+ },
62
+ });
63
+ export default withTheme(Slider);
@@ -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);