mirror of https://github.com/portainer/portainer
refactor(edge): use native progress tag for deployment counter [EE-6075] (#10936)
parent
66770bebd4
commit
521eb5f114
|
@ -729,3 +729,21 @@ input[style*='background-image: url("data:image/png'] {
|
||||||
input:-webkit-autofill {
|
input:-webkit-autofill {
|
||||||
@apply caret-[--grey-25] th-highcontrast:caret-white th-dark:caret-white;
|
@apply caret-[--grey-25] th-highcontrast:caret-white th-dark:caret-white;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
rules for styling the progress bar on both chrome and firefox
|
||||||
|
first rule is for firefox and the second rule is for chrome
|
||||||
|
|
||||||
|
use the `.progress-filled` tailwind variant util to style the filled value of the progress bar,
|
||||||
|
and the usual styles to style the unfilled value.
|
||||||
|
|
||||||
|
see app/react/edge/edge-stacks/ListView/EdgeStacksDatatable/DeploymentCounter.tsx for an example
|
||||||
|
*/
|
||||||
|
|
||||||
|
progress {
|
||||||
|
appearance: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
progress::-webkit-progress-bar {
|
||||||
|
background-color: transparent;
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,45 @@
|
||||||
|
import { StoryObj, Meta } from '@storybook/react';
|
||||||
|
|
||||||
|
import { StatusType } from '../../types';
|
||||||
|
|
||||||
|
import { DeploymentCounter } from './DeploymentCounter';
|
||||||
|
|
||||||
|
const meta: Meta<typeof DeploymentCounter> = {
|
||||||
|
title: 'Edge/DeploymentCounter',
|
||||||
|
component: DeploymentCounter,
|
||||||
|
};
|
||||||
|
export default meta;
|
||||||
|
|
||||||
|
type Story = StoryObj<typeof DeploymentCounter>;
|
||||||
|
|
||||||
|
export const Running: Story = {
|
||||||
|
args: {
|
||||||
|
count: 5,
|
||||||
|
total: 10,
|
||||||
|
type: StatusType.Running,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export const Error: Story = {
|
||||||
|
args: {
|
||||||
|
count: 3,
|
||||||
|
total: 10,
|
||||||
|
type: StatusType.Error,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export const Acknowledged: Story = {
|
||||||
|
args: {
|
||||||
|
count: 7,
|
||||||
|
total: 10,
|
||||||
|
type: StatusType.Acknowledged,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export const ImagesPulled: Story = {
|
||||||
|
args: {
|
||||||
|
count: 9,
|
||||||
|
total: 10,
|
||||||
|
type: StatusType.ImagesPulled,
|
||||||
|
},
|
||||||
|
};
|
|
@ -37,32 +37,33 @@ export function DeploymentCounter({
|
||||||
}: {
|
}: {
|
||||||
count: number;
|
count: number;
|
||||||
total: number;
|
total: number;
|
||||||
type?: StatusType;
|
type: StatusType;
|
||||||
}) {
|
}) {
|
||||||
const width = total ? (count / total) * 100 : 0;
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<TooltipWithChildren message={getTooltip(count, total, type)}>
|
<TooltipWithChildren message={getTooltip(count, total, type)}>
|
||||||
<div className="h-2 w-full overflow-hidden rounded-lg bg-gray-4">
|
<div className="h-2 w-full overflow-hidden rounded-lg">
|
||||||
<div
|
<progress
|
||||||
style={{ width: `${width}%` }}
|
aria-label={`${getLabel(type)}`}
|
||||||
className={clsx('h-full rounded-lg', {
|
className={clsx('bg-gray-4 w-full', {
|
||||||
'bg-success-7': type === StatusType.Running,
|
'progress-filled:bg-success-7': type === StatusType.Running,
|
||||||
'bg-error-7': type === StatusType.Error,
|
'progress-filled:bg-error-7': type === StatusType.Error,
|
||||||
'bg-blue-9': type === StatusType.Acknowledged,
|
'progress-filled:bg-blue-9': type === StatusType.Acknowledged,
|
||||||
'bg-yellow-7': type === StatusType.ImagesPulled,
|
'progress-filled:bg-yellow-7': type === StatusType.ImagesPulled,
|
||||||
})}
|
})}
|
||||||
|
max={total}
|
||||||
|
value={total ? count : 0}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</TooltipWithChildren>
|
</TooltipWithChildren>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getTooltip(count: number, total: number, type?: StatusType) {
|
function getTooltip(count: number, total: number, type: StatusType) {
|
||||||
const label = getLabel(type);
|
const label = getLabel(type);
|
||||||
return `${count} of ${total} ${label}`;
|
return `${count} of ${total} ${label}`;
|
||||||
|
}
|
||||||
|
|
||||||
function getLabel(type?: StatusType): ReactNode {
|
function getLabel(type: StatusType): ReactNode {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case StatusType.Running:
|
case StatusType.Running:
|
||||||
return 'deployments running';
|
return 'deployments running';
|
||||||
|
@ -77,5 +78,4 @@ function getTooltip(count: number, total: number, type?: StatusType) {
|
||||||
default:
|
default:
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,5 +35,8 @@ module.exports = {
|
||||||
addVariant('th-highcontrast', '&:is([theme="highcontrast"] *)');
|
addVariant('th-highcontrast', '&:is([theme="highcontrast"] *)');
|
||||||
addVariant('th-dark', '&:is([theme="dark"] *)');
|
addVariant('th-dark', '&:is([theme="dark"] *)');
|
||||||
}),
|
}),
|
||||||
|
plugin(function ({ addVariant }) {
|
||||||
|
addVariant('progress-filled', ['&::-webkit-progress-value', '&::-moz-progress-bar']);
|
||||||
|
}),
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue