Skip to content

Commit aa84ad2

Browse files
Karthik-B-06kodiakhq[bot]
authored andcommitted
chore(progress-bar): ✨ wrap progress bar component
- add theming to progress bar - restructure progress bar theme file - add props for customising progress bar
1 parent 8c9e89f commit aa84ad2

File tree

4 files changed

+64
-55
lines changed

4 files changed

+64
-55
lines changed

src/components/progress/ProgressBar.tsx

Lines changed: 38 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { forwardRef } from "react";
2-
import { Dimensions } from "react-native";
2+
import { Dimensions, ViewStyle } from "react-native";
33
import {
44
Easing,
55
interpolate,
@@ -11,36 +11,34 @@ import {
1111
withTiming,
1212
} from "react-native-reanimated";
1313

14-
import { AnimatedBox } from "../../primitives";
14+
import { AnimatedBox, BoxProps } from "../../primitives";
1515
import { useTheme } from "../../theme/context";
16-
import { createComponent } from "../../utils";
17-
18-
import { useProgressBarProps } from "./ProgressProps";
16+
import { createComponent, styleAdapter } from "../../utils";
1917

2018
export type ProgressBarSizes = "sm" | "md" | "lg" | "xl";
19+
export type ProgressBarTheme = "base" | "primary";
2120

22-
export interface ProgressProps {
21+
export interface ProgressProps extends BoxProps {
2322
/**
2423
* The size of the Progress Bar component.
2524
* @default lg
2625
*/
2726
size: ProgressBarSizes;
27+
/**
28+
* The theme of the Progress Bar component.
29+
* @default base
30+
*/
31+
themeColor: ProgressBarTheme;
2832
/**
2933
* The progress value
3034
* If null makes it indeterminate
3135
* @default null
3236
*/
3337
value: number | null;
3438
/**
35-
* Track color containing the progress
36-
* @default 'bg-gray-200'
39+
* The progress track style
3740
*/
38-
trackColor: string;
39-
/**
40-
* Track color of the progress value
41-
* @default 'bg-gray-800'
42-
*/
43-
progressTrackColor: string;
41+
trackStyle: ViewStyle;
4442
}
4543

4644
const SPRING_CONFIG = {
@@ -57,9 +55,16 @@ export const RNProgressBar: React.FC<Partial<ProgressProps>> = forwardRef<
5755
Partial<ProgressProps>
5856
>((props, ref) => {
5957
const tailwind = useTheme();
60-
const progressStyles = useTheme("progress");
61-
const { trackColor, progressTrackColor, value, size } =
62-
useProgressBarProps(props);
58+
const progressTheme = useTheme("progress");
59+
const {
60+
size = "lg",
61+
themeColor = "base",
62+
value,
63+
style,
64+
trackStyle = {},
65+
...otherProps
66+
} = props;
67+
6368
const isIndeterminate = React.useMemo(
6469
() => value === null || value === undefined,
6570
[value],
@@ -107,24 +112,34 @@ export const RNProgressBar: React.FC<Partial<ProgressProps>> = forwardRef<
107112
<AnimatedBox
108113
ref={ref}
109114
style={[
110-
tailwind.style(progressStyles.container[size]),
111-
{ backgroundColor: trackColor },
115+
tailwind.style(
116+
progressTheme.size[size]?.container,
117+
progressTheme.themeColor[themeColor]?.track,
118+
),
119+
styleAdapter(style, { pressed: false }, false),
112120
]}
121+
{...otherProps}
113122
>
114123
{isIndeterminate && (
115124
<AnimatedBox
116125
style={[
117-
tailwind.style(progressStyles.bar[size]),
118-
{ backgroundColor: progressTrackColor },
126+
tailwind.style(
127+
progressTheme.size[size]?.bar,
128+
progressTheme.themeColor[themeColor]?.filled,
129+
),
130+
styleAdapter(trackStyle, { pressed: false }, false),
119131
translatingStyle,
120132
]}
121133
/>
122134
)}
123135
{!isIndeterminate && (
124136
<AnimatedBox
125137
style={[
126-
tailwind.style(progressStyles.bar[size]),
127-
{ backgroundColor: progressTrackColor },
138+
tailwind.style(
139+
progressTheme.size[size]?.bar,
140+
progressTheme.themeColor[themeColor]?.filled,
141+
),
142+
styleAdapter(trackStyle, { pressed: false }, false),
128143
animatingWidth,
129144
]}
130145
/>

src/components/progress/ProgressProps.tsx

Lines changed: 0 additions & 19 deletions
This file was deleted.

src/components/progress/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
export * from "./ProgressBar";
2-
export * from "./ProgressProps";

src/theme/defaultTheme/progress.ts

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,30 @@
11
export const progress = {
2-
container: {
3-
sm: "w-full h-0.5 rounded-full overflow-hidden",
4-
md: "w-full h-1 rounded-full overflow-hidden",
5-
lg: "w-full h-2 rounded-full overflow-hidden",
6-
xl: "w-full h-3 rounded-full overflow-hidden",
2+
size: {
3+
sm: {
4+
container: "w-full h-0.5 rounded-full overflow-hidden",
5+
bar: "absolute h-0.5 rounded-full",
6+
},
7+
md: {
8+
container: "w-full h-1 rounded-full overflow-hidden",
9+
bar: "absolute h-1 rounded-full",
10+
},
11+
lg: {
12+
container: "w-full h-2 rounded-full overflow-hidden",
13+
bar: "absolute h-2 rounded-full",
14+
},
15+
xl: {
16+
container: "w-full h-3 rounded-full overflow-hidden",
17+
bar: "absolute h-3 rounded-full",
18+
},
719
},
8-
bar: {
9-
sm: "absolute h-0.5 rounded-full",
10-
md: "absolute h-1 rounded-full",
11-
lg: "absolute h-2 rounded-full",
12-
xl: "absolute h-3 rounded-full",
20+
themeColor: {
21+
base: {
22+
track: "bg-gray-100",
23+
filled: "bg-gray-900",
24+
},
25+
primary: {
26+
track: "bg-blue-100",
27+
filled: "bg-blue-600",
28+
},
1329
},
14-
defaultTrackColor: "bg-gray-200",
15-
defaultProgressTrackColor: "bg-gray-800",
1630
};

0 commit comments

Comments
 (0)