fleet/frontend/components/ProgressBar/ProgressBar.tsx
jacobshandling 994256bcaa
Refactor DiskSpaceIndicator to use ProgressBar (#33198)
## Precursor for #31671 

- Add width option to `ProgressBar`
- Refactor `DiskSpaceIndicator`
  - Use `ProgressBar` with new `width` option
  - Replace raw react tooltip with `TooltipWrapper`
  - Clean up confusing styles
- Update tests, ensure consistent style with previous implementation on
hosts table, hosts details page, my device page

<img width="1020" height="546" alt="Screenshot 2025-09-18 at 4 49 28 PM"
src="https://github.com/user-attachments/assets/a0c958d0-8b2b-466c-b169-a91dc8fb984c"
/>
<img width="1020" height="546" alt="Screenshot 2025-09-18 at 4 49 35 PM"
src="https://github.com/user-attachments/assets/f60f1e0a-573d-438b-9ded-ec45825599c1"
/>


- [x] Added/updated automated tests
- [x] QA'd all new/changed functionality manually

---------

Co-authored-by: Jacob Shandling <jacob@fleetdm.com>
2025-09-19 12:54:43 -07:00

45 lines
1.1 KiB
TypeScript

import React from "react";
import { COLORS } from "styles/var/colors";
import classnames from "classnames";
const baseClass = "progress-bar";
export interface IProgressBarSection {
color: string;
portion: number; // Value between 0 and 1
}
export interface IProgressBar {
sections: IProgressBarSection[];
backgroundColor?: string;
width?: "small" | "large";
}
const ProgressBar = ({
sections,
backgroundColor = COLORS["ui-fleet-black-10"],
width = "large",
}: IProgressBar) => {
const classes = classnames(baseClass, {
[`${baseClass}__small`]: width === "small",
[`${baseClass}__large`]: width === "large",
});
return (
<div className={classes} style={{ backgroundColor }} role="progressbar">
{sections.map((section, index) => (
<div
key={`${section.color}-${section.portion}`}
data-testid={`section-${index}`}
className={`${baseClass}__section`}
style={{
backgroundColor: section.color,
width: `${section.portion * 100}%`,
}}
/>
))}
</div>
);
};
export default ProgressBar;