@luanlu/mk-motion 1.1.0 → 1.2.1
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/package.json +14 -2
- package/src/a11y/focus-trap.ts +64 -0
- package/src/a11y/keyboard.ts +43 -0
- package/src/components/alert/alert.css +111 -0
- package/src/components/alert/alert.ts +107 -0
- package/src/components/avatar/avatar.css +112 -0
- package/src/components/avatar/avatar.ts +175 -0
- package/src/components/breadcrumb/breadcrumb.css +31 -0
- package/src/components/breadcrumb/breadcrumb.ts +71 -0
- package/src/components/button/button.css +108 -0
- package/src/components/button/button.ts +140 -0
- package/src/components/card/card.css +52 -0
- package/src/components/card/card.ts +87 -0
- package/src/components/collapse/collapse.css +76 -0
- package/src/components/collapse/collapse.ts +168 -0
- package/src/components/dialog/dialog.css +78 -0
- package/src/components/dialog/dialog.ts +164 -0
- package/src/components/drawer/drawer.css +73 -0
- package/src/components/drawer/drawer.ts +131 -0
- package/src/components/empty/empty.css +36 -0
- package/src/components/empty/empty.ts +85 -0
- package/src/components/form/checkbox.css +56 -0
- package/src/components/form/checkbox.ts +119 -0
- package/src/components/form/radio.css +57 -0
- package/src/components/form/radio.ts +153 -0
- package/src/components/form/select.css +91 -0
- package/src/components/form/select.ts +174 -0
- package/src/components/form/slider.css +56 -0
- package/src/components/form/slider.ts +148 -0
- package/src/components/input/input.css +92 -0
- package/src/components/input/input.ts +162 -0
- package/src/components/layout/divider.css +32 -0
- package/src/components/layout/divider.ts +42 -0
- package/src/components/layout/row.css +64 -0
- package/src/components/layout/row.ts +57 -0
- package/src/components/layout/space.css +14 -0
- package/src/components/layout/space.ts +48 -0
- package/src/components/loading/loading.css +37 -0
- package/src/components/loading/loading.ts +46 -0
- package/src/components/menu/menu.css +121 -0
- package/src/components/menu/menu.ts +187 -0
- package/src/components/message/message.css +64 -0
- package/src/components/message/message.ts +96 -0
- package/src/components/popover/popover.css +73 -0
- package/src/components/popover/popover.ts +279 -0
- package/src/components/progress/progress.css +112 -0
- package/src/components/progress/progress.ts +171 -0
- package/src/components/steps/steps.css +127 -0
- package/src/components/steps/steps.ts +102 -0
- package/src/components/styles/components.css +28 -0
- package/src/components/styles/reset.css +24 -0
- package/src/components/styles/tokens.css +248 -0
- package/src/components/styles/variables.css +24 -0
- package/src/components/switch/switch.css +53 -0
- package/src/components/switch/switch.ts +103 -0
- package/src/components/table/table.css +192 -0
- package/src/components/table/table.ts +370 -0
- package/src/components/tabs/tabs.css +138 -0
- package/src/components/tabs/tabs.ts +211 -0
- package/src/components/tag/tag.css +123 -0
- package/src/components/tag/tag.ts +112 -0
- package/src/components/tooltip/tooltip.css +66 -0
- package/src/components/tooltip/tooltip.ts +185 -0
- package/src/core/animator.ts +124 -0
- package/src/core/timeline.ts +128 -0
- package/src/core/utils.ts +47 -0
- package/src/effects/glitch.ts +99 -0
- package/src/effects/particle.ts +134 -0
- package/src/effects/text-split.ts +95 -0
- package/src/effects/wave-text.ts +88 -0
- package/src/gesture/draggable.ts +130 -0
- package/src/gesture/spring.ts +152 -0
- package/src/index.ts +162 -0
- package/src/interactive/coverflow.ts +100 -0
- package/src/interactive/cursor-trail.ts +113 -0
- package/src/interactive/flip-card.ts +114 -0
- package/src/interactive/magnetic.ts +121 -0
- package/src/micro/hover-lift.ts +94 -0
- package/src/micro/ripple.ts +130 -0
- package/src/motion/component-motion.ts +177 -0
- package/src/nuxt/module.ts +46 -0
- package/src/presets/index.ts +69 -0
- package/src/scroll/scroll-trigger.ts +104 -0
- package/src/styles/animations.css +135 -0
- package/src/styles/element-plus.css +174 -0
- package/src/text/count-up.ts +108 -0
- package/src/text/typewriter.ts +109 -0
- package/src/theme/dark.css +19 -0
- package/src/theme/light.css +19 -0
- package/src/theme/theme.ts +65 -0
- package/src/transitions/blur-reveal.ts +92 -0
- package/src/transitions/collapse.ts +112 -0
- package/src/transitions/lazy-image.ts +87 -0
- package/src/transitions/list.ts +75 -0
- package/src/transitions/loading.ts +95 -0
- package/src/transitions/parallax.ts +60 -0
- package/src/transitions/shimmer.ts +105 -0
- package/src/transitions/toast.ts +151 -0
- package/src/types.d.ts +4 -0
- package/src/vite/plugin.ts +45 -0
- package/src/vue/button.ts +28 -9
- package/src/vue/card.ts +28 -8
- package/src/vue/composables/index.ts +4 -0
- package/src/vue/composables/useLoading.ts +12 -0
- package/src/vue/composables/useMessage.ts +16 -0
- package/src/vue/composables/useMotion.ts +19 -0
- package/src/vue/composables/useTheme.ts +12 -0
- package/src/vue/dialog.ts +69 -17
- package/src/vue/index.ts +4 -21
- package/src/vue/input.ts +35 -11
- package/src/vue/slider.ts +22 -4
- package/src/vue/switch.ts +16 -9
- package/src/vue/alert.ts +0 -32
- package/src/vue/avatar.ts +0 -34
- package/src/vue/breadcrumb.ts +0 -32
- package/src/vue/checkbox.ts +0 -32
- package/src/vue/collapse.ts +0 -33
- package/src/vue/divider.ts +0 -32
- package/src/vue/drawer.ts +0 -33
- package/src/vue/empty.ts +0 -33
- package/src/vue/menu.ts +0 -33
- package/src/vue/popover.ts +0 -34
- package/src/vue/progress.ts +0 -33
- package/src/vue/row.ts +0 -32
- package/src/vue/select.ts +0 -33
- package/src/vue/space.ts +0 -32
- package/src/vue/steps.ts +0 -33
- package/src/vue/table.ts +0 -33
- package/src/vue/tabs.ts +0 -33
- package/src/vue/tag.ts +0 -33
- package/src/vue/tooltip.ts +0 -34
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import './loading.css'
|
|
2
|
+
|
|
3
|
+
export interface LoadingOptions {
|
|
4
|
+
text?: string
|
|
5
|
+
fullscreen?: boolean
|
|
6
|
+
target?: HTMLElement | string
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function showLoading(options: LoadingOptions = {}): () => void {
|
|
10
|
+
const mask = document.createElement('div')
|
|
11
|
+
mask.className = 'mk-loading-mask'
|
|
12
|
+
|
|
13
|
+
if (options.fullscreen) {
|
|
14
|
+
mask.classList.add('is-fullscreen')
|
|
15
|
+
document.body.appendChild(mask)
|
|
16
|
+
} else {
|
|
17
|
+
const target =
|
|
18
|
+
typeof options.target === 'string'
|
|
19
|
+
? document.querySelector<HTMLElement>(options.target)!
|
|
20
|
+
: options.target || document.body
|
|
21
|
+
|
|
22
|
+
if (target && target !== document.body) {
|
|
23
|
+
target.style.position = 'relative'
|
|
24
|
+
}
|
|
25
|
+
;(target || document.body).appendChild(mask)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const spinner = document.createElement('div')
|
|
29
|
+
spinner.className = 'mk-loading__spinner'
|
|
30
|
+
mask.appendChild(spinner)
|
|
31
|
+
|
|
32
|
+
if (options.text) {
|
|
33
|
+
const text = document.createElement('div')
|
|
34
|
+
text.className = 'mk-loading__text'
|
|
35
|
+
text.textContent = options.text
|
|
36
|
+
mask.appendChild(text)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return () => {
|
|
40
|
+
mask.remove()
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function showFullscreenLoading(text?: string): () => void {
|
|
45
|
+
return showLoading({ fullscreen: true, text })
|
|
46
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
.mk-menu {
|
|
2
|
+
list-style: none;
|
|
3
|
+
padding: 8px 0;
|
|
4
|
+
margin: 0;
|
|
5
|
+
font-size: var(--mk-text-sm);
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
.mk-menu--horizontal {
|
|
9
|
+
display: flex;
|
|
10
|
+
padding: 0;
|
|
11
|
+
border-bottom: 1px solid var(--mk-border);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
.mk-menu-item {
|
|
15
|
+
position: relative;
|
|
16
|
+
transition: var(--mk-transition-colors);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
.mk-menu-item__title {
|
|
20
|
+
display: flex;
|
|
21
|
+
align-items: center;
|
|
22
|
+
gap: 10px;
|
|
23
|
+
padding: 9px 16px;
|
|
24
|
+
color: var(--mk-text-secondary);
|
|
25
|
+
transition: var(--mk-transition-colors);
|
|
26
|
+
border-radius: 6px;
|
|
27
|
+
margin: 2px 8px;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
.mk-menu--horizontal .mk-menu-item__title {
|
|
31
|
+
margin: 0;
|
|
32
|
+
border-radius: 0;
|
|
33
|
+
padding: 12px 16px;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
.mk-menu-item__title:hover {
|
|
37
|
+
color: var(--mk-text);
|
|
38
|
+
background: var(--mk-surface-hover);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
.mk-menu-item.is-active > .mk-menu-item__title {
|
|
42
|
+
color: var(--mk-primary);
|
|
43
|
+
background: var(--mk-primary-muted);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
.mk-menu-item.is-disabled > .mk-menu-item__title {
|
|
47
|
+
opacity: 0.4;
|
|
48
|
+
cursor: not-allowed;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
.mk-menu-item__icon {
|
|
52
|
+
width: 18px;
|
|
53
|
+
text-align: center;
|
|
54
|
+
font-size: 14px;
|
|
55
|
+
flex-shrink: 0;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
.mk-menu-item__text {
|
|
59
|
+
flex: 1;
|
|
60
|
+
white-space: nowrap;
|
|
61
|
+
overflow: hidden;
|
|
62
|
+
text-overflow: ellipsis;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
.mk-menu-item__arrow {
|
|
66
|
+
font-size: 14px;
|
|
67
|
+
transition: transform 0.2s;
|
|
68
|
+
color: var(--mk-text-tertiary);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
.mk-menu-item.is-open > .mk-menu-item__title .mk-menu-item__arrow {
|
|
72
|
+
transform: rotate(90deg);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
.mk-menu-submenu {
|
|
76
|
+
list-style: none;
|
|
77
|
+
padding: 0;
|
|
78
|
+
margin: 0;
|
|
79
|
+
max-height: 0;
|
|
80
|
+
overflow: hidden;
|
|
81
|
+
transition: max-height 0.3s var(--mk-ease-default);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
.mk-menu-submenu.is-open {
|
|
85
|
+
max-height: 1000px;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
.mk-menu--horizontal .mk-menu-submenu {
|
|
89
|
+
position: absolute;
|
|
90
|
+
top: 100%;
|
|
91
|
+
left: 0;
|
|
92
|
+
min-width: 180px;
|
|
93
|
+
background: var(--mk-surface);
|
|
94
|
+
border: 1px solid var(--mk-border);
|
|
95
|
+
border-radius: var(--mk-radius);
|
|
96
|
+
box-shadow: var(--mk-shadow-lg);
|
|
97
|
+
z-index: var(--mk-z-dropdown);
|
|
98
|
+
max-height: none;
|
|
99
|
+
display: none;
|
|
100
|
+
padding: 4px 0;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
.mk-menu--horizontal .mk-menu-item.has-children:hover > .mk-menu-submenu {
|
|
104
|
+
display: block;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/* Collapsed mode */
|
|
108
|
+
.mk-menu.is-collapse .mk-menu-item__text,
|
|
109
|
+
.mk-menu.is-collapse .mk-menu-item__arrow {
|
|
110
|
+
display: none;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
.mk-menu.is-collapse .mk-menu-item__title {
|
|
114
|
+
justify-content: center;
|
|
115
|
+
padding: 12px 0;
|
|
116
|
+
margin: 2px 8px;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
.mk-menu.is-collapse .mk-menu-submenu {
|
|
120
|
+
display: none !important;
|
|
121
|
+
}
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import './menu.css'
|
|
2
|
+
import { Keys } from '../../a11y/keyboard'
|
|
3
|
+
|
|
4
|
+
export interface MenuItem {
|
|
5
|
+
index: string
|
|
6
|
+
label: string
|
|
7
|
+
icon?: string
|
|
8
|
+
disabled?: boolean
|
|
9
|
+
children?: MenuItem[]
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface MenuOptions {
|
|
13
|
+
mode?: 'vertical' | 'horizontal'
|
|
14
|
+
items: MenuItem[]
|
|
15
|
+
defaultActive?: string
|
|
16
|
+
defaultOpeneds?: string[]
|
|
17
|
+
collapse?: boolean
|
|
18
|
+
onSelect?: (index: string) => void
|
|
19
|
+
onOpen?: (index: string) => void
|
|
20
|
+
onClose?: (index: string) => void
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export class MkMenu {
|
|
24
|
+
el: HTMLElement
|
|
25
|
+
private options: MenuOptions
|
|
26
|
+
private openeds: Set<string>
|
|
27
|
+
private activeIndex: string
|
|
28
|
+
|
|
29
|
+
constructor(container: HTMLElement | string, options: MenuOptions) {
|
|
30
|
+
const parent = typeof container === 'string' ? document.querySelector(container)! : container
|
|
31
|
+
this.options = { mode: 'vertical', collapse: false, ...options }
|
|
32
|
+
this.openeds = new Set(options.defaultOpeneds || [])
|
|
33
|
+
this.activeIndex = options.defaultActive || ''
|
|
34
|
+
|
|
35
|
+
this.el = document.createElement('ul')
|
|
36
|
+
this.el.className = `mk-menu mk-menu--${this.options.mode}`
|
|
37
|
+
if (this.options.collapse) this.el.classList.add('is-collapse')
|
|
38
|
+
this.el.setAttribute('role', 'menu')
|
|
39
|
+
|
|
40
|
+
this.render()
|
|
41
|
+
parent.appendChild(this.el)
|
|
42
|
+
|
|
43
|
+
this.setupKeyboard()
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
private render(): void {
|
|
47
|
+
this.el.innerHTML = ''
|
|
48
|
+
this.options.items.forEach(item => {
|
|
49
|
+
this.el.appendChild(this.renderItem(item, 0))
|
|
50
|
+
})
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
private renderItem(item: MenuItem, level: number): HTMLElement {
|
|
54
|
+
const hasChildren = item.children && item.children.length > 0
|
|
55
|
+
const isOpen = this.openeds.has(item.index)
|
|
56
|
+
const isActive = this.activeIndex === item.index
|
|
57
|
+
const isCollapsed = this.options.collapse && this.options.mode === 'vertical'
|
|
58
|
+
|
|
59
|
+
const li = document.createElement('li')
|
|
60
|
+
li.className = 'mk-menu-item'
|
|
61
|
+
if (item.disabled) li.classList.add('is-disabled')
|
|
62
|
+
if (isActive) li.classList.add('is-active')
|
|
63
|
+
if (hasChildren) li.classList.add('has-children')
|
|
64
|
+
if (isOpen) li.classList.add('is-open')
|
|
65
|
+
li.style.paddingLeft = isCollapsed ? '0' : `${16 + level * 16}px`
|
|
66
|
+
|
|
67
|
+
const title = document.createElement('div')
|
|
68
|
+
title.className = 'mk-menu-item__title'
|
|
69
|
+
title.style.cursor = item.disabled ? 'not-allowed' : 'pointer'
|
|
70
|
+
title.setAttribute('role', 'menuitem')
|
|
71
|
+
title.setAttribute('tabindex', item.disabled ? '-1' : '0')
|
|
72
|
+
if (item.disabled) {
|
|
73
|
+
title.setAttribute('aria-disabled', 'true')
|
|
74
|
+
}
|
|
75
|
+
if (hasChildren) {
|
|
76
|
+
title.setAttribute('aria-haspopup', 'true')
|
|
77
|
+
title.setAttribute('aria-expanded', String(isOpen))
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (item.icon) {
|
|
81
|
+
const icon = document.createElement('span')
|
|
82
|
+
icon.className = 'mk-menu-item__icon'
|
|
83
|
+
icon.textContent = item.icon
|
|
84
|
+
title.appendChild(icon)
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const text = document.createElement('span')
|
|
88
|
+
text.className = 'mk-menu-item__text'
|
|
89
|
+
text.textContent = item.label
|
|
90
|
+
title.appendChild(text)
|
|
91
|
+
|
|
92
|
+
if (hasChildren && !isCollapsed) {
|
|
93
|
+
const arrow = document.createElement('span')
|
|
94
|
+
arrow.className = 'mk-menu-item__arrow'
|
|
95
|
+
arrow.textContent = '›'
|
|
96
|
+
title.appendChild(arrow)
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
title.addEventListener('click', () => {
|
|
100
|
+
if (item.disabled) return
|
|
101
|
+
if (hasChildren) {
|
|
102
|
+
if (isOpen) {
|
|
103
|
+
this.openeds.delete(item.index)
|
|
104
|
+
this.options.onClose?.(item.index)
|
|
105
|
+
} else {
|
|
106
|
+
this.openeds.add(item.index)
|
|
107
|
+
this.options.onOpen?.(item.index)
|
|
108
|
+
}
|
|
109
|
+
this.render()
|
|
110
|
+
} else {
|
|
111
|
+
this.activeIndex = item.index
|
|
112
|
+
this.options.onSelect?.(item.index)
|
|
113
|
+
this.render()
|
|
114
|
+
}
|
|
115
|
+
})
|
|
116
|
+
|
|
117
|
+
li.appendChild(title)
|
|
118
|
+
|
|
119
|
+
if (hasChildren && !isCollapsed) {
|
|
120
|
+
const sub = document.createElement('ul')
|
|
121
|
+
sub.className = 'mk-menu-submenu'
|
|
122
|
+
if (isOpen) sub.classList.add('is-open')
|
|
123
|
+
sub.setAttribute('role', 'menu')
|
|
124
|
+
item.children!.forEach(child => {
|
|
125
|
+
sub.appendChild(this.renderItem(child, level + 1))
|
|
126
|
+
})
|
|
127
|
+
li.appendChild(sub)
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
return li
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
private setupKeyboard(): void {
|
|
134
|
+
this.el.addEventListener('keydown', (e) => {
|
|
135
|
+
const active = document.activeElement as HTMLElement
|
|
136
|
+
if (!active?.classList.contains('mk-menu-item__title')) return
|
|
137
|
+
|
|
138
|
+
const li = active.parentElement as HTMLLIElement
|
|
139
|
+
const ul = li.parentElement as HTMLUListElement
|
|
140
|
+
const items = Array.from(ul.children)
|
|
141
|
+
.filter((el): el is HTMLLIElement => el.classList.contains('mk-menu-item'))
|
|
142
|
+
.map((li) => li.querySelector('.mk-menu-item__title') as HTMLElement)
|
|
143
|
+
.filter(Boolean)
|
|
144
|
+
|
|
145
|
+
const index = items.indexOf(active)
|
|
146
|
+
|
|
147
|
+
switch (e.key) {
|
|
148
|
+
case Keys.ArrowDown:
|
|
149
|
+
e.preventDefault()
|
|
150
|
+
items[index + 1]?.focus()
|
|
151
|
+
break
|
|
152
|
+
case Keys.ArrowUp:
|
|
153
|
+
e.preventDefault()
|
|
154
|
+
items[index - 1]?.focus()
|
|
155
|
+
break
|
|
156
|
+
case Keys.Enter:
|
|
157
|
+
case Keys.Space:
|
|
158
|
+
e.preventDefault()
|
|
159
|
+
active.click()
|
|
160
|
+
break
|
|
161
|
+
case Keys.Escape:
|
|
162
|
+
e.preventDefault()
|
|
163
|
+
// Close parent submenu if inside one
|
|
164
|
+
const parentLi = ul.closest('.mk-menu-item') as HTMLLIElement | null
|
|
165
|
+
if (parentLi && ul !== this.el) {
|
|
166
|
+
const parentTitle = parentLi.querySelector('.mk-menu-item__title') as HTMLElement | null
|
|
167
|
+
if (parentTitle) {
|
|
168
|
+
const isExpanded = parentTitle.getAttribute('aria-expanded') === 'true'
|
|
169
|
+
if (isExpanded) {
|
|
170
|
+
parentTitle.click()
|
|
171
|
+
parentTitle.focus()
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
break
|
|
176
|
+
}
|
|
177
|
+
})
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
destroy(): void {
|
|
181
|
+
this.el.remove()
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
export function createMenu(container: HTMLElement | string, options: MenuOptions): MkMenu {
|
|
186
|
+
return new MkMenu(container, options)
|
|
187
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
.mk-message-container {
|
|
2
|
+
position: fixed;
|
|
3
|
+
top: 16px;
|
|
4
|
+
left: 50%;
|
|
5
|
+
transform: translateX(-50%);
|
|
6
|
+
z-index: 9999;
|
|
7
|
+
display: flex;
|
|
8
|
+
flex-direction: column;
|
|
9
|
+
gap: 8px;
|
|
10
|
+
pointer-events: none;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
.mk-message {
|
|
14
|
+
display: inline-flex;
|
|
15
|
+
align-items: center;
|
|
16
|
+
gap: 10px;
|
|
17
|
+
padding: 10px 16px;
|
|
18
|
+
border-radius: var(--mk-radius);
|
|
19
|
+
font-size: 13px;
|
|
20
|
+
background: var(--mk-surface);
|
|
21
|
+
border: 1px solid var(--mk-border);
|
|
22
|
+
pointer-events: auto;
|
|
23
|
+
min-width: 260px;
|
|
24
|
+
opacity: 0;
|
|
25
|
+
transform: translateY(-12px);
|
|
26
|
+
transition: all 0.2s ease;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
.mk-message.is-show {
|
|
30
|
+
opacity: 1;
|
|
31
|
+
transform: translateY(0);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
.mk-message__icon {
|
|
35
|
+
width: 18px; height: 18px;
|
|
36
|
+
display: flex; align-items: center; justify-content: center;
|
|
37
|
+
font-size: 13px;
|
|
38
|
+
flex-shrink: 0;
|
|
39
|
+
border-radius: 50%;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
.mk-message__content {
|
|
43
|
+
flex: 1;
|
|
44
|
+
color: var(--mk-text);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
.mk-message__close {
|
|
48
|
+
cursor: pointer;
|
|
49
|
+
color: var(--mk-text-tertiary);
|
|
50
|
+
font-size: 11px;
|
|
51
|
+
width: 20px; height: 20px;
|
|
52
|
+
display: flex; align-items: center; justify-content: center;
|
|
53
|
+
border-radius: 4px;
|
|
54
|
+
transition: var(--mk-transition);
|
|
55
|
+
}
|
|
56
|
+
.mk-message__close:hover {
|
|
57
|
+
color: var(--mk-text);
|
|
58
|
+
background: var(--mk-surface-hover);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
.mk-message--success .mk-message__icon { color: var(--mk-success); }
|
|
62
|
+
.mk-message--warning .mk-message__icon { color: var(--mk-warning); }
|
|
63
|
+
.mk-message--error .mk-message__icon { color: var(--mk-danger); }
|
|
64
|
+
.mk-message--info .mk-message__icon { color: var(--mk-primary); }
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import './message.css'
|
|
2
|
+
|
|
3
|
+
export interface MessageOptions {
|
|
4
|
+
type?: 'success' | 'warning' | 'error' | 'info'
|
|
5
|
+
duration?: number
|
|
6
|
+
closable?: boolean
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const ICONS: Record<string, string> = {
|
|
10
|
+
success: '✓',
|
|
11
|
+
warning: '!',
|
|
12
|
+
error: '✕',
|
|
13
|
+
info: 'i',
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const COLORS: Record<string, string> = {
|
|
17
|
+
success: '#67c23a',
|
|
18
|
+
warning: '#e6a23c',
|
|
19
|
+
error: '#f56c6c',
|
|
20
|
+
info: '#409eff',
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
let container: HTMLDivElement | null = null
|
|
24
|
+
|
|
25
|
+
function getContainer(): HTMLDivElement {
|
|
26
|
+
if (!container) {
|
|
27
|
+
container = document.createElement('div')
|
|
28
|
+
container.className = 'mk-message-container'
|
|
29
|
+
document.body.appendChild(container)
|
|
30
|
+
}
|
|
31
|
+
return container
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function message(
|
|
35
|
+
msg: string,
|
|
36
|
+
options: MessageOptions = {}
|
|
37
|
+
): () => void {
|
|
38
|
+
const opts = { type: 'info', duration: 3000, closable: true, ...options }
|
|
39
|
+
const el = document.createElement('div')
|
|
40
|
+
el.className = `mk-message mk-message--${opts.type}`
|
|
41
|
+
|
|
42
|
+
const iconWrap = document.createElement('span')
|
|
43
|
+
iconWrap.className = 'mk-message__icon'
|
|
44
|
+
iconWrap.style.color = COLORS[opts.type!]
|
|
45
|
+
iconWrap.textContent = ICONS[opts.type!]
|
|
46
|
+
el.appendChild(iconWrap)
|
|
47
|
+
|
|
48
|
+
const content = document.createElement('span')
|
|
49
|
+
content.className = 'mk-message__content'
|
|
50
|
+
content.textContent = msg
|
|
51
|
+
el.appendChild(content)
|
|
52
|
+
|
|
53
|
+
if (opts.closable) {
|
|
54
|
+
const close = document.createElement('span')
|
|
55
|
+
close.className = 'mk-message__close'
|
|
56
|
+
close.innerHTML = '✕'
|
|
57
|
+
close.addEventListener('click', () => removeMessage(el))
|
|
58
|
+
el.appendChild(close)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
getContainer().appendChild(el)
|
|
62
|
+
|
|
63
|
+
requestAnimationFrame(() => el.classList.add('is-show'))
|
|
64
|
+
|
|
65
|
+
const timer = setTimeout(() => removeMessage(el), opts.duration)
|
|
66
|
+
|
|
67
|
+
return () => {
|
|
68
|
+
clearTimeout(timer)
|
|
69
|
+
removeMessage(el)
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function removeMessage(el: HTMLDivElement): void {
|
|
74
|
+
el.classList.remove('is-show')
|
|
75
|
+
el.style.opacity = '0'
|
|
76
|
+
el.style.transform = 'translateY(-20px) scale(0.95)'
|
|
77
|
+
setTimeout(() => {
|
|
78
|
+
el.remove()
|
|
79
|
+
if (container && container.children.length === 0) {
|
|
80
|
+
container.remove()
|
|
81
|
+
container = null
|
|
82
|
+
}
|
|
83
|
+
}, 300)
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export function messageSuccess(msg: string, options?: Omit<MessageOptions, 'type'>): () => void {
|
|
87
|
+
return message(msg, { ...options, type: 'success' })
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export function messageError(msg: string, options?: Omit<MessageOptions, 'type'>): () => void {
|
|
91
|
+
return message(msg, { ...options, type: 'error' })
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export function messageWarning(msg: string, options?: Omit<MessageOptions, 'type'>): () => void {
|
|
95
|
+
return message(msg, { ...options, type: 'warning' })
|
|
96
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
.mk-popover {
|
|
2
|
+
display: none;
|
|
3
|
+
opacity: 0;
|
|
4
|
+
transform: scale(0.96) translateY(2px);
|
|
5
|
+
transition: opacity var(--mk-duration-fast) var(--mk-ease-default),
|
|
6
|
+
transform var(--mk-duration-fast) var(--mk-ease-out);
|
|
7
|
+
filter: drop-shadow(var(--mk-shadow-lg));
|
|
8
|
+
background: var(--mk-surface-raised);
|
|
9
|
+
border: 1px solid var(--mk-border-hover);
|
|
10
|
+
border-radius: var(--mk-radius-md);
|
|
11
|
+
max-width: 320px;
|
|
12
|
+
pointer-events: auto;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
.mk-popover.is-visible {
|
|
16
|
+
opacity: 1;
|
|
17
|
+
transform: scale(1) translateY(0);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
.mk-popover__title {
|
|
21
|
+
padding: var(--mk-space-3) var(--mk-space-4) 0;
|
|
22
|
+
font-size: var(--mk-text-sm);
|
|
23
|
+
font-weight: var(--mk-font-semibold);
|
|
24
|
+
line-height: var(--mk-leading-tight);
|
|
25
|
+
color: var(--mk-text);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
.mk-popover__content {
|
|
29
|
+
padding: var(--mk-space-3) var(--mk-space-4);
|
|
30
|
+
font-size: var(--mk-text-sm);
|
|
31
|
+
line-height: var(--mk-leading-normal);
|
|
32
|
+
color: var(--mk-text-secondary);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
.mk-popover__arrow {
|
|
36
|
+
position: absolute;
|
|
37
|
+
width: 8px;
|
|
38
|
+
height: 8px;
|
|
39
|
+
background: var(--mk-surface-raised);
|
|
40
|
+
border: 1px solid var(--mk-border-hover);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
.mk-popover__arrow.is-top {
|
|
44
|
+
top: -4px;
|
|
45
|
+
left: 50%;
|
|
46
|
+
transform: translateX(-50%) rotate(45deg);
|
|
47
|
+
border-right: none;
|
|
48
|
+
border-bottom: none;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
.mk-popover__arrow.is-bottom {
|
|
52
|
+
bottom: -4px;
|
|
53
|
+
left: 50%;
|
|
54
|
+
transform: translateX(-50%) rotate(45deg);
|
|
55
|
+
border-left: none;
|
|
56
|
+
border-top: none;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
.mk-popover__arrow.is-left {
|
|
60
|
+
left: -4px;
|
|
61
|
+
top: 50%;
|
|
62
|
+
transform: translateY(-50%) rotate(45deg);
|
|
63
|
+
border-right: none;
|
|
64
|
+
border-top: none;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
.mk-popover__arrow.is-right {
|
|
68
|
+
right: -4px;
|
|
69
|
+
top: 50%;
|
|
70
|
+
transform: translateY(-50%) rotate(45deg);
|
|
71
|
+
border-left: none;
|
|
72
|
+
border-bottom: none;
|
|
73
|
+
}
|