@getcortexlabs/mavis-web 0.1.0-alpha.2 → 0.1.0-alpha.4
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/README.md +4 -4
- package/dist/components/MAccordion.d.ts +109 -0
- package/dist/components/MAccordion.d.ts.map +1 -0
- package/dist/components/MAccordion.js +180 -0
- package/dist/components/MAccordion.js.map +1 -0
- package/dist/components/MAlert.d.ts +99 -0
- package/dist/components/MAlert.d.ts.map +1 -0
- package/dist/components/MAlert.js +88 -0
- package/dist/components/MAlert.js.map +1 -0
- package/dist/components/MAvatar.d.ts +74 -0
- package/dist/components/MAvatar.d.ts.map +1 -0
- package/dist/components/MAvatar.js +88 -0
- package/dist/components/MAvatar.js.map +1 -0
- package/dist/components/MBadge.d.ts +64 -0
- package/dist/components/MBadge.d.ts.map +1 -0
- package/dist/components/MBadge.js +35 -0
- package/dist/components/MBadge.js.map +1 -0
- package/dist/components/MButton.d.ts +59 -7
- package/dist/components/MButton.d.ts.map +1 -1
- package/dist/components/MButton.js +51 -18
- package/dist/components/MButton.js.map +1 -1
- package/dist/components/MCard.d.ts +23 -5
- package/dist/components/MCard.d.ts.map +1 -1
- package/dist/components/MCard.js +28 -6
- package/dist/components/MCard.js.map +1 -1
- package/dist/components/MCheckbox.d.ts +93 -0
- package/dist/components/MCheckbox.d.ts.map +1 -0
- package/dist/components/MCheckbox.js +108 -0
- package/dist/components/MCheckbox.js.map +1 -0
- package/dist/components/MChip.d.ts +107 -0
- package/dist/components/MChip.d.ts.map +1 -0
- package/dist/components/MChip.js +103 -0
- package/dist/components/MChip.js.map +1 -0
- package/dist/components/MDialog.d.ts +94 -0
- package/dist/components/MDialog.d.ts.map +1 -0
- package/dist/components/MDialog.js +214 -0
- package/dist/components/MDialog.js.map +1 -0
- package/dist/components/MEmptyState.d.ts +107 -0
- package/dist/components/MEmptyState.d.ts.map +1 -0
- package/dist/components/MEmptyState.js +79 -0
- package/dist/components/MEmptyState.js.map +1 -0
- package/dist/components/MIcon.d.ts +1 -1
- package/dist/components/MInput.d.ts +66 -8
- package/dist/components/MInput.d.ts.map +1 -1
- package/dist/components/MInput.js +96 -20
- package/dist/components/MInput.js.map +1 -1
- package/dist/components/MListItem.d.ts +92 -0
- package/dist/components/MListItem.d.ts.map +1 -0
- package/dist/components/MListItem.js +53 -0
- package/dist/components/MListItem.js.map +1 -0
- package/dist/components/MProgress.d.ts +112 -0
- package/dist/components/MProgress.d.ts.map +1 -0
- package/dist/components/MProgress.js +69 -0
- package/dist/components/MProgress.js.map +1 -0
- package/dist/components/MRadioGroup.d.ts +94 -0
- package/dist/components/MRadioGroup.d.ts.map +1 -0
- package/dist/components/MRadioGroup.js +167 -0
- package/dist/components/MRadioGroup.js.map +1 -0
- package/dist/components/MReveal.d.ts.map +1 -1
- package/dist/components/MReveal.js +28 -3
- package/dist/components/MReveal.js.map +1 -1
- package/dist/components/MScreen.d.ts +19 -1
- package/dist/components/MScreen.d.ts.map +1 -1
- package/dist/components/MScreen.js +30 -1
- package/dist/components/MScreen.js.map +1 -1
- package/dist/components/MSegmentedControl.d.ts +85 -0
- package/dist/components/MSegmentedControl.d.ts.map +1 -0
- package/dist/components/MSegmentedControl.js +128 -0
- package/dist/components/MSegmentedControl.js.map +1 -0
- package/dist/components/MSelect.d.ts +130 -0
- package/dist/components/MSelect.d.ts.map +1 -0
- package/dist/components/MSelect.js +308 -0
- package/dist/components/MSelect.js.map +1 -0
- package/dist/components/MSeparator.d.ts +54 -0
- package/dist/components/MSeparator.d.ts.map +1 -0
- package/dist/components/MSeparator.js +36 -0
- package/dist/components/MSeparator.js.map +1 -0
- package/dist/components/MSheet.d.ts +102 -0
- package/dist/components/MSheet.d.ts.map +1 -0
- package/dist/components/MSheet.js +265 -0
- package/dist/components/MSheet.js.map +1 -0
- package/dist/components/MSkeleton.d.ts +70 -0
- package/dist/components/MSkeleton.d.ts.map +1 -0
- package/dist/components/MSkeleton.js +43 -0
- package/dist/components/MSkeleton.js.map +1 -0
- package/dist/components/MSlider.d.ts +1 -1
- package/dist/components/MSlider.d.ts.map +1 -1
- package/dist/components/MSlider.js +2 -1
- package/dist/components/MSlider.js.map +1 -1
- package/dist/components/MSwitch.d.ts +79 -0
- package/dist/components/MSwitch.d.ts.map +1 -0
- package/dist/components/MSwitch.js +87 -0
- package/dist/components/MSwitch.js.map +1 -0
- package/dist/components/MTabs.d.ts +91 -0
- package/dist/components/MTabs.d.ts.map +1 -0
- package/dist/components/MTabs.js +228 -0
- package/dist/components/MTabs.js.map +1 -0
- package/dist/components/MText.d.ts +18 -9
- package/dist/components/MText.d.ts.map +1 -1
- package/dist/components/MText.js +26 -7
- package/dist/components/MText.js.map +1 -1
- package/dist/components/MToast.d.ts +24 -0
- package/dist/components/MToast.d.ts.map +1 -0
- package/dist/components/MToast.js +196 -0
- package/dist/components/MToast.js.map +1 -0
- package/dist/index.d.ts +27 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +46 -4
- package/dist/index.js.map +1 -1
- package/dist/input-attrs.d.ts +15 -0
- package/dist/input-attrs.d.ts.map +1 -0
- package/dist/input-attrs.js +18 -0
- package/dist/input-attrs.js.map +1 -0
- package/dist/motion-surface.d.ts +8 -0
- package/dist/motion-surface.d.ts.map +1 -0
- package/dist/motion-surface.js +79 -0
- package/dist/motion-surface.js.map +1 -0
- package/dist/motion.d.ts +20 -0
- package/dist/motion.d.ts.map +1 -0
- package/dist/motion.js +227 -0
- package/dist/motion.js.map +1 -0
- package/dist/screen-viewport.d.ts.map +1 -1
- package/dist/screen-viewport.js +3 -0
- package/dist/screen-viewport.js.map +1 -1
- package/dist/scroll-motion.d.ts +5 -0
- package/dist/scroll-motion.d.ts.map +1 -0
- package/dist/scroll-motion.js +69 -0
- package/dist/scroll-motion.js.map +1 -0
- package/dist/sheet-motion.d.ts +8 -0
- package/dist/sheet-motion.d.ts.map +1 -0
- package/dist/sheet-motion.js +148 -0
- package/dist/sheet-motion.js.map +1 -0
- package/dist/style.d.ts.map +1 -1
- package/dist/style.js +24 -9
- package/dist/style.js.map +1 -1
- package/package.json +4 -3
- package/src/components/MAccordion.ts +231 -0
- package/src/components/MAlert.ts +109 -0
- package/src/components/MAvatar.ts +97 -0
- package/src/components/MBadge.ts +40 -0
- package/src/components/MButton.ts +68 -15
- package/src/components/MCard.ts +43 -5
- package/src/components/MCheckbox.ts +127 -0
- package/src/components/MChip.ts +109 -0
- package/src/components/MDialog.ts +245 -0
- package/src/components/MEmptyState.ts +96 -0
- package/src/components/MInput.ts +166 -71
- package/src/components/MListItem.ts +66 -0
- package/src/components/MProgress.ts +82 -0
- package/src/components/MRadioGroup.ts +184 -0
- package/src/components/MReveal.ts +40 -3
- package/src/components/MScreen.ts +31 -1
- package/src/components/MSegmentedControl.ts +151 -0
- package/src/components/MSelect.ts +362 -0
- package/src/components/MSeparator.ts +40 -0
- package/src/components/MSheet.ts +317 -0
- package/src/components/MSkeleton.ts +52 -0
- package/src/components/MSlider.ts +7 -1
- package/src/components/MSwitch.ts +108 -0
- package/src/components/MTabs.ts +275 -0
- package/src/components/MText.ts +30 -7
- package/src/components/MToast.ts +241 -0
- package/src/index.ts +82 -4
- package/src/input-attrs.ts +41 -0
- package/src/motion-surface.ts +86 -0
- package/src/motion.ts +275 -0
- package/src/screen-viewport.ts +2 -0
- package/src/scroll-motion.ts +75 -0
- package/src/sheet-motion.ts +152 -0
- package/src/style.css +861 -39
- package/src/style.ts +20 -9
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
import {
|
|
2
|
+
defineComponent,
|
|
3
|
+
h,
|
|
4
|
+
nextTick,
|
|
5
|
+
onBeforeUnmount,
|
|
6
|
+
onDeactivated,
|
|
7
|
+
onActivated,
|
|
8
|
+
onMounted,
|
|
9
|
+
provide,
|
|
10
|
+
ref,
|
|
11
|
+
useId,
|
|
12
|
+
watch,
|
|
13
|
+
} from 'vue'
|
|
14
|
+
import {
|
|
15
|
+
useButtonAction,
|
|
16
|
+
sheetProps,
|
|
17
|
+
sheetEmits,
|
|
18
|
+
useMavisTheme,
|
|
19
|
+
useCachedActivity,
|
|
20
|
+
layoutDirection,
|
|
21
|
+
} from '@getcortexlabs/mavis-core/vue'
|
|
22
|
+
import {
|
|
23
|
+
checkSheetName,
|
|
24
|
+
resolveSpace,
|
|
25
|
+
type SheetName,
|
|
26
|
+
type SheetCloseReason,
|
|
27
|
+
} from '@getcortexlabs/mavis-core'
|
|
28
|
+
import { MRow, MColumn, MBox } from './layout.js'
|
|
29
|
+
import { MText } from './MText.js'
|
|
30
|
+
import { MButton } from './MButton.js'
|
|
31
|
+
|
|
32
|
+
import { sheetMotion } from '../sheet-motion.js'
|
|
33
|
+
|
|
34
|
+
const Sheet = defineComponent({
|
|
35
|
+
name: 'MSheet',
|
|
36
|
+
inheritAttrs: false,
|
|
37
|
+
props: sheetProps,
|
|
38
|
+
emits: sheetEmits,
|
|
39
|
+
setup(props, { slots, emit }) {
|
|
40
|
+
useButtonAction()
|
|
41
|
+
const { theme } = useMavisTheme()
|
|
42
|
+
const active = useCachedActivity()
|
|
43
|
+
provide(layoutDirection, 'column')
|
|
44
|
+
const titleId = `m-sheet-${useId()}`
|
|
45
|
+
const dialog = ref<HTMLDialogElement>()
|
|
46
|
+
const panel = ref<HTMLElement>()
|
|
47
|
+
const presented = ref(false)
|
|
48
|
+
const shown = ref(false)
|
|
49
|
+
let closing: SheetCloseReason | undefined
|
|
50
|
+
let generation = 0
|
|
51
|
+
let motion: ReturnType<typeof sheetMotion> | undefined
|
|
52
|
+
const handle = ref<HTMLElement>()
|
|
53
|
+
let outside = false
|
|
54
|
+
let opener: HTMLElement | undefined
|
|
55
|
+
|
|
56
|
+
const announce = (reason: SheetCloseReason) => {
|
|
57
|
+
closing = reason
|
|
58
|
+
emit('update:open', false)
|
|
59
|
+
emit('close', reason)
|
|
60
|
+
}
|
|
61
|
+
const request = (reason: SheetCloseReason) => {
|
|
62
|
+
if (!props.open || closing) return
|
|
63
|
+
announce(reason)
|
|
64
|
+
nextTick(() => {
|
|
65
|
+
if (props.open && closing === reason) {
|
|
66
|
+
closing = undefined
|
|
67
|
+
motion?.show()
|
|
68
|
+
}
|
|
69
|
+
})
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const focusable = (element: HTMLElement) =>
|
|
73
|
+
[
|
|
74
|
+
...element.querySelectorAll<HTMLElement>(
|
|
75
|
+
'button:not(:disabled), [href], input:not(:disabled), select:not(:disabled), textarea:not(:disabled), [tabindex]:not([tabindex="-1"])',
|
|
76
|
+
),
|
|
77
|
+
].filter((control) => !control.closest('[inert]'))
|
|
78
|
+
// Engines differ on which control a modal dialog focuses first; start at the first control,
|
|
79
|
+
// or the panel itself, unless the content asked for focus with `autofocus`.
|
|
80
|
+
function focusInitial(element: HTMLDialogElement) {
|
|
81
|
+
if (typeof document === 'undefined') return
|
|
82
|
+
const active = document.activeElement
|
|
83
|
+
if (active && active !== element && element.contains(active)) return
|
|
84
|
+
const panel = element.querySelector<HTMLElement>('.m-sheet-panel')
|
|
85
|
+
if (panel) panel.tabIndex = -1
|
|
86
|
+
;(focusable(element)[0] ?? panel)?.focus({ preventScroll: true })
|
|
87
|
+
}
|
|
88
|
+
// A modal dialog makes the page inert, yet Tab can still leave for the browser's own controls.
|
|
89
|
+
function trapTab(event: KeyboardEvent) {
|
|
90
|
+
const element = dialog.value
|
|
91
|
+
if (event.key !== 'Tab' || !element) return
|
|
92
|
+
const controls = focusable(element)
|
|
93
|
+
const first = controls[0]
|
|
94
|
+
const last = controls[controls.length - 1]
|
|
95
|
+
if (!first || !last) return
|
|
96
|
+
const active = document.activeElement
|
|
97
|
+
if (event.shiftKey && (active === first || active === element)) {
|
|
98
|
+
event.preventDefault()
|
|
99
|
+
last.focus()
|
|
100
|
+
} else if (!event.shiftKey && active === last) {
|
|
101
|
+
event.preventDefault()
|
|
102
|
+
first.focus()
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
// The dialog restores focus when it closes; some engines leave it on the body instead.
|
|
106
|
+
function restoreFocus() {
|
|
107
|
+
const target = opener
|
|
108
|
+
opener = undefined
|
|
109
|
+
const active = typeof document === 'undefined' ? null : document.activeElement
|
|
110
|
+
if (target?.isConnected && (!active || active === document.body))
|
|
111
|
+
target.focus({ preventScroll: true })
|
|
112
|
+
}
|
|
113
|
+
function present() {
|
|
114
|
+
const current = ++generation
|
|
115
|
+
presented.value = true
|
|
116
|
+
if (
|
|
117
|
+
!dialog.value?.open &&
|
|
118
|
+
typeof document !== 'undefined' &&
|
|
119
|
+
document.activeElement instanceof HTMLElement
|
|
120
|
+
)
|
|
121
|
+
opener = document.activeElement
|
|
122
|
+
nextTick(() => {
|
|
123
|
+
const element = dialog.value
|
|
124
|
+
if (generation !== current || !element) return
|
|
125
|
+
if (typeof element.showModal === 'function' && !element.open) element.showModal()
|
|
126
|
+
focusInitial(element)
|
|
127
|
+
if (!motion)
|
|
128
|
+
motion = sheetMotion(
|
|
129
|
+
element,
|
|
130
|
+
panel.value!,
|
|
131
|
+
handle.value ?? null,
|
|
132
|
+
() => props.dismissible,
|
|
133
|
+
() => {
|
|
134
|
+
if (props.open) return
|
|
135
|
+
motion?.dispose()
|
|
136
|
+
motion = undefined
|
|
137
|
+
if (element.open) element.close()
|
|
138
|
+
presented.value = false
|
|
139
|
+
closing = undefined
|
|
140
|
+
restoreFocus()
|
|
141
|
+
},
|
|
142
|
+
() => request('swipe'),
|
|
143
|
+
)
|
|
144
|
+
shown.value = true
|
|
145
|
+
motion.show()
|
|
146
|
+
})
|
|
147
|
+
}
|
|
148
|
+
function leave() {
|
|
149
|
+
generation++
|
|
150
|
+
shown.value = false
|
|
151
|
+
if (motion) motion.hide()
|
|
152
|
+
else {
|
|
153
|
+
dialog.value?.close?.()
|
|
154
|
+
presented.value = false
|
|
155
|
+
closing = undefined
|
|
156
|
+
restoreFocus()
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
watch(
|
|
160
|
+
() => props.dismissible,
|
|
161
|
+
() => motion?.refresh(),
|
|
162
|
+
)
|
|
163
|
+
|
|
164
|
+
watch(
|
|
165
|
+
() => props.open,
|
|
166
|
+
(open) => {
|
|
167
|
+
if (open && active.value) {
|
|
168
|
+
closing = undefined
|
|
169
|
+
present()
|
|
170
|
+
} else if (presented.value) {
|
|
171
|
+
if (!closing) {
|
|
172
|
+
closing = 'program'
|
|
173
|
+
emit('close', 'program')
|
|
174
|
+
}
|
|
175
|
+
leave()
|
|
176
|
+
}
|
|
177
|
+
},
|
|
178
|
+
)
|
|
179
|
+
onActivated(() => {
|
|
180
|
+
if (props.open && !presented.value) present()
|
|
181
|
+
})
|
|
182
|
+
onMounted(() => {
|
|
183
|
+
if (props.open) present()
|
|
184
|
+
})
|
|
185
|
+
onDeactivated(() => {
|
|
186
|
+
generation++
|
|
187
|
+
motion?.dispose()
|
|
188
|
+
motion = undefined
|
|
189
|
+
dialog.value?.close?.()
|
|
190
|
+
shown.value = presented.value = false
|
|
191
|
+
opener = undefined
|
|
192
|
+
if (props.open) announce('program')
|
|
193
|
+
})
|
|
194
|
+
onBeforeUnmount(() => {
|
|
195
|
+
generation++
|
|
196
|
+
motion?.dispose()
|
|
197
|
+
motion = undefined
|
|
198
|
+
dialog.value?.close?.()
|
|
199
|
+
restoreFocus()
|
|
200
|
+
})
|
|
201
|
+
|
|
202
|
+
return () => {
|
|
203
|
+
const name = checkSheetName(props.title, props.accessibilityLabel)
|
|
204
|
+
const title = props.title?.trim()
|
|
205
|
+
const { colors, radius, space } = theme.value
|
|
206
|
+
const header =
|
|
207
|
+
title || props.dismissible
|
|
208
|
+
? h(
|
|
209
|
+
MRow,
|
|
210
|
+
{ gap: 'sm', justify: 'between' },
|
|
211
|
+
{
|
|
212
|
+
default: () => [
|
|
213
|
+
title
|
|
214
|
+
? h(MText, {
|
|
215
|
+
as: 'h2',
|
|
216
|
+
variant: 'heading',
|
|
217
|
+
grow: 1,
|
|
218
|
+
id: titleId,
|
|
219
|
+
text: title,
|
|
220
|
+
})
|
|
221
|
+
: h(MBox, { grow: 1 }),
|
|
222
|
+
props.dismissible
|
|
223
|
+
? h(MButton, {
|
|
224
|
+
variant: 'ghost',
|
|
225
|
+
size: 'sm',
|
|
226
|
+
icon: 'x',
|
|
227
|
+
shrink: 0,
|
|
228
|
+
accessibilityLabel: props.closeLabel,
|
|
229
|
+
onClick: () => request('button'),
|
|
230
|
+
})
|
|
231
|
+
: null,
|
|
232
|
+
],
|
|
233
|
+
},
|
|
234
|
+
)
|
|
235
|
+
: null
|
|
236
|
+
return h(
|
|
237
|
+
'dialog',
|
|
238
|
+
{
|
|
239
|
+
ref: dialog,
|
|
240
|
+
id: props.id,
|
|
241
|
+
class: ['m-sheet', { 'm-sheet-open': shown.value, 'm-sheet-full': props.fullscreen }],
|
|
242
|
+
'aria-labelledby': title ? titleId : undefined,
|
|
243
|
+
'aria-label': title ? undefined : name,
|
|
244
|
+
style: {
|
|
245
|
+
'--m-sheet-surface': colors.surface,
|
|
246
|
+
'--m-sheet-radius': `${radius.lg}px`,
|
|
247
|
+
'--m-focus': colors.primary,
|
|
248
|
+
color: colors.text,
|
|
249
|
+
colorScheme: theme.value.appearance,
|
|
250
|
+
},
|
|
251
|
+
onCancel: (event: Event) => {
|
|
252
|
+
// Keep modal ownership until Jolt completes the departure.
|
|
253
|
+
event.preventDefault()
|
|
254
|
+
if (props.dismissible) request('escape')
|
|
255
|
+
},
|
|
256
|
+
onClose: () => {
|
|
257
|
+
// close events are queued: a previous dismissal can arrive after a rapid reopen.
|
|
258
|
+
if (dialog.value?.open) return
|
|
259
|
+
// Closed by the browser itself: keep the bound state in step.
|
|
260
|
+
if (props.open && !closing) announce('escape')
|
|
261
|
+
motion?.dispose()
|
|
262
|
+
motion = undefined
|
|
263
|
+
shown.value = false
|
|
264
|
+
presented.value = false
|
|
265
|
+
restoreFocus()
|
|
266
|
+
},
|
|
267
|
+
onKeydown: trapTab,
|
|
268
|
+
onPointerdown: (event: Event) => {
|
|
269
|
+
outside = event.target === event.currentTarget
|
|
270
|
+
},
|
|
271
|
+
onClick: (event: Event) => {
|
|
272
|
+
if (outside && event.target === event.currentTarget && props.dismissible)
|
|
273
|
+
request('backdrop')
|
|
274
|
+
outside = false
|
|
275
|
+
},
|
|
276
|
+
},
|
|
277
|
+
presented.value
|
|
278
|
+
? [
|
|
279
|
+
h(
|
|
280
|
+
'div',
|
|
281
|
+
{
|
|
282
|
+
class: 'm-sheet-panel',
|
|
283
|
+
ref: panel,
|
|
284
|
+
style: {
|
|
285
|
+
padding: `${resolveSpace(theme.value, props.padding ?? 'lg')}px`,
|
|
286
|
+
gap: `${space.md}px`,
|
|
287
|
+
},
|
|
288
|
+
},
|
|
289
|
+
[
|
|
290
|
+
h(
|
|
291
|
+
'div',
|
|
292
|
+
{
|
|
293
|
+
ref: handle,
|
|
294
|
+
class: 'm-sheet-handle',
|
|
295
|
+
'aria-hidden': 'true',
|
|
296
|
+
style: { display: props.dismissible ? undefined : 'none' },
|
|
297
|
+
},
|
|
298
|
+
[h('span')],
|
|
299
|
+
),
|
|
300
|
+
header,
|
|
301
|
+
h(
|
|
302
|
+
MColumn,
|
|
303
|
+
{ class: 'm-sheet-body', shrink: 1, gap: props.gap, align: props.align },
|
|
304
|
+
{ default: () => slots.default?.() },
|
|
305
|
+
),
|
|
306
|
+
],
|
|
307
|
+
),
|
|
308
|
+
]
|
|
309
|
+
: undefined,
|
|
310
|
+
)
|
|
311
|
+
}
|
|
312
|
+
},
|
|
313
|
+
})
|
|
314
|
+
|
|
315
|
+
export const MSheet = Sheet as typeof Sheet & {
|
|
316
|
+
new (): InstanceType<typeof Sheet> & { $props: SheetName }
|
|
317
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { defineComponent, h, mergeProps, onBeforeUnmount, onMounted, ref } from 'vue'
|
|
2
|
+
import { skeletonProps, useMavisTheme } from '@getcortexlabs/mavis-core/vue'
|
|
3
|
+
import { MBox } from './layout.js'
|
|
4
|
+
|
|
5
|
+
export const MSkeleton = defineComponent({
|
|
6
|
+
name: 'MSkeleton',
|
|
7
|
+
inheritAttrs: false,
|
|
8
|
+
props: skeletonProps,
|
|
9
|
+
setup(props, { attrs }) {
|
|
10
|
+
const { theme } = useMavisTheme()
|
|
11
|
+
const hidden = ref(false)
|
|
12
|
+
function visibility() {
|
|
13
|
+
hidden.value = document.hidden
|
|
14
|
+
}
|
|
15
|
+
onMounted(() => {
|
|
16
|
+
visibility()
|
|
17
|
+
document.addEventListener('visibilitychange', visibility)
|
|
18
|
+
})
|
|
19
|
+
onBeforeUnmount(() => document.removeEventListener('visibilitychange', visibility))
|
|
20
|
+
return () =>
|
|
21
|
+
h(
|
|
22
|
+
MBox,
|
|
23
|
+
mergeProps(
|
|
24
|
+
{
|
|
25
|
+
style: {
|
|
26
|
+
alignSelf:
|
|
27
|
+
props.width === undefined || props.width === 'auto' ? 'stretch' : 'flex-start',
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
attrs,
|
|
31
|
+
{
|
|
32
|
+
id: props.id,
|
|
33
|
+
width: props.width,
|
|
34
|
+
height: props.height,
|
|
35
|
+
radius: props.radius,
|
|
36
|
+
grow: props.grow,
|
|
37
|
+
shrink: props.shrink,
|
|
38
|
+
backgroundColor: theme.value.colors.border,
|
|
39
|
+
class: 'm-skeleton',
|
|
40
|
+
'data-animated': props.animated,
|
|
41
|
+
style: {
|
|
42
|
+
animationPlayState: hidden.value ? 'paused' : 'running',
|
|
43
|
+
pointerEvents: 'none',
|
|
44
|
+
},
|
|
45
|
+
accessibilityHidden: true,
|
|
46
|
+
tabindex: undefined,
|
|
47
|
+
inert: true,
|
|
48
|
+
},
|
|
49
|
+
),
|
|
50
|
+
)
|
|
51
|
+
},
|
|
52
|
+
})
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import { defineComponent, h, mergeProps } from 'vue'
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
useButtonAction,
|
|
4
|
+
sliderProps,
|
|
5
|
+
useMavisTheme,
|
|
6
|
+
sliderEmits,
|
|
7
|
+
} from '@getcortexlabs/mavis-core/vue'
|
|
3
8
|
import { sliderScale } from '@getcortexlabs/mavis-core'
|
|
4
9
|
import { webAttrs } from '../style.js'
|
|
5
10
|
|
|
@@ -9,6 +14,7 @@ export const MSlider = defineComponent({
|
|
|
9
14
|
props: sliderProps,
|
|
10
15
|
emits: sliderEmits,
|
|
11
16
|
setup(props, { attrs, emit }) {
|
|
17
|
+
useButtonAction()
|
|
12
18
|
const { theme } = useMavisTheme()
|
|
13
19
|
return () => {
|
|
14
20
|
const scale = sliderScale(props.min, props.max, props.step)
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { fontFamily } from '@getcortexlabs/mavis-core'
|
|
2
|
+
import { defineComponent, h, mergeProps, useId } from 'vue'
|
|
3
|
+
import {
|
|
4
|
+
useButtonAction,
|
|
5
|
+
switchProps,
|
|
6
|
+
switchEmits,
|
|
7
|
+
useMavisTheme,
|
|
8
|
+
useDefaultShrink,
|
|
9
|
+
} from '@getcortexlabs/mavis-core/vue'
|
|
10
|
+
import { nonNegative, resolveDimension } from '@getcortexlabs/mavis-core'
|
|
11
|
+
import { length, webAttrs } from '../style.js'
|
|
12
|
+
|
|
13
|
+
export const MSwitch = defineComponent({
|
|
14
|
+
name: 'MSwitch',
|
|
15
|
+
inheritAttrs: false,
|
|
16
|
+
props: switchProps,
|
|
17
|
+
emits: switchEmits,
|
|
18
|
+
setup(props, { attrs, emit }) {
|
|
19
|
+
useButtonAction()
|
|
20
|
+
const { theme } = useMavisTheme()
|
|
21
|
+
const shrink = useDefaultShrink()
|
|
22
|
+
const labelId = `m-switch-${useId()}`
|
|
23
|
+
return () => {
|
|
24
|
+
const { colors, space, typography, radius } = theme.value
|
|
25
|
+
return h(
|
|
26
|
+
'button',
|
|
27
|
+
mergeProps(
|
|
28
|
+
{
|
|
29
|
+
class: 'm-switch',
|
|
30
|
+
style: {
|
|
31
|
+
display: 'flex',
|
|
32
|
+
flexWrap: 'wrap',
|
|
33
|
+
alignItems: 'center',
|
|
34
|
+
gap: `${space.md}px`,
|
|
35
|
+
boxSizing: 'border-box',
|
|
36
|
+
minWidth: 0,
|
|
37
|
+
minHeight: '48px',
|
|
38
|
+
padding: `${space.sm}px 0`,
|
|
39
|
+
border: 0,
|
|
40
|
+
borderRadius: `${radius.sm}px`,
|
|
41
|
+
margin: 0,
|
|
42
|
+
background: 'transparent',
|
|
43
|
+
color: colors.text,
|
|
44
|
+
textAlign: 'start',
|
|
45
|
+
fontFamily: fontFamily(theme.value.typography.body.fontFamily, 'web'),
|
|
46
|
+
fontSize: `${typography.body.fontSize}px`,
|
|
47
|
+
lineHeight: 1.5,
|
|
48
|
+
opacity: props.disabled ? 0.45 : 1,
|
|
49
|
+
flexGrow: nonNegative(props.grow, 'grow'),
|
|
50
|
+
flexShrink: nonNegative(props.shrink ?? shrink, 'shrink'),
|
|
51
|
+
width: length(resolveDimension(props.width)),
|
|
52
|
+
'--m-focus': colors.primary,
|
|
53
|
+
'--m-switch-track': props.modelValue ? colors.primary : colors.muted,
|
|
54
|
+
'--m-switch-thumb': props.modelValue ? colors.onPrimary : colors.surface,
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
webAttrs({ ...attrs, id: props.id, accessibilityHidden: props.accessibilityHidden }),
|
|
58
|
+
{
|
|
59
|
+
type: 'button',
|
|
60
|
+
role: 'switch',
|
|
61
|
+
disabled: props.disabled,
|
|
62
|
+
'aria-checked': props.modelValue,
|
|
63
|
+
'aria-labelledby': labelId,
|
|
64
|
+
'aria-describedby': props.helperText ? `${labelId}-help` : undefined,
|
|
65
|
+
onClick: () => {
|
|
66
|
+
if (!props.disabled) emit('update:modelValue', !props.modelValue)
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
),
|
|
70
|
+
[
|
|
71
|
+
h(
|
|
72
|
+
'span',
|
|
73
|
+
{
|
|
74
|
+
style: {
|
|
75
|
+
flex: '1 1 min-content',
|
|
76
|
+
minWidth: 0,
|
|
77
|
+
overflowWrap: 'break-word',
|
|
78
|
+
maxWidth: '100%',
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
[
|
|
82
|
+
h('span', { id: labelId, style: { display: 'block', fontWeight: 600 } }, props.label),
|
|
83
|
+
props.helperText
|
|
84
|
+
? h(
|
|
85
|
+
'span',
|
|
86
|
+
{
|
|
87
|
+
id: `${labelId}-help`,
|
|
88
|
+
style: {
|
|
89
|
+
display: 'block',
|
|
90
|
+
marginTop: `${space.xs}px`,
|
|
91
|
+
color: colors.muted,
|
|
92
|
+
fontSize: `${typography.caption.fontSize}px`,
|
|
93
|
+
fontWeight: 'normal',
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
props.helperText,
|
|
97
|
+
)
|
|
98
|
+
: null,
|
|
99
|
+
],
|
|
100
|
+
),
|
|
101
|
+
h('span', { class: 'm-switch-track', 'aria-hidden': 'true' }, [
|
|
102
|
+
h('span', { class: 'm-switch-thumb' }),
|
|
103
|
+
]),
|
|
104
|
+
],
|
|
105
|
+
)
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
})
|