2020-10-30 20:34:04 +00:00
|
|
|
// Copyright 2020 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2020-01-07 02:20:16 +00:00
|
|
|
import * as React from 'react';
|
|
|
|
import { debounce, dropRight } from 'lodash';
|
|
|
|
import { storiesOf } from '@storybook/react';
|
|
|
|
import { text as textKnob } from '@storybook/addon-knobs';
|
|
|
|
|
2020-09-14 21:56:35 +00:00
|
|
|
import { StoryRow } from '../elements/StoryRow';
|
|
|
|
import { Toaster } from './Toaster';
|
|
|
|
|
2020-01-07 02:20:16 +00:00
|
|
|
storiesOf('Sticker Creator/components', module).add('Toaster', () => {
|
|
|
|
const inputText = textKnob('Slices', ['error 1', 'error 2'].join('|'));
|
|
|
|
const initialState = React.useMemo(() => inputText.split('|'), [inputText]);
|
|
|
|
const [state, setState] = React.useState(initialState);
|
|
|
|
|
2020-09-14 21:56:35 +00:00
|
|
|
// TODO not sure how to fix this
|
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
2020-01-07 02:20:16 +00:00
|
|
|
const handleDismiss = React.useCallback(
|
|
|
|
// Debounce is required here since auto-dismiss is asynchronously called
|
|
|
|
// from multiple rendered instances (multiple themes)
|
|
|
|
debounce(() => {
|
|
|
|
setState(dropRight);
|
|
|
|
}, 10),
|
|
|
|
[setState]
|
|
|
|
);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<StoryRow>
|
|
|
|
<Toaster
|
|
|
|
loaf={state.map((text, id) => ({ id, text }))}
|
|
|
|
onDismiss={handleDismiss}
|
|
|
|
/>
|
|
|
|
</StoryRow>
|
|
|
|
);
|
|
|
|
});
|