@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,43 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { Animated, Easing, } from "react-native";
|
|
3
|
+
import CircularProgress from "./CircularProgress";
|
|
4
|
+
const AnimatedProgress = Animated.createAnimatedComponent(CircularProgress);
|
|
5
|
+
const AnimatedCircularProgress = ({ duration = 500, easing = Easing.out(Easing.ease), fill, prefill = 0, useNativeDriver = false, tintColorSecondary, onAnimationComplete, tintColor = "black", ...other }) => {
|
|
6
|
+
const [fillAnimation] = React.useState(new Animated.Value(prefill));
|
|
7
|
+
const animate = React.useCallback((toVal = -1, dur, ease) => {
|
|
8
|
+
const toValue = toVal >= 0 ? toVal : fill;
|
|
9
|
+
const dura = dur || duration;
|
|
10
|
+
const eas = ease || easing;
|
|
11
|
+
const useNative = useNativeDriver;
|
|
12
|
+
const anim = Animated.timing(fillAnimation, {
|
|
13
|
+
useNativeDriver: useNative,
|
|
14
|
+
toValue,
|
|
15
|
+
easing: eas,
|
|
16
|
+
duration: dura,
|
|
17
|
+
});
|
|
18
|
+
anim.start(onAnimationComplete);
|
|
19
|
+
return anim;
|
|
20
|
+
}, [
|
|
21
|
+
duration,
|
|
22
|
+
easing,
|
|
23
|
+
fill,
|
|
24
|
+
useNativeDriver,
|
|
25
|
+
fillAnimation,
|
|
26
|
+
onAnimationComplete,
|
|
27
|
+
]);
|
|
28
|
+
const animateColor = () => {
|
|
29
|
+
if (!tintColorSecondary) {
|
|
30
|
+
return tintColor;
|
|
31
|
+
}
|
|
32
|
+
const tintAnimation = fillAnimation.interpolate({
|
|
33
|
+
inputRange: [0, 100],
|
|
34
|
+
outputRange: [tintColor, tintColorSecondary],
|
|
35
|
+
});
|
|
36
|
+
return tintAnimation;
|
|
37
|
+
};
|
|
38
|
+
React.useEffect(() => {
|
|
39
|
+
animate();
|
|
40
|
+
}, [fill, animate]);
|
|
41
|
+
return (React.createElement(AnimatedProgress, { ...other, style: other.style, childrenContainerStyle: other.childrenContainerStyle, fill: fillAnimation, tintColor: animateColor() }));
|
|
42
|
+
};
|
|
43
|
+
export default AnimatedCircularProgress;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { View, StyleSheet, } from "react-native";
|
|
3
|
+
const AspectRatio = (props) => {
|
|
4
|
+
const [layout, setLayout] = React.useState(null);
|
|
5
|
+
const { aspectRatio = 1, ...inputStyle } = StyleSheet.flatten(props.style) || {};
|
|
6
|
+
const style = [inputStyle, { aspectRatio }];
|
|
7
|
+
if (layout) {
|
|
8
|
+
const { width = 0, height = 0 } = layout;
|
|
9
|
+
if (width === 0) {
|
|
10
|
+
style.push({ width: height * (1 / aspectRatio), height });
|
|
11
|
+
}
|
|
12
|
+
else {
|
|
13
|
+
style.push({ width, height: width * (1 / aspectRatio) });
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
return (React.createElement(View, { ...props, style: style, onLayout: ({ nativeEvent: { layout: l } }) => setLayout(l) }, props.children));
|
|
17
|
+
};
|
|
18
|
+
export default AspectRatio;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { View } from "react-native";
|
|
3
|
+
import Touchable from "./Touchable";
|
|
4
|
+
import CircleImage from "./CircleImage";
|
|
5
|
+
import { withTheme } from "../theming";
|
|
6
|
+
import { GROUPS, COMPONENT_TYPES, FORM_TYPES, PROP_TYPES, } from "@draftbit/types";
|
|
7
|
+
const AvatarEdit = ({ Icon, image, size = 80, onPress = () => { }, style, theme, ...rest }) => {
|
|
8
|
+
const colorStyles = {
|
|
9
|
+
editBackgroundColor: theme.colors.primary,
|
|
10
|
+
editIconColor: theme.colors.surface,
|
|
11
|
+
editBorderColor: theme.colors.surface,
|
|
12
|
+
};
|
|
13
|
+
const dimensions = {
|
|
14
|
+
width: size,
|
|
15
|
+
height: size,
|
|
16
|
+
};
|
|
17
|
+
return (React.createElement(View, { style: [style, dimensions], ...rest },
|
|
18
|
+
React.createElement(Touchable, { onPress: onPress },
|
|
19
|
+
React.createElement(CircleImage, { source: image, size: size }),
|
|
20
|
+
React.createElement(View, { style: {
|
|
21
|
+
position: "absolute",
|
|
22
|
+
top: -3,
|
|
23
|
+
right: -3,
|
|
24
|
+
borderColor: colorStyles.editBorderColor,
|
|
25
|
+
backgroundColor: colorStyles.editBackgroundColor,
|
|
26
|
+
borderRadius: size * (3 / 16),
|
|
27
|
+
padding: size * (3 / 32),
|
|
28
|
+
} },
|
|
29
|
+
React.createElement(Icon, { name: "MaterialIcons/edit", color: colorStyles.editIconColor, size: size * (3 / 16) })))));
|
|
30
|
+
};
|
|
31
|
+
export default withTheme(AvatarEdit);
|
|
32
|
+
export const SEED_DATA = {
|
|
33
|
+
name: "Avatar Edit",
|
|
34
|
+
tag: "AvatarEdit",
|
|
35
|
+
description: "An avatar with an edit icon in the top right",
|
|
36
|
+
category: COMPONENT_TYPES.deprecated,
|
|
37
|
+
layout: {
|
|
38
|
+
width: 64,
|
|
39
|
+
height: 64,
|
|
40
|
+
},
|
|
41
|
+
props: {
|
|
42
|
+
size: {
|
|
43
|
+
group: GROUPS.basic,
|
|
44
|
+
label: "Size",
|
|
45
|
+
description: "Size of avatar / width, height",
|
|
46
|
+
editable: true,
|
|
47
|
+
required: false,
|
|
48
|
+
formType: FORM_TYPES.number,
|
|
49
|
+
propType: PROP_TYPES.NUMBER,
|
|
50
|
+
min: 0,
|
|
51
|
+
max: 300,
|
|
52
|
+
precision: 0,
|
|
53
|
+
step: 1,
|
|
54
|
+
defaultValue: 80,
|
|
55
|
+
},
|
|
56
|
+
image: {
|
|
57
|
+
group: GROUPS.data,
|
|
58
|
+
label: "Image",
|
|
59
|
+
description: "Name of the image",
|
|
60
|
+
editable: true,
|
|
61
|
+
required: true,
|
|
62
|
+
formType: FORM_TYPES.image,
|
|
63
|
+
propType: PROP_TYPES.ASSET,
|
|
64
|
+
defaultValue: "brightness-5",
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
};
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { Text, Pressable, Platform, StyleSheet, ActivityIndicator, } from "react-native";
|
|
3
|
+
import { withTheme } from "../theming";
|
|
4
|
+
import { COMPONENT_TYPES, createIconProp, createBoolProp, createTextProp, GROUPS, createActionProp, Triggers, } from "@draftbit/types";
|
|
5
|
+
const CONSTANTS = {
|
|
6
|
+
baseHeight: 42,
|
|
7
|
+
borderRadius: 4,
|
|
8
|
+
padding: 8,
|
|
9
|
+
icon: 24,
|
|
10
|
+
};
|
|
11
|
+
function Base({ Icon, icon, title, onPress, loading, disabled, style, ...props }) {
|
|
12
|
+
const { color, fontFamily, fontWeight, fontSize, lineHeight, letterSpacing, textTransform, textAlign, textDecorationLine, textDecorationColor, textDecorationStyle, ...buttonStyles } = StyleSheet.flatten(style || {});
|
|
13
|
+
const titleStyles = {
|
|
14
|
+
color,
|
|
15
|
+
fontFamily,
|
|
16
|
+
fontWeight,
|
|
17
|
+
fontSize,
|
|
18
|
+
lineHeight,
|
|
19
|
+
letterSpacing,
|
|
20
|
+
textTransform,
|
|
21
|
+
textAlign,
|
|
22
|
+
textDecorationLine,
|
|
23
|
+
textDecorationColor,
|
|
24
|
+
textDecorationStyle,
|
|
25
|
+
};
|
|
26
|
+
if (textAlign === "left") {
|
|
27
|
+
buttonStyles.justifyContent = "flex-start";
|
|
28
|
+
}
|
|
29
|
+
if (textAlign === "right") {
|
|
30
|
+
buttonStyles.justifyContent = "flex-end";
|
|
31
|
+
}
|
|
32
|
+
return (React.createElement(Pressable, { onPress: onPress, disabled: disabled || loading, style: ({ pressed }) => {
|
|
33
|
+
return [
|
|
34
|
+
styles.base,
|
|
35
|
+
{
|
|
36
|
+
opacity: pressed || disabled ? 0.75 : 1,
|
|
37
|
+
},
|
|
38
|
+
buttonStyles,
|
|
39
|
+
];
|
|
40
|
+
}, ...props },
|
|
41
|
+
loading ? (React.createElement(ActivityIndicator, { size: "small", color: color, style: styles.loading })) : null,
|
|
42
|
+
icon && !loading ? (React.createElement(Icon, { name: icon, color: color, style: styles.icon, size: CONSTANTS.icon })) : null,
|
|
43
|
+
React.createElement(Text, { style: titleStyles }, title)));
|
|
44
|
+
}
|
|
45
|
+
const Solid = ({ style, theme, ...props }) => {
|
|
46
|
+
return (React.createElement(Base, { style: [
|
|
47
|
+
{
|
|
48
|
+
color: "#FFF",
|
|
49
|
+
borderRadius: theme.roundness,
|
|
50
|
+
backgroundColor: theme.colors.primary,
|
|
51
|
+
},
|
|
52
|
+
style,
|
|
53
|
+
], ...props }));
|
|
54
|
+
};
|
|
55
|
+
const ButtonSolid = withTheme(Solid);
|
|
56
|
+
export { ButtonSolid };
|
|
57
|
+
const Outline = ({ style, theme, ...props }) => {
|
|
58
|
+
return (React.createElement(Base, { style: [
|
|
59
|
+
styles.outline,
|
|
60
|
+
{
|
|
61
|
+
borderRadius: theme.roundness,
|
|
62
|
+
borderColor: theme.colors.primary,
|
|
63
|
+
color: theme.colors.primary,
|
|
64
|
+
},
|
|
65
|
+
style,
|
|
66
|
+
], ...props }));
|
|
67
|
+
};
|
|
68
|
+
const ButtonOutline = withTheme(Outline);
|
|
69
|
+
export { ButtonOutline };
|
|
70
|
+
export const BaseLink = ({ style, theme, ...props }) => {
|
|
71
|
+
return (React.createElement(Base, { style: [styles.bare, { color: theme.colors.primary }, style], hitSlop: 8, ...props }));
|
|
72
|
+
};
|
|
73
|
+
const Link = withTheme(BaseLink);
|
|
74
|
+
export { Link };
|
|
75
|
+
const styles = StyleSheet.create({
|
|
76
|
+
base: {
|
|
77
|
+
position: "relative",
|
|
78
|
+
flexDirection: "row",
|
|
79
|
+
alignItems: "center",
|
|
80
|
+
justifyContent: "center",
|
|
81
|
+
minHeight: CONSTANTS.baseHeight,
|
|
82
|
+
paddingHorizontal: 12,
|
|
83
|
+
fontFamily: "System",
|
|
84
|
+
fontWeight: "700",
|
|
85
|
+
...Platform.select({
|
|
86
|
+
web: {
|
|
87
|
+
cursor: "pointer",
|
|
88
|
+
userSelect: "none",
|
|
89
|
+
},
|
|
90
|
+
}),
|
|
91
|
+
},
|
|
92
|
+
outline: {
|
|
93
|
+
backgroundColor: "transparent",
|
|
94
|
+
borderWidth: 1,
|
|
95
|
+
},
|
|
96
|
+
bare: {
|
|
97
|
+
backgroundColor: "transparent",
|
|
98
|
+
padding: 0,
|
|
99
|
+
minHeight: undefined,
|
|
100
|
+
},
|
|
101
|
+
loading: {
|
|
102
|
+
marginRight: 6,
|
|
103
|
+
},
|
|
104
|
+
icon: {
|
|
105
|
+
...Platform.select({
|
|
106
|
+
web: {
|
|
107
|
+
marginTop: 1,
|
|
108
|
+
marginRight: 4,
|
|
109
|
+
alignSelf: "center",
|
|
110
|
+
},
|
|
111
|
+
default: {
|
|
112
|
+
marginBottom: 2,
|
|
113
|
+
marginRight: 4,
|
|
114
|
+
alignSelf: "center",
|
|
115
|
+
},
|
|
116
|
+
}),
|
|
117
|
+
},
|
|
118
|
+
});
|
|
119
|
+
const SEED_DATA_TRIGGERS = [Triggers.OnPress];
|
|
120
|
+
const SEED_DATA_PROPS = {
|
|
121
|
+
onPress: createActionProp(),
|
|
122
|
+
icon: createIconProp({
|
|
123
|
+
defaultValue: null,
|
|
124
|
+
required: false,
|
|
125
|
+
}),
|
|
126
|
+
title: createTextProp({
|
|
127
|
+
label: "Label",
|
|
128
|
+
description: "Button Label",
|
|
129
|
+
defaultValue: "Get Started",
|
|
130
|
+
}),
|
|
131
|
+
disabled: createBoolProp({
|
|
132
|
+
group: GROUPS.basic,
|
|
133
|
+
label: "Disabled",
|
|
134
|
+
description: "Whether the button should be disabled",
|
|
135
|
+
}),
|
|
136
|
+
loading: createBoolProp({
|
|
137
|
+
group: GROUPS.basic,
|
|
138
|
+
label: "Loading",
|
|
139
|
+
description: "Whether to show a loading indicator",
|
|
140
|
+
}),
|
|
141
|
+
};
|
|
142
|
+
const LAYOUT = {
|
|
143
|
+
backgroundColor: "transparent",
|
|
144
|
+
borderRadius: 8,
|
|
145
|
+
fontFamily: "system-700",
|
|
146
|
+
};
|
|
147
|
+
export const SEED_DATA = [
|
|
148
|
+
{
|
|
149
|
+
name: "Button Outline",
|
|
150
|
+
tag: "ButtonOutline",
|
|
151
|
+
category: COMPONENT_TYPES.button,
|
|
152
|
+
layout: {
|
|
153
|
+
...LAYOUT,
|
|
154
|
+
backgroundColor: "transparent",
|
|
155
|
+
borderWidth: 1,
|
|
156
|
+
textAlign: "center",
|
|
157
|
+
},
|
|
158
|
+
triggers: SEED_DATA_TRIGGERS,
|
|
159
|
+
props: SEED_DATA_PROPS,
|
|
160
|
+
},
|
|
161
|
+
{
|
|
162
|
+
name: "Button Solid",
|
|
163
|
+
tag: "ButtonSolid",
|
|
164
|
+
category: COMPONENT_TYPES.button,
|
|
165
|
+
layout: {
|
|
166
|
+
...LAYOUT,
|
|
167
|
+
backgroundColor: "primary",
|
|
168
|
+
textAlign: "center",
|
|
169
|
+
},
|
|
170
|
+
triggers: SEED_DATA_TRIGGERS,
|
|
171
|
+
props: SEED_DATA_PROPS,
|
|
172
|
+
},
|
|
173
|
+
{
|
|
174
|
+
name: "Link",
|
|
175
|
+
tag: "Link",
|
|
176
|
+
category: COMPONENT_TYPES.button,
|
|
177
|
+
layout: {
|
|
178
|
+
...LAYOUT,
|
|
179
|
+
backgroundColor: "transparent",
|
|
180
|
+
color: "primary",
|
|
181
|
+
padding: 0,
|
|
182
|
+
minHeight: undefined,
|
|
183
|
+
},
|
|
184
|
+
triggers: SEED_DATA_TRIGGERS,
|
|
185
|
+
props: SEED_DATA_PROPS,
|
|
186
|
+
},
|
|
187
|
+
];
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { StyleSheet, View, Pressable, } from "react-native";
|
|
3
|
+
import Image from "./Image";
|
|
4
|
+
import Surface from "./Surface";
|
|
5
|
+
import { Title, Subtitle, Caption } from "./Typography";
|
|
6
|
+
import { withTheme } from "../theming";
|
|
7
|
+
import Config from "./Config";
|
|
8
|
+
import { COMPONENT_TYPES, createElevationType, createTextProp, createImageProp, createIconProp, createAspectRatioProp, createStaticBoolProp, createTextStyle, createActionProp, Triggers, } from "@draftbit/types";
|
|
9
|
+
const ICON_SIZE = Config.cardIconSize;
|
|
10
|
+
const ICON_CONTAINER_SIZE = Config.cardIconSize * 2;
|
|
11
|
+
const ICON_CONTAINER_PADDING = Config.cardIconSize / 2 - 1;
|
|
12
|
+
const ICON_ELEVATION = Config.cardIconElevation;
|
|
13
|
+
export const TopRightCircleIcon = withTheme(({ Icon, icon, theme, onPress, }) => {
|
|
14
|
+
return (React.createElement(Surface, { style: {
|
|
15
|
+
justifyContent: "center",
|
|
16
|
+
alignItems: "center",
|
|
17
|
+
elevation: ICON_ELEVATION,
|
|
18
|
+
position: "absolute",
|
|
19
|
+
top: 12,
|
|
20
|
+
right: 12,
|
|
21
|
+
width: ICON_CONTAINER_SIZE,
|
|
22
|
+
height: ICON_CONTAINER_SIZE,
|
|
23
|
+
padding: ICON_CONTAINER_PADDING,
|
|
24
|
+
borderRadius: ICON_CONTAINER_SIZE,
|
|
25
|
+
backgroundColor: "rgba(0, 0, 0, 0.1)",
|
|
26
|
+
} },
|
|
27
|
+
React.createElement(Pressable, { disabled: !onPress, onPress: onPress, style: ({ pressed }) => {
|
|
28
|
+
return [
|
|
29
|
+
{
|
|
30
|
+
opacity: pressed ? 0.8 : 1,
|
|
31
|
+
},
|
|
32
|
+
];
|
|
33
|
+
} },
|
|
34
|
+
React.createElement(Icon, { name: icon, size: ICON_SIZE, color: theme.colors.surface }))));
|
|
35
|
+
});
|
|
36
|
+
const Card = ({ Icon, image = Config.cardImageUrl, title, subtitle, description, textCentered, icon, aspectRatio = 1.5, elevation = 2, style, onPress, onPressIcon, titleStyle, subtitleStyle, descriptionStyle, theme, children, }) => {
|
|
37
|
+
const { backgroundColor: bgColor, padding, ...styles } = StyleSheet.flatten(style || {});
|
|
38
|
+
const backgroundColor = bgColor ? bgColor : theme.colors.surface;
|
|
39
|
+
const innerPadding = padding ? padding : 12;
|
|
40
|
+
return (React.createElement(Surface, { style: [{ elevation, backgroundColor }, styles] },
|
|
41
|
+
React.createElement(Pressable, { disabled: !onPress, onPress: onPress, style: ({ pressed }) => {
|
|
42
|
+
return [
|
|
43
|
+
{
|
|
44
|
+
opacity: pressed ? 0.8 : 1,
|
|
45
|
+
},
|
|
46
|
+
];
|
|
47
|
+
} },
|
|
48
|
+
React.createElement(Image, { style: { aspectRatio }, source: typeof image === "string" ? { uri: image } : image, resizeMode: "cover" }),
|
|
49
|
+
React.createElement(View, { style: { padding: innerPadding } },
|
|
50
|
+
React.createElement(View, { style: { alignItems: textCentered ? "center" : "flex-start" } },
|
|
51
|
+
title || (title && title !== "") ? (React.createElement(Title, { text: title, style: titleStyle })) : null,
|
|
52
|
+
subtitle || (subtitle && subtitle !== "") ? (React.createElement(Subtitle, { text: subtitle, style: subtitleStyle })) : null,
|
|
53
|
+
description || (description && description !== "") ? (React.createElement(View, { style: { marginTop: 4 } },
|
|
54
|
+
React.createElement(Caption, { text: description, style: descriptionStyle }))) : null,
|
|
55
|
+
children)),
|
|
56
|
+
icon ? (React.createElement(TopRightCircleIcon, { Icon: Icon, icon: icon, onPress: onPressIcon })) : null)));
|
|
57
|
+
};
|
|
58
|
+
export default withTheme(Card);
|
|
59
|
+
export const SEED_DATA = {
|
|
60
|
+
name: "Card",
|
|
61
|
+
tag: "Card",
|
|
62
|
+
description: "A card you can customize however you'd like",
|
|
63
|
+
category: COMPONENT_TYPES.card,
|
|
64
|
+
triggers: [Triggers.OnPress],
|
|
65
|
+
props: {
|
|
66
|
+
onPress: createActionProp(),
|
|
67
|
+
onPressIcon: createActionProp({
|
|
68
|
+
handlerPropName: "onPressIcon",
|
|
69
|
+
}),
|
|
70
|
+
elevation: createElevationType(3),
|
|
71
|
+
image: createImageProp(),
|
|
72
|
+
title: createTextProp({
|
|
73
|
+
label: "Title",
|
|
74
|
+
description: "Large title text",
|
|
75
|
+
// defaultValue: "Title",
|
|
76
|
+
defaultValue: null,
|
|
77
|
+
}),
|
|
78
|
+
titleStyle: createTextStyle({
|
|
79
|
+
label: "Title Style",
|
|
80
|
+
}),
|
|
81
|
+
subtitle: createTextProp({
|
|
82
|
+
label: "Subtitle",
|
|
83
|
+
description: "Text underneath the title",
|
|
84
|
+
defaultValue: null,
|
|
85
|
+
// defaultValue: "Edit me in the props panel on the right",
|
|
86
|
+
}),
|
|
87
|
+
subtitleStyle: createTextStyle({
|
|
88
|
+
label: "Subtitle Style",
|
|
89
|
+
}),
|
|
90
|
+
description: createTextProp({
|
|
91
|
+
label: "Description",
|
|
92
|
+
description: "Smallest text underneath subtitle",
|
|
93
|
+
// defaultValue:
|
|
94
|
+
// "This bottom text is optional, but shows up to make your life a little easier!",
|
|
95
|
+
defaultValue: null,
|
|
96
|
+
}),
|
|
97
|
+
descriptionStyle: createTextStyle({
|
|
98
|
+
label: "Description Style",
|
|
99
|
+
}),
|
|
100
|
+
icon: createIconProp(),
|
|
101
|
+
aspectRatio: createAspectRatioProp({
|
|
102
|
+
defaultValue: 1.5,
|
|
103
|
+
}),
|
|
104
|
+
textCentered: createStaticBoolProp({
|
|
105
|
+
label: "Centered Text",
|
|
106
|
+
description: "Places your title and subtitle in the center",
|
|
107
|
+
}),
|
|
108
|
+
},
|
|
109
|
+
};
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { View, Text, } from "react-native";
|
|
3
|
+
import Image from "./Image";
|
|
4
|
+
import Card from "./DeprecatedCardWrapper";
|
|
5
|
+
import Elevation from "./Elevation";
|
|
6
|
+
import { withTheme } from "../theming";
|
|
7
|
+
import { GROUPS, COMPONENT_TYPES, FORM_TYPES, PROP_TYPES, createElevationType, createNumColumnsType, } from "@draftbit/types";
|
|
8
|
+
import Config from "./Config";
|
|
9
|
+
const CardBlock = ({ image = Config.cardImageUrl, title, leftDescription, rightDescription, titleCentered, aspectRatio = 1.5, elevation = 2, numColumns = 3, theme: { colors, roundness, typography }, style, onPress, ...rest }) => {
|
|
10
|
+
let titleJustification;
|
|
11
|
+
let titleStyle;
|
|
12
|
+
if (titleCentered && !leftDescription && !rightDescription) {
|
|
13
|
+
titleJustification = "center";
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
titleJustification = "space-between";
|
|
17
|
+
}
|
|
18
|
+
if (numColumns === 1) {
|
|
19
|
+
titleStyle = typography.button;
|
|
20
|
+
}
|
|
21
|
+
else if (numColumns === 2) {
|
|
22
|
+
titleStyle = typography.headline6;
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
titleStyle = typography.headline5;
|
|
26
|
+
}
|
|
27
|
+
const rightDescriptionStyles = [
|
|
28
|
+
typography.subtitle2,
|
|
29
|
+
{ color: colors.light },
|
|
30
|
+
];
|
|
31
|
+
return (React.createElement(Card, { style: style, onPress: onPress, numColumns: numColumns, ...rest },
|
|
32
|
+
React.createElement(View, { style: { backgroundColor: colors.background } },
|
|
33
|
+
React.createElement(Elevation, { style: { elevation, borderRadius: roundness } },
|
|
34
|
+
React.createElement(Image, { style: {
|
|
35
|
+
borderRadius: roundness,
|
|
36
|
+
aspectRatio,
|
|
37
|
+
}, source: typeof image === "string" ? { uri: image } : image, resizeMode: "cover" })),
|
|
38
|
+
title ? (React.createElement(View, { style: {
|
|
39
|
+
flexDirection: "row",
|
|
40
|
+
alignItems: "center",
|
|
41
|
+
justifyContent: titleJustification,
|
|
42
|
+
marginTop: numColumns === 3 ? 16 : 12,
|
|
43
|
+
} },
|
|
44
|
+
React.createElement(Text, { numberOfLines: 1, style: [titleStyle, { color: colors.strong }] }, title),
|
|
45
|
+
!leftDescription && rightDescription ? (React.createElement(Text, { style: rightDescriptionStyles }, rightDescription)) : null)) : null,
|
|
46
|
+
leftDescription ? (React.createElement(View, { style: {
|
|
47
|
+
flexDirection: "row",
|
|
48
|
+
justifyContent: "space-between",
|
|
49
|
+
alignItems: "center",
|
|
50
|
+
marginTop: numColumns === 3 ? 4 : 4 / 2,
|
|
51
|
+
} },
|
|
52
|
+
React.createElement(Text, { numberOfLines: 1, style: [typography.body2, { color: colors.medium }] }, leftDescription),
|
|
53
|
+
rightDescription ? (React.createElement(Text, { numberOfLines: 1, style: rightDescriptionStyles }, rightDescription)) : null)) : null)));
|
|
54
|
+
};
|
|
55
|
+
export default withTheme(CardBlock);
|
|
56
|
+
const SEED_DATA_PROPS = {
|
|
57
|
+
image: {
|
|
58
|
+
group: GROUPS.data,
|
|
59
|
+
label: "Image",
|
|
60
|
+
description: "Image",
|
|
61
|
+
formType: FORM_TYPES.image,
|
|
62
|
+
propType: PROP_TYPES.ASSET,
|
|
63
|
+
defaultValue: null,
|
|
64
|
+
editable: true,
|
|
65
|
+
required: false,
|
|
66
|
+
},
|
|
67
|
+
title: {
|
|
68
|
+
group: GROUPS.data,
|
|
69
|
+
label: "Title",
|
|
70
|
+
description: "Text to display",
|
|
71
|
+
formType: FORM_TYPES.string,
|
|
72
|
+
propType: PROP_TYPES.STRING,
|
|
73
|
+
defaultValue: "Beautiful West Coast Villa",
|
|
74
|
+
editable: true,
|
|
75
|
+
required: false,
|
|
76
|
+
},
|
|
77
|
+
leftDescription: {
|
|
78
|
+
group: GROUPS.data,
|
|
79
|
+
label: "Left description",
|
|
80
|
+
description: "Text to display on the left",
|
|
81
|
+
formType: FORM_TYPES.string,
|
|
82
|
+
propType: PROP_TYPES.STRING,
|
|
83
|
+
defaultValue: "San Diego",
|
|
84
|
+
editable: true,
|
|
85
|
+
required: false,
|
|
86
|
+
},
|
|
87
|
+
rightDescription: {
|
|
88
|
+
group: GROUPS.data,
|
|
89
|
+
label: "Right description",
|
|
90
|
+
description: "Text to display on the right",
|
|
91
|
+
formType: FORM_TYPES.string,
|
|
92
|
+
propType: PROP_TYPES.STRING,
|
|
93
|
+
defaultValue: "$100",
|
|
94
|
+
editable: true,
|
|
95
|
+
required: false,
|
|
96
|
+
},
|
|
97
|
+
aspectRatio: {
|
|
98
|
+
group: GROUPS.basic,
|
|
99
|
+
label: "Aspect ratio",
|
|
100
|
+
description: "Aspect ratio of the image",
|
|
101
|
+
formType: FORM_TYPES.aspectRatio,
|
|
102
|
+
propType: PROP_TYPES.NUMBER,
|
|
103
|
+
defaultValue: 1.5,
|
|
104
|
+
editable: true,
|
|
105
|
+
required: false,
|
|
106
|
+
},
|
|
107
|
+
titleCentered: {
|
|
108
|
+
group: GROUPS.basic,
|
|
109
|
+
label: "Title centered",
|
|
110
|
+
description: "Whether to center the title",
|
|
111
|
+
formType: FORM_TYPES.boolean,
|
|
112
|
+
propType: PROP_TYPES.BOOLEAN,
|
|
113
|
+
defaultValue: false,
|
|
114
|
+
editable: true,
|
|
115
|
+
required: false,
|
|
116
|
+
},
|
|
117
|
+
elevation: createElevationType(2),
|
|
118
|
+
};
|
|
119
|
+
export const SEED_DATA = [
|
|
120
|
+
{
|
|
121
|
+
name: "Small Card",
|
|
122
|
+
tag: "CardBlock",
|
|
123
|
+
description: "An elevated card with a title and description, that takes up one third of its container.",
|
|
124
|
+
category: COMPONENT_TYPES.card,
|
|
125
|
+
props: {
|
|
126
|
+
...SEED_DATA_PROPS,
|
|
127
|
+
numColumns: createNumColumnsType({
|
|
128
|
+
defaultValue: 1,
|
|
129
|
+
}),
|
|
130
|
+
},
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
name: "Medium Block Card",
|
|
134
|
+
tag: "CardBlock",
|
|
135
|
+
description: "An elevated card with a title and description, that takes up one half of its container.",
|
|
136
|
+
category: COMPONENT_TYPES.card,
|
|
137
|
+
props: {
|
|
138
|
+
...SEED_DATA_PROPS,
|
|
139
|
+
icon: {
|
|
140
|
+
group: GROUPS.basic,
|
|
141
|
+
label: "Icon",
|
|
142
|
+
description: "Icon to display on the top right",
|
|
143
|
+
formType: FORM_TYPES.icon,
|
|
144
|
+
propType: PROP_TYPES.STRING,
|
|
145
|
+
defaultValue: null,
|
|
146
|
+
editable: true,
|
|
147
|
+
required: true,
|
|
148
|
+
},
|
|
149
|
+
numColumns: createNumColumnsType({
|
|
150
|
+
defaultValue: 2,
|
|
151
|
+
}),
|
|
152
|
+
},
|
|
153
|
+
},
|
|
154
|
+
{
|
|
155
|
+
name: "Large Block Card",
|
|
156
|
+
tag: "CardBlock",
|
|
157
|
+
description: "An elevated card with a title and description, that takes up the full width its container.",
|
|
158
|
+
category: COMPONENT_TYPES.card,
|
|
159
|
+
props: {
|
|
160
|
+
...SEED_DATA_PROPS,
|
|
161
|
+
icon: {
|
|
162
|
+
group: GROUPS.basic,
|
|
163
|
+
label: "Icon",
|
|
164
|
+
description: "Icon to display on the top right",
|
|
165
|
+
formType: FORM_TYPES.icon,
|
|
166
|
+
propType: PROP_TYPES.STRING,
|
|
167
|
+
defaultValue: null,
|
|
168
|
+
editable: true,
|
|
169
|
+
required: true,
|
|
170
|
+
},
|
|
171
|
+
numColumns: createNumColumnsType({
|
|
172
|
+
defaultValue: 3,
|
|
173
|
+
}),
|
|
174
|
+
},
|
|
175
|
+
},
|
|
176
|
+
];
|