@jobber/components-native 0.36.0 → 0.37.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.
@@ -0,0 +1,50 @@
1
+ import React, { useState } from "react";
2
+ import { ScrollView, TouchableOpacity, View, } from "react-native";
3
+ import Reanimated, { Easing, useAnimatedStyle, useSharedValue, withTiming, } from "react-native-reanimated";
4
+ import { EASE_CUBIC_IN_OUT } from "./constants";
5
+ import { styles } from "./Disclosure.style";
6
+ import { tokens } from "../utils/design";
7
+ import { Icon } from "../Icon";
8
+ const ReanimatedView = Reanimated.createAnimatedComponent(View);
9
+ const ReanimatedScrollView = Reanimated.createAnimatedComponent(ScrollView);
10
+ export function Disclosure({ content, header, open, onToggle, isEmpty, animationDuration = tokens["timing-slowest"], }) {
11
+ return (React.createElement(View, { style: styles.container },
12
+ React.createElement(DisclosureHeader, Object.assign({}, { header, onToggle, isEmpty, open, animationDuration })),
13
+ React.createElement(DisclosureContent, Object.assign({}, { content, open, animationDuration }))));
14
+ }
15
+ function DisclosureHeader({ header, onToggle, isEmpty, open, animationDuration, }) {
16
+ const rotateZ = useSharedValue(0);
17
+ rotateZ.value = withTiming(open ? 0 : -180, {
18
+ easing: Easing.bezier(...EASE_CUBIC_IN_OUT),
19
+ duration: animationDuration,
20
+ });
21
+ const animatedStyle = useAnimatedStyle(() => {
22
+ return {
23
+ transform: [{ rotateZ: `${rotateZ.value}deg` }],
24
+ };
25
+ });
26
+ return (React.createElement(TouchableOpacity, { activeOpacity: tokens["opacity-pressed"], onPress: onToggle, disabled: isEmpty },
27
+ React.createElement(View, { style: styles.headerContainer },
28
+ header,
29
+ !isEmpty && (React.createElement(ReanimatedView, { style: [animatedStyle] },
30
+ React.createElement(Icon, { name: "arrowUp", color: "grey" }))))));
31
+ }
32
+ function DisclosureContent({ content, open, animationDuration, }) {
33
+ const [maxHeight, setMaxHeight] = useState(0);
34
+ const height = useSharedValue(0);
35
+ const onContentLayoutChange = (event) => {
36
+ const newHeight = event.nativeEvent.layout.height;
37
+ setMaxHeight(newHeight);
38
+ };
39
+ height.value = withTiming(open ? maxHeight : 0, {
40
+ duration: animationDuration,
41
+ easing: Easing.bezier(...EASE_CUBIC_IN_OUT),
42
+ });
43
+ const animatedStyle = useAnimatedStyle(() => {
44
+ return {
45
+ height: height.value,
46
+ };
47
+ }, []);
48
+ return (React.createElement(ReanimatedScrollView, { scrollEnabled: false, showsHorizontalScrollIndicator: false, showsVerticalScrollIndicator: false, style: [styles.contentContainer, animatedStyle] },
49
+ React.createElement(View, { testID: "content", onLayout: onContentLayoutChange }, content)));
50
+ }
@@ -0,0 +1,21 @@
1
+ import { StyleSheet } from "react-native";
2
+ import { tokens } from "../utils/design";
3
+ export const styles = StyleSheet.create({
4
+ container: {
5
+ width: "100%",
6
+ },
7
+ headerContainer: {
8
+ flexDirection: "row",
9
+ alignItems: "flex-start",
10
+ justifyContent: "space-between",
11
+ },
12
+ countColumn: {
13
+ paddingRight: tokens["space-base"],
14
+ },
15
+ titleContainer: {
16
+ flexDirection: "row",
17
+ },
18
+ contentContainer: {
19
+ paddingTop: tokens["space-small"],
20
+ },
21
+ });
@@ -0,0 +1 @@
1
+ export const EASE_CUBIC_IN_OUT = [0.645, 0.045, 0.355, 1.0];
@@ -0,0 +1 @@
1
+ export { Disclosure } from "./Disclosure";
package/dist/src/index.js CHANGED
@@ -10,6 +10,7 @@ export * from "./Card";
10
10
  export * from "./Checkbox";
11
11
  export * from "./Chip";
12
12
  export * from "./Content";
13
+ export * from "./Disclosure";
13
14
  export * from "./Divider";
14
15
  export * from "./EmptyState";
15
16
  export * from "./ErrorMessageWrapper";