@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.
- package/LICENSE +21 -0
- package/lib/commonjs/components/DatePicker/DatePicker.js +6 -1
- package/lib/commonjs/components/DatePicker/DatePicker.js.map +1 -1
- package/lib/commonjs/components/DatePicker/DatePickerComponentType.js +2 -0
- package/lib/commonjs/components/Divider.js +18 -5
- package/lib/commonjs/components/Divider.js.map +1 -1
- package/lib/commonjs/components/Elevation.js +14 -3
- package/lib/commonjs/components/Elevation.js.map +1 -1
- package/lib/commonjs/components/Justification.js +3 -0
- package/lib/commonjs/components/Picker/PickerComponent.android.js +4 -1
- package/lib/commonjs/components/Picker/PickerComponent.android.js.map +1 -1
- package/lib/commonjs/components/Picker/PickerComponent.web.js +4 -1
- package/lib/commonjs/components/Picker/PickerComponent.web.js.map +1 -1
- package/lib/commonjs/components/Picker/PickerTypes.js +3 -0
- package/lib/commonjs/components/Portal/PortalHost.js.map +1 -1
- package/lib/commonjs/components/ResizeMode.js +3 -0
- package/lib/module/components/DatePicker/DatePicker.js +6 -1
- package/lib/module/components/DatePicker/DatePicker.js.map +1 -1
- package/lib/module/components/DatePicker/DatePickerComponentType.js +1 -1
- package/lib/module/components/Justification.js +1 -1
- package/lib/module/components/Picker/PickerComponent.android.js +4 -1
- package/lib/module/components/Picker/PickerComponent.android.js.map +1 -1
- package/lib/module/components/Picker/PickerComponent.web.js +4 -1
- package/lib/module/components/Picker/PickerComponent.web.js.map +1 -1
- package/lib/module/components/Picker/PickerTypes.js +1 -1
- package/lib/module/components/ResizeMode.js +1 -1
- package/package.json +3 -2
- package/src/Provider.js +9 -0
- package/src/components/Accordion/AccordionGroup.js +94 -0
- package/src/components/Accordion/AccordionItem.js +48 -0
- package/src/components/Accordion/index.js +2 -0
- package/src/components/ActionSheet/ActionSheet.js +57 -0
- package/src/components/ActionSheet/ActionSheetCancel.js +28 -0
- package/src/components/ActionSheet/ActionSheetItem.js +49 -0
- package/src/components/ActionSheet/index.js +3 -0
- package/src/components/AnimatedCircularProgress.js +43 -0
- package/src/components/AspectRatio.js +18 -0
- package/src/components/AvatarEdit.js +67 -0
- package/src/components/Button.js +187 -0
- package/src/components/Card.js +109 -0
- package/src/components/CardBlock.js +176 -0
- package/src/components/CardContainer.js +171 -0
- package/src/components/CardContainerRating.js +203 -0
- package/src/components/CardContainerShortImage.js +151 -0
- package/src/components/CardInline.js +87 -0
- package/src/components/Carousel.js +85 -0
- package/src/components/Checkbox/Checkbox.js +114 -0
- package/src/components/Checkbox/CheckboxGroup.js +46 -0
- package/src/components/Checkbox/CheckboxRow.js +109 -0
- package/src/components/Checkbox/context.js +14 -0
- package/src/components/Checkbox/index.js +3 -0
- package/src/components/CircleImage.js +32 -0
- package/src/components/CircularProgress.js +78 -0
- package/src/components/Config.js +63 -0
- package/src/components/Container.js +73 -0
- package/src/components/DatePicker/DatePicker.js +379 -0
- package/src/components/DatePicker/DatePicker.tsx +7 -1
- package/src/components/DatePicker/DatePickerComponent.js +13 -0
- package/src/components/DatePicker/DatePickerComponent.web.js +30 -0
- package/src/components/DatePicker/DatePickerComponentType.js +1 -0
- package/src/components/DeprecatedButton.js +201 -0
- package/src/components/DeprecatedCardWrapper.js +18 -0
- package/src/components/DeprecatedFAB.js +261 -0
- package/src/components/Divider.js +39 -0
- package/src/components/Elevation.js +20 -0
- package/src/components/FAB.js +82 -0
- package/src/components/FieldSearchBarFull.js +92 -0
- package/src/components/FormRow.js +19 -0
- package/src/components/Header.js +44 -0
- package/src/components/HeaderLarge.js +35 -0
- package/src/components/HeaderMedium.js +61 -0
- package/src/components/HeaderOverline.js +61 -0
- package/src/components/IconButton.js +65 -0
- package/src/components/Image.js +62 -0
- package/src/components/Justification.js +1 -0
- package/src/components/Layout.js +245 -0
- package/src/components/Picker/Picker.js +204 -0
- package/src/components/Picker/PickerComponent.android.js +68 -0
- package/src/components/Picker/PickerComponent.android.tsx +6 -1
- package/src/components/Picker/PickerComponent.ios.js +72 -0
- package/src/components/Picker/PickerComponent.web.js +68 -0
- package/src/components/Picker/PickerComponent.web.tsx +6 -1
- package/src/components/Picker/PickerTypes.js +1 -0
- package/src/components/Portal/Portal.js +35 -0
- package/src/components/Portal/PortalConsumer.js +28 -0
- package/src/components/Portal/PortalHost.js +105 -0
- package/src/components/Portal/PortalManager.js +29 -0
- package/src/components/ProgressBar.js +218 -0
- package/src/components/ProgressCircle.js +121 -0
- package/src/components/ProgressIndicator.js +207 -0
- package/src/components/RadioButton/RadioButton.js +66 -0
- package/src/components/RadioButton/RadioButtonFieldGroup.js +17 -0
- package/src/components/RadioButton/RadioButtonGroup.js +43 -0
- package/src/components/RadioButton/RadioButtonRow.js +111 -0
- package/src/components/RadioButton/context.js +14 -0
- package/src/components/RadioButton/index.js +4 -0
- package/src/components/ResizeMode.js +1 -0
- package/src/components/Row.js +48 -0
- package/src/components/RowBodyIcon.js +83 -0
- package/src/components/RowHeadlineImageCaption.js +179 -0
- package/src/components/RowHeadlineImageIcon.js +113 -0
- package/src/components/ScreenContainer.js +35 -0
- package/src/components/Slider.js +114 -0
- package/src/components/StarRating.js +80 -0
- package/src/components/StepIndicator.js +346 -0
- package/src/components/Stepper.js +69 -0
- package/src/components/Surface.js +36 -0
- package/src/components/Switch.js +59 -0
- package/src/components/Text.js +232 -0
- package/src/components/TextField.js +552 -0
- package/src/components/TextInput.js +13 -0
- package/src/components/ToggleButton.js +75 -0
- package/src/components/Touchable.js +24 -0
- package/src/components/Touchable.web.js +2 -0
- package/src/components/Typography.js +36 -0
- package/src/components/useAuthState.js +31 -0
- package/src/constants.js +10 -0
- package/src/hooks.js +12 -0
- package/src/index.js +48 -0
- package/src/interfaces/Icon.js +8 -0
- package/src/styles/DarkTheme.js +26 -0
- package/src/styles/DefaultTheme.js +111 -0
- package/src/styles/fonts.js +62 -0
- package/src/styles/overlay.js +60 -0
- package/src/styles/shadow.js +51 -0
- package/src/theming.js +3 -0
- package/src/utilities.js +42 -0
|
@@ -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,69 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { View, Text } from "react-native";
|
|
3
|
+
import { withTheme } from "../theming";
|
|
4
|
+
import { COMPONENT_TYPES, createIconSizeProp, createColorProp, createFieldNameProp, Triggers, } from "@draftbit/types";
|
|
5
|
+
import IconButton from "./IconButton";
|
|
6
|
+
import { usePrevious } from "../hooks";
|
|
7
|
+
const Stepper = ({ Icon, value = 0, style, onChange, initialValue, theme: { colors, typography, roundness }, iconSize = 24, iconColor = colors.strong, borderRadius = roundness, typeStyle, }) => {
|
|
8
|
+
const [stateValue, setStateValue] = React.useState(value);
|
|
9
|
+
const previousInitialValue = usePrevious(initialValue);
|
|
10
|
+
React.useEffect(() => {
|
|
11
|
+
if (initialValue !== previousInitialValue) {
|
|
12
|
+
setStateValue(initialValue);
|
|
13
|
+
onChange && onChange(initialValue);
|
|
14
|
+
}
|
|
15
|
+
}, [initialValue, previousInitialValue, onChange, setStateValue]);
|
|
16
|
+
const handleMinus = () => {
|
|
17
|
+
if (value || value === 0) {
|
|
18
|
+
onChange && onChange(value - 1);
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
setStateValue(stateValue - 1);
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
const handlePlus = () => {
|
|
25
|
+
if (value || value === 0) {
|
|
26
|
+
onChange && onChange(value + 1);
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
setStateValue(stateValue + 1);
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
return (React.createElement(View, { style: [
|
|
33
|
+
{ flexDirection: "row" },
|
|
34
|
+
style,
|
|
35
|
+
borderRadius ? { borderRadius } : {},
|
|
36
|
+
] },
|
|
37
|
+
React.createElement(IconButton, { Icon: Icon, icon: "MaterialIcons/remove", onPress: handleMinus, size: iconSize, color: iconColor, disabled: value ? value === 0 : stateValue === 0 }),
|
|
38
|
+
React.createElement(Text, { style: [
|
|
39
|
+
typography.body1,
|
|
40
|
+
{
|
|
41
|
+
textAlign: "center",
|
|
42
|
+
alignSelf: "center",
|
|
43
|
+
color: colors.medium,
|
|
44
|
+
marginHorizontal: 8,
|
|
45
|
+
},
|
|
46
|
+
typeStyle,
|
|
47
|
+
] }, value || stateValue),
|
|
48
|
+
React.createElement(IconButton, { Icon: Icon, icon: "MaterialIcons/add", onPress: handlePlus, size: iconSize, color: iconColor })));
|
|
49
|
+
};
|
|
50
|
+
export default withTheme(Stepper);
|
|
51
|
+
export const SEED_DATA = [
|
|
52
|
+
{
|
|
53
|
+
name: "Stepper",
|
|
54
|
+
tag: "Stepper",
|
|
55
|
+
description: "A component used to control the quantity of something",
|
|
56
|
+
category: COMPONENT_TYPES.input,
|
|
57
|
+
layout: {},
|
|
58
|
+
triggers: [Triggers.OnChange],
|
|
59
|
+
props: {
|
|
60
|
+
fieldName: createFieldNameProp({
|
|
61
|
+
defaultValue: "stepperValue",
|
|
62
|
+
handlerPropName: "onChange",
|
|
63
|
+
valuePropName: "value",
|
|
64
|
+
}),
|
|
65
|
+
iconSize: createIconSizeProp({ defaultValue: 24 }),
|
|
66
|
+
iconColor: createColorProp({ defaultValue: "strong" }),
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
];
|
|
@@ -0,0 +1,36 @@
|
|
|
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, View, } from "react-native";
|
|
4
|
+
import shadow from "../styles/shadow";
|
|
5
|
+
import overlay from "../styles/overlay";
|
|
6
|
+
import { withTheme } from "../theming";
|
|
7
|
+
import { COMPONENT_TYPES, createElevationType } from "@draftbit/types";
|
|
8
|
+
const Surface = ({ elevation, style, theme, children, ...rest }) => {
|
|
9
|
+
const { elevation: styleElevation = 3, borderRadius: radius = 0 } = (StyleSheet.flatten(style) || {});
|
|
10
|
+
const { dark: isDarkTheme, mode, colors } = theme;
|
|
11
|
+
const borderRadius = radius;
|
|
12
|
+
const ele = elevation || styleElevation;
|
|
13
|
+
return (React.createElement(Animated.View, { ...rest, style: [
|
|
14
|
+
{
|
|
15
|
+
minHeight: 40,
|
|
16
|
+
borderRadius,
|
|
17
|
+
backgroundColor: isDarkTheme && mode === "adaptive"
|
|
18
|
+
? overlay(ele, colors.surface)
|
|
19
|
+
: colors.surface,
|
|
20
|
+
},
|
|
21
|
+
elevation ? shadow(elevation) : null,
|
|
22
|
+
style,
|
|
23
|
+
] },
|
|
24
|
+
React.createElement(View, { style: { overflow: "hidden", borderRadius } }, children)));
|
|
25
|
+
};
|
|
26
|
+
export default withTheme(Surface);
|
|
27
|
+
export const SEED_DATA = {
|
|
28
|
+
name: "Surface",
|
|
29
|
+
tag: "Surface",
|
|
30
|
+
description: "An elevated container",
|
|
31
|
+
category: COMPONENT_TYPES.layout,
|
|
32
|
+
layout: {},
|
|
33
|
+
props: {
|
|
34
|
+
elevation: createElevationType(0),
|
|
35
|
+
},
|
|
36
|
+
};
|
|
@@ -0,0 +1,59 @@
|
|
|
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 = false, initialValue, 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);
|
|
13
|
+
React.useEffect(() => {
|
|
14
|
+
if (value !== checked) {
|
|
15
|
+
setChecked(value);
|
|
16
|
+
}
|
|
17
|
+
}, [value, checked]);
|
|
18
|
+
const booleanInitialValue = Boolean(initialValue);
|
|
19
|
+
const previousInitialValue = usePrevious(booleanInitialValue);
|
|
20
|
+
React.useEffect(() => {
|
|
21
|
+
if (initialValue != null && booleanInitialValue !== previousInitialValue) {
|
|
22
|
+
setChecked(booleanInitialValue);
|
|
23
|
+
onValueChange && onValueChange(booleanInitialValue);
|
|
24
|
+
}
|
|
25
|
+
}, [
|
|
26
|
+
initialValue,
|
|
27
|
+
booleanInitialValue,
|
|
28
|
+
previousInitialValue,
|
|
29
|
+
setChecked,
|
|
30
|
+
onValueChange,
|
|
31
|
+
]);
|
|
32
|
+
return (React.createElement(NativeSwitch, { value: checked, disabled: disabled, trackColor: {
|
|
33
|
+
false: inactiveTrackThemeColor,
|
|
34
|
+
true: activeTrackThemeColor,
|
|
35
|
+
}, thumbColor: value ? activeThumbThemeColor : inactiveThumbThemeColor,
|
|
36
|
+
// @ts-ignore react-native-web only
|
|
37
|
+
activeThumbColor: activeThumbThemeColor, ios_backgroundColor: inactiveTrackThemeColor, style: style, onValueChange: (bool) => {
|
|
38
|
+
setChecked(bool);
|
|
39
|
+
onValueChange && onValueChange(bool);
|
|
40
|
+
}, ...rest }));
|
|
41
|
+
}
|
|
42
|
+
function Row({ label = "Label", direction = RowDirection.Row, style, value = false, disabled, onValueChange, activeTrackColor, inactiveTrackColor, activeThumbColor, inactiveThumbColor, theme, ...rest }) {
|
|
43
|
+
const [checked, setChecked] = React.useState(value);
|
|
44
|
+
React.useEffect(() => {
|
|
45
|
+
if (value !== checked) {
|
|
46
|
+
setChecked(value);
|
|
47
|
+
}
|
|
48
|
+
}, [value, checked]);
|
|
49
|
+
return (React.createElement(FormRow, { disabled: disabled, onPress: () => {
|
|
50
|
+
setChecked(!checked);
|
|
51
|
+
onValueChange && onValueChange(!checked);
|
|
52
|
+
}, label: label, direction: direction, style: style, ...rest },
|
|
53
|
+
React.createElement(Switch, { theme: theme, value: checked, disabled: disabled, onValueChange: onValueChange, activeTrackColor: activeTrackColor, inactiveTrackColor: inactiveTrackColor, activeThumbColor: activeThumbColor, inactiveThumbColor: inactiveThumbColor })));
|
|
54
|
+
}
|
|
55
|
+
const SwitchRow = withTheme(Row);
|
|
56
|
+
export { SwitchRow };
|
|
57
|
+
export default withTheme(Switch);
|
|
58
|
+
/* README: SEED_DATA lives inside mappings/Switch.js since there were weird issues taking place with sourceMaps being
|
|
59
|
+
* generated */
|