@luanlu/mk-motion 1.2.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 +2 -4
- 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/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
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
.mk-dialog-overlay {
|
|
2
|
+
position: fixed;
|
|
3
|
+
inset: 0;
|
|
4
|
+
background: rgba(0, 0, 0, 0.6);
|
|
5
|
+
display: flex;
|
|
6
|
+
align-items: center;
|
|
7
|
+
justify-content: center;
|
|
8
|
+
z-index: 2000;
|
|
9
|
+
opacity: 0;
|
|
10
|
+
transition: opacity 0.2s ease;
|
|
11
|
+
}
|
|
12
|
+
.mk-dialog-overlay.is-open { opacity: 1; }
|
|
13
|
+
|
|
14
|
+
.mk-dialog {
|
|
15
|
+
background: var(--mk-surface);
|
|
16
|
+
border: 1px solid var(--mk-border);
|
|
17
|
+
border-radius: var(--mk-radius-lg);
|
|
18
|
+
min-width: 400px;
|
|
19
|
+
max-width: 90vw;
|
|
20
|
+
max-height: 85vh;
|
|
21
|
+
display: flex;
|
|
22
|
+
flex-direction: column;
|
|
23
|
+
transform: scale(0.95);
|
|
24
|
+
opacity: 0;
|
|
25
|
+
transition: all 0.2s ease;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
.mk-dialog-overlay.is-open .mk-dialog {
|
|
29
|
+
transform: scale(1);
|
|
30
|
+
opacity: 1;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
.mk-dialog__header {
|
|
34
|
+
padding: 18px 20px 14px;
|
|
35
|
+
display: flex;
|
|
36
|
+
align-items: center;
|
|
37
|
+
justify-content: space-between;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
.mk-dialog__title {
|
|
41
|
+
font-size: 15px;
|
|
42
|
+
font-weight: 600;
|
|
43
|
+
color: var(--mk-text);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
.mk-dialog__close {
|
|
47
|
+
cursor: pointer;
|
|
48
|
+
color: var(--mk-text-tertiary);
|
|
49
|
+
font-size: 16px;
|
|
50
|
+
width: 24px; height: 24px;
|
|
51
|
+
display: flex; align-items: center; justify-content: center;
|
|
52
|
+
border-radius: 4px;
|
|
53
|
+
transition: var(--mk-transition);
|
|
54
|
+
}
|
|
55
|
+
.mk-dialog__close:hover {
|
|
56
|
+
color: var(--mk-text);
|
|
57
|
+
background: var(--mk-surface-hover);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
.mk-dialog__body {
|
|
61
|
+
padding: 6px 20px 18px;
|
|
62
|
+
overflow-y: auto;
|
|
63
|
+
flex: 1;
|
|
64
|
+
color: var(--mk-text-secondary);
|
|
65
|
+
font-size: 13px;
|
|
66
|
+
line-height: 1.6;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
.mk-dialog__footer {
|
|
70
|
+
padding: 12px 20px 16px;
|
|
71
|
+
display: flex;
|
|
72
|
+
justify-content: flex-end;
|
|
73
|
+
gap: 8px;
|
|
74
|
+
border-top: 1px solid var(--mk-border);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
.mk-dialog.is-center { text-align: center; }
|
|
78
|
+
.mk-dialog.is-center .mk-dialog__footer { justify-content: center; }
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import '../button/button.css'
|
|
2
|
+
import './dialog.css'
|
|
3
|
+
import { FocusTrap } from '../../a11y/focus-trap'
|
|
4
|
+
import { onKey, Keys } from '../../a11y/keyboard'
|
|
5
|
+
|
|
6
|
+
export interface DialogOptions {
|
|
7
|
+
title?: string
|
|
8
|
+
content?: string | HTMLElement
|
|
9
|
+
showClose?: boolean
|
|
10
|
+
showCancel?: boolean
|
|
11
|
+
center?: boolean
|
|
12
|
+
cancelText?: string
|
|
13
|
+
confirmText?: string
|
|
14
|
+
onConfirm?: () => void
|
|
15
|
+
onCancel?: () => void
|
|
16
|
+
onClose?: () => void
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
let dialogIdCounter = 0
|
|
20
|
+
|
|
21
|
+
export class MkDialog {
|
|
22
|
+
private overlay: HTMLDivElement
|
|
23
|
+
private dialog: HTMLDivElement
|
|
24
|
+
private options: DialogOptions
|
|
25
|
+
private focusTrap: FocusTrap
|
|
26
|
+
private escapeCleanup: (() => void) | null = null
|
|
27
|
+
private confirmBtn: HTMLButtonElement
|
|
28
|
+
private titleId: string
|
|
29
|
+
|
|
30
|
+
constructor(options: DialogOptions = {}) {
|
|
31
|
+
this.options = {
|
|
32
|
+
showClose: true,
|
|
33
|
+
showCancel: true,
|
|
34
|
+
...options,
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
this.overlay = document.createElement('div')
|
|
38
|
+
this.overlay.className = 'mk-dialog-overlay'
|
|
39
|
+
this.overlay.style.display = 'none'
|
|
40
|
+
|
|
41
|
+
this.dialog = document.createElement('div')
|
|
42
|
+
this.dialog.className = 'mk-dialog'
|
|
43
|
+
if (this.options.center) this.dialog.classList.add('is-center')
|
|
44
|
+
this.dialog.setAttribute('role', 'dialog')
|
|
45
|
+
this.dialog.setAttribute('aria-modal', 'true')
|
|
46
|
+
|
|
47
|
+
// Header
|
|
48
|
+
const header = document.createElement('div')
|
|
49
|
+
header.className = 'mk-dialog__header'
|
|
50
|
+
|
|
51
|
+
const title = document.createElement('span')
|
|
52
|
+
title.className = 'mk-dialog__title'
|
|
53
|
+
title.textContent = this.options.title || ''
|
|
54
|
+
this.titleId = `mk-dialog-title-${++dialogIdCounter}`
|
|
55
|
+
title.id = this.titleId
|
|
56
|
+
this.dialog.setAttribute('aria-labelledby', this.titleId)
|
|
57
|
+
header.appendChild(title)
|
|
58
|
+
|
|
59
|
+
if (this.options.showClose) {
|
|
60
|
+
const close = document.createElement('span')
|
|
61
|
+
close.className = 'mk-dialog__close'
|
|
62
|
+
close.innerHTML = '✕'
|
|
63
|
+
close.setAttribute('role', 'button')
|
|
64
|
+
close.setAttribute('tabindex', '0')
|
|
65
|
+
close.setAttribute('aria-label', 'Close')
|
|
66
|
+
close.addEventListener('click', () => this.close())
|
|
67
|
+
close.addEventListener('keydown', (e) => {
|
|
68
|
+
if (e.key === 'Enter' || e.key === ' ') {
|
|
69
|
+
e.preventDefault()
|
|
70
|
+
this.close()
|
|
71
|
+
}
|
|
72
|
+
})
|
|
73
|
+
header.appendChild(close)
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
this.dialog.appendChild(header)
|
|
77
|
+
|
|
78
|
+
// Body
|
|
79
|
+
const body = document.createElement('div')
|
|
80
|
+
body.className = 'mk-dialog__body'
|
|
81
|
+
if (typeof this.options.content === 'string') {
|
|
82
|
+
body.innerHTML = this.options.content
|
|
83
|
+
} else if (this.options.content) {
|
|
84
|
+
body.appendChild(this.options.content)
|
|
85
|
+
}
|
|
86
|
+
this.dialog.appendChild(body)
|
|
87
|
+
|
|
88
|
+
// Footer
|
|
89
|
+
const footer = document.createElement('div')
|
|
90
|
+
footer.className = 'mk-dialog__footer'
|
|
91
|
+
|
|
92
|
+
if (this.options.showCancel) {
|
|
93
|
+
const cancelBtn = document.createElement('button')
|
|
94
|
+
cancelBtn.className = 'mk-button'
|
|
95
|
+
cancelBtn.textContent = this.options.cancelText || '取消'
|
|
96
|
+
cancelBtn.addEventListener('click', () => {
|
|
97
|
+
this.options.onCancel?.()
|
|
98
|
+
this.close()
|
|
99
|
+
})
|
|
100
|
+
footer.appendChild(cancelBtn)
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
this.confirmBtn = document.createElement('button')
|
|
104
|
+
this.confirmBtn.className = 'mk-button mk-button--primary'
|
|
105
|
+
this.confirmBtn.textContent = this.options.confirmText || '确定'
|
|
106
|
+
this.confirmBtn.addEventListener('click', () => {
|
|
107
|
+
this.options.onConfirm?.()
|
|
108
|
+
this.close()
|
|
109
|
+
})
|
|
110
|
+
footer.appendChild(this.confirmBtn)
|
|
111
|
+
|
|
112
|
+
this.dialog.appendChild(footer)
|
|
113
|
+
|
|
114
|
+
this.overlay.appendChild(this.dialog)
|
|
115
|
+
|
|
116
|
+
this.overlay.addEventListener('click', (e) => {
|
|
117
|
+
if (e.target === this.overlay) {
|
|
118
|
+
this.options.onClose?.()
|
|
119
|
+
this.close()
|
|
120
|
+
}
|
|
121
|
+
})
|
|
122
|
+
|
|
123
|
+
document.body.appendChild(this.overlay)
|
|
124
|
+
|
|
125
|
+
this.focusTrap = new FocusTrap(this.dialog)
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
open(): void {
|
|
129
|
+
this.overlay.style.display = 'flex'
|
|
130
|
+
requestAnimationFrame(() => {
|
|
131
|
+
this.overlay.classList.add('is-open')
|
|
132
|
+
this.focusTrap.activate(this.confirmBtn)
|
|
133
|
+
this.escapeCleanup = onKey(this.dialog, [
|
|
134
|
+
{ key: Keys.Escape, handler: () => this.close() },
|
|
135
|
+
])
|
|
136
|
+
})
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
close(): void {
|
|
140
|
+
this.overlay.classList.remove('is-open')
|
|
141
|
+
if (this.escapeCleanup) {
|
|
142
|
+
this.escapeCleanup()
|
|
143
|
+
this.escapeCleanup = null
|
|
144
|
+
}
|
|
145
|
+
this.focusTrap.deactivate()
|
|
146
|
+
setTimeout(() => {
|
|
147
|
+
this.overlay.style.display = 'none'
|
|
148
|
+
this.options.onClose?.()
|
|
149
|
+
}, 300)
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
destroy(): void {
|
|
153
|
+
if (this.escapeCleanup) {
|
|
154
|
+
this.escapeCleanup()
|
|
155
|
+
this.escapeCleanup = null
|
|
156
|
+
}
|
|
157
|
+
this.focusTrap.deactivate()
|
|
158
|
+
this.overlay.remove()
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
export function createDialog(options?: DialogOptions): MkDialog {
|
|
163
|
+
return new MkDialog(options)
|
|
164
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
.mk-drawer-overlay {
|
|
2
|
+
position: fixed;
|
|
3
|
+
inset: 0;
|
|
4
|
+
background: rgba(0, 0, 0, 0.5);
|
|
5
|
+
z-index: 2000;
|
|
6
|
+
opacity: 0;
|
|
7
|
+
transition: opacity 0.2s ease;
|
|
8
|
+
}
|
|
9
|
+
.mk-drawer-overlay.is-open { opacity: 1; }
|
|
10
|
+
|
|
11
|
+
.mk-drawer {
|
|
12
|
+
position: fixed;
|
|
13
|
+
background: var(--mk-surface);
|
|
14
|
+
border: 1px solid var(--mk-border);
|
|
15
|
+
display: flex;
|
|
16
|
+
flex-direction: column;
|
|
17
|
+
transition: transform 0.25s ease;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
.mk-drawer--right {
|
|
21
|
+
top: 0; right: 0; bottom: 0;
|
|
22
|
+
width: 340px;
|
|
23
|
+
border-left: 1px solid var(--mk-border);
|
|
24
|
+
border-radius: var(--mk-radius-lg) 0 0 var(--mk-radius-lg);
|
|
25
|
+
transform: translateX(100%);
|
|
26
|
+
}
|
|
27
|
+
.mk-drawer-overlay.is-open .mk-drawer--right { transform: translateX(0); }
|
|
28
|
+
|
|
29
|
+
.mk-drawer--left {
|
|
30
|
+
top: 0; left: 0; bottom: 0;
|
|
31
|
+
width: 340px;
|
|
32
|
+
border-right: 1px solid var(--mk-border);
|
|
33
|
+
border-radius: 0 var(--mk-radius-lg) var(--mk-radius-lg) 0;
|
|
34
|
+
transform: translateX(-100%);
|
|
35
|
+
}
|
|
36
|
+
.mk-drawer-overlay.is-open .mk-drawer--left { transform: translateX(0); }
|
|
37
|
+
|
|
38
|
+
.mk-drawer__header {
|
|
39
|
+
padding: 18px 20px;
|
|
40
|
+
display: flex;
|
|
41
|
+
align-items: center;
|
|
42
|
+
justify-content: space-between;
|
|
43
|
+
border-bottom: 1px solid var(--mk-border);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
.mk-drawer__title {
|
|
47
|
+
font-size: 15px;
|
|
48
|
+
font-weight: 600;
|
|
49
|
+
color: var(--mk-text);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
.mk-drawer__close {
|
|
53
|
+
cursor: pointer;
|
|
54
|
+
color: var(--mk-text-tertiary);
|
|
55
|
+
font-size: 16px;
|
|
56
|
+
width: 24px; height: 24px;
|
|
57
|
+
display: flex; align-items: center; justify-content: center;
|
|
58
|
+
border-radius: 4px;
|
|
59
|
+
transition: var(--mk-transition);
|
|
60
|
+
}
|
|
61
|
+
.mk-drawer__close:hover {
|
|
62
|
+
color: var(--mk-text);
|
|
63
|
+
background: var(--mk-surface-hover);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
.mk-drawer__body {
|
|
67
|
+
padding: 16px 20px;
|
|
68
|
+
flex: 1;
|
|
69
|
+
overflow-y: auto;
|
|
70
|
+
color: var(--mk-text-secondary);
|
|
71
|
+
font-size: 13px;
|
|
72
|
+
line-height: 1.6;
|
|
73
|
+
}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import './drawer.css'
|
|
2
|
+
import { FocusTrap } from '../../a11y/focus-trap'
|
|
3
|
+
import { onKey, Keys } from '../../a11y/keyboard'
|
|
4
|
+
|
|
5
|
+
export interface DrawerOptions {
|
|
6
|
+
title?: string
|
|
7
|
+
content?: string | HTMLElement
|
|
8
|
+
direction?: 'right' | 'left' | 'top' | 'bottom'
|
|
9
|
+
size?: number
|
|
10
|
+
showClose?: boolean
|
|
11
|
+
onClose?: () => void
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export class MkDrawer {
|
|
15
|
+
private overlay: HTMLDivElement
|
|
16
|
+
private drawer: HTMLDivElement
|
|
17
|
+
private options: DrawerOptions
|
|
18
|
+
private focusTrap: FocusTrap
|
|
19
|
+
private escapeCleanup: (() => void) | null = null
|
|
20
|
+
|
|
21
|
+
constructor(options: DrawerOptions = {}) {
|
|
22
|
+
this.options = {
|
|
23
|
+
direction: 'right',
|
|
24
|
+
showClose: true,
|
|
25
|
+
...options,
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
this.overlay = document.createElement('div')
|
|
29
|
+
this.overlay.className = 'mk-drawer-overlay'
|
|
30
|
+
this.overlay.style.display = 'none'
|
|
31
|
+
|
|
32
|
+
this.drawer = document.createElement('div')
|
|
33
|
+
this.drawer.className = `mk-drawer mk-drawer--${this.options.direction}`
|
|
34
|
+
this.drawer.setAttribute('role', 'dialog')
|
|
35
|
+
this.drawer.setAttribute('aria-modal', 'true')
|
|
36
|
+
if (this.options.size) {
|
|
37
|
+
if (this.options.direction === 'right' || this.options.direction === 'left') {
|
|
38
|
+
this.drawer.style.width = `${this.options.size}px`
|
|
39
|
+
} else {
|
|
40
|
+
this.drawer.style.height = `${this.options.size}px`
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Header
|
|
45
|
+
const header = document.createElement('div')
|
|
46
|
+
header.className = 'mk-drawer__header'
|
|
47
|
+
|
|
48
|
+
const title = document.createElement('span')
|
|
49
|
+
title.className = 'mk-drawer__title'
|
|
50
|
+
title.textContent = this.options.title || ''
|
|
51
|
+
header.appendChild(title)
|
|
52
|
+
|
|
53
|
+
if (this.options.showClose) {
|
|
54
|
+
const close = document.createElement('span')
|
|
55
|
+
close.className = 'mk-drawer__close'
|
|
56
|
+
close.innerHTML = '✕'
|
|
57
|
+
close.setAttribute('role', 'button')
|
|
58
|
+
close.setAttribute('tabindex', '0')
|
|
59
|
+
close.setAttribute('aria-label', 'Close')
|
|
60
|
+
close.addEventListener('click', () => this.close())
|
|
61
|
+
close.addEventListener('keydown', (e) => {
|
|
62
|
+
if (e.key === 'Enter' || e.key === ' ') {
|
|
63
|
+
e.preventDefault()
|
|
64
|
+
this.close()
|
|
65
|
+
}
|
|
66
|
+
})
|
|
67
|
+
header.appendChild(close)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
this.drawer.appendChild(header)
|
|
71
|
+
|
|
72
|
+
// Body
|
|
73
|
+
const body = document.createElement('div')
|
|
74
|
+
body.className = 'mk-drawer__body'
|
|
75
|
+
if (typeof this.options.content === 'string') {
|
|
76
|
+
body.innerHTML = this.options.content
|
|
77
|
+
} else if (this.options.content) {
|
|
78
|
+
body.appendChild(this.options.content)
|
|
79
|
+
}
|
|
80
|
+
this.drawer.appendChild(body)
|
|
81
|
+
|
|
82
|
+
this.overlay.appendChild(this.drawer)
|
|
83
|
+
|
|
84
|
+
this.overlay.addEventListener('click', (e) => {
|
|
85
|
+
if (e.target === this.overlay) {
|
|
86
|
+
this.close()
|
|
87
|
+
}
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
document.body.appendChild(this.overlay)
|
|
91
|
+
|
|
92
|
+
this.focusTrap = new FocusTrap(this.drawer)
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
open(): void {
|
|
96
|
+
this.overlay.style.display = 'block'
|
|
97
|
+
requestAnimationFrame(() => {
|
|
98
|
+
this.overlay.classList.add('is-open')
|
|
99
|
+
this.focusTrap.activate()
|
|
100
|
+
this.escapeCleanup = onKey(this.drawer, [
|
|
101
|
+
{ key: Keys.Escape, handler: () => this.close() },
|
|
102
|
+
])
|
|
103
|
+
})
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
close(): void {
|
|
107
|
+
this.overlay.classList.remove('is-open')
|
|
108
|
+
if (this.escapeCleanup) {
|
|
109
|
+
this.escapeCleanup()
|
|
110
|
+
this.escapeCleanup = null
|
|
111
|
+
}
|
|
112
|
+
this.focusTrap.deactivate()
|
|
113
|
+
setTimeout(() => {
|
|
114
|
+
this.overlay.style.display = 'none'
|
|
115
|
+
this.options.onClose?.()
|
|
116
|
+
}, 300)
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
destroy(): void {
|
|
120
|
+
if (this.escapeCleanup) {
|
|
121
|
+
this.escapeCleanup()
|
|
122
|
+
this.escapeCleanup = null
|
|
123
|
+
}
|
|
124
|
+
this.focusTrap.deactivate()
|
|
125
|
+
this.overlay.remove()
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export function createDrawer(options?: DrawerOptions): MkDrawer {
|
|
130
|
+
return new MkDrawer(options)
|
|
131
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
.mk-empty {
|
|
2
|
+
display: flex;
|
|
3
|
+
flex-direction: column;
|
|
4
|
+
align-items: center;
|
|
5
|
+
justify-content: center;
|
|
6
|
+
padding: var(--mk-space-8) var(--mk-space-4);
|
|
7
|
+
text-align: center;
|
|
8
|
+
color: var(--mk-text-tertiary);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
.mk-empty__image {
|
|
12
|
+
width: 120px;
|
|
13
|
+
height: 120px;
|
|
14
|
+
margin-bottom: var(--mk-space-4);
|
|
15
|
+
color: var(--mk-text-tertiary);
|
|
16
|
+
opacity: 0.8;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
.mk-empty__image svg {
|
|
20
|
+
width: 100%;
|
|
21
|
+
height: 100%;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
.mk-empty__image img {
|
|
25
|
+
width: 100%;
|
|
26
|
+
height: 100%;
|
|
27
|
+
object-fit: contain;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
.mk-empty__description {
|
|
31
|
+
margin: 0;
|
|
32
|
+
font-size: var(--mk-text-sm);
|
|
33
|
+
font-weight: var(--mk-font-medium);
|
|
34
|
+
line-height: var(--mk-leading-normal);
|
|
35
|
+
color: var(--mk-text-secondary);
|
|
36
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import '../../styles/element-plus.css'
|
|
2
|
+
import './empty.css'
|
|
3
|
+
|
|
4
|
+
export interface EmptyOptions {
|
|
5
|
+
description?: string
|
|
6
|
+
image?: string | 'default'
|
|
7
|
+
imageStyle?: Partial<CSSStyleDeclaration>
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const defaultSvg = `<svg viewBox="0 0 120 120" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
11
|
+
<rect x="20" y="30" width="80" height="60" rx="8" stroke="currentColor" stroke-width="1.5" opacity="0.3"/>
|
|
12
|
+
<circle cx="45" cy="55" r="8" fill="currentColor" opacity="0.2"/>
|
|
13
|
+
<rect x="60" y="48" width="28" height="4" rx="2" fill="currentColor" opacity="0.2"/>
|
|
14
|
+
<rect x="60" y="58" width="20" height="4" rx="2" fill="currentColor" opacity="0.15"/>
|
|
15
|
+
<line x1="35" y1="82" x2="85" y2="82" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" opacity="0.15"/>
|
|
16
|
+
<line x1="45" y1="90" x2="75" y2="90" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" opacity="0.1"/>
|
|
17
|
+
</svg>`
|
|
18
|
+
|
|
19
|
+
export class MkEmpty {
|
|
20
|
+
el: HTMLDivElement
|
|
21
|
+
private options: EmptyOptions
|
|
22
|
+
|
|
23
|
+
constructor(container: HTMLElement | string, options: EmptyOptions = {}) {
|
|
24
|
+
const parent =
|
|
25
|
+
typeof container === 'string'
|
|
26
|
+
? document.querySelector(container)!
|
|
27
|
+
: container
|
|
28
|
+
|
|
29
|
+
this.options = {
|
|
30
|
+
image: 'default',
|
|
31
|
+
...options,
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
this.el = document.createElement('div')
|
|
35
|
+
this.el.className = 'mk-empty'
|
|
36
|
+
|
|
37
|
+
const imageWrap = document.createElement('div')
|
|
38
|
+
imageWrap.className = 'mk-empty__image'
|
|
39
|
+
if (this.options.imageStyle) {
|
|
40
|
+
Object.assign(imageWrap.style, this.options.imageStyle)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (this.options.image === 'default') {
|
|
44
|
+
imageWrap.innerHTML = defaultSvg
|
|
45
|
+
} else if (this.options.image) {
|
|
46
|
+
const img = document.createElement('img')
|
|
47
|
+
img.src = this.options.image
|
|
48
|
+
img.alt = ''
|
|
49
|
+
imageWrap.appendChild(img)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
this.el.appendChild(imageWrap)
|
|
53
|
+
|
|
54
|
+
if (this.options.description) {
|
|
55
|
+
const desc = document.createElement('p')
|
|
56
|
+
desc.className = 'mk-empty__description'
|
|
57
|
+
desc.textContent = this.options.description
|
|
58
|
+
this.el.appendChild(desc)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
parent.appendChild(this.el)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
setDescription(text: string): void {
|
|
65
|
+
this.options.description = text
|
|
66
|
+
let desc = this.el.querySelector('.mk-empty__description') as HTMLParagraphElement | null
|
|
67
|
+
if (!desc) {
|
|
68
|
+
desc = document.createElement('p')
|
|
69
|
+
desc.className = 'mk-empty__description'
|
|
70
|
+
this.el.appendChild(desc)
|
|
71
|
+
}
|
|
72
|
+
desc.textContent = text
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
destroy(): void {
|
|
76
|
+
this.el.remove()
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export function createEmpty(
|
|
81
|
+
container: HTMLElement | string,
|
|
82
|
+
options?: EmptyOptions
|
|
83
|
+
): MkEmpty {
|
|
84
|
+
return new MkEmpty(container, options)
|
|
85
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
.mk-checkbox {
|
|
2
|
+
display: inline-flex;
|
|
3
|
+
align-items: center;
|
|
4
|
+
gap: 8px;
|
|
5
|
+
cursor: pointer;
|
|
6
|
+
user-select: none;
|
|
7
|
+
font-size: 13px;
|
|
8
|
+
color: var(--mk-text);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
.mk-checkbox__input {
|
|
12
|
+
width: 16px;
|
|
13
|
+
height: 16px;
|
|
14
|
+
border: 1.5px solid var(--mk-border);
|
|
15
|
+
border-radius: 4px;
|
|
16
|
+
display: flex;
|
|
17
|
+
align-items: center;
|
|
18
|
+
justify-content: center;
|
|
19
|
+
transition: var(--mk-transition);
|
|
20
|
+
flex-shrink: 0;
|
|
21
|
+
background: var(--mk-surface);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
.mk-checkbox:hover .mk-checkbox__input {
|
|
25
|
+
border-color: var(--mk-border-hover);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
.mk-checkbox.is-checked .mk-checkbox__input {
|
|
29
|
+
background: var(--mk-primary);
|
|
30
|
+
border-color: var(--mk-primary);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
.mk-checkbox__check {
|
|
34
|
+
color: #fff;
|
|
35
|
+
font-size: 11px;
|
|
36
|
+
opacity: 0;
|
|
37
|
+
transform: scale(0.5);
|
|
38
|
+
transition: all 0.15s ease;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
.mk-checkbox.is-checked .mk-checkbox__check {
|
|
42
|
+
opacity: 1;
|
|
43
|
+
transform: scale(1);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
.mk-checkbox.is-disabled {
|
|
47
|
+
opacity: 0.4;
|
|
48
|
+
cursor: not-allowed;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/* Group */
|
|
52
|
+
.mk-checkbox-group {
|
|
53
|
+
display: flex;
|
|
54
|
+
flex-wrap: wrap;
|
|
55
|
+
gap: 12px;
|
|
56
|
+
}
|