-
Notifications
You must be signed in to change notification settings - Fork 183
/
Alert.svelte
52 lines (49 loc) · 1.28 KB
/
Alert.svelte
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
<script>
import { fade as fadeTransition } from 'svelte/transition';
import classnames from './utils';
let className = '';
export { className as class };
export let children = undefined;
export let color = 'success';
export let closeClassName = '';
export let closeAriaLabel = 'Close';
export let dismissible = false;
export let heading = undefined;
export let isOpen = true;
export let toggle = undefined;
export let fade = true;
export let transition = { duration: fade ? 400 : 0 };
$: showClose = dismissible || toggle;
$: handleToggle = toggle || (() => (isOpen = false));
$: classes = classnames(className, 'alert', `alert-${color}`, {
'alert-dismissible': showClose
});
$: closeClassNames = classnames('btn-close', closeClassName);
</script>
{#if isOpen}
<div
{...$$restProps}
transition:fadeTransition={transition}
class={classes}
role="alert"
>
{#if heading || $$slots.heading}
<h4 class="alert-heading">
{heading}<slot name="heading" />
</h4>
{/if}
{#if showClose}
<button
type="button"
class={closeClassNames}
aria-label={closeAriaLabel}
on:click={handleToggle}
/>
{/if}
{#if children}
{children}
{:else}
<slot />
{/if}
</div>
{/if}