Skip to content

Commit 56308de

Browse files
committed
feat(shared-types,ui-progress): add customization options for progressbar
1 parent ee9cafd commit 56308de

File tree

6 files changed

+54
-5
lines changed

6 files changed

+54
-5
lines changed

packages/shared-types/src/ComponentThemeVariables.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,6 +1014,7 @@ export type ProgressBarTheme = {
10141014
trackBottomBorderWidth: Border['widthSmall']
10151015
trackBottomBorderColor: Colors['contrasts']['grey1214']
10161016
trackBottomBorderColorInverse: Colors['contrasts']['white1010']
1017+
borderRadius: string
10171018
}
10181019

10191020
export type ProgressCircleTheme = {

packages/ui-progress/src/ProgressBar/__new-tests__/ProgressBar.test.tsx

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,36 @@ describe('<ProgressBar />', () => {
8383
const axeCheck = await runAxeCheck(container)
8484
expect(axeCheck).toBe(true)
8585
})
86+
87+
it('should not render the value inside when the prop is set to false', () => {
88+
const valueNow = 33
89+
const { container } = render(
90+
<ProgressBar
91+
screenReaderLabel="Chapters read"
92+
valueMax={100}
93+
valueNow={valueNow}
94+
renderValueInside={false}
95+
renderValue={`${valueNow}%`}
96+
/>
97+
)
98+
const progressMeter = container.querySelector('[class$="-progressBar__trackValue"]')
99+
100+
expect(progressMeter).not.toHaveTextContent('33%')
101+
})
102+
103+
it('should render the value inside when the prop is set', () => {
104+
const valueNow = 33
105+
const { container } = render(
106+
<ProgressBar
107+
screenReaderLabel="Chapters read"
108+
valueMax={100}
109+
valueNow={valueNow}
110+
renderValueInside
111+
renderValue={`${valueNow}%`}
112+
/>
113+
)
114+
const progressMeter = container.querySelector('[class$="-progressBar__trackValue"]')
115+
116+
expect(progressMeter).toHaveTextContent('33%')
117+
})
86118
})

packages/ui-progress/src/ProgressBar/index.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ class ProgressBar extends Component<ProgressBarProps> {
9595
size,
9696
color,
9797
meterColor,
98+
renderValueInside,
9899
styles,
99100
...props
100101
} = this.props
@@ -130,11 +131,11 @@ class ProgressBar extends Component<ProgressBarProps> {
130131
/>
131132

132133
<span css={styles?.track} role="presentation" aria-hidden="true">
133-
<span css={styles?.trackValue}></span>
134+
<span css={styles?.trackValue}>{renderValueInside && value}</span>
134135
</span>
135136
</span>
136137

137-
{value && (
138+
{value && !renderValueInside && (
138139
<span css={styles?.value} aria-hidden="true">
139140
{value}
140141
</span>

packages/ui-progress/src/ProgressBar/props.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,14 @@ type ProgressBarOwnProps = {
114114
* Set the element type of the component's root
115115
*/
116116
as?: AsElementType
117+
118+
/**
119+
* If true, displays the `renderValue` inside the progress meter for customization.
120+
*
121+
* Note: This should not be used in most cases. When enabled, ensure `renderValue` is styled for proper
122+
* legibility and alignment across themes and sizes.
123+
*/
124+
renderValueInside?: boolean
117125
}
118126

119127
type PropKeys = keyof ProgressBarOwnProps
@@ -148,7 +156,8 @@ const propTypes: PropValidators<PropKeys> = {
148156
shouldAnimate: PropTypes.bool,
149157
margin: ThemeablePropTypes.spacing,
150158
elementRef: PropTypes.func,
151-
as: PropTypes.elementType
159+
as: PropTypes.elementType,
160+
renderValueInside: PropTypes.bool,
152161
}
153162

154163
const allowedProps: AllowedPropKeys = [

packages/ui-progress/src/ProgressBar/styles.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,15 @@ const generateStyle = (
119119
fontFamily: componentTheme.fontFamily,
120120
fontWeight: componentTheme.fontWeight,
121121
lineHeight: componentTheme.lineHeight,
122-
fontSize: componentTheme.fontSize
122+
fontSize: componentTheme.fontSize,
123+
borderRadius: componentTheme.borderRadius
123124
},
124125

125126
trackLayout: {
126127
label: 'progressBar__trackLayout',
127128
position: 'relative',
128129
flex: 1,
130+
borderRadius: 'inherit',
129131

130132
...colorVariants[color!].trackLayout
131133
},
@@ -138,6 +140,7 @@ const generateStyle = (
138140
borderBottomWidth: componentTheme.trackBottomBorderWidth,
139141
borderBottomStyle: 'solid',
140142
background: 'transparent',
143+
borderRadius: 'inherit',
141144

142145
...sizeVariants[size!].track,
143146
...colorVariants[color!].trackBorder
@@ -150,6 +153,7 @@ const generateStyle = (
150153
height: '100%',
151154
width: currentValuePercent,
152155
maxWidth: '100%',
156+
borderRadius: 'inherit',
153157

154158
...(shouldAnimate && { transition: 'all 0.5s' }),
155159
...(meterColorClassName &&

packages/ui-progress/src/ProgressBar/theme.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,9 @@ const generateComponentTheme = (theme: Theme): ProgressBarTheme => {
9494
trackColorInverse: 'transparent',
9595
trackBottomBorderWidth: borders?.widthSmall,
9696
trackBottomBorderColor: colors?.contrasts?.grey3045,
97-
trackBottomBorderColorInverse: colors?.contrasts?.white1010
97+
trackBottomBorderColorInverse: colors?.contrasts?.white1010,
98+
99+
borderRadius: '0px'
98100
}
99101

100102
return {

0 commit comments

Comments
 (0)