An opinionated toast component for React.
Update (#220)
Emil Kowalskiefa3a6ec090b
diff --git a/src/index.tsx b/src/index.tsxindex 2763272..f893423 100644--- a/src/index.tsx+++ b/src/index.tsx@@ -361,7 +361,7 @@ const Toast = (props: ToastProps) => {<buttondata-buttondata-cancel- style={cancelButtonStyle}+ style={toast.cancelButtonStyle || cancelButtonStyle}onClick={() => {if (!dismissible) return;deleteToast();@@ -376,7 +376,7 @@ const Toast = (props: ToastProps) => {{toast.action ? (<buttondata-button=""- style={actionButtonStyle}+ style={toast.actionButtonStyle || actionButtonStyle}onClick={(event) => {toast.action?.onClick(event);if (event.defaultPrevented) return;diff --git a/src/styles.css b/src/styles.cssindex 01a6c78..cf3fce9 100644--- a/src/styles.css+++ b/src/styles.css@@ -178,6 +178,9 @@ html[dir='rtl'],border: none;cursor: pointer;outline: none;+ display: flex;+ align-items: center;+ flex-shrink: 0;transition: opacity 400ms, box-shadow 200ms;}diff --git a/src/types.ts b/src/types.tsindex 3362a15..149136e 100644--- a/src/types.ts+++ b/src/types.ts@@ -34,6 +34,8 @@ export interface ToastT {onDismiss?: (toast: ToastT) => void;onAutoClose?: (toast: ToastT) => void;promise?: PromiseT;+ cancelButtonStyle?: React.CSSProperties;+ actionButtonStyle?: React.CSSProperties;style?: React.CSSProperties;unstyled?: boolean;className?: string;diff --git a/website/src/pages/toast.mdx b/website/src/pages/toast.mdxindex 3ec320e..caa0b9d 100644--- a/website/src/pages/toast.mdx+++ b/website/src/pages/toast.mdx@@ -170,19 +170,21 @@ toast.dismiss();## API Reference-| Property | Description | Default |-| :---------- | :----------------------------------------------------------------------------------------------------: | -------------: |-| description | Toast's description, renders underneath the title. | `-` |-| closeButton | Adds a close button which shows on hover. | `false` |-| invert | Dark toast in light mode and vice versa. | `false` |-| important | Control the sensitivity of the toast for screen readers | `false` |-| duration | Time in milliseconds that should elapse before automatically closing the toast. | `4000` |-| position | Position of the toast. | `bottom-right` |-| dismissible | If `false`, it'll prevent the user from dismissing the toast. | `true` |-| icon | Icon displayed in front of toast's text, aligned vertically. | `-` |-| action | Renders a primary button, clicking it will close the toast. | `-` |-| cancel | Renders a secondary button, clicking it will close the toast. | `-` |-| id | Custom id for the toast. | `-` |-| onDismiss | The function gets called when either the close button is clicked, or the toast is swiped. | `-` |-| onAutoClose | Function that gets called when the toast disappears automatically after it's timeout (duration` prop). | `-` |-| unstyled | Removes the default styling, which allows for easier customization. | `false` |+| Property | Description | Default |+| :----------------- | :----------------------------------------------------------------------------------------------------: | -------------: |+| description | Toast's description, renders underneath the title. | `-` |+| closeButton | Adds a close button which shows on hover. | `false` |+| invert | Dark toast in light mode and vice versa. | `false` |+| important | Control the sensitivity of the toast for screen readers | `false` |+| duration | Time in milliseconds that should elapse before automatically closing the toast. | `4000` |+| position | Position of the toast. | `bottom-right` |+| dismissible | If `false`, it'll prevent the user from dismissing the toast. | `true` |+| icon | Icon displayed in front of toast's text, aligned vertically. | `-` |+| action | Renders a primary button, clicking it will close the toast. | `-` |+| cancel | Renders a secondary button, clicking it will close the toast. | `-` |+| id | Custom id for the toast. | `-` |+| onDismiss | The function gets called when either the close button is clicked, or the toast is swiped. | `-` |+| onAutoClose | Function that gets called when the toast disappears automatically after it's timeout (duration` prop). | `-` |+| unstyled | Removes the default styling, which allows for easier customization. | `false` |+| actionButtonStyles | Styles for the action button | `{}` |+| cancelButtonStyles | Styles for the cancel button | `{}` |