@draftbit/core 42.3.3-fdd04d.0 → 42.4.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.
- package/lib/commonjs/components/Checkbox/Checkbox.js +13 -2
- package/lib/commonjs/components/Checkbox/Checkbox.js.map +1 -1
- package/lib/commonjs/components/DatePicker/DatePicker.js +2 -1
- package/lib/commonjs/components/DatePicker/DatePicker.js.map +1 -1
- package/lib/commonjs/components/FieldSearchBarFull.js +16 -3
- package/lib/commonjs/components/FieldSearchBarFull.js.map +1 -1
- package/lib/commonjs/components/Picker/Picker.js +16 -2
- package/lib/commonjs/components/Picker/Picker.js.map +1 -1
- package/lib/commonjs/components/RadioButton/RadioButtonGroup.js +7 -2
- package/lib/commonjs/components/RadioButton/RadioButtonGroup.js.map +1 -1
- package/lib/commonjs/components/Slider.js +13 -2
- package/lib/commonjs/components/Slider.js.map +1 -1
- package/lib/commonjs/components/StarRating.js +2 -1
- package/lib/commonjs/components/StarRating.js.map +1 -1
- package/lib/commonjs/components/Stepper.js +5 -1
- package/lib/commonjs/components/Stepper.js.map +1 -1
- package/lib/commonjs/components/Swiper/Swiper.js +1 -33
- package/lib/commonjs/components/Swiper/Swiper.js.map +1 -1
- package/lib/commonjs/components/Switch.js +3 -0
- package/lib/commonjs/components/Switch.js.map +1 -1
- package/lib/commonjs/components/TextField.js +4 -1
- package/lib/commonjs/components/TextField.js.map +1 -1
- package/lib/commonjs/components/TextInput.js +1 -1
- package/lib/commonjs/components/TextInput.js.map +1 -1
- package/lib/commonjs/components/ToggleButton.js +13 -2
- package/lib/commonjs/components/ToggleButton.js.map +1 -1
- package/lib/module/components/Checkbox/Checkbox.js +13 -2
- package/lib/module/components/Checkbox/Checkbox.js.map +1 -1
- package/lib/module/components/DatePicker/DatePicker.js +2 -1
- package/lib/module/components/DatePicker/DatePicker.js.map +1 -1
- package/lib/module/components/DatePicker/DatePickerComponent.web.js.map +1 -1
- package/lib/module/components/FieldSearchBarFull.js +16 -3
- package/lib/module/components/FieldSearchBarFull.js.map +1 -1
- package/lib/module/components/Picker/Picker.js +16 -2
- package/lib/module/components/Picker/Picker.js.map +1 -1
- package/lib/module/components/RadioButton/RadioButtonGroup.js +7 -2
- package/lib/module/components/RadioButton/RadioButtonGroup.js.map +1 -1
- package/lib/module/components/Slider.js +13 -2
- package/lib/module/components/Slider.js.map +1 -1
- package/lib/module/components/StarRating.js +2 -1
- package/lib/module/components/StarRating.js.map +1 -1
- package/lib/module/components/Stepper.js +5 -1
- package/lib/module/components/Stepper.js.map +1 -1
- package/lib/module/components/Swiper/Swiper.js +2 -34
- package/lib/module/components/Swiper/Swiper.js.map +1 -1
- package/lib/module/components/Switch.js +3 -0
- package/lib/module/components/Switch.js.map +1 -1
- package/lib/module/components/TextField.js +4 -1
- package/lib/module/components/TextField.js.map +1 -1
- package/lib/module/components/TextInput.js +1 -1
- package/lib/module/components/TextInput.js.map +1 -1
- package/lib/module/components/ToggleButton.js +13 -2
- package/lib/module/components/ToggleButton.js.map +1 -1
- package/lib/typescript/src/components/Checkbox/Checkbox.d.ts +1 -0
- package/lib/typescript/src/components/DatePicker/DatePicker.d.ts +1 -0
- package/lib/typescript/src/components/FieldSearchBarFull.d.ts +3 -2
- package/lib/typescript/src/components/Picker/Picker.d.ts +1 -1
- package/lib/typescript/src/components/Picker/PickerTypes.d.ts +2 -1
- package/lib/typescript/src/components/RadioButton/RadioButtonGroup.d.ts +2 -1
- package/lib/typescript/src/components/Slider.d.ts +4 -1
- package/lib/typescript/src/components/StarRating.d.ts +1 -0
- package/lib/typescript/src/components/Stepper.d.ts +1 -0
- package/lib/typescript/src/components/Swiper/Swiper.d.ts +1 -45
- package/lib/typescript/src/components/TextField.d.ts +1 -0
- package/lib/typescript/src/components/TextInput.d.ts +1 -1
- package/lib/typescript/src/components/ToggleButton.d.ts +1 -0
- package/package.json +2 -2
- package/src/components/Checkbox/Checkbox.js +13 -3
- package/src/components/Checkbox/Checkbox.tsx +22 -3
- package/src/components/DatePicker/DatePicker.js +2 -2
- package/src/components/DatePicker/DatePicker.tsx +4 -2
- package/src/components/FieldSearchBarFull.js +12 -2
- package/src/components/FieldSearchBarFull.tsx +22 -5
- package/src/components/Picker/Picker.js +12 -2
- package/src/components/Picker/Picker.tsx +19 -3
- package/src/components/Picker/PickerTypes.ts +3 -2
- package/src/components/RadioButton/RadioButtonGroup.js +10 -2
- package/src/components/RadioButton/RadioButtonGroup.tsx +19 -3
- package/src/components/Slider.js +11 -3
- package/src/components/Slider.tsx +18 -3
- package/src/components/StarRating.js +2 -2
- package/src/components/StarRating.tsx +5 -1
- package/src/components/Stepper.js +5 -2
- package/src/components/Stepper.tsx +10 -2
- package/src/components/Swiper/Swiper.js +2 -20
- package/src/components/Swiper/Swiper.tsx +0 -27
- package/src/components/Switch.js +3 -0
- package/src/components/Switch.tsx +5 -0
- package/src/components/TextField.js +5 -1
- package/src/components/TextField.tsx +5 -1
- package/src/components/TextInput.js +1 -1
- package/src/components/TextInput.tsx +2 -2
- package/src/components/ToggleButton.js +10 -2
- package/src/components/ToggleButton.tsx +18 -3
|
@@ -38,7 +38,8 @@ export interface CheckboxProps {
|
|
|
38
38
|
checkedIcon?: string;
|
|
39
39
|
uncheckedIcon?: string;
|
|
40
40
|
indeterminateIcon?: string;
|
|
41
|
-
initialValue?: boolean;
|
|
41
|
+
initialValue?: boolean; // deprecated
|
|
42
|
+
defaultValue?: CheckboxStatus;
|
|
42
43
|
size?: number;
|
|
43
44
|
style?: StyleProp<ViewStyle>;
|
|
44
45
|
}
|
|
@@ -53,6 +54,7 @@ const Checkbox: React.FC<CheckboxProps & TouchableHighlightProps & IconSlot> =
|
|
|
53
54
|
uncheckedColor,
|
|
54
55
|
indeterminateColor,
|
|
55
56
|
initialValue,
|
|
57
|
+
defaultValue,
|
|
56
58
|
checkedIcon = "MaterialCommunityIcons/checkbox-marked",
|
|
57
59
|
uncheckedIcon = "MaterialCommunityIcons/checkbox-blank-outline",
|
|
58
60
|
indeterminateIcon = "AntDesign/minussquareo",
|
|
@@ -60,6 +62,14 @@ const Checkbox: React.FC<CheckboxProps & TouchableHighlightProps & IconSlot> =
|
|
|
60
62
|
style,
|
|
61
63
|
...rest
|
|
62
64
|
}) => {
|
|
65
|
+
const [internalValue, setInternalValue] = React.useState<CheckboxStatus>(
|
|
66
|
+
status || defaultValue
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
React.useEffect(() => {
|
|
70
|
+
setInternalValue(status);
|
|
71
|
+
}, [status]);
|
|
72
|
+
|
|
63
73
|
const previousInitialValue = usePrevious(initialValue);
|
|
64
74
|
React.useEffect(() => {
|
|
65
75
|
if (initialValue !== previousInitialValue) {
|
|
@@ -82,10 +92,19 @@ const Checkbox: React.FC<CheckboxProps & TouchableHighlightProps & IconSlot> =
|
|
|
82
92
|
|
|
83
93
|
const checkboxColor = colorsMap[status];
|
|
84
94
|
|
|
95
|
+
const handlePress = () => {
|
|
96
|
+
setInternalValue(
|
|
97
|
+
internalValue === CheckboxStatus.Unchecked
|
|
98
|
+
? CheckboxStatus.Checked
|
|
99
|
+
: CheckboxStatus.Unchecked
|
|
100
|
+
);
|
|
101
|
+
onPress(internalValue === CheckboxStatus.Unchecked);
|
|
102
|
+
};
|
|
103
|
+
|
|
85
104
|
return (
|
|
86
105
|
<Touchable
|
|
87
106
|
{...rest}
|
|
88
|
-
onPress={
|
|
107
|
+
onPress={handlePress}
|
|
89
108
|
disabled={disabled}
|
|
90
109
|
accessibilityState={{ disabled }}
|
|
91
110
|
accessibilityRole="button"
|
|
@@ -94,7 +113,7 @@ const Checkbox: React.FC<CheckboxProps & TouchableHighlightProps & IconSlot> =
|
|
|
94
113
|
>
|
|
95
114
|
<Icon
|
|
96
115
|
style={styles.icon}
|
|
97
|
-
name={iconsMap[
|
|
116
|
+
name={iconsMap[internalValue]}
|
|
98
117
|
size={size}
|
|
99
118
|
color={checkboxColor}
|
|
100
119
|
/>
|
|
@@ -26,8 +26,8 @@ const MONTHS = [
|
|
|
26
26
|
"November",
|
|
27
27
|
"December",
|
|
28
28
|
];
|
|
29
|
-
const DatePicker = ({ Icon, style, theme: { colors, typography, roundness, disabledOpacity }, date, onDateChange = () => { }, initialValue, disabled = false, mode = "date", format, type = "underline", leftIconName, rightIconName, leftIconMode = "inset", label, placeholder, ...props }) => {
|
|
30
|
-
const [value, setValue] = React.useState(date);
|
|
29
|
+
const DatePicker = ({ Icon, style, theme: { colors, typography, roundness, disabledOpacity }, date, onDateChange = () => { }, initialValue, defaultValue, disabled = false, mode = "date", format, type = "underline", leftIconName, rightIconName, leftIconMode = "inset", label, placeholder, ...props }) => {
|
|
30
|
+
const [value, setValue] = React.useState(date || defaultValue);
|
|
31
31
|
const [pickerVisible, setPickerVisible] = React.useState(false);
|
|
32
32
|
const [labeled] = React.useState(new Animated.Value(date ? 0 : 1));
|
|
33
33
|
const [placeholder1, setPlaceholder1] = React.useState("");
|
|
@@ -45,7 +45,8 @@ type Props = {
|
|
|
45
45
|
date?: Date;
|
|
46
46
|
format?: string;
|
|
47
47
|
onDateChange?: (data?: Date) => void;
|
|
48
|
-
initialValue?: Date;
|
|
48
|
+
initialValue?: Date; // deprecated
|
|
49
|
+
defaultValue?: Date;
|
|
49
50
|
disabled?: boolean;
|
|
50
51
|
mode?: "date" | "time" | "datetime";
|
|
51
52
|
type?: "solid" | "underline";
|
|
@@ -79,6 +80,7 @@ const DatePicker: React.FC<Props> = ({
|
|
|
79
80
|
date,
|
|
80
81
|
onDateChange = () => {},
|
|
81
82
|
initialValue,
|
|
83
|
+
defaultValue,
|
|
82
84
|
disabled = false,
|
|
83
85
|
mode = "date",
|
|
84
86
|
format,
|
|
@@ -90,7 +92,7 @@ const DatePicker: React.FC<Props> = ({
|
|
|
90
92
|
placeholder,
|
|
91
93
|
...props
|
|
92
94
|
}) => {
|
|
93
|
-
const [value, setValue] = React.useState<any>(date);
|
|
95
|
+
const [value, setValue] = React.useState<any>(date || defaultValue);
|
|
94
96
|
const [pickerVisible, setPickerVisible] = React.useState(false);
|
|
95
97
|
const [labeled] = React.useState<Animated.Value>(
|
|
96
98
|
new Animated.Value(date ? 0 : 1)
|
|
@@ -4,11 +4,15 @@ import { withTheme } from "../theming";
|
|
|
4
4
|
import { GROUPS, COMPONENT_TYPES, FORM_TYPES, PROP_TYPES, FIELD_NAME, Triggers, } from "@draftbit/types";
|
|
5
5
|
import Config from "./Config";
|
|
6
6
|
import { usePrevious } from "../hooks";
|
|
7
|
-
const FieldSearchBarFull = ({ Icon, icon = "search", placeholder = "", style, theme: { colors, typography }, onChange: changeOverride, onSubmit: submitOverride, value, initialValue, }) => {
|
|
7
|
+
const FieldSearchBarFull = ({ Icon, icon = "search", placeholder = "", style, theme: { colors, typography }, onChange: changeOverride, onSubmit: submitOverride, value, initialValue, defaultValue, }) => {
|
|
8
8
|
const [focused, setIsFocused] = React.useState(false);
|
|
9
9
|
const onBlur = () => {
|
|
10
10
|
setIsFocused(false);
|
|
11
11
|
};
|
|
12
|
+
const [internalValue, setIntervalValue] = React.useState(value || defaultValue);
|
|
13
|
+
React.useEffect(() => {
|
|
14
|
+
setIntervalValue(value);
|
|
15
|
+
}, [value]);
|
|
12
16
|
const onChange = React.useCallback((text) => {
|
|
13
17
|
changeOverride && changeOverride(text);
|
|
14
18
|
}, [changeOverride]);
|
|
@@ -25,10 +29,16 @@ const FieldSearchBarFull = ({ Icon, icon = "search", placeholder = "", style, th
|
|
|
25
29
|
submitOverride && submitOverride(e);
|
|
26
30
|
};
|
|
27
31
|
const { lineHeight, ...typeStyles } = typography.body2; // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
32
|
+
const handleChangeText = (newValue) => {
|
|
33
|
+
setIntervalValue(newValue);
|
|
34
|
+
if (onChange) {
|
|
35
|
+
onChange(newValue);
|
|
36
|
+
}
|
|
37
|
+
};
|
|
28
38
|
return (React.createElement(View, { style: [{ padding: 16 }, styles.container, style] },
|
|
29
39
|
React.createElement(Icon, { name: icon, size: Config.fieldSearchBarFullIconSize, color: focused ? colors.primary : colors.light }),
|
|
30
40
|
React.createElement(View, { style: { marginLeft: 12, flex: 1 } },
|
|
31
|
-
React.createElement(TextInput, { clearButtonMode: "while-editing", placeholder: placeholder, value:
|
|
41
|
+
React.createElement(TextInput, { clearButtonMode: "while-editing", placeholder: placeholder, value: internalValue, onBlur: onBlur, onFocus: onFocus, onChangeText: handleChangeText, onSubmitEditing: onSubmit, placeholderTextColor: colors.light, style: [
|
|
32
42
|
{
|
|
33
43
|
color: colors.medium,
|
|
34
44
|
},
|
|
@@ -27,10 +27,11 @@ type Props = {
|
|
|
27
27
|
placeholder?: string;
|
|
28
28
|
style?: StyleProp<ViewStyle>;
|
|
29
29
|
theme: Theme;
|
|
30
|
-
onChange
|
|
30
|
+
onChange?: (text: string) => void;
|
|
31
31
|
onSubmit?: (e: NativeSyntheticEvent<TextInputSubmitEditingEventData>) => void;
|
|
32
|
-
value
|
|
33
|
-
initialValue?: string;
|
|
32
|
+
value?: string;
|
|
33
|
+
initialValue?: string; // deprecated
|
|
34
|
+
defaultValue?: string;
|
|
34
35
|
} & IconSlot;
|
|
35
36
|
|
|
36
37
|
const FieldSearchBarFull: React.FC<Props> = ({
|
|
@@ -43,6 +44,7 @@ const FieldSearchBarFull: React.FC<Props> = ({
|
|
|
43
44
|
onSubmit: submitOverride,
|
|
44
45
|
value,
|
|
45
46
|
initialValue,
|
|
47
|
+
defaultValue,
|
|
46
48
|
}) => {
|
|
47
49
|
const [focused, setIsFocused] = React.useState(false);
|
|
48
50
|
|
|
@@ -50,6 +52,14 @@ const FieldSearchBarFull: React.FC<Props> = ({
|
|
|
50
52
|
setIsFocused(false);
|
|
51
53
|
};
|
|
52
54
|
|
|
55
|
+
const [internalValue, setIntervalValue] = React.useState<string | undefined>(
|
|
56
|
+
value || defaultValue
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
React.useEffect(() => {
|
|
60
|
+
setIntervalValue(value);
|
|
61
|
+
}, [value]);
|
|
62
|
+
|
|
53
63
|
const onChange = React.useCallback(
|
|
54
64
|
(text: string) => {
|
|
55
65
|
changeOverride && changeOverride(text);
|
|
@@ -76,6 +86,13 @@ const FieldSearchBarFull: React.FC<Props> = ({
|
|
|
76
86
|
|
|
77
87
|
const { lineHeight, ...typeStyles } = typography.body2; // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
78
88
|
|
|
89
|
+
const handleChangeText = (newValue: string) => {
|
|
90
|
+
setIntervalValue(newValue);
|
|
91
|
+
if (onChange) {
|
|
92
|
+
onChange(newValue);
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
|
|
79
96
|
return (
|
|
80
97
|
<View style={[{ padding: 16 }, styles.container, style]}>
|
|
81
98
|
<Icon
|
|
@@ -87,10 +104,10 @@ const FieldSearchBarFull: React.FC<Props> = ({
|
|
|
87
104
|
<TextInput
|
|
88
105
|
clearButtonMode="while-editing"
|
|
89
106
|
placeholder={placeholder}
|
|
90
|
-
value={
|
|
107
|
+
value={internalValue}
|
|
91
108
|
onBlur={onBlur}
|
|
92
109
|
onFocus={onFocus}
|
|
93
|
-
onChangeText={
|
|
110
|
+
onChangeText={handleChangeText}
|
|
94
111
|
onSubmitEditing={onSubmit}
|
|
95
112
|
placeholderTextColor={colors.light}
|
|
96
113
|
style={[
|
|
@@ -24,7 +24,11 @@ function normalizeOptions(options) {
|
|
|
24
24
|
}
|
|
25
25
|
throw new Error('Picker options must be either an array of strings or array of { "label": string; "value": string; } objects.');
|
|
26
26
|
}
|
|
27
|
-
const Picker = ({ options = [], placeholder, onValueChange: onValueChangeOverride, value, initialValue, ...props }) => {
|
|
27
|
+
const Picker = ({ options = [], placeholder, onValueChange: onValueChangeOverride, value, initialValue, defaultValue, ...props }) => {
|
|
28
|
+
const [internalValue, setIntervalValue] = React.useState(value || defaultValue);
|
|
29
|
+
React.useEffect(() => {
|
|
30
|
+
setIntervalValue(value);
|
|
31
|
+
}, [value]);
|
|
28
32
|
const onValueChange = React.useCallback((itemValue, itemIndex) => {
|
|
29
33
|
if (placeholder && itemIndex === 0) {
|
|
30
34
|
return;
|
|
@@ -46,7 +50,13 @@ const Picker = ({ options = [], placeholder, onValueChange: onValueChangeOverrid
|
|
|
46
50
|
const pickerOptions = placeholder
|
|
47
51
|
? [{ value: placeholder, label: placeholder }, ...normalizedOptions]
|
|
48
52
|
: normalizedOptions;
|
|
49
|
-
|
|
53
|
+
const handleValueChange = (newValue, itemIndex) => {
|
|
54
|
+
setIntervalValue(newValue);
|
|
55
|
+
if (onValueChange) {
|
|
56
|
+
onValueChange(newValue, itemIndex);
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
return (React.createElement(PickerComponent, { ...props, selectedValue: String(internalValue), placeholder: placeholder, options: pickerOptions, onValueChange: handleValueChange }));
|
|
50
60
|
};
|
|
51
61
|
export default withTheme(Picker);
|
|
52
62
|
const SEED_DATA_PROPS = {
|
|
@@ -16,7 +16,7 @@ import { usePrevious } from "../../hooks";
|
|
|
16
16
|
|
|
17
17
|
type Props = PickerComponentProps & {
|
|
18
18
|
placeholder?: string;
|
|
19
|
-
value
|
|
19
|
+
value?: string;
|
|
20
20
|
options: PickerOption[] | string[];
|
|
21
21
|
};
|
|
22
22
|
|
|
@@ -52,8 +52,17 @@ const Picker: React.FC<Props> = ({
|
|
|
52
52
|
onValueChange: onValueChangeOverride,
|
|
53
53
|
value,
|
|
54
54
|
initialValue,
|
|
55
|
+
defaultValue,
|
|
55
56
|
...props
|
|
56
57
|
}) => {
|
|
58
|
+
const [internalValue, setIntervalValue] = React.useState<string | undefined>(
|
|
59
|
+
value || defaultValue
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
React.useEffect(() => {
|
|
63
|
+
setIntervalValue(value);
|
|
64
|
+
}, [value]);
|
|
65
|
+
|
|
57
66
|
const onValueChange = React.useCallback(
|
|
58
67
|
(itemValue: string, itemIndex: number) => {
|
|
59
68
|
if (placeholder && itemIndex === 0) {
|
|
@@ -86,13 +95,20 @@ const Picker: React.FC<Props> = ({
|
|
|
86
95
|
? [{ value: placeholder, label: placeholder }, ...normalizedOptions]
|
|
87
96
|
: normalizedOptions;
|
|
88
97
|
|
|
98
|
+
const handleValueChange = (newValue: string, itemIndex: number) => {
|
|
99
|
+
setIntervalValue(newValue);
|
|
100
|
+
if (onValueChange) {
|
|
101
|
+
onValueChange(newValue, itemIndex);
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
|
|
89
105
|
return (
|
|
90
106
|
<PickerComponent
|
|
91
107
|
{...props}
|
|
92
|
-
selectedValue={String(
|
|
108
|
+
selectedValue={String(internalValue)}
|
|
93
109
|
placeholder={placeholder}
|
|
94
110
|
options={pickerOptions}
|
|
95
|
-
onValueChange={
|
|
111
|
+
onValueChange={handleValueChange}
|
|
96
112
|
/>
|
|
97
113
|
);
|
|
98
114
|
};
|
|
@@ -13,6 +13,7 @@ export interface PickerComponentProps extends TextFieldProps {
|
|
|
13
13
|
placeholder?: string;
|
|
14
14
|
selectedValue: string;
|
|
15
15
|
disabled?: boolean;
|
|
16
|
-
onValueChange
|
|
17
|
-
initialValue?: string;
|
|
16
|
+
onValueChange?: (value: string, index: number) => void;
|
|
17
|
+
initialValue?: string; // deprecated
|
|
18
|
+
defaultValue?: string;
|
|
18
19
|
}
|
|
@@ -4,7 +4,11 @@ import { COMPONENT_TYPES, createFieldNameProp, createDirectionProp, Triggers, }
|
|
|
4
4
|
import { radioButtonGroupContext, Direction } from "./context";
|
|
5
5
|
import { usePrevious } from "../../hooks";
|
|
6
6
|
const { Provider } = radioButtonGroupContext;
|
|
7
|
-
const RadioButtonGroup = ({ direction = Direction.Vertical, value, onValueChange = () => { }, initialValue, style, children, ...rest }) => {
|
|
7
|
+
const RadioButtonGroup = ({ direction = Direction.Vertical, value, onValueChange = () => { }, initialValue, defaultValue, style, children, ...rest }) => {
|
|
8
|
+
const [internalValue, setIntervalValue] = React.useState(value || defaultValue);
|
|
9
|
+
React.useEffect(() => {
|
|
10
|
+
setIntervalValue(value);
|
|
11
|
+
}, [value]);
|
|
8
12
|
const previousInitialValue = usePrevious(initialValue);
|
|
9
13
|
React.useEffect(() => {
|
|
10
14
|
if (initialValue !== previousInitialValue) {
|
|
@@ -22,7 +26,11 @@ const RadioButtonGroup = ({ direction = Direction.Vertical, value, onValueChange
|
|
|
22
26
|
});
|
|
23
27
|
}
|
|
24
28
|
return (React.createElement(View, { style: [{ minHeight: 40 }, style], ...rest },
|
|
25
|
-
React.createElement(Provider, { value: {
|
|
29
|
+
React.createElement(Provider, { value: {
|
|
30
|
+
value: internalValue || "",
|
|
31
|
+
onValueChange: setIntervalValue,
|
|
32
|
+
direction,
|
|
33
|
+
} },
|
|
26
34
|
React.createElement(View, { style: _containerStyle }, children))));
|
|
27
35
|
};
|
|
28
36
|
export default RadioButtonGroup;
|
|
@@ -12,9 +12,10 @@ import { usePrevious } from "../../hooks";
|
|
|
12
12
|
export interface RadioButtonGroupProps {
|
|
13
13
|
direction?: Direction;
|
|
14
14
|
style?: StyleProp<ViewStyle>;
|
|
15
|
-
value
|
|
15
|
+
value?: string;
|
|
16
16
|
onValueChange: (value: string) => void;
|
|
17
|
-
initialValue?: string;
|
|
17
|
+
initialValue?: string; // deprecated
|
|
18
|
+
defaultValue?: string;
|
|
18
19
|
theme: Theme;
|
|
19
20
|
children: React.ReactNode;
|
|
20
21
|
}
|
|
@@ -26,10 +27,19 @@ const RadioButtonGroup: React.FC<RadioButtonGroupProps> = ({
|
|
|
26
27
|
value,
|
|
27
28
|
onValueChange = () => {},
|
|
28
29
|
initialValue,
|
|
30
|
+
defaultValue,
|
|
29
31
|
style,
|
|
30
32
|
children,
|
|
31
33
|
...rest
|
|
32
34
|
}) => {
|
|
35
|
+
const [internalValue, setIntervalValue] = React.useState<string | undefined>(
|
|
36
|
+
value || defaultValue
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
React.useEffect(() => {
|
|
40
|
+
setIntervalValue(value);
|
|
41
|
+
}, [value]);
|
|
42
|
+
|
|
33
43
|
const previousInitialValue = usePrevious(initialValue);
|
|
34
44
|
React.useEffect(() => {
|
|
35
45
|
if (initialValue !== previousInitialValue) {
|
|
@@ -51,7 +61,13 @@ const RadioButtonGroup: React.FC<RadioButtonGroupProps> = ({
|
|
|
51
61
|
|
|
52
62
|
return (
|
|
53
63
|
<View style={[{ minHeight: 40 }, style]} {...rest}>
|
|
54
|
-
<Provider
|
|
64
|
+
<Provider
|
|
65
|
+
value={{
|
|
66
|
+
value: internalValue || "",
|
|
67
|
+
onValueChange: setIntervalValue,
|
|
68
|
+
direction,
|
|
69
|
+
}}
|
|
70
|
+
>
|
|
55
71
|
<View style={_containerStyle}>{children}</View>
|
|
56
72
|
</Provider>
|
|
57
73
|
</View>
|
package/src/components/Slider.js
CHANGED
|
@@ -24,22 +24,30 @@ function maybeParseValue(value) {
|
|
|
24
24
|
}
|
|
25
25
|
return undefined;
|
|
26
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 }) {
|
|
27
|
+
function Slider({ Icon, leftIcon, rightIcon, leftIconColor, rightIconColor, value, initialValue, defaultValue, minimumTrackTintColor, maximumTrackTintColor, thumbTintColor, minimumValue = 0, maximumValue = 100, tapToSeek, step = 1, onValueChange = () => { }, style, theme, ...rest }) {
|
|
28
28
|
const previousInitialValue = usePrevious(initialValue);
|
|
29
29
|
React.useEffect(() => {
|
|
30
30
|
if (initialValue !== previousInitialValue) {
|
|
31
31
|
onValueChange(initialValue);
|
|
32
32
|
}
|
|
33
33
|
}, [initialValue, previousInitialValue, onValueChange]);
|
|
34
|
+
const [internalValue, setIntervalValue] = React.useState(value || defaultValue);
|
|
35
|
+
React.useEffect(() => {
|
|
36
|
+
setIntervalValue(value);
|
|
37
|
+
}, [value]);
|
|
34
38
|
const minTrackColor = minimumTrackTintColor || theme.colors.primary;
|
|
35
39
|
const maxTrackColor = maximumTrackTintColor || theme.colors.light;
|
|
36
40
|
const thumbColor = thumbTintColor || theme.colors.primary;
|
|
37
41
|
const leftIconThemeColor = leftIconColor || theme.colors.light;
|
|
38
42
|
const rightIconThemeColor = rightIconColor || theme.colors.light;
|
|
39
|
-
const parsedValue = maybeParseValue(
|
|
43
|
+
const parsedValue = maybeParseValue(internalValue);
|
|
44
|
+
const handleSlidingComplete = (newValue) => {
|
|
45
|
+
setIntervalValue(newValue);
|
|
46
|
+
onValueChange(newValue);
|
|
47
|
+
};
|
|
40
48
|
return (React.createElement(View, { style: [styles.container, style], ...rest },
|
|
41
49
|
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:
|
|
50
|
+
React.createElement(NativeSlider, { value: parsedValue, step: step, minimumValue: minimumValue, maximumValue: maximumValue, tapToSeek: tapToSeek, minimumTrackTintColor: minTrackColor, maximumTrackTintColor: maxTrackColor, thumbTintColor: thumbColor, onSlidingComplete: handleSlidingComplete, style: styles.slider }),
|
|
43
51
|
rightIcon ? (React.createElement(Icon, { color: rightIconThemeColor, name: rightIcon, size: 24 })) : null));
|
|
44
52
|
}
|
|
45
53
|
const styles = StyleSheet.create({
|
|
@@ -21,7 +21,8 @@ import { usePrevious } from "../hooks";
|
|
|
21
21
|
export type Props = {
|
|
22
22
|
style?: StyleProp<ViewStyle>;
|
|
23
23
|
value?: number;
|
|
24
|
-
initialValue?: number;
|
|
24
|
+
initialValue?: number; // deprecated
|
|
25
|
+
defaultValue?: number;
|
|
25
26
|
minimumTrackTintColor: string;
|
|
26
27
|
maximumTrackTintColor: string;
|
|
27
28
|
leftIcon?: string;
|
|
@@ -66,6 +67,7 @@ function Slider({
|
|
|
66
67
|
rightIconColor,
|
|
67
68
|
value,
|
|
68
69
|
initialValue,
|
|
70
|
+
defaultValue,
|
|
69
71
|
minimumTrackTintColor,
|
|
70
72
|
maximumTrackTintColor,
|
|
71
73
|
thumbTintColor,
|
|
@@ -85,6 +87,14 @@ function Slider({
|
|
|
85
87
|
}
|
|
86
88
|
}, [initialValue, previousInitialValue, onValueChange]);
|
|
87
89
|
|
|
90
|
+
const [internalValue, setIntervalValue] = React.useState<number | undefined>(
|
|
91
|
+
value || defaultValue
|
|
92
|
+
);
|
|
93
|
+
|
|
94
|
+
React.useEffect(() => {
|
|
95
|
+
setIntervalValue(value);
|
|
96
|
+
}, [value]);
|
|
97
|
+
|
|
88
98
|
const minTrackColor = minimumTrackTintColor || theme.colors.primary;
|
|
89
99
|
const maxTrackColor = maximumTrackTintColor || theme.colors.light;
|
|
90
100
|
const thumbColor = thumbTintColor || theme.colors.primary;
|
|
@@ -92,7 +102,12 @@ function Slider({
|
|
|
92
102
|
const leftIconThemeColor = leftIconColor || theme.colors.light;
|
|
93
103
|
const rightIconThemeColor = rightIconColor || theme.colors.light;
|
|
94
104
|
|
|
95
|
-
const parsedValue = maybeParseValue(
|
|
105
|
+
const parsedValue = maybeParseValue(internalValue);
|
|
106
|
+
|
|
107
|
+
const handleSlidingComplete = (newValue: number) => {
|
|
108
|
+
setIntervalValue(newValue);
|
|
109
|
+
onValueChange(newValue);
|
|
110
|
+
};
|
|
96
111
|
|
|
97
112
|
return (
|
|
98
113
|
<View style={[styles.container, style]} {...rest}>
|
|
@@ -108,7 +123,7 @@ function Slider({
|
|
|
108
123
|
minimumTrackTintColor={minTrackColor}
|
|
109
124
|
maximumTrackTintColor={maxTrackColor}
|
|
110
125
|
thumbTintColor={thumbColor}
|
|
111
|
-
onSlidingComplete={
|
|
126
|
+
onSlidingComplete={handleSlidingComplete}
|
|
112
127
|
style={styles.slider}
|
|
113
128
|
/>
|
|
114
129
|
{rightIcon ? (
|
|
@@ -2,8 +2,8 @@ import * as React from "react";
|
|
|
2
2
|
import { View, StyleSheet, Pressable, } from "react-native";
|
|
3
3
|
import { withTheme } from "../theming";
|
|
4
4
|
import { COMPONENT_TYPES, createStaticNumberProp, createFieldNameProp, createStaticBoolProp, Triggers, createColorProp, GROUPS, } from "@draftbit/types";
|
|
5
|
-
const StarRating = ({ Icon, starSize = 16, maxStars = 5, rating = 0, isEditable = false, activeColor, inactiveColor, style, onPress, ...rest }) => {
|
|
6
|
-
const [localRating, setLocalRating] = React.useState(rating);
|
|
5
|
+
const StarRating = ({ Icon, starSize = 16, maxStars = 5, rating = 0, defaultValue, isEditable = false, activeColor, inactiveColor, style, onPress, ...rest }) => {
|
|
6
|
+
const [localRating, setLocalRating] = React.useState(rating || defaultValue || 0);
|
|
7
7
|
React.useEffect(() => {
|
|
8
8
|
setLocalRating(rating);
|
|
9
9
|
}, [rating]);
|
|
@@ -24,6 +24,7 @@ type Props = {
|
|
|
24
24
|
starSize?: number;
|
|
25
25
|
maxStars?: number;
|
|
26
26
|
rating?: number;
|
|
27
|
+
defaultValue?: number;
|
|
27
28
|
isEditable?: boolean;
|
|
28
29
|
activeColor?: string;
|
|
29
30
|
inactiveColor?: string;
|
|
@@ -37,6 +38,7 @@ const StarRating: React.FC<Props> = ({
|
|
|
37
38
|
starSize = 16,
|
|
38
39
|
maxStars = 5,
|
|
39
40
|
rating = 0,
|
|
41
|
+
defaultValue,
|
|
40
42
|
isEditable = false,
|
|
41
43
|
activeColor,
|
|
42
44
|
inactiveColor,
|
|
@@ -44,7 +46,9 @@ const StarRating: React.FC<Props> = ({
|
|
|
44
46
|
onPress,
|
|
45
47
|
...rest
|
|
46
48
|
}) => {
|
|
47
|
-
const [localRating, setLocalRating] = React.useState(
|
|
49
|
+
const [localRating, setLocalRating] = React.useState<number>(
|
|
50
|
+
rating || defaultValue || 0
|
|
51
|
+
);
|
|
48
52
|
|
|
49
53
|
React.useEffect(() => {
|
|
50
54
|
setLocalRating(rating);
|
|
@@ -4,8 +4,11 @@ import { withTheme } from "../theming";
|
|
|
4
4
|
import { COMPONENT_TYPES, createIconSizeProp, createColorProp, createFieldNameProp, Triggers, } from "@draftbit/types";
|
|
5
5
|
import IconButton from "./IconButton";
|
|
6
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);
|
|
7
|
+
const Stepper = ({ Icon, value = 0, style, onChange, initialValue, defaultValue, theme: { colors, typography, roundness }, iconSize = 24, iconColor = colors.strong, borderRadius = roundness, typeStyle, }) => {
|
|
8
|
+
const [stateValue, setStateValue] = React.useState(value || defaultValue || 0);
|
|
9
|
+
React.useEffect(() => {
|
|
10
|
+
setStateValue(value);
|
|
11
|
+
}, [value]);
|
|
9
12
|
const previousInitialValue = usePrevious(initialValue);
|
|
10
13
|
React.useEffect(() => {
|
|
11
14
|
if (initialValue !== previousInitialValue) {
|
|
@@ -19,7 +19,8 @@ type Props = {
|
|
|
19
19
|
theme: Theme;
|
|
20
20
|
style?: StyleProp<ViewStyle>;
|
|
21
21
|
onChange?: (value: number) => void;
|
|
22
|
-
initialValue?: number;
|
|
22
|
+
initialValue?: number; // deprecated
|
|
23
|
+
defaultValue?: number;
|
|
23
24
|
iconSize?: number;
|
|
24
25
|
iconColor?: string;
|
|
25
26
|
borderRadius?: number;
|
|
@@ -32,13 +33,20 @@ const Stepper: React.FC<Props> = ({
|
|
|
32
33
|
style,
|
|
33
34
|
onChange,
|
|
34
35
|
initialValue,
|
|
36
|
+
defaultValue,
|
|
35
37
|
theme: { colors, typography, roundness },
|
|
36
38
|
iconSize = 24,
|
|
37
39
|
iconColor = colors.strong,
|
|
38
40
|
borderRadius = roundness,
|
|
39
41
|
typeStyle,
|
|
40
42
|
}) => {
|
|
41
|
-
const [stateValue, setStateValue] = React.useState(
|
|
43
|
+
const [stateValue, setStateValue] = React.useState(
|
|
44
|
+
value || defaultValue || 0
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
React.useEffect(() => {
|
|
48
|
+
setStateValue(value);
|
|
49
|
+
}, [value]);
|
|
42
50
|
|
|
43
51
|
const previousInitialValue = usePrevious(initialValue);
|
|
44
52
|
React.useEffect(() => {
|
|
@@ -1,16 +1,12 @@
|
|
|
1
|
-
import { COMPONENT_TYPES, createBoolProp,
|
|
1
|
+
import { COMPONENT_TYPES, createBoolProp, createNumberProp, createTextProp, GROUPS, } from "@draftbit/types";
|
|
2
2
|
import React from "react";
|
|
3
3
|
import { View } from "react-native";
|
|
4
4
|
import SwiperComponent from "react-native-web-swiper";
|
|
5
|
-
const Swiper = ({ vertical = false, loop = false, timeout = 0, from = 0, prevTitle = "", nextTitle = "",
|
|
5
|
+
const Swiper = ({ vertical = false, loop = false, timeout = 0, from = 0, prevTitle = "", nextTitle = "", dotsTouchable = true, children, style, }) => (React.createElement(View, { style: style },
|
|
6
6
|
React.createElement(SwiperComponent, { from: from, loop: loop, timeout: timeout, vertical: vertical, controlsProps: {
|
|
7
7
|
prevTitle,
|
|
8
8
|
nextTitle,
|
|
9
|
-
prevTitleStyle: { color: prevTitleColor },
|
|
10
|
-
nextTitleStyle: { color: nextTitleColor },
|
|
11
9
|
dotsTouchable,
|
|
12
|
-
dotActiveStyle: { backgroundColor: dotActiveColor },
|
|
13
|
-
dotProps: { badgeStyle: { backgroundColor: dotColor } },
|
|
14
10
|
} }, children)));
|
|
15
11
|
export default Swiper;
|
|
16
12
|
export const SEED_DATA = {
|
|
@@ -51,20 +47,6 @@ export const SEED_DATA = {
|
|
|
51
47
|
label: "Next Title",
|
|
52
48
|
defaultValue: "",
|
|
53
49
|
}),
|
|
54
|
-
prevTitleColor: createColorProp({
|
|
55
|
-
label: "Previous Title Color",
|
|
56
|
-
}),
|
|
57
|
-
nextTitleColor: createColorProp({
|
|
58
|
-
label: "Next Title Color",
|
|
59
|
-
}),
|
|
60
|
-
dotColor: createColorProp({
|
|
61
|
-
label: "Dot Color",
|
|
62
|
-
defaultValue: "#86939e",
|
|
63
|
-
}),
|
|
64
|
-
dotActiveColor: createColorProp({
|
|
65
|
-
label: "Dot Active Color",
|
|
66
|
-
defaultValue: "#2089dc",
|
|
67
|
-
}),
|
|
68
50
|
dotsTouchable: createBoolProp({
|
|
69
51
|
group: GROUPS.basic,
|
|
70
52
|
label: "Dots Touchable",
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
COMPONENT_TYPES,
|
|
3
3
|
createBoolProp,
|
|
4
|
-
createColorProp,
|
|
5
4
|
createNumberProp,
|
|
6
5
|
createTextProp,
|
|
7
6
|
GROUPS,
|
|
@@ -17,11 +16,7 @@ export interface SwiperProps {
|
|
|
17
16
|
timeout?: number;
|
|
18
17
|
prevTitle?: string;
|
|
19
18
|
nextTitle?: string;
|
|
20
|
-
prevTitleColor: string;
|
|
21
|
-
nextTitleColor: string;
|
|
22
19
|
dotsTouchable?: boolean;
|
|
23
|
-
dotColor?: string;
|
|
24
|
-
dotActiveColor?: string;
|
|
25
20
|
children: React.ReactNode;
|
|
26
21
|
style?: StyleProp<ViewStyle>;
|
|
27
22
|
}
|
|
@@ -33,11 +28,7 @@ const Swiper = ({
|
|
|
33
28
|
from = 0,
|
|
34
29
|
prevTitle = "",
|
|
35
30
|
nextTitle = "",
|
|
36
|
-
prevTitleColor = "red",
|
|
37
|
-
nextTitleColor = "blue",
|
|
38
31
|
dotsTouchable = true,
|
|
39
|
-
dotColor,
|
|
40
|
-
dotActiveColor,
|
|
41
32
|
children,
|
|
42
33
|
style,
|
|
43
34
|
}: SwiperProps) => (
|
|
@@ -50,11 +41,7 @@ const Swiper = ({
|
|
|
50
41
|
controlsProps={{
|
|
51
42
|
prevTitle,
|
|
52
43
|
nextTitle,
|
|
53
|
-
prevTitleStyle: { color: prevTitleColor },
|
|
54
|
-
nextTitleStyle: { color: nextTitleColor },
|
|
55
44
|
dotsTouchable,
|
|
56
|
-
dotActiveStyle: { backgroundColor: dotActiveColor },
|
|
57
|
-
dotProps: { badgeStyle: { backgroundColor: dotColor } },
|
|
58
45
|
}}
|
|
59
46
|
>
|
|
60
47
|
{children}
|
|
@@ -102,20 +89,6 @@ export const SEED_DATA = {
|
|
|
102
89
|
label: "Next Title",
|
|
103
90
|
defaultValue: "",
|
|
104
91
|
}),
|
|
105
|
-
prevTitleColor: createColorProp({
|
|
106
|
-
label: "Previous Title Color",
|
|
107
|
-
}),
|
|
108
|
-
nextTitleColor: createColorProp({
|
|
109
|
-
label: "Next Title Color",
|
|
110
|
-
}),
|
|
111
|
-
dotColor: createColorProp({
|
|
112
|
-
label: "Dot Color",
|
|
113
|
-
defaultValue: "#86939e",
|
|
114
|
-
}),
|
|
115
|
-
dotActiveColor: createColorProp({
|
|
116
|
-
label: "Dot Active Color",
|
|
117
|
-
defaultValue: "#2089dc",
|
|
118
|
-
}),
|
|
119
92
|
dotsTouchable: createBoolProp({
|
|
120
93
|
group: GROUPS.basic,
|
|
121
94
|
label: "Dots Touchable",
|
package/src/components/Switch.js
CHANGED
|
@@ -10,6 +10,9 @@ function Switch({ value, initialValue, defaultValue, disabled, onValueChange, ac
|
|
|
10
10
|
const activeThumbThemeColor = activeThumbColor || "#FFF";
|
|
11
11
|
const inactiveThumbThemeColor = inactiveThumbColor || "#FFF";
|
|
12
12
|
const [checked, setChecked] = React.useState(value || defaultValue);
|
|
13
|
+
React.useEffect(() => {
|
|
14
|
+
setChecked(value);
|
|
15
|
+
}, [value]);
|
|
13
16
|
React.useEffect(() => {
|
|
14
17
|
if (value != null && value !== checked) {
|
|
15
18
|
setChecked(value);
|
|
@@ -45,6 +45,11 @@ function Switch({
|
|
|
45
45
|
const inactiveThumbThemeColor = inactiveThumbColor || "#FFF";
|
|
46
46
|
|
|
47
47
|
const [checked, setChecked] = React.useState(value || defaultValue);
|
|
48
|
+
|
|
49
|
+
React.useEffect(() => {
|
|
50
|
+
setChecked(value);
|
|
51
|
+
}, [value]);
|
|
52
|
+
|
|
48
53
|
React.useEffect(() => {
|
|
49
54
|
if (value != null && value !== checked) {
|
|
50
55
|
setChecked(value);
|