Skip to content

Commit 4c9239f

Browse files
committed
feat: add support for persistant progress bar
1 parent 23fdfa0 commit 4c9239f

File tree

4 files changed

+30
-4
lines changed

4 files changed

+30
-4
lines changed

src/Shared/Services/ToastManager/ToastContent.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@ import { Button, ButtonStyleType, ButtonVariantType } from '@Shared/Components'
22
import { ComponentSizeType } from '@Shared/constants'
33
import { ToastProps } from './types'
44

5-
export const ToastContent = ({ title, description, buttonProps }: Omit<ToastProps, 'variant'>) => (
5+
export const ToastContent = ({
6+
title,
7+
description,
8+
buttonProps,
9+
}: Pick<ToastProps, 'title' | 'description' | 'buttonProps'>) => (
610
<div className="flexbox-col dc__gap-8">
711
<div className="flexbox-col dc__gap-4">
812
<h3 className="m-0 fs-13 fw-6 lh-20 cn-0 dc__truncate">{title}</h3>

src/Shared/Services/ToastManager/constants.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,31 +27,36 @@ export const TOAST_BASE_CONFIG: ToastContainerProps = {
2727

2828
export const TOAST_VARIANT_TO_CONFIG_MAP: Record<
2929
ToastVariantType,
30-
Required<Pick<ToastProps, 'icon' | 'title'>> & Pick<ToastOptions, 'type'>
30+
Required<Pick<ToastProps, 'icon' | 'title' | 'progressBarBg'>> & Pick<ToastOptions, 'type'>
3131
> = {
3232
[ToastVariantType.info]: {
3333
icon: <ICInfoFilled />,
3434
type: 'info',
3535
title: 'Information',
36+
progressBarBg: 'var(--B500)',
3637
},
3738
[ToastVariantType.success]: {
3839
icon: <ICSuccess />,
3940
type: 'success',
4041
title: 'Success',
42+
progressBarBg: 'var(--G500)',
4143
},
4244
[ToastVariantType.error]: {
4345
icon: <ICError />,
4446
type: 'error',
4547
title: 'Error',
48+
progressBarBg: 'var(--R500)',
4649
},
4750
[ToastVariantType.warn]: {
4851
icon: <ICWarning className="warning-icon-y5-imp" />,
4952
type: 'warning',
5053
title: 'Warning',
54+
progressBarBg: 'var(--Y500)',
5155
},
5256
[ToastVariantType.notAuthorized]: {
5357
icon: <ICLocked />,
5458
type: 'warning',
5559
title: 'Not authorized',
60+
progressBarBg: 'var(--Y500)',
5661
},
5762
}

src/Shared/Services/ToastManager/toastManager.service.tsx

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,17 @@ class ToastManager {
1919

2020
// eslint-disable-next-line class-methods-use-this
2121
showToast = (
22-
{ variant = ToastVariantType.info, icon: customIcon, title, description, buttonProps }: ToastProps,
22+
{
23+
variant = ToastVariantType.info,
24+
icon: customIcon,
25+
title,
26+
description,
27+
buttonProps,
28+
progressBarBg: customProgressBarBg,
29+
}: ToastProps,
2330
options: Pick<ToastOptions, 'autoClose'> = {},
2431
) => {
25-
const { icon, type, title: defaultTitle } = TOAST_VARIANT_TO_CONFIG_MAP[variant]
32+
const { icon, type, title: defaultTitle, progressBarBg } = TOAST_VARIANT_TO_CONFIG_MAP[variant]
2633

2734
return toast(
2835
<ToastContent title={title || defaultTitle} description={description} buttonProps={buttonProps} />,
@@ -32,6 +39,15 @@ class ToastManager {
3239
<div className="dc__no-shrink flex dc__fill-available-space icon-dim-20">{customIcon ?? icon}</div>
3340
),
3441
type,
42+
// Show the progress bar if the auto close is disabled
43+
...(options.autoClose === false
44+
? {
45+
progress: 1,
46+
progressStyle: {
47+
background: customProgressBarBg || progressBarBg,
48+
},
49+
}
50+
: {}),
3551
},
3652
)
3753
}

src/Shared/Services/ToastManager/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,5 @@ export interface ToastProps {
1515
icon?: ReactElement
1616
variant?: ToastVariantType
1717
buttonProps?: ButtonProps
18+
progressBarBg?: `var(--${string})`
1819
}

0 commit comments

Comments
 (0)