Skip to content

Commit

Permalink
feat(Toaster)!: rename timeout to autoHiding (#248)
Browse files Browse the repository at this point in the history
* `timeout` renamed to `autoHiding`
* `allowAutoHiding` option removed, use `autoHiding=false` instead
  • Loading branch information
ogonkov authored and amje committed Jan 26, 2023
1 parent c3b1aeb commit ed0585a
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 23 deletions.
21 changes: 10 additions & 11 deletions src/components/Toaster/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,17 +90,16 @@ On initialization it is possible to pass className, that will be assigned to dom

Accepts argument `toastOptions` with ongoing notification details:

| Parameter | Type | Required | Default | Description |
| :-------------- | :-------------- | :------- | :---------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| name | `string` | yes | | Notification unique name. Notifications with same names collapse into one |
| title | `string` | yes | | Notification title |
| className | `string` | | | CSS-class |
| allowAutoHiding | `boolean` | | `true` | Configuration that manages notification automatic hiding |
| timeout | `number` | | 5000 | Time (in milliseconds)after which the notification will hide |
| content | `node` | | `undefined` | Notification content. [Anything that can be rendered: numbers, strings, elements or an array](https://reactjs.org/docs/typechecking-with-proptypes.html#proptypes) |
| type | `string` | | `undefined` | Notification type. Possible values: `error`, `success`. If `type` is set, icon (success/error) will be added into notification title. _By default there is no icon_ |
| isClosable | `boolean` | | `true` | Configuration that manages visibility of cross icon, which allows to close notification |
| actions | `ToastAction[]` | | `undefined` | Array of [actions](./types.ts#L9) which displays after `content` |
| Parameter | Type | Required | Default | Description |
| :--------- | :------------------ | :------- | :---------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| name | `string` | yes | | Notification unique name. Notifications with same names collapse into one |
| title | `string` | yes | | Notification title |
| className | `string` | | | CSS-class |
| autoHiding | `number` or `false` | | 5000 | Time (in milliseconds) after which the notification will hide. Use `false` to disable toast hiding after timeout. |
| content | `node` | | `undefined` | Notification content. [Anything that can be rendered: numbers, strings, elements or an array](https://reactjs.org/docs/typechecking-with-proptypes.html#proptypes) |
| type | `string` | | `undefined` | Notification type. Possible values: `error`, `success`. If `type` is set, icon (success/error) will be added into notification title. _By default there is no icon_ |
| isClosable | `boolean` | | `true` | Configuration that manages visibility of cross icon, which allows to close notification |
| actions | `ToastAction[]` | | `undefined` | Array of [actions](./types.ts#L9) which displays after `content` |

Every `action` is an object with following parameters:

Expand Down
4 changes: 2 additions & 2 deletions src/components/Toaster/Toast/Toast.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ export function Toast(props: ToastUnitedProps) {
title,
className,
type,
allowAutoHiding = true,
autoHiding: timeoutProp = DEFAULT_TIMEOUT,
isClosable = true,
isOverride = false,
mobile = false,
Expand All @@ -190,7 +190,7 @@ export function Toast(props: ToastUnitedProps) {

const heightProps = useToastHeight({isOverride, status});

const timeout = allowAutoHiding ? props.timeout || DEFAULT_TIMEOUT : undefined;
const timeout = typeof timeoutProp === 'number' ? timeoutProp : undefined;
const closeOnTimeoutProps = useCloseOnTimeout<HTMLDivElement>({onClose: handleClose, timeout});

const mods = {
Expand Down
2 changes: 1 addition & 1 deletion src/components/Toaster/__stories__/Toaster.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export default {
name: disabledControl,
title: disabledControl,
className: disabledControl,
timeout: disabledControl,
autoHiding: disabledControl,
content: disabledControl,
type: disabledControl,
isClosable: disabledControl,
Expand Down
9 changes: 7 additions & 2 deletions src/components/Toaster/__stories__/ToasterShowcase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,20 @@ export const ToasterDemo = ({
content = CONTENT;
}

let timeout = allowAutoHiding ? 5000 : false;

if (setTimeout) {
timeout = customTimeout;
}

return {
content,
name: getToastName(extra.name),
className: extra.className,
title: extra.title,
type: extra.type,
isClosable: showCloseIcon,
timeout: setTimeout ? Number(customTimeout) : undefined,
allowAutoHiding: allowAutoHiding,
autoHiding: timeout,
actions: setActions
? ACTIONS.map((action, index) => ({
...action,
Expand Down
10 changes: 5 additions & 5 deletions src/components/Toaster/__tests__/ToasterProvider.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ describe('api.remove', () => {
act(() => {
providerAPI.add({
...toastProps,
timeout: toastTimeout,
autoHiding: toastTimeout,
});
});

Expand All @@ -106,7 +106,7 @@ it('should remove toast after timeout', function () {
act(() => {
providerAPI.add({
...toastProps,
timeout: toastTimeout,
autoHiding: toastTimeout,
});
});

Expand Down Expand Up @@ -134,7 +134,7 @@ it('should preserve toast on hover', function () {
act(() => {
providerAPI.add({
...toastProps,
timeout: toastTimeout,
autoHiding: toastTimeout,
});
});

Expand Down Expand Up @@ -172,7 +172,7 @@ describe('api.update', () => {
act(() => {
providerAPI.add({
...toastProps,
timeout: toastTimeout,
autoHiding: toastTimeout,
});
});

Expand Down Expand Up @@ -204,7 +204,7 @@ describe('api.update', () => {
act(() => {
providerAPI.add({
...toastProps,
timeout: toastTimeout,
autoHiding: toastTimeout,
});
});

Expand Down
3 changes: 1 addition & 2 deletions src/components/Toaster/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ export type ToastProps = {
name: string;
title?: string;
className?: string;
timeout?: number;
allowAutoHiding?: boolean;
autoHiding?: number | false;
content?: React.ReactNode;
type?: ToastType;
isClosable?: boolean;
Expand Down

0 comments on commit ed0585a

Please sign in to comment.