@getcortexlabs/mavis-web 0.1.0-alpha.5 → 0.1.0-alpha.7
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/ChoicePaint.d.ts +17 -0
- package/dist/components/ChoicePaint.d.ts.map +1 -0
- package/dist/components/ChoicePaint.js +81 -0
- package/dist/components/ChoicePaint.js.map +1 -0
- package/dist/components/DateCalendar.d.ts +3 -3
- package/dist/components/MAccordion.d.ts +1 -1
- package/dist/components/MAlert.d.ts +1 -1
- package/dist/components/MAvatar.d.ts +1 -1
- package/dist/components/MBadge.d.ts +1 -1
- package/dist/components/MButton.d.ts +55 -9
- package/dist/components/MButton.d.ts.map +1 -1
- package/dist/components/MButton.js +13 -8
- package/dist/components/MButton.js.map +1 -1
- package/dist/components/MCard.d.ts +49 -2
- package/dist/components/MCard.d.ts.map +1 -1
- package/dist/components/MCard.js +44 -31
- package/dist/components/MCard.js.map +1 -1
- package/dist/components/MCheckbox.d.ts +1 -1
- package/dist/components/MCheckbox.d.ts.map +1 -1
- package/dist/components/MCheckbox.js +11 -6
- package/dist/components/MCheckbox.js.map +1 -1
- package/dist/components/MChip.d.ts +3 -3
- package/dist/components/MCombobox.d.ts +2 -2
- package/dist/components/MCombobox.js +3 -3
- package/dist/components/MCombobox.js.map +1 -1
- package/dist/components/MDatePicker.d.ts +72 -24
- package/dist/components/MDatePicker.d.ts.map +1 -1
- package/dist/components/MDatePicker.js +9 -0
- package/dist/components/MDatePicker.js.map +1 -1
- package/dist/components/MDialog.d.ts +2 -2
- package/dist/components/MEmptyState.d.ts +1 -1
- package/dist/components/MFilePicker.d.ts +2 -2
- package/dist/components/MIcon.d.ts +1 -1
- package/dist/components/MImage.d.ts +192 -0
- package/dist/components/MImage.d.ts.map +1 -0
- package/dist/components/MImage.js +97 -0
- package/dist/components/MImage.js.map +1 -0
- package/dist/components/MInput.d.ts +7 -7
- package/dist/components/MInput.js +3 -3
- package/dist/components/MInput.js.map +1 -1
- package/dist/components/MLink.d.ts +120 -0
- package/dist/components/MLink.d.ts.map +1 -0
- package/dist/components/MLink.js +75 -0
- package/dist/components/MLink.js.map +1 -0
- package/dist/components/MListItem.d.ts +3 -1
- package/dist/components/MListItem.d.ts.map +1 -1
- package/dist/components/MProgress.d.ts +3 -3
- package/dist/components/MRadioGroup.d.ts +1 -1
- package/dist/components/MRadioGroup.d.ts.map +1 -1
- package/dist/components/MRadioGroup.js +5 -3
- package/dist/components/MRadioGroup.js.map +1 -1
- package/dist/components/MReveal.d.ts +2 -2
- package/dist/components/MReveal.d.ts.map +1 -1
- package/dist/components/MReveal.js +39 -50
- package/dist/components/MReveal.js.map +1 -1
- package/dist/components/MSegmentedControl.d.ts +1 -1
- package/dist/components/MSelect.d.ts +1 -1
- package/dist/components/MSeparator.d.ts +1 -1
- package/dist/components/MSheet.d.ts +1 -1
- package/dist/components/MSlider.d.ts +1 -1
- package/dist/components/MStack.d.ts +198 -0
- package/dist/components/MStack.d.ts.map +1 -0
- package/dist/components/MStack.js +62 -0
- package/dist/components/MStack.js.map +1 -0
- package/dist/components/MSwitch.d.ts +1 -1
- package/dist/components/MSwitch.d.ts.map +1 -1
- package/dist/components/MSwitch.js +12 -5
- package/dist/components/MSwitch.js.map +1 -1
- package/dist/components/MTabs.d.ts +1 -1
- package/dist/components/MText.d.ts +4 -4
- package/dist/components/MText.js +6 -6
- package/dist/components/MText.js.map +1 -1
- package/dist/components/configurator.d.ts +541 -0
- package/dist/components/configurator.d.ts.map +1 -0
- package/dist/components/configurator.js +20 -0
- package/dist/components/configurator.js.map +1 -0
- package/dist/components/layout.d.ts +179 -2
- package/dist/components/layout.d.ts.map +1 -1
- package/dist/components/layout.js +10 -10
- package/dist/components/layout.js.map +1 -1
- package/dist/components/workflows.d.ts +1 -1
- package/dist/connected-motion.d.ts +6 -0
- package/dist/connected-motion.d.ts.map +1 -0
- package/dist/connected-motion.js +18 -0
- package/dist/connected-motion.js.map +1 -0
- package/dist/experimental.d.ts +9 -0
- package/dist/experimental.d.ts.map +1 -0
- package/dist/experimental.js +27 -0
- package/dist/experimental.js.map +1 -0
- package/dist/index.d.ts +6 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -1
- package/dist/index.js.map +1 -1
- package/dist/motion-region.d.ts +3 -0
- package/dist/motion-region.d.ts.map +1 -1
- package/dist/motion-region.js +69 -39
- package/dist/motion-region.js.map +1 -1
- package/dist/motion-surface.d.ts +4 -0
- package/dist/motion-surface.d.ts.map +1 -1
- package/dist/motion-surface.js +66 -2
- package/dist/motion-surface.js.map +1 -1
- package/dist/motion.d.ts +2 -2
- package/dist/motion.d.ts.map +1 -1
- package/dist/motion.js +8 -27
- package/dist/motion.js.map +1 -1
- package/dist/navigation.d.ts +12 -0
- package/dist/navigation.d.ts.map +1 -0
- package/dist/navigation.js +38 -0
- package/dist/navigation.js.map +1 -0
- package/dist/reveal-motion.d.ts +5 -0
- package/dist/reveal-motion.d.ts.map +1 -0
- package/dist/reveal-motion.js +53 -0
- package/dist/reveal-motion.js.map +1 -0
- package/dist/scroll-motion.d.ts.map +1 -1
- package/dist/scroll-motion.js +33 -18
- package/dist/scroll-motion.js.map +1 -1
- package/dist/tokens.d.ts +7 -0
- package/dist/tokens.d.ts.map +1 -0
- package/dist/tokens.js +29 -0
- package/dist/tokens.js.map +1 -0
- package/package.json +7 -3
- package/src/components/ChoicePaint.ts +96 -0
- package/src/components/MButton.ts +17 -7
- package/src/components/MCard.ts +54 -28
- package/src/components/MCheckbox.ts +17 -6
- package/src/components/MCombobox.ts +3 -3
- package/src/components/MDatePicker.ts +8 -0
- package/src/components/MImage.ts +108 -0
- package/src/components/MInput.ts +3 -3
- package/src/components/MLink.ts +85 -0
- package/src/components/MRadioGroup.ts +9 -3
- package/src/components/MReveal.ts +57 -64
- package/src/components/MStack.ts +90 -0
- package/src/components/MSwitch.ts +17 -6
- package/src/components/MText.ts +6 -6
- package/src/components/configurator.ts +24 -0
- package/src/components/layout.ts +10 -10
- package/src/connected-motion.ts +23 -0
- package/src/experimental.ts +29 -0
- package/src/index.ts +15 -0
- package/src/motion-region.ts +94 -41
- package/src/motion-surface.ts +72 -4
- package/src/motion.ts +10 -40
- package/src/navigation.ts +44 -0
- package/src/reveal-motion.ts +59 -0
- package/src/scroll-motion.ts +31 -18
- package/src/style.css +13 -10
- package/src/tokens.ts +29 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@getcortexlabs/mavis-web",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.7",
|
|
4
4
|
"description": "Mavis components for Vue Web.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": [
|
|
@@ -14,6 +14,10 @@
|
|
|
14
14
|
"./style.css": {
|
|
15
15
|
"types": "./src/style.d.ts",
|
|
16
16
|
"default": "./src/style.css"
|
|
17
|
+
},
|
|
18
|
+
"./experimental": {
|
|
19
|
+
"types": "./dist/experimental.d.ts",
|
|
20
|
+
"default": "./dist/experimental.js"
|
|
17
21
|
}
|
|
18
22
|
},
|
|
19
23
|
"files": [
|
|
@@ -26,11 +30,11 @@
|
|
|
26
30
|
"build": "tsc -p tsconfig.build.json"
|
|
27
31
|
},
|
|
28
32
|
"dependencies": {
|
|
29
|
-
"@getcortexlabs/mavis-core": "0.1.0-alpha.
|
|
33
|
+
"@getcortexlabs/mavis-core": "0.1.0-alpha.7"
|
|
30
34
|
},
|
|
31
35
|
"peerDependencies": {
|
|
32
36
|
"vue": "^3.5.42",
|
|
33
|
-
"@rafaelaugusto/jolt": "^0.1.0-rc.
|
|
37
|
+
"@rafaelaugusto/jolt": "^0.1.0-rc.9"
|
|
34
38
|
},
|
|
35
39
|
"license": "MIT",
|
|
36
40
|
"author": "Rafael Augusto",
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { defineComponent, h, ref, watch, type PropType } from 'vue'
|
|
2
|
+
import { choiceMotion, type ChoicePaint } from '@getcortexlabs/mavis-core'
|
|
3
|
+
import { useMavisTheme } from '@getcortexlabs/mavis-core/vue'
|
|
4
|
+
import { useConnectedMotion } from '../connected-motion.js'
|
|
5
|
+
import { useMotionContext } from '../motion-context.js'
|
|
6
|
+
|
|
7
|
+
/** One paint owner per decorative surface; native control semantics remain in the parent. */
|
|
8
|
+
export const ChoicePaintSurface = defineComponent({
|
|
9
|
+
name: 'MavisChoicePaint',
|
|
10
|
+
inheritAttrs: false,
|
|
11
|
+
props: { paint: { type: Object as PropType<ChoicePaint>, required: true } },
|
|
12
|
+
setup(props, { slots, attrs }) {
|
|
13
|
+
const element = ref<HTMLElement>()
|
|
14
|
+
const { theme } = useMavisTheme()
|
|
15
|
+
const forcedColors = ref(false)
|
|
16
|
+
const initial = {
|
|
17
|
+
position: 'absolute' as const,
|
|
18
|
+
inset: 'calc(-1 * var(--m-choice-border, 0px))',
|
|
19
|
+
border: 'inherit',
|
|
20
|
+
borderRadius: 'inherit',
|
|
21
|
+
boxSizing: 'border-box' as const,
|
|
22
|
+
display: 'flex',
|
|
23
|
+
alignItems: 'center',
|
|
24
|
+
justifyContent: 'center',
|
|
25
|
+
...props.paint,
|
|
26
|
+
}
|
|
27
|
+
useConnectedMotion(element, useMotionContext(), (runtime, target) => {
|
|
28
|
+
const forced = target.ownerDocument.defaultView!.matchMedia('(forced-colors: active)')
|
|
29
|
+
let playback: ReturnType<typeof runtime.animate> | undefined
|
|
30
|
+
let geometry: ReturnType<typeof runtime.observeGeometry> | undefined
|
|
31
|
+
function update(instant = false) {
|
|
32
|
+
forcedColors.value = forced.matches
|
|
33
|
+
if (forced.matches) {
|
|
34
|
+
playback?.stop()
|
|
35
|
+
playback = undefined
|
|
36
|
+
runtime.release(target)
|
|
37
|
+
geometry?.dispose()
|
|
38
|
+
geometry = undefined
|
|
39
|
+
for (const key of ['background-color', 'border-color', 'color'])
|
|
40
|
+
target.style.removeProperty(key)
|
|
41
|
+
return
|
|
42
|
+
}
|
|
43
|
+
if (!geometry) {
|
|
44
|
+
runtime.set(target, props.paint)
|
|
45
|
+
geometry = runtime.observeGeometry(target)
|
|
46
|
+
}
|
|
47
|
+
const previous = playback
|
|
48
|
+
playback = runtime.animate(
|
|
49
|
+
target,
|
|
50
|
+
props.paint,
|
|
51
|
+
instant ? { duration: 0 } : choiceMotion(theme.value),
|
|
52
|
+
)
|
|
53
|
+
previous?.stop()
|
|
54
|
+
}
|
|
55
|
+
const changed = () => update(true)
|
|
56
|
+
forced.addEventListener('change', changed)
|
|
57
|
+
update(true)
|
|
58
|
+
const unwatch = watch(
|
|
59
|
+
() => [props.paint, theme.value.motion],
|
|
60
|
+
() => update(),
|
|
61
|
+
{ deep: true, flush: 'post' },
|
|
62
|
+
)
|
|
63
|
+
return () => {
|
|
64
|
+
unwatch()
|
|
65
|
+
forced.removeEventListener('change', changed)
|
|
66
|
+
playback?.stop()
|
|
67
|
+
runtime.release(target)
|
|
68
|
+
geometry?.dispose()
|
|
69
|
+
}
|
|
70
|
+
})
|
|
71
|
+
return () =>
|
|
72
|
+
h('span', { ...attrs, 'aria-hidden': 'true' }, [
|
|
73
|
+
h(
|
|
74
|
+
'span',
|
|
75
|
+
{
|
|
76
|
+
ref: element,
|
|
77
|
+
style: {
|
|
78
|
+
...initial,
|
|
79
|
+
// Vue patches style objects on slot updates. Preserve the paint written by Jolt.
|
|
80
|
+
...Object.fromEntries(
|
|
81
|
+
Object.keys(props.paint).map((key) => [
|
|
82
|
+
key,
|
|
83
|
+
forcedColors.value
|
|
84
|
+
? undefined
|
|
85
|
+
: element.value?.style?.[key as 'backgroundColor'] ||
|
|
86
|
+
initial[key as keyof typeof initial],
|
|
87
|
+
]),
|
|
88
|
+
),
|
|
89
|
+
},
|
|
90
|
+
'data-m-choice-paint': '',
|
|
91
|
+
},
|
|
92
|
+
slots.default?.(),
|
|
93
|
+
),
|
|
94
|
+
])
|
|
95
|
+
},
|
|
96
|
+
})
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
useMavisTheme,
|
|
8
8
|
actionEmits,
|
|
9
9
|
textContent,
|
|
10
|
-
|
|
10
|
+
useLayoutShrink,
|
|
11
11
|
viewAttrs,
|
|
12
12
|
} from '@getcortexlabs/mavis-core/vue'
|
|
13
13
|
import {
|
|
@@ -22,6 +22,7 @@ import {
|
|
|
22
22
|
} from '@getcortexlabs/mavis-core'
|
|
23
23
|
import { webAttrs } from '../style.js'
|
|
24
24
|
import { usePressFeedback } from '../motion.js'
|
|
25
|
+
import { navigationAttrs } from '../navigation.js'
|
|
25
26
|
|
|
26
27
|
export const MButton = defineComponent({
|
|
27
28
|
name: 'MButton',
|
|
@@ -41,7 +42,7 @@ export const MButton = defineComponent({
|
|
|
41
42
|
theme,
|
|
42
43
|
() => props.motionSurface,
|
|
43
44
|
)
|
|
44
|
-
const shrink =
|
|
45
|
+
const shrink = useLayoutShrink()
|
|
45
46
|
return () => {
|
|
46
47
|
const { colors, control } = theme.value
|
|
47
48
|
const tokens = theme.value.components.button
|
|
@@ -81,7 +82,7 @@ export const MButton = defineComponent({
|
|
|
81
82
|
)
|
|
82
83
|
: null
|
|
83
84
|
return h(
|
|
84
|
-
'button',
|
|
85
|
+
props.href === undefined ? 'button' : 'a',
|
|
85
86
|
mergeProps(
|
|
86
87
|
lifecycle,
|
|
87
88
|
{
|
|
@@ -109,20 +110,21 @@ export const MButton = defineComponent({
|
|
|
109
110
|
boxShadow: `var(--m-button-shadow, ${shadowStyle(theme.value.elevation[tokens.elevation])})`,
|
|
110
111
|
border: 0,
|
|
111
112
|
margin: 0,
|
|
113
|
+
textDecoration: 'none',
|
|
112
114
|
filter: props.disabled ? 'opacity(0.45)' : undefined,
|
|
113
115
|
flexGrow: nonNegative(props.grow, 'grow'),
|
|
114
|
-
flexShrink: nonNegative(props.shrink ?? shrink, 'shrink'),
|
|
116
|
+
flexShrink: nonNegative(props.shrink ?? shrink.value, 'shrink'),
|
|
115
117
|
minWidth: '44px',
|
|
116
118
|
'--m-focus': colors.primary,
|
|
117
119
|
},
|
|
118
120
|
},
|
|
119
121
|
webAttrs({ ...attrs, ...viewAttrs(props) }),
|
|
120
122
|
{
|
|
121
|
-
type: props.type,
|
|
123
|
+
type: props.href === undefined ? props.type : undefined,
|
|
122
124
|
name: props.name,
|
|
123
125
|
value: props.value,
|
|
124
126
|
form: props.form,
|
|
125
|
-
disabled: props.disabled,
|
|
127
|
+
disabled: props.href === undefined ? props.disabled : undefined,
|
|
126
128
|
'aria-disabled': props.disabled || props.loading || undefined,
|
|
127
129
|
'aria-busy': props.loading || undefined,
|
|
128
130
|
onClick: (event: MouseEvent) => {
|
|
@@ -130,9 +132,17 @@ export const MButton = defineComponent({
|
|
|
130
132
|
event.preventDefault()
|
|
131
133
|
return
|
|
132
134
|
}
|
|
133
|
-
emit('click')
|
|
135
|
+
if (props.href === undefined && !event.defaultPrevented) emit('click')
|
|
134
136
|
},
|
|
135
137
|
},
|
|
138
|
+
props.href === undefined
|
|
139
|
+
? {}
|
|
140
|
+
: navigationAttrs(
|
|
141
|
+
props,
|
|
142
|
+
props.disabled || props.loading,
|
|
143
|
+
() => emit('click'),
|
|
144
|
+
(error) => emit('error', error),
|
|
145
|
+
),
|
|
136
146
|
),
|
|
137
147
|
hasIcon
|
|
138
148
|
? [
|
package/src/components/MCard.ts
CHANGED
|
@@ -1,38 +1,53 @@
|
|
|
1
1
|
import { resolveSpace, resolveRadius, shadowStyle } from '@getcortexlabs/mavis-core'
|
|
2
|
-
import { defineComponent, h, mergeProps } from 'vue'
|
|
2
|
+
import { defineComponent, h, mergeProps, shallowRef, type VNode } from 'vue'
|
|
3
|
+
import { preserveBoundPaint } from '../motion-surface.js'
|
|
3
4
|
import {
|
|
4
5
|
useButtonAction,
|
|
5
6
|
cardProps,
|
|
6
7
|
useMavisTheme,
|
|
7
8
|
actionEmits,
|
|
8
9
|
} from '@getcortexlabs/mavis-core/vue'
|
|
9
|
-
import { MColumn } from './layout.js'
|
|
10
|
+
import { MColumn, createLayout } from './layout.js'
|
|
11
|
+
import { navigationAttrs } from '../navigation.js'
|
|
10
12
|
import { usePressFeedback } from '../motion.js'
|
|
11
13
|
|
|
14
|
+
const LinkColumn = createLayout('MCardLink', 'column', 'a')
|
|
15
|
+
|
|
12
16
|
export const MCard = defineComponent({
|
|
13
17
|
name: 'MCard',
|
|
14
18
|
inheritAttrs: false,
|
|
15
19
|
props: cardProps,
|
|
16
20
|
emits: actionEmits,
|
|
17
21
|
setup(props, { attrs, slots, emit }) {
|
|
18
|
-
useButtonAction(() => props.interactive)
|
|
22
|
+
useButtonAction(() => props.interactive || props.href !== undefined)
|
|
19
23
|
const { theme } = useMavisTheme()
|
|
24
|
+
const element = shallowRef<HTMLElement>()
|
|
20
25
|
const lifecycle = usePressFeedback(
|
|
21
|
-
() => props.interactive && !props.disabled,
|
|
26
|
+
() => (props.interactive || props.href !== undefined) && !props.disabled,
|
|
22
27
|
theme,
|
|
23
28
|
() => props.motionSurface,
|
|
24
29
|
() => !props.disabled,
|
|
25
30
|
)
|
|
26
31
|
const activate = () => {
|
|
27
|
-
if (props.interactive && !props.disabled) emit('click')
|
|
32
|
+
if ((props.interactive || props.href !== undefined) && !props.disabled) emit('click')
|
|
28
33
|
}
|
|
29
34
|
return () => {
|
|
30
|
-
const {
|
|
35
|
+
const {
|
|
36
|
+
interactive,
|
|
37
|
+
disabled,
|
|
38
|
+
elevation,
|
|
39
|
+
motionSurface,
|
|
40
|
+
href,
|
|
41
|
+
navigate,
|
|
42
|
+
target,
|
|
43
|
+
rel,
|
|
44
|
+
...layout
|
|
45
|
+
} = props
|
|
31
46
|
const tokens = theme.value.components.card
|
|
32
47
|
layout.padding ??= tokens.padding
|
|
33
48
|
layout.radius ??= tokens.radius
|
|
34
49
|
return h(
|
|
35
|
-
MColumn,
|
|
50
|
+
href === undefined ? MColumn : LinkColumn,
|
|
36
51
|
mergeProps(
|
|
37
52
|
lifecycle,
|
|
38
53
|
layout,
|
|
@@ -60,32 +75,43 @@ export const MCard = defineComponent({
|
|
|
60
75
|
? `${resolveRadius(theme.value, props.radius)}px`
|
|
61
76
|
: `var(--m-card-radius, ${resolveRadius(theme.value, tokens.radius)}px)`,
|
|
62
77
|
boxShadow: `var(--m-card-shadow, ${shadowStyle(theme.value.elevation[elevation ?? tokens.elevation])})`,
|
|
63
|
-
backgroundColor:
|
|
64
|
-
|
|
78
|
+
backgroundColor:
|
|
79
|
+
props.backgroundColor ?? `var(--m-card-background, ${theme.value.colors.surface})`,
|
|
80
|
+
border: `var(--m-card-border, 1px solid ${theme.value.colors.border})`,
|
|
65
81
|
filter: interactive && disabled ? 'opacity(0.45)' : undefined,
|
|
66
82
|
'--m-focus': theme.value.colors.primary,
|
|
83
|
+
textDecoration: 'none',
|
|
84
|
+
color: 'inherit',
|
|
67
85
|
},
|
|
68
86
|
},
|
|
69
87
|
attrs,
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
88
|
+
{
|
|
89
|
+
onVnodeMounted: (node: VNode) => {
|
|
90
|
+
element.value = node.el as HTMLElement
|
|
91
|
+
},
|
|
92
|
+
style: preserveBoundPaint(element.value),
|
|
93
|
+
},
|
|
94
|
+
href !== undefined
|
|
95
|
+
? navigationAttrs(props, disabled, activate, (error) => emit('error', error))
|
|
96
|
+
: interactive
|
|
97
|
+
? {
|
|
98
|
+
role: 'button',
|
|
99
|
+
tabindex: disabled ? -1 : 0,
|
|
100
|
+
'aria-disabled': disabled || undefined,
|
|
101
|
+
onClick: activate,
|
|
102
|
+
onKeydown: (event: KeyboardEvent) => {
|
|
103
|
+
if (event.target !== event.currentTarget) return
|
|
104
|
+
if (event.key === 'Enter' || event.key === ' ') event.preventDefault()
|
|
105
|
+
if (event.key === 'Enter' && !event.repeat) activate()
|
|
106
|
+
},
|
|
107
|
+
onKeyup: (event: KeyboardEvent) => {
|
|
108
|
+
if (event.target === event.currentTarget && event.key === ' ') {
|
|
109
|
+
event.preventDefault()
|
|
110
|
+
activate()
|
|
111
|
+
}
|
|
112
|
+
},
|
|
113
|
+
}
|
|
114
|
+
: {},
|
|
89
115
|
),
|
|
90
116
|
slots,
|
|
91
117
|
)
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ChoicePaintSurface } from './ChoicePaint.js'
|
|
1
2
|
import { fontFamily } from '@getcortexlabs/mavis-core'
|
|
2
3
|
import { defineComponent, h, mergeProps, nextTick, onBeforeUnmount, useId } from 'vue'
|
|
3
4
|
import {
|
|
@@ -5,7 +6,7 @@ import {
|
|
|
5
6
|
checkboxProps,
|
|
6
7
|
checkboxEmits,
|
|
7
8
|
useMavisTheme,
|
|
8
|
-
|
|
9
|
+
useLayoutShrink,
|
|
9
10
|
} from '@getcortexlabs/mavis-core/vue'
|
|
10
11
|
import { nonNegative, resolveDimension } from '@getcortexlabs/mavis-core'
|
|
11
12
|
import { length, webAttrs } from '../style.js'
|
|
@@ -19,7 +20,7 @@ export const MCheckbox = defineComponent({
|
|
|
19
20
|
setup(props, { attrs, emit }) {
|
|
20
21
|
useButtonAction()
|
|
21
22
|
const { theme } = useMavisTheme()
|
|
22
|
-
const shrink =
|
|
23
|
+
const shrink = useLayoutShrink()
|
|
23
24
|
const generatedId = `m-checkbox-${useId()}`
|
|
24
25
|
useHydrationEdit(
|
|
25
26
|
(root) => {
|
|
@@ -71,7 +72,7 @@ export const MCheckbox = defineComponent({
|
|
|
71
72
|
borderRadius: '10px',
|
|
72
73
|
opacity: props.disabled ? 0.45 : 1,
|
|
73
74
|
flexGrow: nonNegative(props.grow, 'grow'),
|
|
74
|
-
flexShrink: nonNegative(props.shrink ?? shrink, 'shrink'),
|
|
75
|
+
flexShrink: nonNegative(props.shrink ?? shrink.value, 'shrink'),
|
|
75
76
|
width: length(resolveDimension(props.width)),
|
|
76
77
|
color: colors.text,
|
|
77
78
|
fontSize: `${typography.body.fontSize}px`,
|
|
@@ -110,9 +111,19 @@ export const MCheckbox = defineComponent({
|
|
|
110
111
|
})
|
|
111
112
|
},
|
|
112
113
|
}),
|
|
113
|
-
h(
|
|
114
|
-
|
|
115
|
-
|
|
114
|
+
h(
|
|
115
|
+
ChoicePaintSurface,
|
|
116
|
+
{
|
|
117
|
+
class: 'm-checkbox-box',
|
|
118
|
+
paint: {
|
|
119
|
+
backgroundColor:
|
|
120
|
+
props.modelValue || props.indeterminate ? colors.primary : colors.surface,
|
|
121
|
+
borderColor:
|
|
122
|
+
props.modelValue || props.indeterminate ? colors.primary : colors.muted,
|
|
123
|
+
},
|
|
124
|
+
},
|
|
125
|
+
() => [h('span', { class: 'm-checkbox-mark' })],
|
|
126
|
+
),
|
|
116
127
|
h(
|
|
117
128
|
'span',
|
|
118
129
|
{
|
|
@@ -27,7 +27,7 @@ import {
|
|
|
27
27
|
useCombobox,
|
|
28
28
|
useMavisTheme,
|
|
29
29
|
useButtonAction,
|
|
30
|
-
|
|
30
|
+
useLayoutShrink,
|
|
31
31
|
} from '@getcortexlabs/mavis-core/vue'
|
|
32
32
|
import { MColumn } from './layout.js'
|
|
33
33
|
import { MText } from './MText.js'
|
|
@@ -46,7 +46,7 @@ const Combobox = defineComponent({
|
|
|
46
46
|
useButtonAction()
|
|
47
47
|
const { theme } = useMavisTheme()
|
|
48
48
|
const combo = useCombobox(props, emit)
|
|
49
|
-
const shrink =
|
|
49
|
+
const shrink = useLayoutShrink()
|
|
50
50
|
const generatedId = `m-combobox-${useId()}`
|
|
51
51
|
const root = ref<HTMLElement>()
|
|
52
52
|
const editor = ref<HTMLInputElement>()
|
|
@@ -243,7 +243,7 @@ const Combobox = defineComponent({
|
|
|
243
243
|
minWidth: 0,
|
|
244
244
|
width: length(resolveDimension(props.width)),
|
|
245
245
|
flexGrow: nonNegative(props.grow, 'grow'),
|
|
246
|
-
flexShrink: nonNegative(props.shrink ?? shrink, 'shrink'),
|
|
246
|
+
flexShrink: nonNegative(props.shrink ?? shrink.value, 'shrink'),
|
|
247
247
|
},
|
|
248
248
|
}),
|
|
249
249
|
[
|
|
@@ -17,6 +17,14 @@ export const { MDatePicker, MDateRangePicker } = createDatePickers({
|
|
|
17
17
|
Row: MRow,
|
|
18
18
|
Sheet: MSheet,
|
|
19
19
|
Calendar: DateCalendar,
|
|
20
|
+
deferActions: true,
|
|
21
|
+
openerAttrs: {
|
|
22
|
+
// Safari does not focus buttons on pointer activation. Capture the actual trigger
|
|
23
|
+
// before the Sheet snapshots focus; keyboard activation already has the right owner.
|
|
24
|
+
onMousedown(event: MouseEvent) {
|
|
25
|
+
if (event.button === 0) (event.currentTarget as HTMLElement).focus({ preventScroll: true })
|
|
26
|
+
},
|
|
27
|
+
},
|
|
20
28
|
beforeOpen: focusOpener,
|
|
21
29
|
// MSheet restores the Web opener after its close animation.
|
|
22
30
|
afterClose: () => {},
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { defineComponent, h, mergeProps, onBeforeUnmount, ref, watch } from 'vue'
|
|
2
|
+
import { imageProps, useMavisTheme } from '@getcortexlabs/mavis-core/vue'
|
|
3
|
+
import { resolveRadius, resolveDimension } from '@getcortexlabs/mavis-core'
|
|
4
|
+
import { boxStyle, webAttrs, length } from '../style.js'
|
|
5
|
+
|
|
6
|
+
export const MImage = defineComponent({
|
|
7
|
+
name: 'MImage',
|
|
8
|
+
inheritAttrs: false,
|
|
9
|
+
props: imageProps,
|
|
10
|
+
emits: { load: (_src: string) => true, error: (_src: string) => true },
|
|
11
|
+
setup(props, { attrs, emit }) {
|
|
12
|
+
const { theme } = useMavisTheme()
|
|
13
|
+
const status = ref<'loading' | 'ready' | 'error'>('loading')
|
|
14
|
+
let generation = 0,
|
|
15
|
+
alive = true
|
|
16
|
+
watch(
|
|
17
|
+
() => props.src,
|
|
18
|
+
() => {
|
|
19
|
+
generation++
|
|
20
|
+
status.value = props.src.trim() ? 'loading' : 'error'
|
|
21
|
+
},
|
|
22
|
+
{ flush: 'sync', immediate: true },
|
|
23
|
+
)
|
|
24
|
+
onBeforeUnmount(() => {
|
|
25
|
+
alive = false
|
|
26
|
+
generation++
|
|
27
|
+
})
|
|
28
|
+
return () => {
|
|
29
|
+
if (!Number.isFinite(props.aspectRatio) || props.aspectRatio <= 0)
|
|
30
|
+
throw new RangeError('aspectRatio must be finite and positive.')
|
|
31
|
+
const current = generation,
|
|
32
|
+
src = props.src
|
|
33
|
+
const settle = (success: boolean) => {
|
|
34
|
+
if (!alive || current !== generation || status.value !== 'loading') return
|
|
35
|
+
status.value = success ? 'ready' : 'error'
|
|
36
|
+
if (success) emit('load', src)
|
|
37
|
+
else emit('error', src)
|
|
38
|
+
}
|
|
39
|
+
const radius = resolveRadius(theme.value, props.radius)
|
|
40
|
+
return h(
|
|
41
|
+
'div',
|
|
42
|
+
mergeProps(webAttrs(attrs), {
|
|
43
|
+
id: props.id,
|
|
44
|
+
class: 'm-image',
|
|
45
|
+
'data-state': status.value,
|
|
46
|
+
'aria-hidden': props.accessibilityHidden || !props.alt || undefined,
|
|
47
|
+
role: status.value === 'ready' ? undefined : 'img',
|
|
48
|
+
'aria-label':
|
|
49
|
+
status.value === 'ready'
|
|
50
|
+
? undefined
|
|
51
|
+
: `${props.alt}: ${status.value === 'error' ? props.errorLabel : props.loadingLabel}`,
|
|
52
|
+
style: {
|
|
53
|
+
...boxStyle(theme.value, props),
|
|
54
|
+
position: 'relative',
|
|
55
|
+
overflow: 'hidden',
|
|
56
|
+
width: length(resolveDimension(props.width)) ?? '100%',
|
|
57
|
+
aspectRatio: String(props.aspectRatio),
|
|
58
|
+
borderRadius: `${radius}px`,
|
|
59
|
+
backgroundColor: props.backgroundColor || theme.value.colors.elevated,
|
|
60
|
+
},
|
|
61
|
+
}),
|
|
62
|
+
[
|
|
63
|
+
src.trim()
|
|
64
|
+
? h('img', {
|
|
65
|
+
key: `${current}:${src}`,
|
|
66
|
+
src,
|
|
67
|
+
alt: props.alt,
|
|
68
|
+
onLoad: () => settle(true),
|
|
69
|
+
onError: () => settle(false),
|
|
70
|
+
onVnodeMounted: (node) => {
|
|
71
|
+
const image = node.el as HTMLImageElement
|
|
72
|
+
if (image.complete) settle(image.naturalWidth > 0)
|
|
73
|
+
},
|
|
74
|
+
style: {
|
|
75
|
+
position: 'absolute',
|
|
76
|
+
inset: 0,
|
|
77
|
+
width: '100%',
|
|
78
|
+
height: '100%',
|
|
79
|
+
objectFit: props.fit,
|
|
80
|
+
opacity: status.value === 'ready' ? 1 : 0,
|
|
81
|
+
},
|
|
82
|
+
})
|
|
83
|
+
: null,
|
|
84
|
+
status.value !== 'ready'
|
|
85
|
+
? h(
|
|
86
|
+
'span',
|
|
87
|
+
{
|
|
88
|
+
'aria-hidden': 'true',
|
|
89
|
+
style: {
|
|
90
|
+
position: 'absolute',
|
|
91
|
+
inset: 0,
|
|
92
|
+
display: 'flex',
|
|
93
|
+
alignItems: 'center',
|
|
94
|
+
justifyContent: 'center',
|
|
95
|
+
padding: '16px',
|
|
96
|
+
color: theme.value.colors.muted,
|
|
97
|
+
fontSize: `${theme.value.typography.caption.fontSize}px`,
|
|
98
|
+
textAlign: 'center',
|
|
99
|
+
},
|
|
100
|
+
},
|
|
101
|
+
status.value === 'error' ? props.errorLabel : props.loadingLabel,
|
|
102
|
+
)
|
|
103
|
+
: null,
|
|
104
|
+
],
|
|
105
|
+
)
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
})
|
package/src/components/MInput.ts
CHANGED
|
@@ -16,7 +16,7 @@ import {
|
|
|
16
16
|
inputProps,
|
|
17
17
|
inputEmits,
|
|
18
18
|
useMavisTheme,
|
|
19
|
-
|
|
19
|
+
useLayoutShrink,
|
|
20
20
|
} from '@getcortexlabs/mavis-core/vue'
|
|
21
21
|
import {
|
|
22
22
|
fontFamily,
|
|
@@ -43,7 +43,7 @@ const Input = defineComponent({
|
|
|
43
43
|
useButtonAction()
|
|
44
44
|
const instance = getCurrentInstance()!
|
|
45
45
|
const { theme } = useMavisTheme()
|
|
46
|
-
const shrink =
|
|
46
|
+
const shrink = useLayoutShrink()
|
|
47
47
|
const generatedId = `m-input-${useId()}`
|
|
48
48
|
const editor = ref<HTMLInputElement | HTMLTextAreaElement>()
|
|
49
49
|
const focused = ref(false)
|
|
@@ -186,7 +186,7 @@ const Input = defineComponent({
|
|
|
186
186
|
minWidth: 0,
|
|
187
187
|
fontFamily: fontFamily(typography.body.fontFamily, 'web'),
|
|
188
188
|
flexGrow: nonNegative(props.grow, 'grow'),
|
|
189
|
-
flexShrink: nonNegative(props.shrink ?? shrink, 'shrink'),
|
|
189
|
+
flexShrink: nonNegative(props.shrink ?? shrink.value, 'shrink'),
|
|
190
190
|
width: length(resolveDimension(props.width)),
|
|
191
191
|
opacity: props.disabled ? 0.5 : 1,
|
|
192
192
|
'--m-input-placeholder': colors.muted,
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { defineComponent, h, mergeProps } from 'vue'
|
|
2
|
+
import { fontFamily, linkDestination, linkRel, nonNegative } from '@getcortexlabs/mavis-core'
|
|
3
|
+
import {
|
|
4
|
+
linkProps,
|
|
5
|
+
linkEmits,
|
|
6
|
+
textContent,
|
|
7
|
+
useLayoutShrink,
|
|
8
|
+
useMavisTheme,
|
|
9
|
+
viewAttrs,
|
|
10
|
+
} from '@getcortexlabs/mavis-core/vue'
|
|
11
|
+
import { webAttrs } from '../style.js'
|
|
12
|
+
|
|
13
|
+
export const MLink = defineComponent({
|
|
14
|
+
name: 'MLink',
|
|
15
|
+
inheritAttrs: false,
|
|
16
|
+
props: linkProps,
|
|
17
|
+
emits: linkEmits,
|
|
18
|
+
setup(props, { attrs, slots, emit }) {
|
|
19
|
+
const { theme } = useMavisTheme()
|
|
20
|
+
const shrink = useLayoutShrink()
|
|
21
|
+
return () => {
|
|
22
|
+
const href = linkDestination(props.href)
|
|
23
|
+
const text = props.text ?? textContent(slots.default?.())
|
|
24
|
+
if (!(props.accessibilityLabel ?? text).trim()) throw new TypeError('MLink requires a name.')
|
|
25
|
+
const type = theme.value.typography.body
|
|
26
|
+
return h(
|
|
27
|
+
'a',
|
|
28
|
+
mergeProps(webAttrs({ ...attrs, ...viewAttrs(props) }), {
|
|
29
|
+
class: 'm-link',
|
|
30
|
+
href: props.disabled ? undefined : href,
|
|
31
|
+
target: props.target,
|
|
32
|
+
rel: linkRel(props.target, props.rel),
|
|
33
|
+
role: 'link',
|
|
34
|
+
tabindex: props.disabled ? -1 : undefined,
|
|
35
|
+
'aria-disabled': props.disabled || undefined,
|
|
36
|
+
style: {
|
|
37
|
+
'--m-focus': theme.value.colors.primary,
|
|
38
|
+
display: props.inline ? 'inline' : 'inline-flex',
|
|
39
|
+
alignItems: 'center',
|
|
40
|
+
justifyContent: 'center',
|
|
41
|
+
minHeight: props.inline ? undefined : '44px',
|
|
42
|
+
fontFamily: fontFamily(type.fontFamily, 'web'),
|
|
43
|
+
fontSize: `${type.fontSize}px`,
|
|
44
|
+
fontWeight: type.fontWeight,
|
|
45
|
+
lineHeight: type.lineHeight,
|
|
46
|
+
color: theme.value.colors.primary,
|
|
47
|
+
textDecoration: 'underline',
|
|
48
|
+
textUnderlineOffset: '0.18em',
|
|
49
|
+
cursor: props.disabled ? 'default' : 'pointer',
|
|
50
|
+
opacity: props.disabled ? 0.45 : 1,
|
|
51
|
+
overflowWrap: 'anywhere',
|
|
52
|
+
flexGrow: nonNegative(props.grow, 'grow'),
|
|
53
|
+
flexShrink: nonNegative(props.shrink ?? shrink.value, 'shrink'),
|
|
54
|
+
minWidth: 0,
|
|
55
|
+
},
|
|
56
|
+
onClick(event: MouseEvent) {
|
|
57
|
+
if (props.disabled) {
|
|
58
|
+
event.preventDefault()
|
|
59
|
+
return
|
|
60
|
+
}
|
|
61
|
+
if (event.defaultPrevented) return
|
|
62
|
+
emit('click')
|
|
63
|
+
if (
|
|
64
|
+
!props.navigate ||
|
|
65
|
+
props.target !== '_self' ||
|
|
66
|
+
event.button !== 0 ||
|
|
67
|
+
event.metaKey ||
|
|
68
|
+
event.ctrlKey ||
|
|
69
|
+
event.shiftKey ||
|
|
70
|
+
event.altKey
|
|
71
|
+
)
|
|
72
|
+
return
|
|
73
|
+
event.preventDefault()
|
|
74
|
+
try {
|
|
75
|
+
Promise.resolve(props.navigate(href)).catch((error) => emit('error', error))
|
|
76
|
+
} catch (error) {
|
|
77
|
+
emit('error', error)
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
}),
|
|
81
|
+
text,
|
|
82
|
+
)
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
})
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ChoicePaintSurface } from './ChoicePaint.js'
|
|
1
2
|
import { fontFamily } from '@getcortexlabs/mavis-core'
|
|
2
3
|
import { computed, defineComponent, h, mergeProps, nextTick, onBeforeUnmount, useId } from 'vue'
|
|
3
4
|
import { choiceKey, validateChoices, canChoose, type ChoiceOption } from '@getcortexlabs/mavis-core'
|
|
@@ -167,9 +168,14 @@ export const MRadioGroup = defineComponent({
|
|
|
167
168
|
onChange: () => request(option),
|
|
168
169
|
onKeydown: (event: KeyboardEvent) => keydown(event, option),
|
|
169
170
|
}),
|
|
170
|
-
h(
|
|
171
|
-
|
|
172
|
-
|
|
171
|
+
h(
|
|
172
|
+
ChoicePaintSurface,
|
|
173
|
+
{
|
|
174
|
+
class: 'm-radio-indicator',
|
|
175
|
+
paint: { borderColor: selected ? colors.primary : colors.muted },
|
|
176
|
+
},
|
|
177
|
+
() => [h('span', { class: 'm-radio-dot' })],
|
|
178
|
+
),
|
|
173
179
|
h(
|
|
174
180
|
'span',
|
|
175
181
|
{
|