forked from riccardoperra/codeimage
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSnackbar.tsx
More file actions
72 lines (68 loc) · 2.13 KB
/
Snackbar.tsx
File metadata and controls
72 lines (68 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import clsx from 'clsx';
import {Toast} from 'solid-headless';
import {createSignal, JSX, Show} from 'solid-js';
import {Dynamic} from 'solid-js/web';
import {Box} from '../Box';
import {Button} from '../Button';
import {ButtonSizes} from '../Button/Button.css';
import {SvgIcon} from '../Icon';
import {Text} from '../Text';
import {FadeInOutWithScaleTransition} from '../Transition';
import * as styles from './Snackbar.css';
import {SnackbarData, toast} from './SnackbarHost';
export function SnackBar(props: SnackbarData & {id: string}): JSX.Element {
const [isOpen, setIsOpen] = createSignal(true);
function dismiss() {
setIsOpen(() => false);
}
return (
<FadeInOutWithScaleTransition
show={isOpen()}
afterLeave={() => toast.remove(props.id)}
>
<Box as={props.wrapper ?? 'div'}>
<Toast class={clsx(styles.snackbar)}>
<Text size={'sm'} weight={'semibold'}>
{typeof props.message === 'string' ? (
props.message
) : (
<Dynamic component={props.message} />
)}
</Text>
<Show when={!!props.actions}>
<Box marginLeft={'4'}>
<Dynamic component={props.actions} />
</Box>
</Show>
<Show when={props.closeable}>
<Box marginLeft={'4'}>
<Button
type={'button'}
size={ButtonSizes.xs}
pill
variant={'solid'}
theme={'secondary'}
onClick={dismiss}
>
<SvgIcon
xmlns="http://www.w3.org/2000/svg"
size={'xs'}
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
stroke-width="2"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
d="M6 18L18 6M6 6l12 12"
/>
</SvgIcon>
</Button>
</Box>
</Show>
</Toast>
</Box>
</FadeInOutWithScaleTransition>
);
}