refactor(edge): use native progress tag for deployment counter [EE-6075] (#10936)

pull/11505/head
Chaim Lev-Ari 8 months ago committed by GitHub
parent 66770bebd4
commit 521eb5f114
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -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,45 +37,45 @@ 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';
case StatusType.DeploymentReceived: case StatusType.DeploymentReceived:
return 'deployments received'; return 'deployments received';
case StatusType.Error: case StatusType.Error:
return 'deployments failed'; return 'deployments failed';
case StatusType.Acknowledged: case StatusType.Acknowledged:
return 'deployments acknowledged'; return 'deployments acknowledged';
case StatusType.ImagesPulled: case StatusType.ImagesPulled:
return 'images pre-pulled'; return 'images pre-pulled';
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…
Cancel
Save