@draftbit/core 43.4.19 → 43.4.20-9e993c.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/Banner.js +182 -0
- package/lib/commonjs/components/Banner.js.map +1 -0
- package/lib/commonjs/components/DeprecatedCardWrapper.js +14 -2
- package/lib/commonjs/components/DeprecatedCardWrapper.js.map +1 -1
- package/lib/commonjs/components/DeprecatedFAB.js +20 -4
- package/lib/commonjs/components/DeprecatedFAB.js.map +1 -1
- package/lib/commonjs/components/Divider.js +3 -13
- package/lib/commonjs/components/Divider.js.map +1 -1
- package/lib/commonjs/components/Elevation.js +3 -14
- package/lib/commonjs/components/Elevation.js.map +1 -1
- package/lib/commonjs/index.js +8 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/mappings/Banner.js +42 -0
- package/lib/commonjs/mappings/Banner.js.map +1 -0
- package/lib/commonjs/mappings/RadioButtonRow.js.map +1 -1
- package/lib/commonjs/mappings/RowHeadlineImageCaption.js.map +1 -1
- package/lib/module/components/Banner.js +159 -0
- package/lib/module/components/Banner.js.map +1 -0
- package/lib/module/index.js +1 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/mappings/Banner.js +33 -0
- package/lib/module/mappings/Banner.js.map +1 -0
- package/lib/typescript/src/components/Banner.d.ts +22 -0
- package/lib/typescript/src/index.d.ts +1 -0
- package/lib/typescript/src/mappings/Banner.d.ts +48 -0
- package/package.json +2 -2
- package/src/components/Banner.js +109 -0
- package/src/components/Banner.tsx +204 -0
- package/src/index.js +1 -0
- package/src/index.tsx +1 -0
- package/src/mappings/Banner.js +32 -0
- package/src/mappings/Banner.ts +40 -0
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
2
|
+
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import { Button, Text, View, StyleSheet, Animated } from "react-native";
|
|
5
|
+
import Surface from "./Surface";
|
|
6
|
+
import shadow from "../styles/shadow";
|
|
7
|
+
import { withTheme } from "../theming";
|
|
8
|
+
const ELEVATION = 1;
|
|
9
|
+
const DEFAULT_MAX_WIDTH = 960;
|
|
10
|
+
|
|
11
|
+
const Banner = _ref => {
|
|
12
|
+
let {
|
|
13
|
+
initiallyVisible = true,
|
|
14
|
+
dismissable = true,
|
|
15
|
+
icon,
|
|
16
|
+
buttonColor,
|
|
17
|
+
content,
|
|
18
|
+
contentStyle,
|
|
19
|
+
style,
|
|
20
|
+
theme,
|
|
21
|
+
Icon,
|
|
22
|
+
...rest
|
|
23
|
+
} = _ref;
|
|
24
|
+
const [visible, setVisible] = React.useState(initiallyVisible);
|
|
25
|
+
React.useEffect(() => {
|
|
26
|
+
if (initiallyVisible) {
|
|
27
|
+
setVisible(true);
|
|
28
|
+
}
|
|
29
|
+
}, [initiallyVisible]);
|
|
30
|
+
const {
|
|
31
|
+
current: position
|
|
32
|
+
} = React.useRef(new Animated.Value(visible ? 1 : 0));
|
|
33
|
+
const [layout, setLayout] = React.useState({
|
|
34
|
+
height: 0,
|
|
35
|
+
measured: false
|
|
36
|
+
});
|
|
37
|
+
React.useEffect(() => {
|
|
38
|
+
if (visible) {
|
|
39
|
+
// show
|
|
40
|
+
Animated.timing(position, {
|
|
41
|
+
duration: 250,
|
|
42
|
+
toValue: 1,
|
|
43
|
+
useNativeDriver: false
|
|
44
|
+
}).start();
|
|
45
|
+
} else {
|
|
46
|
+
// hide
|
|
47
|
+
Animated.timing(position, {
|
|
48
|
+
duration: 200,
|
|
49
|
+
toValue: 0,
|
|
50
|
+
useNativeDriver: false
|
|
51
|
+
}).start();
|
|
52
|
+
}
|
|
53
|
+
}, [visible, position]);
|
|
54
|
+
|
|
55
|
+
const handleLayout = _ref2 => {
|
|
56
|
+
let {
|
|
57
|
+
nativeEvent
|
|
58
|
+
} = _ref2;
|
|
59
|
+
const {
|
|
60
|
+
height
|
|
61
|
+
} = nativeEvent.layout;
|
|
62
|
+
setLayout({
|
|
63
|
+
height,
|
|
64
|
+
measured: true
|
|
65
|
+
});
|
|
66
|
+
}; // The banner animation has 2 parts:
|
|
67
|
+
// 1. Blank spacer element which animates its height to move the content
|
|
68
|
+
// 2. Actual banner which animates its translateY
|
|
69
|
+
// In initial render, we position everything normally and measure the height of the banner
|
|
70
|
+
// Once we have the height, we apply the height to the spacer and switch the banner to position: absolute
|
|
71
|
+
// We need this because we need to move the content below as if banner's height was being animated
|
|
72
|
+
// However we can't animated banner's height directly as it'll also resize the content inside
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
const height = Animated.multiply(position, layout.height);
|
|
76
|
+
const translateY = Animated.multiply(Animated.add(position, -1), layout.height);
|
|
77
|
+
return /*#__PURE__*/React.createElement(Surface, _extends({}, rest, {
|
|
78
|
+
style: [styles.container, shadow(ELEVATION), style]
|
|
79
|
+
}), /*#__PURE__*/React.createElement(View, {
|
|
80
|
+
style: [styles.wrapper, contentStyle]
|
|
81
|
+
}, /*#__PURE__*/React.createElement(Animated.View, {
|
|
82
|
+
style: {
|
|
83
|
+
height
|
|
84
|
+
}
|
|
85
|
+
}), /*#__PURE__*/React.createElement(Animated.View, {
|
|
86
|
+
onLayout: handleLayout,
|
|
87
|
+
style: [layout.measured || !visible ? // If we have measured banner's height or it's invisible,
|
|
88
|
+
// Position it absolutely, the layout will be taken care of the spacer
|
|
89
|
+
[styles.absolute, {
|
|
90
|
+
transform: [{
|
|
91
|
+
translateY
|
|
92
|
+
}]
|
|
93
|
+
}] : // Otherwise position it normally
|
|
94
|
+
null, !layout.measured && !visible ? // If we haven't measured banner's height yet and it's invisible,
|
|
95
|
+
// hide it with opacity: 0 so user doesn't see it
|
|
96
|
+
{
|
|
97
|
+
opacity: 0
|
|
98
|
+
} : null]
|
|
99
|
+
}, /*#__PURE__*/React.createElement(View, {
|
|
100
|
+
style: [styles.content, {
|
|
101
|
+
marginBottom: dismissable ? 0 : 16
|
|
102
|
+
}]
|
|
103
|
+
}, icon ? /*#__PURE__*/React.createElement(View, {
|
|
104
|
+
style: styles.icon
|
|
105
|
+
}, /*#__PURE__*/React.createElement(Icon, {
|
|
106
|
+
name: icon,
|
|
107
|
+
size: 40
|
|
108
|
+
})) : null, /*#__PURE__*/React.createElement(Text, {
|
|
109
|
+
style: [styles.message, {
|
|
110
|
+
color: theme.colors.text
|
|
111
|
+
}],
|
|
112
|
+
accessibilityLiveRegion: visible ? "polite" : "none",
|
|
113
|
+
accessibilityRole: "alert"
|
|
114
|
+
}, content)), dismissable ? /*#__PURE__*/React.createElement(View, {
|
|
115
|
+
style: styles.actions
|
|
116
|
+
}, /*#__PURE__*/React.createElement(Button, {
|
|
117
|
+
color: buttonColor || theme.colors.primary,
|
|
118
|
+
title: "Close",
|
|
119
|
+
onPress: () => setVisible(false)
|
|
120
|
+
})) : null)));
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
const styles = StyleSheet.create({
|
|
124
|
+
container: {
|
|
125
|
+
elevation: ELEVATION
|
|
126
|
+
},
|
|
127
|
+
wrapper: {
|
|
128
|
+
overflow: "hidden",
|
|
129
|
+
alignSelf: "center",
|
|
130
|
+
width: "100%",
|
|
131
|
+
maxWidth: DEFAULT_MAX_WIDTH
|
|
132
|
+
},
|
|
133
|
+
absolute: {
|
|
134
|
+
position: "absolute",
|
|
135
|
+
top: 0,
|
|
136
|
+
width: "100%"
|
|
137
|
+
},
|
|
138
|
+
content: {
|
|
139
|
+
flexDirection: "row",
|
|
140
|
+
justifyContent: "flex-start",
|
|
141
|
+
marginHorizontal: 8,
|
|
142
|
+
marginTop: 16,
|
|
143
|
+
marginBottom: 0
|
|
144
|
+
},
|
|
145
|
+
icon: {
|
|
146
|
+
margin: 8
|
|
147
|
+
},
|
|
148
|
+
message: {
|
|
149
|
+
flex: 1,
|
|
150
|
+
margin: 8
|
|
151
|
+
},
|
|
152
|
+
actions: {
|
|
153
|
+
flexDirection: "row",
|
|
154
|
+
justifyContent: "flex-end",
|
|
155
|
+
margin: 8
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
export default withTheme(Banner);
|
|
159
|
+
//# sourceMappingURL=Banner.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["Banner.tsx"],"names":["React","Button","Text","View","StyleSheet","Animated","Surface","shadow","withTheme","ELEVATION","DEFAULT_MAX_WIDTH","Banner","initiallyVisible","dismissable","icon","buttonColor","content","contentStyle","style","theme","Icon","rest","visible","setVisible","useState","useEffect","current","position","useRef","Value","layout","setLayout","height","measured","timing","duration","toValue","useNativeDriver","start","handleLayout","nativeEvent","multiply","translateY","add","styles","container","wrapper","absolute","transform","opacity","marginBottom","message","color","colors","text","actions","primary","create","elevation","overflow","alignSelf","width","maxWidth","top","flexDirection","justifyContent","marginHorizontal","marginTop","margin","flex"],"mappings":";;AAAA,OAAO,KAAKA,KAAZ,MAAuB,OAAvB;AACA,SACEC,MADF,EAEEC,IAFF,EAGEC,IAHF,EAKEC,UALF,EAOEC,QAPF,QAQO,cARP;AASA,OAAOC,OAAP,MAAoB,WAApB;AAEA,OAAOC,MAAP,MAAmB,kBAAnB;AACA,SAASC,SAAT,QAA0B,YAA1B;AAGA,MAAMC,SAAS,GAAG,CAAlB;AACA,MAAMC,iBAAiB,GAAG,GAA1B;;AA4BA,MAAMC,MAAuB,GAAG,QAW1B;AAAA,MAX2B;AAC/BC,IAAAA,gBAAgB,GAAG,IADY;AAE/BC,IAAAA,WAAW,GAAG,IAFiB;AAG/BC,IAAAA,IAH+B;AAI/BC,IAAAA,WAJ+B;AAK/BC,IAAAA,OAL+B;AAM/BC,IAAAA,YAN+B;AAO/BC,IAAAA,KAP+B;AAQ/BC,IAAAA,KAR+B;AAS/BC,IAAAA,IAT+B;AAU/B,OAAGC;AAV4B,GAW3B;AACJ,QAAM,CAACC,OAAD,EAAUC,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KADR;AAEPC,IAAAA,cAAc,EAAE,YAFT;AAGPC,IAAAA,gBAAgB,EAAE,CAHX;AAIPC,IAAAA,SAAS,EAAE,EAJJ;AAKPjB,IAAAA,YAAY,EAAE;AALP,GAfsB;AAsB/BpC,EAAAA,IAAI,EAAE;AACJsD,IAAAA,MAAM,EAAE;AADJ,GAtByB;AAyB/BjB,EAAAA,OAAO,EAAE;AACPkB,IAAAA,IAAI,EAAE,CADC;AAEPD,IAAAA,MAAM,EAAE;AAFD,GAzBsB;AA6B/Bb,EAAAA,OAAO,EAAE;AACPS,IAAAA,aAAa,EAAE,KADR;AAEPC,IAAAA,cAAc,EAAE,UAFT;AAGPG,IAAAA,MAAM,EAAE;AAHD;AA7BsB,CAAlB,CAAf;AAoCA,eAAe5D,SAAS,CAACG,MAAD,CAAxB","sourcesContent":["import * as React from \"react\";\nimport {\n Button,\n Text,\n View,\n ViewStyle,\n StyleSheet,\n StyleProp,\n Animated,\n} from \"react-native\";\nimport Surface from \"./Surface\";\nimport type { IconSlot } from \"../interfaces/Icon\";\nimport shadow from \"../styles/shadow\";\nimport { withTheme } from \"../theming\";\nimport type { Theme } from \"../styles/DefaultTheme\";\n\nconst ELEVATION = 1;\nconst DEFAULT_MAX_WIDTH = 960;\n\ntype Props = {\n initiallyVisible: boolean;\n dismissable: boolean;\n buttonColor?: string;\n icon?: string;\n content?: string;\n contentStyle?: StyleProp<ViewStyle>;\n style?: StyleProp<ViewStyle>;\n ref?: React.RefObject<View>;\n /**\n * @optional\n */\n theme: Theme;\n} & IconSlot;\n\ntype NativeEvent = {\n nativeEvent: {\n layout: {\n x: number;\n y: number;\n width: number;\n height: number;\n };\n };\n};\n\nconst Banner: React.FC<Props> = ({\n initiallyVisible = true,\n dismissable = true,\n icon,\n buttonColor,\n content,\n contentStyle,\n style,\n theme,\n Icon,\n ...rest\n}) => {\n const [visible, setVisible] = React.useState(initiallyVisible);\n\n React.useEffect(() => {\n if (initiallyVisible) {\n setVisible(true);\n }\n }, [initiallyVisible]);\n\n const { current: position } = React.useRef<Animated.Value>(\n new Animated.Value(visible ? 1 : 0)\n );\n const [layout, setLayout] = React.useState<{\n height: number;\n measured: boolean;\n }>({\n height: 0,\n measured: false,\n });\n\n React.useEffect(() => {\n if (visible) {\n // show\n Animated.timing(position, {\n duration: 250,\n toValue: 1,\n useNativeDriver: false,\n }).start();\n } else {\n // hide\n Animated.timing(position, {\n duration: 200,\n toValue: 0,\n useNativeDriver: false,\n }).start();\n }\n }, [visible, position]);\n\n const handleLayout = ({ nativeEvent }: NativeEvent) => {\n const { height } = nativeEvent.layout;\n setLayout({ height, measured: true });\n };\n\n // The banner animation has 2 parts:\n // 1. Blank spacer element which animates its height to move the content\n // 2. Actual banner which animates its translateY\n // In initial render, we position everything normally and measure the height of the banner\n // Once we have the height, we apply the height to the spacer and switch the banner to position: absolute\n // We need this because we need to move the content below as if banner's height was being animated\n // However we can't animated banner's height directly as it'll also resize the content inside\n const height = Animated.multiply(position, layout.height);\n\n const translateY = Animated.multiply(\n Animated.add(position, -1),\n layout.height\n );\n\n return (\n <Surface\n {...rest}\n style={[styles.container, shadow(ELEVATION) as ViewStyle, style]}\n >\n <View style={[styles.wrapper, contentStyle]}>\n <Animated.View style={{ height }} />\n <Animated.View\n onLayout={handleLayout}\n style={[\n layout.measured || !visible\n ? // If we have measured banner's height or it's invisible,\n // Position it absolutely, the layout will be taken care of the spacer\n [styles.absolute, { transform: [{ translateY }] }]\n : // Otherwise position it normally\n null,\n !layout.measured && !visible\n ? // If we haven't measured banner's height yet and it's invisible,\n // hide it with opacity: 0 so user doesn't see it\n { opacity: 0 }\n : null,\n ]}\n >\n <View\n style={[styles.content, { marginBottom: dismissable ? 0 : 16 }]}\n >\n {icon ? (\n <View style={styles.icon}>\n <Icon name={icon} size={40} />\n </View>\n ) : null}\n <Text\n style={[styles.message, { color: theme.colors.text }]}\n accessibilityLiveRegion={visible ? \"polite\" : \"none\"}\n accessibilityRole=\"alert\"\n >\n {content}\n </Text>\n </View>\n {dismissable ? (\n <View style={styles.actions}>\n <Button\n color={buttonColor || theme.colors.primary}\n title=\"Close\"\n onPress={() => setVisible(false)}\n />\n </View>\n ) : null}\n </Animated.View>\n </View>\n </Surface>\n );\n};\n\nconst styles = StyleSheet.create({\n container: {\n elevation: ELEVATION,\n },\n wrapper: {\n overflow: \"hidden\",\n alignSelf: \"center\",\n width: \"100%\",\n maxWidth: DEFAULT_MAX_WIDTH,\n },\n absolute: {\n position: \"absolute\",\n top: 0,\n width: \"100%\",\n },\n content: {\n flexDirection: \"row\",\n justifyContent: \"flex-start\",\n marginHorizontal: 8,\n marginTop: 16,\n marginBottom: 0,\n },\n icon: {\n margin: 8,\n },\n message: {\n flex: 1,\n margin: 8,\n },\n actions: {\n flexDirection: \"row\",\n justifyContent: \"flex-end\",\n margin: 8,\n },\n});\n\nexport default withTheme(Banner);\n"]}
|
package/lib/module/index.js
CHANGED
|
@@ -3,6 +3,7 @@ export { withTheme, ThemeProvider } from "./theming";
|
|
|
3
3
|
export { default as Provider } from "./Provider";
|
|
4
4
|
export { default as DefaultTheme } from "./styles/DefaultTheme";
|
|
5
5
|
export { Link } from "./components/Text";
|
|
6
|
+
export { default as Banner } from "./components/Banner";
|
|
6
7
|
export { ButtonSolid, ButtonOutline } from "./components/Button";
|
|
7
8
|
export { default as Avatar } from "./components/CircleImage";
|
|
8
9
|
export { default as AvatarEdit } from "./components/AvatarEdit";
|
package/lib/module/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["index.tsx"],"names":["injectIcon","withTheme","ThemeProvider","default","Provider","DefaultTheme","Link","ButtonSolid","ButtonOutline","Avatar","AvatarEdit","Card","Carousel","Checkbox","CheckboxGroup","CheckboxRow","CircleImage","Container","Divider","FAB","FieldSearchBarFull","IconButton","Image","NumberInput","ScreenContainer","StarRating","Surface","Switch","SwitchRow","TextField","ToggleButton","Touchable","AccordionGroup","AccordionItem","ActionSheet","ActionSheetItem","ActionSheetCancel","Swiper","SwiperItem","Center","Circle","Square","Row","Stack","Spacer","RadioButton","RadioButtonGroup","RadioButtonRow","RadioButtonFieldGroup","Button","CardBlock","CardContainer","CardContainerRating","CardInline","DatePicker","HeaderLarge","HeaderMedium","HeaderOverline","Picker","ProgressBar","ProgressCircle","RowBodyIcon","RowHeadlineImageCaption","RowHeadlineImageIcon","Slider","Stepper","useAuthState"],"mappings":"AAAA,SAASA,UAAT,QAA2B,mBAA3B;AACA,SAASC,SAAT,EAAoBC,aAApB,QAAyC,WAAzC;AACA,SAASC,OAAO,IAAIC,QAApB,QAAoC,YAApC;AACA,SAASD,OAAO,IAAIE,YAApB,QAAwC,uBAAxC;AAEA,SAASC,IAAT,QAAqB,mBAArB;AACA,SAASC,WAAT,EAAsBC,aAAtB,QAA2C,qBAA3C;AACA,
|
|
1
|
+
{"version":3,"sources":["index.tsx"],"names":["injectIcon","withTheme","ThemeProvider","default","Provider","DefaultTheme","Link","Banner","ButtonSolid","ButtonOutline","Avatar","AvatarEdit","Card","Carousel","Checkbox","CheckboxGroup","CheckboxRow","CircleImage","Container","Divider","FAB","FieldSearchBarFull","IconButton","Image","NumberInput","ScreenContainer","StarRating","Surface","Switch","SwitchRow","TextField","ToggleButton","Touchable","AccordionGroup","AccordionItem","ActionSheet","ActionSheetItem","ActionSheetCancel","Swiper","SwiperItem","Center","Circle","Square","Row","Stack","Spacer","RadioButton","RadioButtonGroup","RadioButtonRow","RadioButtonFieldGroup","Button","CardBlock","CardContainer","CardContainerRating","CardInline","DatePicker","HeaderLarge","HeaderMedium","HeaderOverline","Picker","ProgressBar","ProgressCircle","RowBodyIcon","RowHeadlineImageCaption","RowHeadlineImageIcon","Slider","Stepper","useAuthState"],"mappings":"AAAA,SAASA,UAAT,QAA2B,mBAA3B;AACA,SAASC,SAAT,EAAoBC,aAApB,QAAyC,WAAzC;AACA,SAASC,OAAO,IAAIC,QAApB,QAAoC,YAApC;AACA,SAASD,OAAO,IAAIE,YAApB,QAAwC,uBAAxC;AAEA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jB,QAAmC,qBAAnC;AAEA,SACEC,MADF,EAEEC,MAFF,EAGEC,MAHF,EAIEC,GAJF,EAKEC,KALF,EAMEC,MANF,QAOO,qBAPP;AASA,SACEC,WADF,EAEEC,gBAFF,EAGEC,cAHF,EAIEC,qBAJF,QAKO,gCALP;AAOA;;AACA,SAAS9C,OAAO,IAAI+C,MAApB,QAAkC,+BAAlC;AACA,SAAS/C,OAAO,IAAIgD,SAApB,QAAqC,wBAArC;AACA,SAAShD,OAAO,IAAIiD,aAApB,QAAyC,4BAAzC;AACA,SAASjD,OAAO,IAAIkD,mBAApB,QAA+C,kCAA/C;AACA,SAASlD,OAAO,IAAImD,UAApB,QAAsC,yBAAtC;AACA,SAASnD,OAAO,IAAIoD,UAApB,QAAsC,oCAAtC;AACA,SAASpD,OAAO,IAAIqD,WAApB,QAAuC,0BAAvC;AACA,SAASrD,OAAO,IAAIsD,YAApB,QAAwC,2BAAxC;AACA,SAAStD,OAAO,IAAIuD,cAApB,QAA0C,6BAA1C;AACA,SAASvD,OAAO,IAAIwD,MAApB,QAAkC,4BAAlC;AACA,SAASxD,OAAO,IAAIyD,WAApB,QAAuC,0BAAvC;AACA,SAASzD,OAAO,IAAI0D,cAApB,QAA0C,6BAA1C;AACA,SAAS1D,OAAO,IAAI2D,WAApB,QAAuC,0BAAvC;AACA,SAAS3D,OAAO,IAAI4D,uBAApB,QAAmD,sCAAnD;AACA,SAAS5D,OAAO,IAAI6D,oBAApB,QAAgD,mCAAhD;AACA,SAAS7D,OAAO,IAAI8D,MAApB,QAAkC,qBAAlC;AACA,SAAS9D,OAAO,IAAI+D,OAApB,QAAmC,sBAAnC;AACA,SAASC,YAAT,QAA6B,2BAA7B","sourcesContent":["export { injectIcon } from \"./interfaces/Icon\";\nexport { withTheme, ThemeProvider } from \"./theming\";\nexport { default as Provider } from \"./Provider\";\nexport { default as DefaultTheme } from \"./styles/DefaultTheme\";\n\nexport { Link } from \"./components/Text\";\nexport { default as Banner } from \"./components/Banner\";\nexport { ButtonSolid, ButtonOutline } from \"./components/Button\";\nexport { default as Avatar } from \"./components/CircleImage\";\nexport { default as AvatarEdit } from \"./components/AvatarEdit\";\nexport { default as Card } from \"./components/Card\";\nexport { default as Carousel } from \"./components/Carousel\";\nexport { Checkbox, CheckboxGroup, CheckboxRow } from \"./components/Checkbox\";\nexport { default as CircleImage } from \"./components/CircleImage\";\nexport { default as Container } from \"./components/Container\";\nexport { default as Divider } from \"./components/Divider\";\nexport { default as FAB } from \"./components/FAB\";\nexport { default as FieldSearchBarFull } from \"./components/FieldSearchBarFull\";\nexport { default as IconButton } from \"./components/IconButton\";\nexport { default as Image } from \"./components/Image\";\nexport { default as NumberInput } from \"./components/NumberInput\";\nexport { default as ScreenContainer } from \"./components/ScreenContainer\";\nexport { default as StarRating } from \"./components/StarRating\";\nexport { default as Surface } from \"./components/Surface\";\nexport { default as Switch, SwitchRow } from \"./components/Switch\";\nexport { default as TextField } from \"./components/TextField\";\nexport { default as ToggleButton } from \"./components/ToggleButton\";\nexport { default as Touchable } from \"./components/Touchable\";\nexport { AccordionGroup, AccordionItem } from \"./components/Accordion\";\nexport {\n ActionSheet,\n ActionSheetItem,\n ActionSheetCancel,\n} from \"./components/ActionSheet\";\nexport { Swiper, SwiperItem } from \"./components/Swiper\";\n\nexport {\n Center,\n Circle,\n Square,\n Row,\n Stack,\n Spacer,\n} from \"./components/Layout\";\n\nexport {\n RadioButton,\n RadioButtonGroup,\n RadioButtonRow,\n RadioButtonFieldGroup,\n} from \"./components/RadioButton/index\";\n\n/* Deprecated: Fix or Delete! */\nexport { default as Button } from \"./components/DeprecatedButton\";\nexport { default as CardBlock } from \"./components/CardBlock\";\nexport { default as CardContainer } from \"./components/CardContainer\";\nexport { default as CardContainerRating } from \"./components/CardContainerRating\";\nexport { default as CardInline } from \"./components/CardInline\";\nexport { default as DatePicker } from \"./components/DatePicker/DatePicker\";\nexport { default as HeaderLarge } from \"./components/HeaderLarge\";\nexport { default as HeaderMedium } from \"./components/HeaderMedium\";\nexport { default as HeaderOverline } from \"./components/HeaderOverline\";\nexport { default as Picker } from \"./components/Picker/Picker\";\nexport { default as ProgressBar } from \"./components/ProgressBar\";\nexport { default as ProgressCircle } from \"./components/ProgressCircle\";\nexport { default as RowBodyIcon } from \"./components/RowBodyIcon\";\nexport { default as RowHeadlineImageCaption } from \"./components/RowHeadlineImageCaption\";\nexport { default as RowHeadlineImageIcon } from \"./components/RowHeadlineImageIcon\";\nexport { default as Slider } from \"./components/Slider\";\nexport { default as Stepper } from \"./components/Stepper\";\nexport { useAuthState } from \"./components/useAuthState\";\n"]}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { COMPONENT_TYPES, createIconProp, createBoolProp, createColorProp, createTextProp, GROUPS } from "@draftbit/types";
|
|
2
|
+
export const SEED_DATA = {
|
|
3
|
+
name: "Banner",
|
|
4
|
+
tag: "Banner",
|
|
5
|
+
category: COMPONENT_TYPES.button,
|
|
6
|
+
props: {
|
|
7
|
+
icon: createIconProp({
|
|
8
|
+
defaultValue: null,
|
|
9
|
+
required: false
|
|
10
|
+
}),
|
|
11
|
+
content: createTextProp({
|
|
12
|
+
label: "Content",
|
|
13
|
+
description: "Banner text content"
|
|
14
|
+
}),
|
|
15
|
+
initiallyVisible: createBoolProp({
|
|
16
|
+
group: GROUPS.basic,
|
|
17
|
+
label: "Initially visible",
|
|
18
|
+
description: "Whether the banner should be visible",
|
|
19
|
+
defaultValue: true
|
|
20
|
+
}),
|
|
21
|
+
dismissable: createBoolProp({
|
|
22
|
+
group: GROUPS.basic,
|
|
23
|
+
label: "Dismissable",
|
|
24
|
+
description: "Whether the banner should be able to be closed",
|
|
25
|
+
defaultValue: true
|
|
26
|
+
}),
|
|
27
|
+
buttonColor: createColorProp({
|
|
28
|
+
label: "Button color",
|
|
29
|
+
defaultValue: "primary"
|
|
30
|
+
})
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
//# sourceMappingURL=Banner.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["Banner.ts"],"names":["COMPONENT_TYPES","createIconProp","createBoolProp","createColorProp","createTextProp","GROUPS","SEED_DATA","name","tag","category","button","props","icon","defaultValue","required","content","label","description","initiallyVisible","group","basic","dismissable","buttonColor"],"mappings":"AAAA,SACEA,eADF,EAEEC,cAFF,EAGEC,cAHF,EAIEC,eAJF,EAKEC,cALF,EAMEC,MANF,QAOO,iBAPP;AASA,OAAO,MAAMC,SAAS,GAAG;AACvBC,EAAAA,IAAI,EAAE,QADiB;AAEvBC,EAAAA,GAAG,EAAE,QAFkB;AAGvBC,EAAAA,QAAQ,EAAET,eAAe,CAACU,MAHH;AAIvBC,EAAAA,KAAK,EAAE;AACLC,IAAAA,IAAI,EAAEX,cAAc,CAAC;AACnBY,MAAAA,YAAY,EAAE,IADK;AAEnBC,MAAAA,QAAQ,EAAE;AAFS,KAAD,CADf;AAKLC,IAAAA,OAAO,EAAEX,cAAc,CAAC;AACtBY,MAAAA,KAAK,EAAE,SADe;AAEtBC,MAAAA,WAAW,EAAE;AAFS,KAAD,CALlB;AASLC,IAAAA,gBAAgB,EAAEhB,cAAc,CAAC;AAC/BiB,MAAAA,KAAK,EAAEd,MAAM,CAACe,KADiB;AAE/BJ,MAAAA,KAAK,EAAE,mBAFwB;AAG/BC,MAAAA,WAAW,EAAE,sCAHkB;AAI/BJ,MAAAA,YAAY,EAAE;AAJiB,KAAD,CAT3B;AAeLQ,IAAAA,WAAW,EAAEnB,cAAc,CAAC;AAC1BiB,MAAAA,KAAK,EAAEd,MAAM,CAACe,KADY;AAE1BJ,MAAAA,KAAK,EAAE,aAFmB;AAG1BC,MAAAA,WAAW,EAAE,gDAHa;AAI1BJ,MAAAA,YAAY,EAAE;AAJY,KAAD,CAftB;AAqBLS,IAAAA,WAAW,EAAEnB,eAAe,CAAC;AAC3Ba,MAAAA,KAAK,EAAE,cADoB;AAE3BH,MAAAA,YAAY,EAAE;AAFa,KAAD;AArBvB;AAJgB,CAAlB","sourcesContent":["import {\n COMPONENT_TYPES,\n createIconProp,\n createBoolProp,\n createColorProp,\n createTextProp,\n GROUPS,\n} from \"@draftbit/types\";\n\nexport const SEED_DATA = {\n name: \"Banner\",\n tag: \"Banner\",\n category: COMPONENT_TYPES.button,\n props: {\n icon: createIconProp({\n defaultValue: null,\n required: false,\n }),\n content: createTextProp({\n label: \"Content\",\n description: \"Banner text content\",\n }),\n initiallyVisible: createBoolProp({\n group: GROUPS.basic,\n label: \"Initially visible\",\n description: \"Whether the banner should be visible\",\n defaultValue: true,\n }),\n dismissable: createBoolProp({\n group: GROUPS.basic,\n label: \"Dismissable\",\n description: \"Whether the banner should be able to be closed\",\n defaultValue: true,\n }),\n buttonColor: createColorProp({\n label: \"Button color\",\n defaultValue: \"primary\",\n }),\n },\n};\n"]}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { View, ViewStyle, StyleProp } from "react-native";
|
|
3
|
+
import type { IconSlot } from "../interfaces/Icon";
|
|
4
|
+
import type { Theme } from "../styles/DefaultTheme";
|
|
5
|
+
declare type Props = {
|
|
6
|
+
initiallyVisible: boolean;
|
|
7
|
+
dismissable: boolean;
|
|
8
|
+
buttonColor?: string;
|
|
9
|
+
icon?: string;
|
|
10
|
+
content?: string;
|
|
11
|
+
contentStyle?: StyleProp<ViewStyle>;
|
|
12
|
+
style?: StyleProp<ViewStyle>;
|
|
13
|
+
ref?: React.RefObject<View>;
|
|
14
|
+
/**
|
|
15
|
+
* @optional
|
|
16
|
+
*/
|
|
17
|
+
theme: Theme;
|
|
18
|
+
} & IconSlot;
|
|
19
|
+
declare const _default: React.ComponentType<import("@draftbit/react-theme-provider").$Without<Props, "theme"> & {
|
|
20
|
+
theme?: import("@draftbit/react-theme-provider").$DeepPartial<any> | undefined;
|
|
21
|
+
}> & import("@draftbit/react-theme-provider/typings/hoist-non-react-statics").NonReactStatics<React.ComponentType<Props> & React.FC<Props>, {}>;
|
|
22
|
+
export default _default;
|
|
@@ -3,6 +3,7 @@ export { withTheme, ThemeProvider } from "./theming";
|
|
|
3
3
|
export { default as Provider } from "./Provider";
|
|
4
4
|
export { default as DefaultTheme } from "./styles/DefaultTheme";
|
|
5
5
|
export { Link } from "./components/Text";
|
|
6
|
+
export { default as Banner } from "./components/Banner";
|
|
6
7
|
export { ButtonSolid, ButtonOutline } from "./components/Button";
|
|
7
8
|
export { default as Avatar } from "./components/CircleImage";
|
|
8
9
|
export { default as AvatarEdit } from "./components/AvatarEdit";
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
export declare const SEED_DATA: {
|
|
2
|
+
name: string;
|
|
3
|
+
tag: string;
|
|
4
|
+
category: string;
|
|
5
|
+
props: {
|
|
6
|
+
icon: {
|
|
7
|
+
label: string;
|
|
8
|
+
description: string;
|
|
9
|
+
formType: string;
|
|
10
|
+
propType: string;
|
|
11
|
+
defaultValue: string;
|
|
12
|
+
required: boolean;
|
|
13
|
+
editable: boolean;
|
|
14
|
+
group: string;
|
|
15
|
+
};
|
|
16
|
+
content: any;
|
|
17
|
+
initiallyVisible: {
|
|
18
|
+
label: string;
|
|
19
|
+
description: string;
|
|
20
|
+
formType: string;
|
|
21
|
+
propType: string;
|
|
22
|
+
defaultValue: boolean;
|
|
23
|
+
editable: boolean;
|
|
24
|
+
required: boolean;
|
|
25
|
+
group: string;
|
|
26
|
+
};
|
|
27
|
+
dismissable: {
|
|
28
|
+
label: string;
|
|
29
|
+
description: string;
|
|
30
|
+
formType: string;
|
|
31
|
+
propType: string;
|
|
32
|
+
defaultValue: boolean;
|
|
33
|
+
editable: boolean;
|
|
34
|
+
required: boolean;
|
|
35
|
+
group: string;
|
|
36
|
+
};
|
|
37
|
+
buttonColor: {
|
|
38
|
+
group: string;
|
|
39
|
+
label: string;
|
|
40
|
+
description: string;
|
|
41
|
+
editable: boolean;
|
|
42
|
+
required: boolean;
|
|
43
|
+
defaultValue: null;
|
|
44
|
+
formType: string;
|
|
45
|
+
propType: string;
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@draftbit/core",
|
|
3
|
-
"version": "43.4.
|
|
3
|
+
"version": "43.4.20-9e993c.0+9e993cd7",
|
|
4
4
|
"description": "Core (non-native) Components",
|
|
5
5
|
"main": "lib/commonjs/index.js",
|
|
6
6
|
"module": "lib/module/index.js",
|
|
@@ -80,5 +80,5 @@
|
|
|
80
80
|
]
|
|
81
81
|
]
|
|
82
82
|
},
|
|
83
|
-
"gitHead": "
|
|
83
|
+
"gitHead": "9e993cd788186bc68a86eb65e38dfc105d75fe9f"
|
|
84
84
|
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { Button, Text, View, StyleSheet, Animated, } from "react-native";
|
|
3
|
+
import Surface from "./Surface";
|
|
4
|
+
import shadow from "../styles/shadow";
|
|
5
|
+
import { withTheme } from "../theming";
|
|
6
|
+
const ELEVATION = 1;
|
|
7
|
+
const DEFAULT_MAX_WIDTH = 960;
|
|
8
|
+
const Banner = ({ initiallyVisible = true, dismissable = true, icon, buttonColor, content, contentStyle, style, theme, Icon, ...rest }) => {
|
|
9
|
+
const [visible, setVisible] = React.useState(initiallyVisible);
|
|
10
|
+
React.useEffect(() => {
|
|
11
|
+
if (initiallyVisible) {
|
|
12
|
+
setVisible(true);
|
|
13
|
+
}
|
|
14
|
+
}, [initiallyVisible]);
|
|
15
|
+
const { current: position } = React.useRef(new Animated.Value(visible ? 1 : 0));
|
|
16
|
+
const [layout, setLayout] = React.useState({
|
|
17
|
+
height: 0,
|
|
18
|
+
measured: false,
|
|
19
|
+
});
|
|
20
|
+
React.useEffect(() => {
|
|
21
|
+
if (visible) {
|
|
22
|
+
// show
|
|
23
|
+
Animated.timing(position, {
|
|
24
|
+
duration: 250,
|
|
25
|
+
toValue: 1,
|
|
26
|
+
useNativeDriver: false,
|
|
27
|
+
}).start();
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
// hide
|
|
31
|
+
Animated.timing(position, {
|
|
32
|
+
duration: 200,
|
|
33
|
+
toValue: 0,
|
|
34
|
+
useNativeDriver: false,
|
|
35
|
+
}).start();
|
|
36
|
+
}
|
|
37
|
+
}, [visible, position]);
|
|
38
|
+
const handleLayout = ({ nativeEvent }) => {
|
|
39
|
+
const { height } = nativeEvent.layout;
|
|
40
|
+
setLayout({ height, measured: true });
|
|
41
|
+
};
|
|
42
|
+
// The banner animation has 2 parts:
|
|
43
|
+
// 1. Blank spacer element which animates its height to move the content
|
|
44
|
+
// 2. Actual banner which animates its translateY
|
|
45
|
+
// In initial render, we position everything normally and measure the height of the banner
|
|
46
|
+
// Once we have the height, we apply the height to the spacer and switch the banner to position: absolute
|
|
47
|
+
// We need this because we need to move the content below as if banner's height was being animated
|
|
48
|
+
// However we can't animated banner's height directly as it'll also resize the content inside
|
|
49
|
+
const height = Animated.multiply(position, layout.height);
|
|
50
|
+
const translateY = Animated.multiply(Animated.add(position, -1), layout.height);
|
|
51
|
+
return (React.createElement(Surface, { ...rest, style: [styles.container, shadow(ELEVATION), style] },
|
|
52
|
+
React.createElement(View, { style: [styles.wrapper, contentStyle] },
|
|
53
|
+
React.createElement(Animated.View, { style: { height } }),
|
|
54
|
+
React.createElement(Animated.View, { onLayout: handleLayout, style: [
|
|
55
|
+
layout.measured || !visible
|
|
56
|
+
? // If we have measured banner's height or it's invisible,
|
|
57
|
+
// Position it absolutely, the layout will be taken care of the spacer
|
|
58
|
+
[styles.absolute, { transform: [{ translateY }] }]
|
|
59
|
+
: // Otherwise position it normally
|
|
60
|
+
null,
|
|
61
|
+
!layout.measured && !visible
|
|
62
|
+
? // If we haven't measured banner's height yet and it's invisible,
|
|
63
|
+
// hide it with opacity: 0 so user doesn't see it
|
|
64
|
+
{ opacity: 0 }
|
|
65
|
+
: null,
|
|
66
|
+
] },
|
|
67
|
+
React.createElement(View, { style: [styles.content, { marginBottom: dismissable ? 0 : 16 }] },
|
|
68
|
+
icon ? (React.createElement(View, { style: styles.icon },
|
|
69
|
+
React.createElement(Icon, { name: icon, size: 40 }))) : null,
|
|
70
|
+
React.createElement(Text, { style: [styles.message, { color: theme.colors.text }], accessibilityLiveRegion: visible ? "polite" : "none", accessibilityRole: "alert" }, content)),
|
|
71
|
+
dismissable ? (React.createElement(View, { style: styles.actions },
|
|
72
|
+
React.createElement(Button, { color: buttonColor || theme.colors.primary, title: "Close", onPress: () => setVisible(false) }))) : null))));
|
|
73
|
+
};
|
|
74
|
+
const styles = StyleSheet.create({
|
|
75
|
+
container: {
|
|
76
|
+
elevation: ELEVATION,
|
|
77
|
+
},
|
|
78
|
+
wrapper: {
|
|
79
|
+
overflow: "hidden",
|
|
80
|
+
alignSelf: "center",
|
|
81
|
+
width: "100%",
|
|
82
|
+
maxWidth: DEFAULT_MAX_WIDTH,
|
|
83
|
+
},
|
|
84
|
+
absolute: {
|
|
85
|
+
position: "absolute",
|
|
86
|
+
top: 0,
|
|
87
|
+
width: "100%",
|
|
88
|
+
},
|
|
89
|
+
content: {
|
|
90
|
+
flexDirection: "row",
|
|
91
|
+
justifyContent: "flex-start",
|
|
92
|
+
marginHorizontal: 8,
|
|
93
|
+
marginTop: 16,
|
|
94
|
+
marginBottom: 0,
|
|
95
|
+
},
|
|
96
|
+
icon: {
|
|
97
|
+
margin: 8,
|
|
98
|
+
},
|
|
99
|
+
message: {
|
|
100
|
+
flex: 1,
|
|
101
|
+
margin: 8,
|
|
102
|
+
},
|
|
103
|
+
actions: {
|
|
104
|
+
flexDirection: "row",
|
|
105
|
+
justifyContent: "flex-end",
|
|
106
|
+
margin: 8,
|
|
107
|
+
},
|
|
108
|
+
});
|
|
109
|
+
export default withTheme(Banner);
|