Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Close All button for react-toastify #221 #909

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,12 @@ You can find the release note for the latest release [here](https://github.com/f

You can browse them all [here](https://github.com/fkhadra/react-toastify/releases)

## Latest Code Changes
Import toast file from Core
Added button for Close all toastr as svg (X)
in ToastContainer.tsx file
Added closeAllprop variable for style property

## License

Licensed under MIT
25 changes: 23 additions & 2 deletions src/components/ToastContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,25 @@
/* eslint react/prop-types: "off" */
import React, { forwardRef, StyleHTMLAttributes, useEffect } from 'react';
import cx from 'clsx';

import { toast } from '../core';
import { Toast } from './Toast';
import { CloseButton } from './CloseButton';
import { Bounce } from './Transitions';
import { Direction, Default, parseClassName, isFn } from '../utils';
import { useToastContainer } from '../hooks/useToastContainer';
import { ToastContainerProps, ToastPosition } from '../types';

export const ToastContainer = forwardRef<HTMLDivElement, ToastContainerProps>(
(props, ref) => {
const { getToastToRender, containerRef, isToastActive } =
useToastContainer(props);
const { className, style, rtl, containerId } = props;
const closeAllprop = {
backgroundColor: '#fff',
border: '2px solid white',
padding: '5px',
borderRadius: '50%',
color: '#000'
};

function getClassName(position: ToastPosition) {
const defaultClassName = cx(
Expand Down Expand Up @@ -73,6 +79,21 @@ export const ToastContainer = forwardRef<HTMLDivElement, ToastContainerProps>(
</Toast>
);
})}
{toastList.length > 1 && (
<button
className={`${Default.CSS_NAMESPACE}__close-button ${Default.CSS_NAMESPACE}__close-button`}
style={closeAllprop}
onClick={() => toast.dismiss()}
>
{' '}
<svg aria-hidden="true" viewBox="0 0 14 16">
<path
fillRule="evenodd"
d="M7.71 8.23l3.75 3.75-1.48 1.48-3.75-3.75-3.75 3.75L1 11.98l3.75-3.75L1 4.48 2.48 3l3.75 3.75L9.98 3l1.48 1.48-3.75 3.75z"
/>
</svg>
</button>
)}
</div>
);
})}
Expand Down