Skip to content

Commit

Permalink
feat(shared-types,ui-progress): add customization options for progres…
Browse files Browse the repository at this point in the history
…sbar
  • Loading branch information
balzss committed Dec 3, 2024
1 parent ce86cdb commit b45639c
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 4 deletions.
1 change: 1 addition & 0 deletions packages/shared-types/src/ComponentThemeVariables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1014,6 +1014,7 @@ export type ProgressBarTheme = {
trackBottomBorderWidth: Border['widthSmall']
trackBottomBorderColor: Colors['contrasts']['grey1214']
trackBottomBorderColorInverse: Colors['contrasts']['white1010']
borderRadius: string
}

export type ProgressCircleTheme = {
Expand Down
5 changes: 3 additions & 2 deletions packages/ui-progress/src/ProgressBar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ class ProgressBar extends Component<ProgressBarProps> {
size,
color,
meterColor,
renderValueInside,
styles,
...props
} = this.props
Expand Down Expand Up @@ -130,11 +131,11 @@ class ProgressBar extends Component<ProgressBarProps> {
/>

<span css={styles?.track} role="presentation" aria-hidden="true">
<span css={styles?.trackValue}></span>
<span css={styles?.trackValue}>{renderValueInside && value}</span>
</span>
</span>

{value && (
{value && !renderValueInside && (
<span css={styles?.value} aria-hidden="true">
{value}
</span>
Expand Down
8 changes: 8 additions & 0 deletions packages/ui-progress/src/ProgressBar/props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,14 @@ type ProgressBarOwnProps = {
* Set the element type of the component's root
*/
as?: AsElementType

/**
* If true, displays the `renderValue` inside the progress meter for customization.
*
* Note: This should not be used in most cases. When enabled, ensure `renderValue` is styled for proper
* legibility and alignment across themes and sizes.
*/
renderValueInside?: boolean
}

type PropKeys = keyof ProgressBarOwnProps
Expand Down
6 changes: 5 additions & 1 deletion packages/ui-progress/src/ProgressBar/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,15 @@ const generateStyle = (
fontFamily: componentTheme.fontFamily,
fontWeight: componentTheme.fontWeight,
lineHeight: componentTheme.lineHeight,
fontSize: componentTheme.fontSize
fontSize: componentTheme.fontSize,
borderRadius: componentTheme.borderRadius
},

trackLayout: {
label: 'progressBar__trackLayout',
position: 'relative',
flex: 1,
borderRadius: 'inherit',

...colorVariants[color!].trackLayout
},
Expand All @@ -138,6 +140,7 @@ const generateStyle = (
borderBottomWidth: componentTheme.trackBottomBorderWidth,
borderBottomStyle: 'solid',
background: 'transparent',
borderRadius: 'inherit',

...sizeVariants[size!].track,
...colorVariants[color!].trackBorder
Expand All @@ -150,6 +153,7 @@ const generateStyle = (
height: '100%',
width: currentValuePercent,
maxWidth: '100%',
borderRadius: 'inherit',

...(shouldAnimate && { transition: 'all 0.5s' }),
...(meterColorClassName &&
Expand Down
4 changes: 3 additions & 1 deletion packages/ui-progress/src/ProgressBar/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ const generateComponentTheme = (theme: Theme): ProgressBarTheme => {
trackColorInverse: 'transparent',
trackBottomBorderWidth: borders?.widthSmall,
trackBottomBorderColor: colors?.contrasts?.grey3045,
trackBottomBorderColorInverse: colors?.contrasts?.white1010
trackBottomBorderColorInverse: colors?.contrasts?.white1010,

borderRadius: 0

Check failure on line 99 in packages/ui-progress/src/ProgressBar/theme.ts

View workflow job for this annotation

GitHub Actions / chromatic_deployment

Type 'number' is not assignable to type 'string'.

Check failure on line 99 in packages/ui-progress/src/ProgressBar/theme.ts

View workflow job for this annotation

GitHub Actions / deploy-preview

Type 'number' is not assignable to type 'string'.

Check failure on line 99 in packages/ui-progress/src/ProgressBar/theme.ts

View workflow job for this annotation

GitHub Actions / Lint commit msg + code

Type 'number' is not assignable to type 'string'.

Check failure on line 99 in packages/ui-progress/src/ProgressBar/theme.ts

View workflow job for this annotation

GitHub Actions / Cypress component tests

Type 'number' is not assignable to type 'string'.

Check failure on line 99 in packages/ui-progress/src/ProgressBar/theme.ts

View workflow job for this annotation

GitHub Actions / Vitest unit tests

Type 'number' is not assignable to type 'string'.

Check failure on line 99 in packages/ui-progress/src/ProgressBar/theme.ts

View workflow job for this annotation

GitHub Actions / Legacy unit tests

Type 'number' is not assignable to type 'string'.
}

return {
Expand Down

0 comments on commit b45639c

Please sign in to comment.