diff --git a/apps/web-twig-demo/assets/scripts/toast-dynamic.ts b/apps/web-twig-demo/assets/scripts/toast-dynamic.ts index 2d0061596d..3c0dde72c6 100644 --- a/apps/web-twig-demo/assets/scripts/toast-dynamic.ts +++ b/apps/web-twig-demo/assets/scripts/toast-dynamic.ts @@ -6,11 +6,17 @@ const addDynamicToast = (event, containerId) => { autoCloseInterval: formElement.querySelector('#toast-auto-close-interval').value, color: formElement.querySelector('#toast-color').value, containerId, - content: formElement.querySelector('#toast-content').value, enableAutoClose: formElement.querySelector('#toast-enable-auto-close').checked, hasIcon: formElement.querySelector('#toast-has-icon').checked, id: `my-dynamic-toast-${Date.now()}`, isDismissible: formElement.querySelector('#toast-is-dismissible').checked, + message: formElement.querySelector('#toast-message').value, + linkContent: formElement.querySelector('#toast-enable-link').checked + ? formElement.querySelector('#toast-link').value + : null, + linkProps: { + href: '#', + }, }; const toast = new Toast(null, config); diff --git a/packages/web-react/src/components/Toast/README.md b/packages/web-react/src/components/Toast/README.md index 1cb89cf1a8..eda3fd157f 100644 --- a/packages/web-react/src/components/Toast/README.md +++ b/packages/web-react/src/components/Toast/README.md @@ -8,6 +8,8 @@ Toast is a composition of a few subcomponents: - [Toast](#toast) - [ToastBar](#toastbar) + - [ToastBarMessage](#toastbarmessage) + - [ToastBarLink](#toastbarlink) - [UncontrolledToast](#uncontrolledToast) ## Toast @@ -150,11 +152,11 @@ elements. Minimum example: ```jsx -import { ToastBar } from '@lmc-eu/spirit-web-react/components'; -``` +import { ToastBar, ToastBarMessage } from '@lmc-eu/spirit-web-react/components'; -```jsx -Message only + + Message only +; ``` ### Optional Icon @@ -163,7 +165,7 @@ An icon can be displayed in the ToastBar component, depending on the color of th ```jsx - Message with icon + Message with icon ``` @@ -171,7 +173,7 @@ Alternatively, a custom icon can be used: ```jsx - Message with custom icon + Message with custom icon ``` @@ -185,21 +187,59 @@ Alternatively, a custom icon can be used: | `success` | `check-plain` | | `warning` | `warning` | -### Action Link +### ToastBar Components + +The content of `ToastBar` can be assembled from the following subcomponents: -An action link can be added to the ToastBar component: +#### ToastBarMessage + +`ToastBarMessage` is a subcomponent designated for the main message in `ToastBar`. + +Usage example: ```jsx - - Message with action - - Action - + setIsOpen(false)} isDismissible> + This is the main toast message. ``` -👉 For the sake of flexibility, developers can pass the link as part of the message. However, it is strongly recommended -to use the **inverted underlined** variant of the link (for all ToastBar colors) to make it stand out from the message. +#### API + +| Name | Type | Default | Required | Description | +| ---------- | ----------- | ------- | -------- | ------------------------------ | +| `children` | `ReactNode` | — | ✓ | Content of the ToastBarMessage | + +On top of the API options, the components accept [additional attributes][readme-additional-attributes]. +If you need more control over the styling of a component, you can use [style props][readme-style-props] +and [escape hatches][readme-escape-hatches]. + +#### ToastBarLink + +`ToastBarLink` is a subcomponent designated to create an action link within `ToastBar`. + +Usage example: + +```jsx + setIsOpen(false)} isDismissible> + This is the action link. + +``` + +#### API + +| Name | Type | Default | Required | Description | +| -------------- | ------------------------------------------------ | ---------- | -------- | ------------------------------ | +| `children` | `ReactNode` | — | ✓ | Content of the ToastBarLink | +| `color` | [Action Link Color dictionary][dictionary-color] | `inverted` | ✕ | Color of the link | +| `elementType` | `ElementType` | `a` | ✕ | Type of element used as | +| `href` | `string` | — | ✕ | ToastBarLink's href attribute | +| `isDisabled` | `bool` | `false` | ✕ | Whether is the link disabled | +| `isUnderlined` | `bool` | `true` | ✕ | Whether is the link underlined | +| `ref` | `ForwardedRef` | — | ✕ | Link element reference | + +On top of the API options, the components accept [additional attributes][readme-additional-attributes]. +If you need more control over the styling of a component, you can use [style props][readme-style-props] +and [escape hatches][readme-escape-hatches]. 👉 **Do not put any important actions** like "Undo" in the ToastBar component (unless there are other means to perform said action), as it is very hard (if not impossible) to reach for users with assistive technologies. Read more about @@ -213,9 +253,11 @@ Use the `color` option to change the color of the ToastBar component. For example: ```jsx +import { ToastBarMessage } from '@lmc-eu/spirit-web-react/components'; + - Success message - + Success message +; ``` ### Opening the ToastBar @@ -224,7 +266,7 @@ Set `isOpen` prop to `true` to open a Toast **that is present in the DOM,** e.g. ```jsx - Opened ToastBar + Opened ToastBar ``` @@ -236,7 +278,7 @@ To make the ToastBar dismissible, add the `isDismissible` prop along with a `onC ```jsx {}} isDismissible> - Dismissible message + Dismissible message ``` @@ -248,7 +290,7 @@ To make the ToastBar dismissible, add the `isDismissible` prop along with a `onC | `color` | [[Emotion Color dictionary][dictionary-color] \| `inverted`] | `inverted` | ✕ | Color variant | | `hasIcon` | `bool` | `false` \* | ✕ | If true, an icon is shown along the message | | `iconName` | `string` | `info` \* | ✕ | Name of a custom icon to be shown along the message | -| `id` | `string` | — | ✔ | ToastBar ID | +| `id` | `string` | — | ✓ | ToastBar ID | | `isDismissible` | `bool` | `false` | ✕ | If true, ToastBar can be dismissed by user | | `isOpen` | `bool` | `true` | ✕ | If true, ToastBar is visible | | `onClose` | `function` | — | ✕ | Close button callback | @@ -264,9 +306,9 @@ and [escape hatches][readme-escape-hatches]. ## Full Example ```jsx -import { Button, Toast, ToastBar } from '@lmc-eu/spirit-web-react/components'; +import { Button, Toast, ToastBar, ToastBarMessage, ToastBarLink } from '@lmc-eu/spirit-web-react/components'; -const [isOpen, setIsOpen] = React.useState(false) +const [isOpen, setIsOpen] = useState(false);