@redsift/popovers 9.2.3-patch → 9.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/coverage/clover.xml +763 -0
- package/coverage/coverage-final.json +53 -0
- package/coverage/lcov-report/base.css +224 -0
- package/coverage/lcov-report/block-navigation.js +87 -0
- package/coverage/lcov-report/dialog/Dialog.tsx.html +271 -0
- package/coverage/lcov-report/dialog/context.ts.html +97 -0
- package/coverage/lcov-report/dialog/index.html +191 -0
- package/coverage/lcov-report/dialog/index.ts.html +100 -0
- package/coverage/lcov-report/dialog/types.ts.html +241 -0
- package/coverage/lcov-report/dialog/useDialog.tsx.html +346 -0
- package/coverage/lcov-report/dialog/useDialogContext.tsx.html +121 -0
- package/coverage/lcov-report/dialog-content/DialogContent.tsx.html +484 -0
- package/coverage/lcov-report/dialog-content/index.html +146 -0
- package/coverage/lcov-report/dialog-content/index.ts.html +91 -0
- package/coverage/lcov-report/dialog-content/intl/index.html +116 -0
- package/coverage/lcov-report/dialog-content/intl/index.ts.html +106 -0
- package/coverage/lcov-report/dialog-content/styles.ts.html +256 -0
- package/coverage/lcov-report/dialog-content-actions/DialogContentActions.tsx.html +205 -0
- package/coverage/lcov-report/dialog-content-actions/index.html +146 -0
- package/coverage/lcov-report/dialog-content-actions/index.ts.html +91 -0
- package/coverage/lcov-report/dialog-content-actions/styles.ts.html +139 -0
- package/coverage/lcov-report/dialog-content-body/DialogContentBody.tsx.html +232 -0
- package/coverage/lcov-report/dialog-content-body/index.html +146 -0
- package/coverage/lcov-report/dialog-content-body/index.ts.html +91 -0
- package/coverage/lcov-report/dialog-content-body/styles.ts.html +259 -0
- package/coverage/lcov-report/dialog-content-header/DialogContentHeader.tsx.html +280 -0
- package/coverage/lcov-report/dialog-content-header/index.html +146 -0
- package/coverage/lcov-report/dialog-content-header/index.ts.html +91 -0
- package/coverage/lcov-report/dialog-content-header/styles.ts.html +193 -0
- package/coverage/lcov-report/dialog-trigger/DialogTrigger.tsx.html +217 -0
- package/coverage/lcov-report/dialog-trigger/index.html +131 -0
- package/coverage/lcov-report/dialog-trigger/index.ts.html +91 -0
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +341 -0
- package/coverage/lcov-report/popover/Popover.tsx.html +295 -0
- package/coverage/lcov-report/popover/context.ts.html +97 -0
- package/coverage/lcov-report/popover/index.html +191 -0
- package/coverage/lcov-report/popover/index.ts.html +100 -0
- package/coverage/lcov-report/popover/types.ts.html +283 -0
- package/coverage/lcov-report/popover/usePopover.tsx.html +415 -0
- package/coverage/lcov-report/popover/usePopoverContext.tsx.html +121 -0
- package/coverage/lcov-report/popover-content/PopoverContent.tsx.html +229 -0
- package/coverage/lcov-report/popover-content/index.html +146 -0
- package/coverage/lcov-report/popover-content/index.ts.html +94 -0
- package/coverage/lcov-report/popover-content/styles.ts.html +370 -0
- package/coverage/lcov-report/popover-trigger/PopoverTrigger.tsx.html +202 -0
- package/coverage/lcov-report/popover-trigger/index.html +131 -0
- package/coverage/lcov-report/popover-trigger/index.ts.html +91 -0
- package/coverage/lcov-report/prettify.css +1 -0
- package/coverage/lcov-report/prettify.js +2 -0
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +196 -0
- package/coverage/lcov-report/toast/Toast.tsx.html +373 -0
- package/coverage/lcov-report/toast/index.html +161 -0
- package/coverage/lcov-report/toast/index.ts.html +91 -0
- package/coverage/lcov-report/toast/intl/index.html +116 -0
- package/coverage/lcov-report/toast/intl/index.ts.html +106 -0
- package/coverage/lcov-report/toast/styles.ts.html +193 -0
- package/coverage/lcov-report/toast/types.ts.html +217 -0
- package/coverage/lcov-report/toast-container/ToastContainer.tsx.html +217 -0
- package/coverage/lcov-report/toast-container/index.html +161 -0
- package/coverage/lcov-report/toast-container/index.ts.html +94 -0
- package/coverage/lcov-report/toast-container/styles.ts.html +2284 -0
- package/coverage/lcov-report/toast-container/useToast.tsx.html +469 -0
- package/coverage/lcov-report/tooltip/Tooltip.tsx.html +250 -0
- package/coverage/lcov-report/tooltip/context.ts.html +97 -0
- package/coverage/lcov-report/tooltip/index.html +191 -0
- package/coverage/lcov-report/tooltip/index.ts.html +100 -0
- package/coverage/lcov-report/tooltip/types.ts.html +250 -0
- package/coverage/lcov-report/tooltip/useTooltip.tsx.html +358 -0
- package/coverage/lcov-report/tooltip/useTooltipContext.tsx.html +121 -0
- package/coverage/lcov-report/tooltip-content/TooltipContent.tsx.html +313 -0
- package/coverage/lcov-report/tooltip-content/index.html +146 -0
- package/coverage/lcov-report/tooltip-content/index.ts.html +91 -0
- package/coverage/lcov-report/tooltip-content/styles.ts.html +337 -0
- package/coverage/lcov-report/tooltip-trigger/TooltipTrigger.tsx.html +211 -0
- package/coverage/lcov-report/tooltip-trigger/index.html +131 -0
- package/coverage/lcov-report/tooltip-trigger/index.ts.html +91 -0
- package/coverage/lcov.info +1510 -0
- package/coverage/storybook/coverage-storybook.json +58724 -0
- package/dist/package.json +96 -0
- package/index.ts +1 -0
- package/jest.config.js +3 -0
- package/package.json +2 -3
- package/rollup.config.js +13 -0
- package/src/components/dialog/Dialog.stories.tsx +264 -0
- package/src/components/dialog/Dialog.test.tsx +116 -0
- package/src/components/dialog/Dialog.tsx +62 -0
- package/src/components/dialog/context.ts +4 -0
- package/src/components/dialog/index.ts +5 -0
- package/src/components/dialog/types.ts +52 -0
- package/src/components/dialog/useDialog.tsx +87 -0
- package/src/components/dialog/useDialogContext.tsx +12 -0
- package/src/components/dialog-content/DialogContent.stories.tsx +348 -0
- package/src/components/dialog-content/DialogContent.tsx +133 -0
- package/src/components/dialog-content/index.ts +2 -0
- package/src/components/dialog-content/intl/en-US.json +3 -0
- package/src/components/dialog-content/intl/fr-FR.json +3 -0
- package/src/components/dialog-content/intl/index.ts +7 -0
- package/src/components/dialog-content/styles.ts +57 -0
- package/src/components/dialog-content/types.ts +10 -0
- package/src/components/dialog-content-actions/DialogContentActions.test.tsx +68 -0
- package/src/components/dialog-content-actions/DialogContentActions.tsx +40 -0
- package/src/components/dialog-content-actions/index.ts +2 -0
- package/src/components/dialog-content-actions/styles.ts +18 -0
- package/src/components/dialog-content-actions/types.ts +11 -0
- package/src/components/dialog-content-body/DialogContentBody.test.tsx +63 -0
- package/src/components/dialog-content-body/DialogContentBody.tsx +49 -0
- package/src/components/dialog-content-body/index.ts +2 -0
- package/src/components/dialog-content-body/styles.ts +58 -0
- package/src/components/dialog-content-body/types.ts +14 -0
- package/src/components/dialog-content-header/DialogContentHeader.test.tsx +63 -0
- package/src/components/dialog-content-header/DialogContentHeader.tsx +65 -0
- package/src/components/dialog-content-header/index.ts +2 -0
- package/src/components/dialog-content-header/styles.ts +36 -0
- package/src/components/dialog-content-header/types.ts +21 -0
- package/src/components/dialog-trigger/DialogTrigger.tsx +44 -0
- package/src/components/dialog-trigger/index.ts +2 -0
- package/src/components/dialog-trigger/types.ts +9 -0
- package/src/components/popover/Popover.stories.tsx +129 -0
- package/src/components/popover/Popover.test.tsx +102 -0
- package/src/components/popover/Popover.tsx +70 -0
- package/src/components/popover/context.ts +4 -0
- package/src/components/popover/index.ts +5 -0
- package/src/components/popover/types.ts +66 -0
- package/src/components/popover/usePopover.tsx +110 -0
- package/src/components/popover/usePopoverContext.tsx +12 -0
- package/src/components/popover-content/PopoverContent.tsx +48 -0
- package/src/components/popover-content/index.ts +3 -0
- package/src/components/popover-content/styles.ts +95 -0
- package/src/components/popover-content/types.ts +11 -0
- package/src/components/popover-trigger/PopoverTrigger.tsx +39 -0
- package/src/components/popover-trigger/index.ts +2 -0
- package/src/components/popover-trigger/types.ts +9 -0
- package/src/components/toast/Toast.stories.tsx +68 -0
- package/src/components/toast/Toast.test.tsx +63 -0
- package/src/components/toast/Toast.tsx +96 -0
- package/src/components/toast/index.ts +2 -0
- package/src/components/toast/intl/en-US.json +3 -0
- package/src/components/toast/intl/fr-FR.json +3 -0
- package/src/components/toast/intl/index.ts +7 -0
- package/src/components/toast/styles.ts +36 -0
- package/src/components/toast/types.ts +44 -0
- package/src/components/toast-container/ToastContainer.stories.tsx +349 -0
- package/src/components/toast-container/ToastContainer.tsx +44 -0
- package/src/components/toast-container/index.ts +3 -0
- package/src/components/toast-container/styles.ts +733 -0
- package/src/components/toast-container/types.ts +110 -0
- package/src/components/toast-container/useToast.test.tsx +111 -0
- package/src/components/toast-container/useToast.tsx +128 -0
- package/src/components/tooltip/Tooltip.stories.tsx +196 -0
- package/src/components/tooltip/Tooltip.test.tsx +119 -0
- package/src/components/tooltip/Tooltip.tsx +55 -0
- package/src/components/tooltip/context.ts +4 -0
- package/src/components/tooltip/index.ts +5 -0
- package/src/components/tooltip/types.ts +55 -0
- package/src/components/tooltip/useTooltip.tsx +93 -0
- package/src/components/tooltip/useTooltipContext.tsx +12 -0
- package/src/components/tooltip-content/TooltipContent.tsx +76 -0
- package/src/components/tooltip-content/index.ts +2 -0
- package/src/components/tooltip-content/styles.ts +84 -0
- package/src/components/tooltip-content/types.ts +14 -0
- package/src/components/tooltip-trigger/TooltipTrigger.tsx +42 -0
- package/src/components/tooltip-trigger/index.ts +2 -0
- package/src/components/tooltip-trigger/types.ts +9 -0
- package/src/index.ts +16 -0
- package/tsconfig.json +3 -0
- /package/{CONTRIBUTING.md → dist/CONTRIBUTING.md} +0 -0
- /package/{index.d.ts → dist/index.d.ts} +0 -0
- /package/{index.js → dist/index.js} +0 -0
- /package/{index.js.map → dist/index.js.map} +0 -0
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import React, { forwardRef, ReactElement } from 'react';
|
|
2
|
+
import { useMergeRefs } from '@floating-ui/react';
|
|
3
|
+
|
|
4
|
+
import { Comp, isComponent } from '@redsift/design-system';
|
|
5
|
+
import { usePopoverContext } from '../popover';
|
|
6
|
+
import { PopoverTriggerProps } from './types';
|
|
7
|
+
|
|
8
|
+
const COMPONENT_NAME = 'PopoverTrigger';
|
|
9
|
+
const CLASSNAME = 'redsift-popover-trigger';
|
|
10
|
+
const DEFAULT_PROPS: Partial<PopoverTriggerProps> = {};
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* The PopoverTrigger component.
|
|
14
|
+
*/
|
|
15
|
+
export const PopoverTrigger: Comp<PopoverTriggerProps, HTMLButtonElement> = forwardRef((props, ref) => {
|
|
16
|
+
const { children } = props;
|
|
17
|
+
|
|
18
|
+
const { getReferenceProps, isOpen, handleOpen, refs } = usePopoverContext();
|
|
19
|
+
const childrenRef = (children as any).ref;
|
|
20
|
+
const triggerRef = useMergeRefs([refs.setReference, ref, childrenRef]);
|
|
21
|
+
|
|
22
|
+
if (isComponent('Button')(children) || isComponent('IconButton')(children) || isComponent('LinkButton')(children)) {
|
|
23
|
+
return React.cloneElement(children as ReactElement, {
|
|
24
|
+
...getReferenceProps({
|
|
25
|
+
ref: triggerRef,
|
|
26
|
+
...props,
|
|
27
|
+
...children.props,
|
|
28
|
+
children: children.props.children ?? '',
|
|
29
|
+
}),
|
|
30
|
+
onClick: () => handleOpen(!isOpen),
|
|
31
|
+
isActive: isOpen,
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return null;
|
|
36
|
+
});
|
|
37
|
+
PopoverTrigger.className = CLASSNAME;
|
|
38
|
+
PopoverTrigger.defaultProps = DEFAULT_PROPS;
|
|
39
|
+
PopoverTrigger.displayName = COMPONENT_NAME;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
import { Toast, ToastVariant } from '.';
|
|
4
|
+
import { Flexbox } from '@redsift/design-system';
|
|
5
|
+
import { Button, ButtonColor } from '@redsift/design-system';
|
|
6
|
+
|
|
7
|
+
export default {
|
|
8
|
+
title: 'Popovers/Toast/Toast',
|
|
9
|
+
component: Toast,
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export const Simple = () => <Toast>Cupcake ipsum dolor sit amet pastry tootsie roll sugar plum.</Toast>;
|
|
13
|
+
|
|
14
|
+
export const WithTitle = () => (
|
|
15
|
+
<Toast title="Title">Cupcake ipsum dolor sit amet pastry tootsie roll sugar plum.</Toast>
|
|
16
|
+
);
|
|
17
|
+
|
|
18
|
+
export const AllVariants = () => (
|
|
19
|
+
<Flexbox flexDirection="column">
|
|
20
|
+
{Object.keys(ToastVariant).map((variant) => (
|
|
21
|
+
<Toast
|
|
22
|
+
key={variant}
|
|
23
|
+
variant={variant as ToastVariant}
|
|
24
|
+
title={`${variant[0].toUpperCase()}${variant.slice(1, variant.length)}`}
|
|
25
|
+
>
|
|
26
|
+
Cupcake ipsum dolor sit amet pastry tootsie roll sugar plum.
|
|
27
|
+
</Toast>
|
|
28
|
+
))}
|
|
29
|
+
</Flexbox>
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
export const WithoutCloseButton = () => (
|
|
33
|
+
<Toast title="Without close button" closeButton={false}>
|
|
34
|
+
Cupcake ipsum dolor sit amet pastry tootsie roll sugar plum.
|
|
35
|
+
</Toast>
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
export const WithCustomCloseButton = () => (
|
|
39
|
+
<Flexbox flexDirection="column">
|
|
40
|
+
{Object.keys(ToastVariant).map((variant) => (
|
|
41
|
+
<Toast
|
|
42
|
+
key={variant}
|
|
43
|
+
variant={variant as ToastVariant}
|
|
44
|
+
title={`${variant[0].toUpperCase()}${variant.slice(1, variant.length)}`}
|
|
45
|
+
closeButton={<Button>Click me</Button>}
|
|
46
|
+
>
|
|
47
|
+
Cupcake ipsum dolor sit amet pastry tootsie roll sugar plum.
|
|
48
|
+
</Toast>
|
|
49
|
+
))}
|
|
50
|
+
</Flexbox>
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
export const WithComponents = () => (
|
|
54
|
+
<Flexbox flexDirection="column">
|
|
55
|
+
{Object.keys(ToastVariant).map((variant) => (
|
|
56
|
+
<Toast
|
|
57
|
+
key={variant}
|
|
58
|
+
variant={variant as ToastVariant}
|
|
59
|
+
title={`${variant[0].toUpperCase()}${variant.slice(1, variant.length)}`}
|
|
60
|
+
>
|
|
61
|
+
Cupcake ipsum dolor sit amet pastry tootsie roll sugar plum.
|
|
62
|
+
<Button color={variant === 'loading' ? 'primary' : (variant as ButtonColor)} marginTop="8px">
|
|
63
|
+
Click me
|
|
64
|
+
</Button>
|
|
65
|
+
</Toast>
|
|
66
|
+
))}
|
|
67
|
+
</Flexbox>
|
|
68
|
+
);
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { fireEvent, render } from '@testing-library/react';
|
|
3
|
+
|
|
4
|
+
import { Toast } from '.';
|
|
5
|
+
import { Button } from '@redsift/design-system';
|
|
6
|
+
|
|
7
|
+
describe('Toast', () => {
|
|
8
|
+
const onClickSpy = jest.fn();
|
|
9
|
+
const onClickSpy2 = jest.fn();
|
|
10
|
+
|
|
11
|
+
afterEach(() => {
|
|
12
|
+
onClickSpy.mockClear();
|
|
13
|
+
onClickSpy2.mockClear();
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it('handles default', () => {
|
|
17
|
+
const { getByText } = render(<Toast>Content</Toast>);
|
|
18
|
+
expect(getByText('Content')).toBeVisible();
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it('supports custom className', () => {
|
|
22
|
+
const tree = render(<Toast className="test-class">Content</Toast>);
|
|
23
|
+
const component = tree.asFragment().firstChild;
|
|
24
|
+
expect(component).toHaveAttribute(
|
|
25
|
+
'class',
|
|
26
|
+
expect.stringContaining(Toast.className!)
|
|
27
|
+
);
|
|
28
|
+
expect(component).toHaveAttribute(
|
|
29
|
+
'class',
|
|
30
|
+
expect.stringContaining('test-class')
|
|
31
|
+
);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('supports custom data attributes', () => {
|
|
35
|
+
const tree = render(<Toast data-testid="test">Content</Toast>);
|
|
36
|
+
const component = tree.asFragment().firstChild;
|
|
37
|
+
expect(component).toHaveAttribute('data-testid', 'test');
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it('supports custom close button with onClick', () => {
|
|
41
|
+
const { getByRole } = render(
|
|
42
|
+
<Toast closeButton={<Button onClick={onClickSpy}>Click me</Button>}>
|
|
43
|
+
Cupcake ipsum dolor sit amet pastry tootsie roll sugar plum.
|
|
44
|
+
</Toast>
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
const button = getByRole('button');
|
|
48
|
+
fireEvent.click(button);
|
|
49
|
+
expect(onClickSpy).toHaveBeenCalled();
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it('supports custom close button without onClick', () => {
|
|
53
|
+
const { getByRole } = render(
|
|
54
|
+
<Toast closeToast={onClickSpy2} closeButton={<Button>Click me</Button>}>
|
|
55
|
+
Cupcake ipsum dolor sit amet pastry tootsie roll sugar plum.
|
|
56
|
+
</Toast>
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
const button = getByRole('button');
|
|
60
|
+
fireEvent.click(button);
|
|
61
|
+
expect(onClickSpy2).toHaveBeenCalled();
|
|
62
|
+
});
|
|
63
|
+
});
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import React, { forwardRef, RefObject } from 'react';
|
|
2
|
+
import classNames from 'classnames';
|
|
3
|
+
|
|
4
|
+
import { useLocalizedStringFormatter } from '@react-aria/i18n';
|
|
5
|
+
import intlMessages from './intl';
|
|
6
|
+
|
|
7
|
+
import { mdiAlert, mdiAlertCircle, mdiCheckCircle, mdiClose, mdiInformation } from '@redsift/icons';
|
|
8
|
+
import {
|
|
9
|
+
NotificationsColorPalette,
|
|
10
|
+
Comp,
|
|
11
|
+
Icon,
|
|
12
|
+
Flexbox,
|
|
13
|
+
Spinner,
|
|
14
|
+
Text,
|
|
15
|
+
isComponent,
|
|
16
|
+
ButtonColor,
|
|
17
|
+
IconButton,
|
|
18
|
+
RedsiftTypographyFontWeightSemiBold,
|
|
19
|
+
} from '@redsift/design-system';
|
|
20
|
+
import { StyledToast } from './styles';
|
|
21
|
+
import { ToastProps, ToastVariant } from './types';
|
|
22
|
+
|
|
23
|
+
const COMPONENT_NAME = 'Toast';
|
|
24
|
+
const CLASSNAME = 'redsift-toast';
|
|
25
|
+
const DEFAULT_PROPS: Partial<ToastProps> = {
|
|
26
|
+
variant: 'info',
|
|
27
|
+
closeButton: true,
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const getVariant = (variant: ToastVariant) => {
|
|
31
|
+
switch (variant) {
|
|
32
|
+
case ToastVariant.info:
|
|
33
|
+
default:
|
|
34
|
+
return <Icon icon={mdiInformation} color={NotificationsColorPalette.info} />;
|
|
35
|
+
case ToastVariant.error:
|
|
36
|
+
return <Icon icon={mdiAlertCircle} color={NotificationsColorPalette.error} />;
|
|
37
|
+
case ToastVariant.success:
|
|
38
|
+
return <Icon icon={mdiCheckCircle} color={NotificationsColorPalette.success} />;
|
|
39
|
+
case ToastVariant.warning:
|
|
40
|
+
return <Icon icon={mdiAlert} color={NotificationsColorPalette.warning} />;
|
|
41
|
+
case ToastVariant.loading:
|
|
42
|
+
return <Spinner size="small" />;
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* The Toast component.
|
|
48
|
+
*/
|
|
49
|
+
export const Toast: Comp<ToastProps & { closeToast?: () => void }, HTMLDivElement> = forwardRef((props, ref) => {
|
|
50
|
+
const { children, className, closeToast, closeButton, title, variant, ...forwardedProps } = props;
|
|
51
|
+
|
|
52
|
+
const stringFormatter = useLocalizedStringFormatter(intlMessages);
|
|
53
|
+
|
|
54
|
+
const icon = getVariant(variant!);
|
|
55
|
+
|
|
56
|
+
return (
|
|
57
|
+
<StyledToast
|
|
58
|
+
{...forwardedProps}
|
|
59
|
+
className={classNames(Toast.className, className)}
|
|
60
|
+
ref={ref as RefObject<HTMLDivElement>}
|
|
61
|
+
$hasTitle={Boolean(title)}
|
|
62
|
+
$variant={variant}
|
|
63
|
+
>
|
|
64
|
+
<Flexbox className={`${Toast.className}__header`} justifyContent="space-between">
|
|
65
|
+
<Flexbox justifyContent="space-between" flexDirection="column" gap="0">
|
|
66
|
+
<Flexbox className={`${Toast.className}-header__title`} gap="14px" alignItems="flex-start">
|
|
67
|
+
{icon}
|
|
68
|
+
{title ? <Text fontWeight={RedsiftTypographyFontWeightSemiBold}>{title}</Text> : null}
|
|
69
|
+
</Flexbox>
|
|
70
|
+
|
|
71
|
+
{children ? <div className={`${Toast.className}__content`}>{children}</div> : null}
|
|
72
|
+
</Flexbox>
|
|
73
|
+
|
|
74
|
+
{closeButton === true ? (
|
|
75
|
+
<IconButton
|
|
76
|
+
aria-label={stringFormatter.format('close')}
|
|
77
|
+
className={`${Toast.className}-header__icon-button`}
|
|
78
|
+
icon={mdiClose}
|
|
79
|
+
onClick={closeToast}
|
|
80
|
+
/>
|
|
81
|
+
) : isComponent('Button')(closeButton) || isComponent('IconButton')(closeButton) ? (
|
|
82
|
+
React.cloneElement(closeButton, {
|
|
83
|
+
color: variant === 'loading' ? 'default' : (variant as ButtonColor),
|
|
84
|
+
onClick: () => {
|
|
85
|
+
closeButton.props.onClick?.();
|
|
86
|
+
closeToast?.();
|
|
87
|
+
},
|
|
88
|
+
})
|
|
89
|
+
) : null}
|
|
90
|
+
</Flexbox>
|
|
91
|
+
</StyledToast>
|
|
92
|
+
);
|
|
93
|
+
});
|
|
94
|
+
Toast.className = CLASSNAME;
|
|
95
|
+
Toast.defaultProps = DEFAULT_PROPS;
|
|
96
|
+
Toast.displayName = COMPONENT_NAME;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import styled, { css } from 'styled-components';
|
|
2
|
+
import { baseStyling } from '@redsift/design-system';
|
|
3
|
+
import { StyledToastProps } from './types';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Component style.
|
|
7
|
+
*/
|
|
8
|
+
export const StyledToast = styled.div<StyledToastProps>`
|
|
9
|
+
${baseStyling}
|
|
10
|
+
|
|
11
|
+
padding: 16px;
|
|
12
|
+
box-shadow: 0px 2px 4px -1px rgb(0 0 0 / 20%), 0px 4px 5px rgb(0 0 0 / 14%), 0px 1px 10px rgb(0 0 0 / 12%);
|
|
13
|
+
|
|
14
|
+
${({ $hasTitle, $variant }) => css`
|
|
15
|
+
background-color: ${$variant === 'loading'
|
|
16
|
+
? 'var(--redsift-color-neutral-white)'
|
|
17
|
+
: `var(--redsift-color-notifications-${$variant}-hover)`};
|
|
18
|
+
|
|
19
|
+
.redsift-toast-header__icon-button {
|
|
20
|
+
padding: 0px;
|
|
21
|
+
.redsift-icon {
|
|
22
|
+
color: var(--redsift-color-neutral-black);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
&:hover,
|
|
26
|
+
&:focus-visible {
|
|
27
|
+
background-color: var(--redsift-color-notifications-${$variant}-active);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
.redsift-toast__content {
|
|
32
|
+
margin-top: ${$hasTitle ? '8px' : '-24px'};
|
|
33
|
+
margin-left: 38px;
|
|
34
|
+
}
|
|
35
|
+
`}
|
|
36
|
+
`;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { ComponentProps, ReactNode } from 'react';
|
|
2
|
+
import { ValueOf, SizingProps, SpacingProps } from '@redsift/design-system';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Component variant.
|
|
6
|
+
*/
|
|
7
|
+
export const ToastVariant = {
|
|
8
|
+
success: 'success',
|
|
9
|
+
error: 'error',
|
|
10
|
+
warning: 'warning',
|
|
11
|
+
info: 'info',
|
|
12
|
+
loading: 'loading',
|
|
13
|
+
} as const;
|
|
14
|
+
export type ToastVariant = ValueOf<typeof ToastVariant>;
|
|
15
|
+
|
|
16
|
+
export const ToastPlacement = {
|
|
17
|
+
'top-right': 'top-right',
|
|
18
|
+
'top-center': 'top-center',
|
|
19
|
+
'top-left': 'top-left',
|
|
20
|
+
'bottom-right': 'bottom-right',
|
|
21
|
+
'bottom-center': 'bottom-center',
|
|
22
|
+
'bottom-left': 'bottom-left',
|
|
23
|
+
} as const;
|
|
24
|
+
export type ToastPlacement = ValueOf<typeof ToastPlacement>;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Component props.
|
|
28
|
+
*/
|
|
29
|
+
export interface ToastProps
|
|
30
|
+
extends Omit<ComponentProps<'div'>, 'id' | 'style'>,
|
|
31
|
+
SpacingProps,
|
|
32
|
+
SizingProps {
|
|
33
|
+
/** Whether the component has a close button or not. */
|
|
34
|
+
closeButton?: boolean | ReactNode;
|
|
35
|
+
/** Title. */
|
|
36
|
+
title?: string;
|
|
37
|
+
/** Variant */
|
|
38
|
+
variant?: ToastVariant;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export type StyledToastProps = Omit<ToastProps, 'variant' | 'id'> & {
|
|
42
|
+
$hasTitle: boolean;
|
|
43
|
+
$variant: ToastProps['variant'];
|
|
44
|
+
};
|