@jobber/components-native 0.12.0 → 0.14.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/dist/src/Chip/Chip.js +43 -0
- package/dist/src/Chip/Chip.style.js +32 -0
- package/dist/src/Chip/index.js +1 -0
- package/dist/src/ProgressBar/ProgressBar.js +21 -0
- package/dist/src/ProgressBar/ProgressBar.style.js +24 -0
- package/dist/src/ProgressBar/ProgressBarInner.js +29 -0
- package/dist/src/ProgressBar/index.js +1 -0
- package/dist/src/ProgressBar/messages.js +13 -0
- package/dist/src/ProgressBar/types.js +1 -0
- package/dist/src/index.js +2 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/src/Chip/Chip.d.ts +45 -0
- package/dist/types/src/Chip/Chip.style.d.ts +29 -0
- package/dist/types/src/Chip/index.d.ts +2 -0
- package/dist/types/src/ProgressBar/ProgressBar.d.ts +3 -0
- package/dist/types/src/ProgressBar/ProgressBar.style.d.ts +22 -0
- package/dist/types/src/ProgressBar/ProgressBarInner.d.ts +9 -0
- package/dist/types/src/ProgressBar/index.d.ts +2 -0
- package/dist/types/src/ProgressBar/messages.d.ts +12 -0
- package/dist/types/src/ProgressBar/types.d.ts +28 -0
- package/dist/types/src/index.d.ts +2 -0
- package/package.json +2 -2
- package/src/Chip/Chip.style.ts +34 -0
- package/src/Chip/Chip.test.tsx +133 -0
- package/src/Chip/Chip.tsx +142 -0
- package/src/Chip/index.ts +2 -0
- package/src/ProgressBar/ProgressBar.style.ts +25 -0
- package/src/ProgressBar/ProgressBar.test.tsx +41 -0
- package/src/ProgressBar/ProgressBar.tsx +58 -0
- package/src/ProgressBar/ProgressBarInner.tsx +47 -0
- package/src/ProgressBar/__snapshots__/ProgressBar.test.tsx.snap +138 -0
- package/src/ProgressBar/index.tsx +2 -0
- package/src/ProgressBar/messages.ts +14 -0
- package/src/ProgressBar/types.ts +34 -0
- package/src/index.ts +2 -0
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import React, { useMemo } from "react";
|
|
2
|
+
import { Pressable, View } from "react-native";
|
|
3
|
+
import { styles } from "./Chip.style";
|
|
4
|
+
import { Icon } from "../Icon";
|
|
5
|
+
import { Typography } from "../Typography";
|
|
6
|
+
import { tokens } from "../utils/design";
|
|
7
|
+
const defaultAccentColor = tokens["color-surface--reverse"];
|
|
8
|
+
export function Chip({ icon, label, onPress, isDismissible, isActive, inactiveBackgroundColor = "background", accessibilityLabel, accessibilityRole = "radio", accent, }) {
|
|
9
|
+
const { chipStyle, iconCustomColor, dismissColor } = useMemo(() => {
|
|
10
|
+
const accentColor = accent ? tokens[`color-${accent}`] : defaultAccentColor;
|
|
11
|
+
const iconColor = isActive ? tokens["color-surface"] : accentColor;
|
|
12
|
+
const chip = [
|
|
13
|
+
styles.container,
|
|
14
|
+
{
|
|
15
|
+
backgroundColor: inactiveBackgroundColor === "surface"
|
|
16
|
+
? tokens["color-surface"]
|
|
17
|
+
: tokens["color-surface--background"],
|
|
18
|
+
},
|
|
19
|
+
isActive && { backgroundColor: accentColor },
|
|
20
|
+
];
|
|
21
|
+
const dismiss = (isActive || inactiveBackgroundColor === "surface") &&
|
|
22
|
+
styles.activeDismissIcon;
|
|
23
|
+
return {
|
|
24
|
+
chipStyle: chip,
|
|
25
|
+
iconCustomColor: iconColor,
|
|
26
|
+
dismissColor: dismiss,
|
|
27
|
+
};
|
|
28
|
+
}, [accent, isActive, inactiveBackgroundColor]);
|
|
29
|
+
const accessibilityState = useMemo(() => {
|
|
30
|
+
const checkableRoles = ["radio", "switch", "togglebutton", "checkbox"];
|
|
31
|
+
if (checkableRoles.includes(accessibilityRole)) {
|
|
32
|
+
return { checked: isActive };
|
|
33
|
+
}
|
|
34
|
+
return {};
|
|
35
|
+
}, [accessibilityRole, isActive]);
|
|
36
|
+
return (React.createElement(Pressable, { testID: "chipTest", hitSlop: { top: 8, bottom: 8, left: 4, right: 4 }, onPress: onPress, disabled: typeof onPress !== "function", style: chipStyle, accessibilityLabel: accessibilityLabel || label, accessibilityRole: accessibilityRole, accessibilityState: accessibilityState },
|
|
37
|
+
icon && (React.createElement(View, { style: styles.iconLeft },
|
|
38
|
+
React.createElement(Icon, { name: icon, size: "base", customColor: iconCustomColor }))),
|
|
39
|
+
label && (React.createElement(View, { style: styles.chipText },
|
|
40
|
+
React.createElement(Typography, { color: "base", fontWeight: "medium", maxFontScaleSize: tokens["typography--fontSize-large"], maxLines: "single", reverseTheme: isActive }, label))),
|
|
41
|
+
isDismissible && (React.createElement(View, { style: [styles.dismissIcon, dismissColor] },
|
|
42
|
+
React.createElement(Icon, { name: "remove", size: "small" })))));
|
|
43
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { StyleSheet } from "react-native";
|
|
2
|
+
import { tokens } from "../utils/design";
|
|
3
|
+
const chipHeight = tokens["space-larger"] + tokens["space-small"];
|
|
4
|
+
export const styles = StyleSheet.create({
|
|
5
|
+
container: {
|
|
6
|
+
alignItems: "center",
|
|
7
|
+
borderRadius: tokens["radius-circle"],
|
|
8
|
+
flexDirection: "row",
|
|
9
|
+
height: chipHeight,
|
|
10
|
+
justifyContent: "center",
|
|
11
|
+
marginHorizontal: tokens["space-smaller"],
|
|
12
|
+
marginTop: tokens["space-small"],
|
|
13
|
+
paddingHorizontal: tokens["space-small"],
|
|
14
|
+
},
|
|
15
|
+
iconLeft: {
|
|
16
|
+
marginHorizontal: tokens["space-smallest"],
|
|
17
|
+
},
|
|
18
|
+
chipText: {
|
|
19
|
+
flexGrow: 1,
|
|
20
|
+
flexShrink: 1,
|
|
21
|
+
marginHorizontal: tokens["space-smallest"],
|
|
22
|
+
},
|
|
23
|
+
dismissIcon: {
|
|
24
|
+
backgroundColor: tokens["color-surface"],
|
|
25
|
+
borderRadius: tokens["radius-circle"],
|
|
26
|
+
marginLeft: tokens["space-smaller"],
|
|
27
|
+
padding: tokens["space-smaller"],
|
|
28
|
+
},
|
|
29
|
+
activeDismissIcon: {
|
|
30
|
+
backgroundColor: tokens["color-surface--background"],
|
|
31
|
+
},
|
|
32
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Chip } from "./Chip";
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { View } from "react-native";
|
|
3
|
+
import { useIntl } from "react-intl";
|
|
4
|
+
import { styles } from "./ProgressBar.style";
|
|
5
|
+
import { ProgressBarInner, calculateWidth } from "./ProgressBarInner";
|
|
6
|
+
import { messages } from "./messages";
|
|
7
|
+
import { tokens } from "../utils/design";
|
|
8
|
+
export function ProgressBar({ loading, total, current, inProgress = 0, reverseTheme = false, header, }) {
|
|
9
|
+
const { formatMessage } = useIntl();
|
|
10
|
+
const accessibilityLabel = [];
|
|
11
|
+
accessibilityLabel.push(formatMessage(messages.complete, { current, total }));
|
|
12
|
+
inProgress &&
|
|
13
|
+
accessibilityLabel.push(formatMessage(messages.inProgress, { inProgress }));
|
|
14
|
+
return (React.createElement(View, { accessible: true, accessibilityRole: "progressbar", accessibilityLabel: accessibilityLabel.join(", ") },
|
|
15
|
+
header,
|
|
16
|
+
React.createElement(View, { style: styles.progressBarContainer },
|
|
17
|
+
React.createElement(ProgressBarInner, { width: 100, animationDuration: 0, color: reverseTheme ? undefined : tokens["color-surface--background"] }),
|
|
18
|
+
!loading && (React.createElement(React.Fragment, null,
|
|
19
|
+
inProgress && inProgress > 0 ? (React.createElement(ProgressBarInner, { width: calculateWidth(total, current + inProgress), color: tokens["color-informative"], animationDuration: 800 })) : (React.createElement(React.Fragment, null)),
|
|
20
|
+
React.createElement(ProgressBarInner, { width: calculateWidth(total, current), color: tokens["color-interactive"], animationDuration: 600 }))))));
|
|
21
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { StyleSheet } from "react-native";
|
|
2
|
+
import { tokens } from "../utils/design";
|
|
3
|
+
export const styles = StyleSheet.create({
|
|
4
|
+
progressBarContainer: {
|
|
5
|
+
marginTop: tokens["space-small"],
|
|
6
|
+
marginBottom: tokens["space-small"],
|
|
7
|
+
height: 20,
|
|
8
|
+
position: "relative",
|
|
9
|
+
flexDirection: "row",
|
|
10
|
+
},
|
|
11
|
+
progressBarInner: {
|
|
12
|
+
backgroundColor: "rgba(255,255,255,0.3)",
|
|
13
|
+
width: "100%",
|
|
14
|
+
height: "100%",
|
|
15
|
+
position: "absolute",
|
|
16
|
+
left: 0,
|
|
17
|
+
top: 0,
|
|
18
|
+
borderRadius: 100,
|
|
19
|
+
},
|
|
20
|
+
progressInner: {
|
|
21
|
+
height: "100%",
|
|
22
|
+
borderRadius: 100,
|
|
23
|
+
},
|
|
24
|
+
});
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { View } from "react-native";
|
|
3
|
+
// import Reanimated from "react-native-reanimated";
|
|
4
|
+
// import { useTiming } from "utils/reanimated";
|
|
5
|
+
import { styles } from "./ProgressBar.style";
|
|
6
|
+
export function ProgressBarInner({ width,
|
|
7
|
+
// animationDuration = 0,
|
|
8
|
+
color, }) {
|
|
9
|
+
// Animation breaking on Android
|
|
10
|
+
// const [animatedOpacity] = useTiming({
|
|
11
|
+
// duration: animationDuration,
|
|
12
|
+
// fromValue: 0,
|
|
13
|
+
// toValue: 1,
|
|
14
|
+
// });
|
|
15
|
+
return (React.createElement(View, { style: [
|
|
16
|
+
styles.progressBarInner,
|
|
17
|
+
Object.assign({ width: `${width}%` }, (color && { backgroundColor: color })),
|
|
18
|
+
] }));
|
|
19
|
+
}
|
|
20
|
+
export function calculateWidth(total, current) {
|
|
21
|
+
if (total <= 0)
|
|
22
|
+
return 0;
|
|
23
|
+
if (current >= total)
|
|
24
|
+
return 100;
|
|
25
|
+
const curr = Math.max(0, current);
|
|
26
|
+
if (curr >= total)
|
|
27
|
+
return 100;
|
|
28
|
+
return (curr / total) * 100;
|
|
29
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { ProgressBar } from "./ProgressBar";
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { defineMessages } from "react-intl";
|
|
2
|
+
export const messages = defineMessages({
|
|
3
|
+
complete: {
|
|
4
|
+
id: "complete",
|
|
5
|
+
defaultMessage: "{current} of {total} complete",
|
|
6
|
+
description: "Progress bar accessibilityLabel for current/total",
|
|
7
|
+
},
|
|
8
|
+
inProgress: {
|
|
9
|
+
id: "inProgress",
|
|
10
|
+
defaultMessage: "{inProgress} in progress",
|
|
11
|
+
description: "Progress bar accessibilityLabel for inProgress/total",
|
|
12
|
+
},
|
|
13
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|