@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,83 @@
1
+ import * as React from "react";
2
+ import { withTheme } from "../theming";
3
+ import { COMPONENT_TYPES, FORM_TYPES, GROUPS, PROP_TYPES, } from "@draftbit/types";
4
+ import Row from "./Row";
5
+ import Config from "./Config";
6
+ const RowBodyIcon = ({ Icon, title, subtitle, icon, style, theme: { colors, typography }, }) => {
7
+ 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 }));
8
+ };
9
+ export default withTheme(RowBodyIcon);
10
+ export const SEED_DATA = [
11
+ {
12
+ name: "Row Single Line Body Icon",
13
+ tag: "RowBodyIcon",
14
+ description: "A row with left aligned body text and a right aligned icon",
15
+ category: COMPONENT_TYPES.row,
16
+ preview_image_url: "{CLOUDINARY_URL}/Row_SingleLine_BodyIcon.png",
17
+ supports_list_render: true,
18
+ props: {
19
+ title: {
20
+ group: GROUPS.data,
21
+ label: "Title",
22
+ description: "Text to display",
23
+ formType: FORM_TYPES.string,
24
+ propType: PROP_TYPES.STRING,
25
+ defaultValue: "Beautiful West Coast Villa",
26
+ editable: true,
27
+ required: false,
28
+ },
29
+ icon: {
30
+ group: GROUPS.basic,
31
+ label: "Icon",
32
+ description: "Icon to display",
33
+ formType: FORM_TYPES.icon,
34
+ propType: PROP_TYPES.ASSET,
35
+ defaultValue: null,
36
+ editable: true,
37
+ required: false,
38
+ },
39
+ },
40
+ layout: {},
41
+ },
42
+ {
43
+ name: "Row Double Line Body Icon",
44
+ tag: "RowBodyIcon",
45
+ description: "A row with left aligned body text and subtitle text and a right aligned icon",
46
+ category: COMPONENT_TYPES.row,
47
+ preview_image_url: "{CLOUDINARY_URL}/Row_DoubleLine_BodyIcon.png",
48
+ supports_list_render: true,
49
+ props: {
50
+ title: {
51
+ group: GROUPS.data,
52
+ label: "Title",
53
+ description: "Text to display",
54
+ formType: FORM_TYPES.string,
55
+ propType: PROP_TYPES.STRING,
56
+ defaultValue: "Beautiful West Coast Villa",
57
+ editable: true,
58
+ required: false,
59
+ },
60
+ subtitle: {
61
+ group: GROUPS.data,
62
+ label: "Subtitle",
63
+ description: "Subtitle text to display",
64
+ formType: FORM_TYPES.string,
65
+ propType: PROP_TYPES.STRING,
66
+ defaultValue: "San Diego",
67
+ editable: true,
68
+ required: false,
69
+ },
70
+ icon: {
71
+ group: GROUPS.basic,
72
+ label: "Icon",
73
+ description: "Icon to display",
74
+ formType: FORM_TYPES.icon,
75
+ propType: PROP_TYPES.ASSET,
76
+ defaultValue: null,
77
+ editable: true,
78
+ required: false,
79
+ },
80
+ },
81
+ layout: {},
82
+ },
83
+ ];
@@ -0,0 +1,179 @@
1
+ import * as React from "react";
2
+ import { Text } from "react-native";
3
+ import { withTheme } from "../theming";
4
+ import { COMPONENT_TYPES, FORM_TYPES, PROP_TYPES, GROUPS, } from "@draftbit/types";
5
+ import Row from "./Row";
6
+ const RowHeadlineImageCaption = ({ title, subtitle, caption, image, style, theme: { colors, typography }, }) => {
7
+ 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: {
8
+ ...typography.caption,
9
+ color: colors.strong,
10
+ marginLeft: 16,
11
+ } }, caption)), style: style }));
12
+ };
13
+ export default withTheme(RowHeadlineImageCaption);
14
+ export const SEED_DATA = [
15
+ {
16
+ name: "Row Single Line Headline Caption",
17
+ tag: "RowHeadlineImageCaption",
18
+ description: "A row with left aligned headline text and right aligned caption text",
19
+ category: COMPONENT_TYPES.row,
20
+ preview_image_url: "{CLOUDINARY_URL}/Row_SingleLine_HeadlineCaption.png",
21
+ supports_list_render: true,
22
+ props: {
23
+ title: {
24
+ group: GROUPS.data,
25
+ label: "Title",
26
+ description: "Headline text to display",
27
+ formType: FORM_TYPES.string,
28
+ propType: PROP_TYPES.STRING,
29
+ defaultValue: "Beautiful West Coast Villa",
30
+ editable: true,
31
+ required: false,
32
+ },
33
+ caption: {
34
+ group: GROUPS.data,
35
+ label: "Caption",
36
+ description: "Caption text to display",
37
+ formType: FORM_TYPES.string,
38
+ propType: PROP_TYPES.STRING,
39
+ defaultValue: "$100",
40
+ editable: true,
41
+ required: false,
42
+ },
43
+ },
44
+ layout: {},
45
+ },
46
+ {
47
+ name: "Row Single Line Headline Image Caption",
48
+ tag: "RowHeadlineImageCaption",
49
+ description: "A row with left aligned image and headline text and right aligned caption text",
50
+ category: COMPONENT_TYPES.row,
51
+ preview_image_url: "{CLOUDINARY_URL}/Row_SingleLine_HeadlineImageCaption.png",
52
+ supports_list_render: true,
53
+ props: {
54
+ title: {
55
+ group: GROUPS.data,
56
+ label: "Title",
57
+ description: "Headline text to display",
58
+ formType: FORM_TYPES.string,
59
+ propType: PROP_TYPES.STRING,
60
+ defaultValue: "Beautiful West Coast Villa",
61
+ editable: true,
62
+ required: false,
63
+ },
64
+ caption: {
65
+ group: GROUPS.data,
66
+ label: "Caption",
67
+ description: "Caption text to display",
68
+ formType: FORM_TYPES.string,
69
+ propType: PROP_TYPES.STRING,
70
+ defaultValue: "$100",
71
+ editable: true,
72
+ required: false,
73
+ },
74
+ image: {
75
+ group: GROUPS.data,
76
+ label: "Image",
77
+ description: "Image to display",
78
+ formType: FORM_TYPES.image,
79
+ propType: PROP_TYPES.ASSET,
80
+ defaultValue: null,
81
+ editable: true,
82
+ required: false,
83
+ },
84
+ },
85
+ layout: {},
86
+ },
87
+ {
88
+ name: "Row Double Line Headline Caption",
89
+ tag: "RowHeadlineImageCaption",
90
+ description: "A row with left aligned headline text and subtitle text and right aligned caption text",
91
+ category: COMPONENT_TYPES.row,
92
+ preview_image_url: "{CLOUDINARY_URL}/Row_DoubleLine_HeadlineCaption.png",
93
+ supports_list_render: true,
94
+ props: {
95
+ title: {
96
+ group: GROUPS.data,
97
+ label: "Title",
98
+ description: "Headline text to display",
99
+ formType: FORM_TYPES.string,
100
+ propType: PROP_TYPES.STRING,
101
+ defaultValue: "Beautiful West Coast Villa",
102
+ editable: true,
103
+ required: false,
104
+ },
105
+ subtitle: {
106
+ group: GROUPS.data,
107
+ label: "Subtitle",
108
+ description: "Subtitle text to display",
109
+ formType: FORM_TYPES.string,
110
+ propType: PROP_TYPES.STRING,
111
+ defaultValue: "San Diego",
112
+ editable: true,
113
+ required: false,
114
+ },
115
+ caption: {
116
+ group: GROUPS.data,
117
+ label: "Caption",
118
+ description: "Caption text to display",
119
+ formType: FORM_TYPES.string,
120
+ propType: PROP_TYPES.STRING,
121
+ defaultValue: "$100",
122
+ editable: true,
123
+ required: false,
124
+ },
125
+ },
126
+ layout: {},
127
+ },
128
+ {
129
+ name: "Row Double Line Headline Image Caption",
130
+ tag: "RowHeadlineImageCaption",
131
+ description: "A row with left aligned image, headline text, and subtitle text, and right aligned caption text",
132
+ category: COMPONENT_TYPES.row,
133
+ preview_image_url: "{CLOUDINARY_URL}/Row_DoubleLine_HeadlineCaption.png",
134
+ supports_list_render: true,
135
+ props: {
136
+ title: {
137
+ group: GROUPS.data,
138
+ label: "Title",
139
+ description: "Headline text to display",
140
+ formType: FORM_TYPES.string,
141
+ propType: PROP_TYPES.STRING,
142
+ defaultValue: "Beautiful West Coast Villa",
143
+ editable: true,
144
+ required: false,
145
+ },
146
+ subtitle: {
147
+ group: GROUPS.data,
148
+ label: "Subtitle",
149
+ description: "Subtitle text to display",
150
+ formType: FORM_TYPES.string,
151
+ propType: PROP_TYPES.STRING,
152
+ defaultValue: "San Diego",
153
+ editable: true,
154
+ required: false,
155
+ },
156
+ caption: {
157
+ group: GROUPS.data,
158
+ label: "Caption",
159
+ description: "Caption text to display",
160
+ formType: FORM_TYPES.string,
161
+ propType: PROP_TYPES.STRING,
162
+ defaultValue: "$100",
163
+ editable: true,
164
+ required: false,
165
+ },
166
+ image: {
167
+ group: GROUPS.data,
168
+ label: "Image",
169
+ description: "Image to display",
170
+ formType: FORM_TYPES.image,
171
+ propType: PROP_TYPES.ASSET,
172
+ defaultValue: null,
173
+ editable: true,
174
+ required: false,
175
+ },
176
+ },
177
+ layout: {},
178
+ },
179
+ ];
@@ -0,0 +1,113 @@
1
+ import * as React from "react";
2
+ import { withTheme } from "../theming";
3
+ import { COMPONENT_TYPES, createIconProp, createTextProp, createImageProp, createStaticBoolProp, } from "@draftbit/types";
4
+ import Row from "./Row";
5
+ import Config from "./Config";
6
+ const RowHeadlineImageIcon = ({ Icon, icon, title, image, subtitle, multilineSubtitle = false, style, theme: { colors, typography }, }) => {
7
+ 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
8
+ ? Config.rowMultiLineIconSize
9
+ : Config.rowSingleLineIconSize, color: colors.light, style: {
10
+ marginLeft: 16,
11
+ alignSelf: multilineSubtitle ? "flex-start" : "center",
12
+ marginTop: multilineSubtitle ? 4 : 0,
13
+ } })), style: style }));
14
+ };
15
+ export default withTheme(RowHeadlineImageIcon);
16
+ const SEED_DATA_PROPS = {
17
+ title: createTextProp({
18
+ label: "Title",
19
+ description: "Headline text to display",
20
+ }),
21
+ icon: createIconProp({
22
+ defaultValue: null,
23
+ }),
24
+ };
25
+ const IMAGE_PROP = createImageProp();
26
+ const MULTILINE_PROP = createStaticBoolProp({
27
+ defaultValue: true,
28
+ editable: false,
29
+ });
30
+ const SUBTITLE_PROP = createTextProp({
31
+ label: "Subtitle",
32
+ description: "Subtitle text to display",
33
+ defaultValue: "San Diego",
34
+ });
35
+ export const SEED_DATA = [
36
+ {
37
+ name: "Row Single Line Headline Icon",
38
+ tag: "RowHeadlineImageIcon",
39
+ description: "A row with left aligned headline text and a right aligned icon",
40
+ category: COMPONENT_TYPES.row,
41
+ layout: {},
42
+ props: {
43
+ ...SEED_DATA_PROPS,
44
+ },
45
+ },
46
+ {
47
+ name: "Row Single Line Headline Icon Image",
48
+ tag: "RowHeadlineImageIcon",
49
+ description: "A row with left aligned image and headline text and a right aligned icon",
50
+ category: COMPONENT_TYPES.row,
51
+ layout: {},
52
+ props: {
53
+ ...SEED_DATA_PROPS,
54
+ image: IMAGE_PROP,
55
+ },
56
+ },
57
+ {
58
+ name: "Row Double Line Headline Icon",
59
+ tag: "RowHeadlineImageIcon",
60
+ description: "A row with left aligned headline text and subtitle text and a right aligned icon",
61
+ category: COMPONENT_TYPES.row,
62
+ layout: {},
63
+ props: {
64
+ ...SEED_DATA_PROPS,
65
+ subtitle: SUBTITLE_PROP,
66
+ },
67
+ },
68
+ {
69
+ name: "Row Double Line Headline Image Icon",
70
+ tag: "RowHeadlineImageIcon",
71
+ description: "A row with left aligned headline text and subtitle text and a right aligned icon",
72
+ category: COMPONENT_TYPES.row,
73
+ layout: {},
74
+ props: {
75
+ ...SEED_DATA_PROPS,
76
+ image: IMAGE_PROP,
77
+ subtitle: SUBTITLE_PROP,
78
+ },
79
+ },
80
+ {
81
+ name: "Row Multiline Headline Icon",
82
+ tag: "RowHeadlineImageIcon",
83
+ description: "A row with left aligned headline text and multiline subtitle text and a right aligned icon",
84
+ category: COMPONENT_TYPES.row,
85
+ layout: {},
86
+ props: {
87
+ ...SEED_DATA_PROPS,
88
+ multilineSubtitle: MULTILINE_PROP,
89
+ subtitle: createTextProp({
90
+ label: "Subtitle",
91
+ description: "Subtitle text to display",
92
+ defaultValue: "San Diego is a city on the Pacific coast of California known for its beaches, parks and warm climate",
93
+ }),
94
+ },
95
+ },
96
+ {
97
+ name: "Row Multiline Headline Image Icon",
98
+ tag: "RowHeadlineImageIcon",
99
+ description: "A row with left aligned image, headline text, and multiline subtitle text, and a right aligned icon",
100
+ category: COMPONENT_TYPES.row,
101
+ layout: {},
102
+ props: {
103
+ ...SEED_DATA_PROPS,
104
+ image: IMAGE_PROP,
105
+ multilineSubtitle: MULTILINE_PROP,
106
+ subtitle: createTextProp({
107
+ label: "Subtitle",
108
+ description: "Subtitle text to display",
109
+ defaultValue: "San Diego is a city on the Pacific coast of California known for its beaches, parks and warm climate",
110
+ }),
111
+ },
112
+ },
113
+ ];
@@ -0,0 +1,35 @@
1
+ import * as React from "react";
2
+ import { StyleSheet, ScrollView as NativeScrollView, View, } from "react-native";
3
+ import { SafeAreaView } from "react-native-safe-area-context";
4
+ import { withTheme } from "../theming";
5
+ function ScrollView({ children, style, }) {
6
+ return (React.createElement(NativeScrollView, { contentContainerStyle: [
7
+ {
8
+ flexGrow: 1,
9
+ },
10
+ style,
11
+ ] }, children));
12
+ }
13
+ function ScreenContainer({ hasSafeArea = false, scrollable = false, hasBottomSafeArea, hasTopSafeArea, theme, style, children, ...rest }) {
14
+ const backgroundColor = theme.colors.background;
15
+ const edges = ["left", "right"];
16
+ if (hasSafeArea || hasTopSafeArea) {
17
+ edges.push("top");
18
+ }
19
+ if (hasSafeArea || hasBottomSafeArea) {
20
+ edges.push("bottom");
21
+ }
22
+ return (React.createElement(SafeAreaView, { edges: edges, style: [
23
+ styles.container,
24
+ {
25
+ backgroundColor,
26
+ },
27
+ ], ...rest },
28
+ React.createElement(View, { style: [styles.container, { backgroundColor }, style] }, scrollable ? (React.createElement(ScrollView, { style: style }, children)) : (children))));
29
+ }
30
+ const styles = StyleSheet.create({
31
+ container: {
32
+ flex: 1,
33
+ },
34
+ });
35
+ export default withTheme(ScreenContainer);
@@ -0,0 +1,114 @@
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 { COMPONENT_TYPES, GROUPS, createNumberProp, createColorProp, createFieldNameProp, createIconProp, Triggers, } from "@draftbit/types";
7
+ import { withTheme } from "../theming";
8
+ import { usePrevious } from "../hooks";
9
+ function maybeParseValue(value) {
10
+ if (value === undefined) {
11
+ return undefined;
12
+ }
13
+ if (isNumber(value)) {
14
+ return value;
15
+ }
16
+ try {
17
+ const maybe = toNumber(value);
18
+ if (isNumber(maybe)) {
19
+ return maybe;
20
+ }
21
+ }
22
+ catch {
23
+ return undefined;
24
+ }
25
+ return undefined;
26
+ }
27
+ function Slider({ Icon, leftIcon, rightIcon, leftIconColor, rightIconColor, value, initialValue, minimumTrackTintColor, maximumTrackTintColor, thumbTintColor, minimumValue = 0, maximumValue = 100, tapToSeek, step = 1, onValueChange = () => { }, style, theme, ...rest }) {
28
+ const previousInitialValue = usePrevious(initialValue);
29
+ React.useEffect(() => {
30
+ if (initialValue !== previousInitialValue) {
31
+ onValueChange(initialValue);
32
+ }
33
+ }, [initialValue, previousInitialValue, onValueChange]);
34
+ const minTrackColor = minimumTrackTintColor || theme.colors.primary;
35
+ const maxTrackColor = maximumTrackTintColor || theme.colors.light;
36
+ const thumbColor = thumbTintColor || theme.colors.primary;
37
+ const leftIconThemeColor = leftIconColor || theme.colors.light;
38
+ const rightIconThemeColor = rightIconColor || theme.colors.light;
39
+ const parsedValue = maybeParseValue(value);
40
+ return (React.createElement(View, { style: [styles.container, style], ...rest },
41
+ leftIcon ? (React.createElement(Icon, { color: leftIconThemeColor, name: leftIcon, size: 24 })) : null,
42
+ React.createElement(NativeSlider, { value: parsedValue, step: step, minimumValue: minimumValue, maximumValue: maximumValue, tapToSeek: tapToSeek, minimumTrackTintColor: minTrackColor, maximumTrackTintColor: maxTrackColor, thumbTintColor: thumbColor, onSlidingComplete: onValueChange, style: styles.slider }),
43
+ rightIcon ? (React.createElement(Icon, { color: rightIconThemeColor, name: rightIcon, size: 24 })) : null));
44
+ }
45
+ const styles = StyleSheet.create({
46
+ container: {
47
+ height: 40,
48
+ flexDirection: "row",
49
+ alignItems: "center",
50
+ },
51
+ slider: {
52
+ flex: 1,
53
+ marginHorizontal: 12,
54
+ },
55
+ });
56
+ export default withTheme(Slider);
57
+ export const SEED_DATA = {
58
+ name: "Slider",
59
+ tag: "Slider",
60
+ description: "A component used to set a value in a range",
61
+ category: COMPONENT_TYPES.input,
62
+ layout: {
63
+ marginLeft: 12,
64
+ marginRight: 12,
65
+ },
66
+ triggers: [Triggers.OnValueChange],
67
+ props: {
68
+ fieldName: createFieldNameProp({
69
+ defaultValue: "sliderValue",
70
+ handlerPropName: "onValueChange",
71
+ valuePropName: "value",
72
+ }),
73
+ minimumValue: createNumberProp({
74
+ group: GROUPS.basic,
75
+ label: "Min Value",
76
+ min: 0,
77
+ max: 1000,
78
+ }),
79
+ maximumValue: createNumberProp({
80
+ group: GROUPS.basic,
81
+ label: "Max Value",
82
+ min: 1,
83
+ max: 10000,
84
+ }),
85
+ step: createNumberProp({
86
+ group: GROUPS.basic,
87
+ label: "Step",
88
+ min: 0,
89
+ max: 100,
90
+ step: 0.01,
91
+ precision: 2,
92
+ }),
93
+ leftIcon: createIconProp({
94
+ label: "Left Icon",
95
+ defaultValue: null,
96
+ }),
97
+ rightIcon: createIconProp({
98
+ label: "Right Icon",
99
+ defaultValue: null,
100
+ }),
101
+ minimumTrackTintColor: createColorProp({
102
+ label: "Min Track Color",
103
+ defaultValue: null,
104
+ }),
105
+ maximumTrackTintColor: createColorProp({
106
+ label: "Max Track Color",
107
+ defaultValue: null,
108
+ }),
109
+ thumbTintColor: createColorProp({
110
+ label: "Thumb Color",
111
+ defaultValue: null,
112
+ }),
113
+ },
114
+ };
@@ -0,0 +1,80 @@
1
+ import * as React from "react";
2
+ import { View, StyleSheet, Pressable, } from "react-native";
3
+ import { withTheme } from "../theming";
4
+ import { COMPONENT_TYPES, createStaticNumberProp, createFieldNameProp, createStaticBoolProp, Triggers, } from "@draftbit/types";
5
+ const StarRating = ({ Icon, starSize = 16, maxStars = 5, rating = 0, isEditable = false, theme, style, onPress, ...rest }) => {
6
+ const [localRating, setLocalRating] = React.useState(rating);
7
+ React.useEffect(() => {
8
+ setLocalRating(rating);
9
+ }, [rating]);
10
+ const ratingHandler = React.useCallback((r) => {
11
+ setLocalRating(r);
12
+ !!onPress && onPress(r);
13
+ }, [onPress]);
14
+ const ratingRounded = Math.round(localRating * 2) / 2;
15
+ return (React.createElement(View, { style: [styles.container, style], ...rest }, [...Array(maxStars)].map((_, i) => (React.createElement(View, { key: i, style: { display: "flex" } },
16
+ React.createElement(Icon, { name: ratingRounded - i === 0.5
17
+ ? "MaterialIcons/star-half"
18
+ : "MaterialIcons/star", size: starSize, color: ratingRounded > i ? theme.colors.primary : theme.colors.divider }),
19
+ isEditable && (React.createElement(View, { style: styles.touchContainer },
20
+ React.createElement(Pressable, { style: styles.pressable, onPress: () => ratingHandler(i + 0.5) }),
21
+ React.createElement(Pressable, { style: styles.pressable, onPress: () => ratingHandler(i + 1) }))))))));
22
+ };
23
+ const styles = StyleSheet.create({
24
+ container: {
25
+ flexDirection: "row",
26
+ alignItems: "center",
27
+ },
28
+ touchContainer: {
29
+ display: "flex",
30
+ flexDirection: "row",
31
+ position: "absolute",
32
+ top: 0,
33
+ right: 0,
34
+ left: 0,
35
+ bottom: 0,
36
+ zIndex: 1,
37
+ },
38
+ pressable: {
39
+ flex: 1,
40
+ height: "100%",
41
+ width: "50%",
42
+ },
43
+ });
44
+ export default withTheme(StarRating);
45
+ export const SEED_DATA = {
46
+ name: "Star Rating",
47
+ tag: "StarRating",
48
+ description: "A star rating component",
49
+ category: COMPONENT_TYPES.button,
50
+ triggers: [Triggers.OnPress],
51
+ props: {
52
+ starSize: createStaticNumberProp({
53
+ label: "Star size",
54
+ description: "Size of each individual star",
55
+ defaultValue: 16,
56
+ min: 8,
57
+ max: 36,
58
+ step: 1,
59
+ }),
60
+ fieldName: createFieldNameProp({
61
+ defaultValue: "ratingValue",
62
+ handlerPropName: "onPress",
63
+ valuePropName: "rating", // the value prop in this component
64
+ }),
65
+ maxStars: createStaticNumberProp({
66
+ label: "Max stars",
67
+ description: "The max number of stars",
68
+ defaultValue: 5,
69
+ min: 0,
70
+ max: 10,
71
+ step: 1,
72
+ }),
73
+ rating: createStaticNumberProp({
74
+ label: "Rating",
75
+ }),
76
+ isEditable: createStaticBoolProp({
77
+ label: "Editable",
78
+ }),
79
+ },
80
+ };