diff --git a/components/Progress.tsx b/components/Progress.tsx index 9912cc0..a916323 100644 --- a/components/Progress.tsx +++ b/components/Progress.tsx @@ -19,6 +19,13 @@ type BarProps = { striped?: boolean; animated?: boolean; class?: string; + label?: string; + set_label?: ( + per: number, + value: number, + max: number, + min: number, + ) => string; }; class ProgressBar extends Component { @@ -38,7 +45,12 @@ class ProgressBar extends Component { const max = this.context?.max || 100; const min = this.context?.min || 0; const v = this.props.value; - const style = `width: ${(v - min) / (max - min) * 100}%;`; + const per = (v - min) / (max - min) * 100; + const style = `width: ${per}%;`; + let label = this.props.label; + if (this.props.set_label) { + label = this.props.set_label(per, v, max, min); + } return (
{ aria-valuenow={v} aria-valuemin={min} aria-valuemax={max} - /> + > + {label} +
); } } diff --git a/components/Task.tsx b/components/Task.tsx index de58927..4fa4fea 100644 --- a/components/Task.tsx +++ b/components/Task.tsx @@ -6,6 +6,7 @@ import t from "../server/i18n.ts"; import { tw } from "twind"; import Progress from "./Progress.tsx"; import { TaskStatusFlag } from "./TaskFilterBar.tsx"; +import { filesize } from "filesize"; type Props = { task: TaskDetail; @@ -76,8 +77,15 @@ export default class Task extends Component { + `${v} (${per}%)`} + /> + + `${v} (${per}%)`} /> - ); progress_div = ( @@ -94,6 +102,13 @@ export default class Task extends Component { + `${ + filesize(v, { + base: 2, + round: 3, + }) + } (${per}%)`} /> diff --git a/import_map.json b/import_map.json index c4ba93d..7c911df 100644 --- a/import_map.json +++ b/import_map.json @@ -26,6 +26,7 @@ "randomstring": "https://esm.sh/randomstring@1.3.0", "@material/web/": "https://unpkg.lifegpc.workers.dev/@material/web@1.0.0-pre.13/", "@lit-labs/react/": "https://esm.sh/@lit-labs/react@1.2.1/", - "bootstrap/": "https://esm.sh/bootstrap@5.3.0/" + "bootstrap/": "https://esm.sh/bootstrap@5.3.0/", + "filesize": "https://esm.sh/filesize@10.0.7" } }