@jobber/components-native 0.50.0 → 0.51.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/package.json +2 -2
- package/dist/src/ProgressBar/ProgressBar.js +4 -3
- package/dist/src/ProgressBar/ProgressBar.style.js +13 -0
- package/dist/src/ProgressBar/ProgressBarStepped.js +21 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/src/ProgressBar/ProgressBar.d.ts +1 -1
- package/dist/types/src/ProgressBar/ProgressBar.style.d.ts +13 -0
- package/dist/types/src/ProgressBar/ProgressBarStepped.d.ts +10 -0
- package/dist/types/src/ProgressBar/types.d.ts +7 -1
- package/package.json +2 -2
- package/src/ProgressBar/ProgressBar.style.ts +13 -0
- package/src/ProgressBar/ProgressBar.test.tsx +40 -1
- package/src/ProgressBar/ProgressBar.tsx +35 -21
- package/src/ProgressBar/ProgressBarStepped.tsx +47 -0
- package/src/ProgressBar/types.ts +8 -1
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { ProgressBarProps } from "./types";
|
|
3
|
-
export declare function ProgressBar({ loading, total, current, inProgress, reverseTheme, header, }: ProgressBarProps): JSX.Element;
|
|
3
|
+
export declare function ProgressBar({ loading, total, current, inProgress, reverseTheme, header, variation, }: ProgressBarProps): JSX.Element;
|
|
@@ -19,4 +19,17 @@ export declare const styles: {
|
|
|
19
19
|
height: string;
|
|
20
20
|
borderRadius: number;
|
|
21
21
|
};
|
|
22
|
+
step: {
|
|
23
|
+
flex: number;
|
|
24
|
+
marginRight: number;
|
|
25
|
+
height: string;
|
|
26
|
+
borderRadius: number;
|
|
27
|
+
borderColor: string;
|
|
28
|
+
};
|
|
29
|
+
completedStep: {
|
|
30
|
+
backgroundColor: string;
|
|
31
|
+
};
|
|
32
|
+
inProgressStep: {
|
|
33
|
+
backgroundColor: string;
|
|
34
|
+
};
|
|
22
35
|
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
interface ProgressBarSteppedProps {
|
|
3
|
+
readonly total: number;
|
|
4
|
+
readonly current: number;
|
|
5
|
+
readonly color?: string;
|
|
6
|
+
readonly loading?: boolean;
|
|
7
|
+
readonly inProgress?: number;
|
|
8
|
+
}
|
|
9
|
+
export declare function ProgressBarStepped({ total, current, color, loading, inProgress, }: ProgressBarSteppedProps): JSX.Element;
|
|
10
|
+
export {};
|
|
@@ -9,7 +9,8 @@ export interface ProgressBarProps {
|
|
|
9
9
|
*/
|
|
10
10
|
readonly current: number;
|
|
11
11
|
/**
|
|
12
|
-
* The number of items in progress (not completed, but to be less than the total)
|
|
12
|
+
* The number of items in progress (not completed, but to be less than the total);
|
|
13
|
+
* not applicable with stepped variation
|
|
13
14
|
*/
|
|
14
15
|
readonly inProgress?: number;
|
|
15
16
|
/**
|
|
@@ -25,4 +26,9 @@ export interface ProgressBarProps {
|
|
|
25
26
|
* Component to render above the progress bar.
|
|
26
27
|
*/
|
|
27
28
|
readonly header?: ReactNode;
|
|
29
|
+
/**
|
|
30
|
+
* Set the variation of the progress bar
|
|
31
|
+
* @default progress
|
|
32
|
+
*/
|
|
33
|
+
readonly variation?: "progress" | "stepped";
|
|
28
34
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jobber/components-native",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.51.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "React Native implementation of Atlantis",
|
|
6
6
|
"repository": {
|
|
@@ -84,5 +84,5 @@
|
|
|
84
84
|
"react-native-reanimated": "^2.17.0",
|
|
85
85
|
"react-native-safe-area-context": "^4.5.2"
|
|
86
86
|
},
|
|
87
|
-
"gitHead": "
|
|
87
|
+
"gitHead": "7096004da05ede6fff2bfaaed572b3e91a9ee1d9"
|
|
88
88
|
}
|
|
@@ -22,4 +22,17 @@ export const styles = StyleSheet.create({
|
|
|
22
22
|
height: "100%",
|
|
23
23
|
borderRadius: 100,
|
|
24
24
|
},
|
|
25
|
+
step: {
|
|
26
|
+
flex: 1,
|
|
27
|
+
marginRight: tokens["space-small"],
|
|
28
|
+
height: "100%",
|
|
29
|
+
borderRadius: 100,
|
|
30
|
+
borderColor: "rgba(255,255,255,0.3)",
|
|
31
|
+
},
|
|
32
|
+
completedStep: {
|
|
33
|
+
backgroundColor: tokens["color-interactive"],
|
|
34
|
+
},
|
|
35
|
+
inProgressStep: {
|
|
36
|
+
backgroundColor: tokens["color-informative"],
|
|
37
|
+
},
|
|
25
38
|
});
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import { render } from "@testing-library/react-native";
|
|
2
|
+
import { render, screen } from "@testing-library/react-native";
|
|
3
3
|
import { ProgressBar, ProgressBarProps } from ".";
|
|
4
|
+
import { styles } from "./ProgressBar.style";
|
|
4
5
|
|
|
5
6
|
const defaultSetupProps = {
|
|
6
7
|
total: 0,
|
|
@@ -39,3 +40,41 @@ it("renders green CompletedProgress bar when 1 or more jobs is completed", () =>
|
|
|
39
40
|
expect(bar).toMatchSnapshot();
|
|
40
41
|
expect(bar.getByLabelText("1 of 2 complete")).toBeDefined();
|
|
41
42
|
});
|
|
43
|
+
|
|
44
|
+
describe("with stepped variation", () => {
|
|
45
|
+
beforeEach(() => {
|
|
46
|
+
render(
|
|
47
|
+
<ProgressBar
|
|
48
|
+
total={3}
|
|
49
|
+
current={2}
|
|
50
|
+
inProgress={1}
|
|
51
|
+
variation={"stepped"}
|
|
52
|
+
/>,
|
|
53
|
+
);
|
|
54
|
+
});
|
|
55
|
+
it("renders the correct number of steps", () => {
|
|
56
|
+
const stepElements = screen.getAllByTestId("progress-step");
|
|
57
|
+
expect(stepElements).toHaveLength(3);
|
|
58
|
+
});
|
|
59
|
+
it("renders the correct number of completed steps", () => {
|
|
60
|
+
const stepElements = screen.getAllByTestId("progress-step");
|
|
61
|
+
const completedSteps = stepElements.filter(step =>
|
|
62
|
+
step.props.style.includes(styles.completedStep),
|
|
63
|
+
);
|
|
64
|
+
expect(completedSteps).toHaveLength(2);
|
|
65
|
+
});
|
|
66
|
+
it("renders the correct number of incomplete steps", () => {
|
|
67
|
+
const stepElements = screen.getAllByTestId("progress-step");
|
|
68
|
+
const incompleteSteps = stepElements.filter(
|
|
69
|
+
step => !step.props.style.includes(styles.completedStep),
|
|
70
|
+
);
|
|
71
|
+
expect(incompleteSteps).toHaveLength(1);
|
|
72
|
+
});
|
|
73
|
+
it("renders the correct number of inProgress steps", () => {
|
|
74
|
+
const stepElements = screen.getAllByTestId("progress-step");
|
|
75
|
+
const inProgressSteps = stepElements.filter(step =>
|
|
76
|
+
step.props.style.includes(styles.inProgressStep),
|
|
77
|
+
);
|
|
78
|
+
expect(inProgressSteps).toHaveLength(1);
|
|
79
|
+
});
|
|
80
|
+
});
|
|
@@ -3,6 +3,7 @@ import { View } from "react-native";
|
|
|
3
3
|
import { ProgressBarProps } from "./types";
|
|
4
4
|
import { styles } from "./ProgressBar.style";
|
|
5
5
|
import { ProgressBarInner, calculateWidth } from "./ProgressBarInner";
|
|
6
|
+
import { ProgressBarStepped } from "./ProgressBarStepped";
|
|
6
7
|
import { tokens } from "../utils/design";
|
|
7
8
|
import { useAtlantisI18n } from "../hooks/useAtlantisI18n";
|
|
8
9
|
|
|
@@ -13,6 +14,7 @@ export function ProgressBar({
|
|
|
13
14
|
inProgress = 0,
|
|
14
15
|
reverseTheme = false,
|
|
15
16
|
header,
|
|
17
|
+
variation = "progress",
|
|
16
18
|
}: ProgressBarProps): JSX.Element {
|
|
17
19
|
const { t } = useAtlantisI18n();
|
|
18
20
|
|
|
@@ -23,31 +25,43 @@ export function ProgressBar({
|
|
|
23
25
|
accessibilityLabel={getA11yLabel()}
|
|
24
26
|
>
|
|
25
27
|
{header}
|
|
26
|
-
|
|
27
|
-
<
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
{variation === "stepped" ? (
|
|
29
|
+
<ProgressBarStepped
|
|
30
|
+
total={total}
|
|
31
|
+
current={current}
|
|
30
32
|
color={reverseTheme ? undefined : tokens["color-surface--background"]}
|
|
33
|
+
loading={loading}
|
|
34
|
+
inProgress={inProgress}
|
|
31
35
|
/>
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
36
|
+
) : (
|
|
37
|
+
<View style={styles.progressBarContainer}>
|
|
38
|
+
<ProgressBarInner
|
|
39
|
+
width={100}
|
|
40
|
+
animationDuration={0}
|
|
41
|
+
color={
|
|
42
|
+
reverseTheme ? undefined : tokens["color-surface--background"]
|
|
43
|
+
}
|
|
44
|
+
/>
|
|
45
|
+
{!loading && (
|
|
46
|
+
<>
|
|
47
|
+
{inProgress && inProgress > 0 ? (
|
|
48
|
+
<ProgressBarInner
|
|
49
|
+
width={calculateWidth(total, current + inProgress)}
|
|
50
|
+
color={tokens["color-informative"]}
|
|
51
|
+
animationDuration={800}
|
|
52
|
+
/>
|
|
53
|
+
) : (
|
|
54
|
+
<></>
|
|
55
|
+
)}
|
|
35
56
|
<ProgressBarInner
|
|
36
|
-
width={calculateWidth(total, current
|
|
37
|
-
color={tokens["color-
|
|
38
|
-
animationDuration={
|
|
57
|
+
width={calculateWidth(total, current)}
|
|
58
|
+
color={tokens["color-interactive"]}
|
|
59
|
+
animationDuration={600}
|
|
39
60
|
/>
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
width={calculateWidth(total, current)}
|
|
45
|
-
color={tokens["color-interactive"]}
|
|
46
|
-
animationDuration={600}
|
|
47
|
-
/>
|
|
48
|
-
</>
|
|
49
|
-
)}
|
|
50
|
-
</View>
|
|
61
|
+
</>
|
|
62
|
+
)}
|
|
63
|
+
</View>
|
|
64
|
+
)}
|
|
51
65
|
</View>
|
|
52
66
|
);
|
|
53
67
|
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { View } from "react-native";
|
|
3
|
+
import { styles } from "./ProgressBar.style";
|
|
4
|
+
|
|
5
|
+
interface ProgressBarSteppedProps {
|
|
6
|
+
readonly total: number;
|
|
7
|
+
readonly current: number;
|
|
8
|
+
readonly color?: string;
|
|
9
|
+
readonly loading?: boolean;
|
|
10
|
+
readonly inProgress?: number;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function ProgressBarStepped({
|
|
14
|
+
total,
|
|
15
|
+
current,
|
|
16
|
+
color,
|
|
17
|
+
loading,
|
|
18
|
+
inProgress,
|
|
19
|
+
}: ProgressBarSteppedProps) {
|
|
20
|
+
return (
|
|
21
|
+
<View style={[styles.progressBarContainer, { height: 10 }]}>
|
|
22
|
+
{Array.from({ length: total }).map((_, index) => {
|
|
23
|
+
const step = index + 1;
|
|
24
|
+
const isCompleted = step <= current;
|
|
25
|
+
const lastStep = step === total;
|
|
26
|
+
const inProgressSteps = current + (inProgress || 0);
|
|
27
|
+
|
|
28
|
+
return (
|
|
29
|
+
<View
|
|
30
|
+
key={step}
|
|
31
|
+
style={[
|
|
32
|
+
styles.step,
|
|
33
|
+
{ ...(color && { backgroundColor: color }) },
|
|
34
|
+
!loading && isCompleted && styles.completedStep,
|
|
35
|
+
!loading &&
|
|
36
|
+
!isCompleted &&
|
|
37
|
+
step <= inProgressSteps &&
|
|
38
|
+
styles.inProgressStep,
|
|
39
|
+
lastStep && { marginRight: 0 },
|
|
40
|
+
]}
|
|
41
|
+
testID={"progress-step"}
|
|
42
|
+
></View>
|
|
43
|
+
);
|
|
44
|
+
})}
|
|
45
|
+
</View>
|
|
46
|
+
);
|
|
47
|
+
}
|
package/src/ProgressBar/types.ts
CHANGED
|
@@ -12,7 +12,8 @@ export interface ProgressBarProps {
|
|
|
12
12
|
readonly current: number;
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
|
-
* The number of items in progress (not completed, but to be less than the total)
|
|
15
|
+
* The number of items in progress (not completed, but to be less than the total);
|
|
16
|
+
* not applicable with stepped variation
|
|
16
17
|
*/
|
|
17
18
|
readonly inProgress?: number;
|
|
18
19
|
|
|
@@ -31,4 +32,10 @@ export interface ProgressBarProps {
|
|
|
31
32
|
* Component to render above the progress bar.
|
|
32
33
|
*/
|
|
33
34
|
readonly header?: ReactNode;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Set the variation of the progress bar
|
|
38
|
+
* @default progress
|
|
39
|
+
*/
|
|
40
|
+
readonly variation?: "progress" | "stepped";
|
|
34
41
|
}
|