@lumen-design/alert 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Alert.svelte +77 -0
- package/dist/Alert.svelte.d.ts +16 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +3 -0
- package/dist/types.d.ts +23 -0
- package/dist/types.js +1 -0
- package/package.json +34 -0
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { Snippet } from 'svelte'
|
|
3
|
+
import type { IconNode } from 'lucide'
|
|
4
|
+
import { CheckCircle, AlertTriangle, AlertCircle, Info, X } from 'lucide'
|
|
5
|
+
import Icon from '@lumen-design/icon'
|
|
6
|
+
|
|
7
|
+
interface AlertProps {
|
|
8
|
+
type?: 'info' | 'success' | 'warning' | 'danger'
|
|
9
|
+
title?: string
|
|
10
|
+
closable?: boolean
|
|
11
|
+
showIcon?: boolean
|
|
12
|
+
center?: boolean
|
|
13
|
+
closeText?: string
|
|
14
|
+
duration?: number
|
|
15
|
+
children?: Snippet
|
|
16
|
+
onclose?: () => void
|
|
17
|
+
class?: string
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const ICON_MAP: Record<string, IconNode> = {
|
|
21
|
+
success: CheckCircle,
|
|
22
|
+
warning: AlertTriangle,
|
|
23
|
+
danger: AlertCircle,
|
|
24
|
+
info: Info,
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
let { type = 'info', title, closable = false, showIcon = true, center = false, closeText, duration = 0, children, onclose, class: cls = '', ...attrs }: AlertProps = $props()
|
|
28
|
+
|
|
29
|
+
let visible = $state(true)
|
|
30
|
+
|
|
31
|
+
let timer: ReturnType<typeof setTimeout> | null = null
|
|
32
|
+
|
|
33
|
+
const classes = $derived(`lm-alert lm-alert--${type}${!visible ? ' is-hidden' : ''}${center ? ' is-center' : ''}${cls ? ` ${cls}` : ''}`)
|
|
34
|
+
|
|
35
|
+
const handleClose = (): void => {
|
|
36
|
+
visible = false
|
|
37
|
+
onclose?.()
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
$effect(() => {
|
|
41
|
+
if (!visible || !duration || duration <= 0) return
|
|
42
|
+
if (timer) clearTimeout(timer)
|
|
43
|
+
timer = setTimeout(handleClose, duration)
|
|
44
|
+
return () => {
|
|
45
|
+
if (timer) clearTimeout(timer)
|
|
46
|
+
}
|
|
47
|
+
})
|
|
48
|
+
</script>
|
|
49
|
+
|
|
50
|
+
{#if visible}
|
|
51
|
+
<div {...attrs} class={classes} role="alert">
|
|
52
|
+
{#if showIcon}
|
|
53
|
+
<div class="lm-alert__icon">
|
|
54
|
+
<Icon icon={ICON_MAP[type]} size={20} />
|
|
55
|
+
</div>
|
|
56
|
+
{/if}
|
|
57
|
+
<div class="lm-alert__content">
|
|
58
|
+
{#if title}
|
|
59
|
+
<div class="lm-alert__title">{title}</div>
|
|
60
|
+
{/if}
|
|
61
|
+
{#if children}
|
|
62
|
+
<div class="lm-alert__description">
|
|
63
|
+
{@render children()}
|
|
64
|
+
</div>
|
|
65
|
+
{/if}
|
|
66
|
+
</div>
|
|
67
|
+
{#if closable}
|
|
68
|
+
<button type="button" class="lm-alert__close" onclick={handleClose} aria-label="Close">
|
|
69
|
+
{#if closeText}
|
|
70
|
+
{closeText}
|
|
71
|
+
{:else}
|
|
72
|
+
<Icon icon={X} size={16} />
|
|
73
|
+
{/if}
|
|
74
|
+
</button>
|
|
75
|
+
{/if}
|
|
76
|
+
</div>
|
|
77
|
+
{/if}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
2
|
+
interface AlertProps {
|
|
3
|
+
type?: 'info' | 'success' | 'warning' | 'danger';
|
|
4
|
+
title?: string;
|
|
5
|
+
closable?: boolean;
|
|
6
|
+
showIcon?: boolean;
|
|
7
|
+
center?: boolean;
|
|
8
|
+
closeText?: string;
|
|
9
|
+
duration?: number;
|
|
10
|
+
children?: Snippet;
|
|
11
|
+
onclose?: () => void;
|
|
12
|
+
class?: string;
|
|
13
|
+
}
|
|
14
|
+
declare const Alert: import("svelte").Component<AlertProps, {}, "">;
|
|
15
|
+
type Alert = ReturnType<typeof Alert>;
|
|
16
|
+
export default Alert;
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
2
|
+
export type AlertType = 'info' | 'success' | 'warning' | 'danger';
|
|
3
|
+
export interface AlertProps {
|
|
4
|
+
type?: AlertType;
|
|
5
|
+
title?: string;
|
|
6
|
+
closable?: boolean;
|
|
7
|
+
showIcon?: boolean;
|
|
8
|
+
center?: boolean;
|
|
9
|
+
closeText?: string;
|
|
10
|
+
duration?: number;
|
|
11
|
+
children?: Snippet;
|
|
12
|
+
onclose?: () => void;
|
|
13
|
+
class?: string;
|
|
14
|
+
}
|
|
15
|
+
export interface AlertEmits {
|
|
16
|
+
close: void;
|
|
17
|
+
}
|
|
18
|
+
export interface AlertSlots {
|
|
19
|
+
icon?: any;
|
|
20
|
+
title?: any;
|
|
21
|
+
default?: any;
|
|
22
|
+
actions?: any;
|
|
23
|
+
}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@lumen-design/alert",
|
|
3
|
+
"version": "0.0.2",
|
|
4
|
+
"description": "Alert component for Lumen UI",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"module": "dist/index.js",
|
|
8
|
+
"types": "dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"svelte": "./dist/index.js",
|
|
13
|
+
"import": "./dist/index.js"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist"
|
|
18
|
+
],
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build": "svelte-package -i src -o dist --types",
|
|
21
|
+
"build:watch": "svelte-package -i src -o dist --types -w"
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"@sveltejs/package": "^2.5.7",
|
|
25
|
+
"svelte": "5.48.2"
|
|
26
|
+
},
|
|
27
|
+
"peerDependencies": {
|
|
28
|
+
"svelte": "^5.0.0"
|
|
29
|
+
},
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"@lumen-design/icon": "0.0.2",
|
|
32
|
+
"lucide": "^0.563.0"
|
|
33
|
+
}
|
|
34
|
+
}
|