@getcortexlabs/mavis-web 0.1.0-alpha.3 → 0.1.0-alpha.5
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 +6 -4
- package/dist/components/DateCalendar.d.ts +95 -0
- package/dist/components/DateCalendar.d.ts.map +1 -0
- package/dist/components/DateCalendar.js +157 -0
- package/dist/components/DateCalendar.js.map +1 -0
- package/dist/components/MAccordion.d.ts +119 -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 +109 -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 +80 -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 +70 -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 +126 -32
- 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 +65 -19
- 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 +103 -0
- package/dist/components/MCheckbox.d.ts.map +1 -0
- package/dist/components/MCheckbox.js +127 -0
- package/dist/components/MCheckbox.js.map +1 -0
- package/dist/components/MChip.d.ts +117 -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/MCombobox.d.ts +282 -0
- package/dist/components/MCombobox.d.ts.map +1 -0
- package/dist/components/MCombobox.js +440 -0
- package/dist/components/MCombobox.js.map +1 -0
- package/dist/components/MDatePicker.d.ts +1254 -0
- package/dist/components/MDatePicker.d.ts.map +1 -0
- package/dist/components/MDatePicker.js +22 -0
- package/dist/components/MDatePicker.js.map +1 -0
- package/dist/components/MDialog.d.ts +96 -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 +117 -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/MFilePicker.d.ts +112 -0
- package/dist/components/MFilePicker.d.ts.map +1 -0
- package/dist/components/MFilePicker.js +193 -0
- package/dist/components/MFilePicker.js.map +1 -0
- package/dist/components/MIcon.d.ts +5 -3
- package/dist/components/MIcon.d.ts.map +1 -1
- package/dist/components/MInput.d.ts +182 -52
- package/dist/components/MInput.d.ts.map +1 -1
- package/dist/components/MInput.js +113 -21
- package/dist/components/MInput.js.map +1 -1
- package/dist/components/MListItem.d.ts +104 -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 +122 -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 +104 -0
- package/dist/components/MRadioGroup.d.ts.map +1 -0
- package/dist/components/MRadioGroup.js +189 -0
- package/dist/components/MRadioGroup.js.map +1 -0
- package/dist/components/MReveal.d.ts +71 -35
- 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 +22 -7
- package/dist/components/MScreen.d.ts.map +1 -1
- package/dist/components/MScreen.js +13 -1
- package/dist/components/MScreen.js.map +1 -1
- package/dist/components/MSegmentedControl.d.ts +95 -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 +140 -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 +56 -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 +27 -15
- package/dist/components/MSheet.d.ts.map +1 -1
- package/dist/components/MSheet.js +82 -55
- package/dist/components/MSheet.js.map +1 -1
- package/dist/components/MSkeleton.d.ts +78 -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 +8 -4
- package/dist/components/MSlider.d.ts.map +1 -1
- package/dist/components/MSlider.js +14 -2
- package/dist/components/MSlider.js.map +1 -1
- package/dist/components/MSwitch.d.ts +89 -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 +101 -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 +51 -26
- 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/components/layout.d.ts +193 -84
- package/dist/components/layout.d.ts.map +1 -1
- package/dist/components/layout.js +5 -3
- package/dist/components/layout.js.map +1 -1
- package/dist/components/workflows.d.ts +251 -0
- package/dist/components/workflows.d.ts.map +1 -0
- package/dist/components/workflows.js +23 -0
- package/dist/components/workflows.js.map +1 -0
- package/dist/files.d.ts +6 -0
- package/dist/files.d.ts.map +1 -0
- package/dist/files.js +82 -0
- package/dist/files.js.map +1 -0
- package/dist/hydration.d.ts +3 -0
- package/dist/hydration.d.ts.map +1 -0
- package/dist/hydration.js +20 -0
- package/dist/hydration.js.map +1 -0
- package/dist/index.d.ts +31 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +57 -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-context.d.ts +13 -0
- package/dist/motion-context.d.ts.map +1 -0
- package/dist/motion-context.js +33 -0
- package/dist/motion-context.js.map +1 -0
- package/dist/motion-region.d.ts +13 -0
- package/dist/motion-region.d.ts.map +1 -0
- package/dist/motion-region.js +134 -0
- package/dist/motion-region.js.map +1 -0
- package/dist/motion-surface.d.ts +12 -0
- package/dist/motion-surface.d.ts.map +1 -0
- package/dist/motion-surface.js +135 -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 +263 -0
- package/dist/motion.js.map +1 -0
- package/dist/screen-viewport.d.ts.map +1 -1
- package/dist/screen-viewport.js +8 -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 +182 -0
- package/dist/sheet-motion.js.map +1 -0
- package/package.json +4 -3
- package/src/components/DateCalendar.ts +213 -0
- 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 +149 -0
- package/src/components/MChip.ts +109 -0
- package/src/components/MCombobox.ts +510 -0
- package/src/components/MDatePicker.ts +23 -0
- package/src/components/MDialog.ts +245 -0
- package/src/components/MEmptyState.ts +96 -0
- package/src/components/MFilePicker.ts +233 -0
- package/src/components/MInput.ts +186 -71
- package/src/components/MListItem.ts +66 -0
- package/src/components/MProgress.ts +82 -0
- package/src/components/MRadioGroup.ts +210 -0
- package/src/components/MReveal.ts +40 -3
- package/src/components/MScreen.ts +17 -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 +101 -52
- package/src/components/MSkeleton.ts +52 -0
- package/src/components/MSlider.ts +25 -2
- 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/components/layout.ts +5 -2
- package/src/components/workflows.ts +27 -0
- package/src/files.ts +77 -0
- package/src/hydration.ts +21 -0
- package/src/index.ts +94 -3
- package/src/input-attrs.ts +41 -0
- package/src/motion-context.ts +35 -0
- package/src/motion-region.ts +145 -0
- package/src/motion-surface.ts +150 -0
- package/src/motion.ts +311 -0
- package/src/screen-viewport.ts +6 -0
- package/src/scroll-motion.ts +75 -0
- package/src/sheet-motion.ts +181 -0
- package/src/style.css +806 -54
|
@@ -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,7 +1,13 @@
|
|
|
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'
|
|
10
|
+
import { useHydrationEdit } from '../hydration.js'
|
|
5
11
|
|
|
6
12
|
export const MSlider = defineComponent({
|
|
7
13
|
name: 'MSlider',
|
|
@@ -9,7 +15,24 @@ export const MSlider = defineComponent({
|
|
|
9
15
|
props: sliderProps,
|
|
10
16
|
emits: sliderEmits,
|
|
11
17
|
setup(props, { attrs, emit }) {
|
|
18
|
+
useButtonAction()
|
|
12
19
|
const { theme } = useMavisTheme()
|
|
20
|
+
const hydrationEdit = useHydrationEdit(
|
|
21
|
+
(root) => {
|
|
22
|
+
const input = root as HTMLInputElement
|
|
23
|
+
const scale = sliderScale(props.min, props.max, props.step)
|
|
24
|
+
if (
|
|
25
|
+
!props.disabled &&
|
|
26
|
+
Number(input.defaultValue) === scale.toNative(props.modelValue) &&
|
|
27
|
+
input.value !== input.defaultValue
|
|
28
|
+
) {
|
|
29
|
+
input.defaultValue = input.value
|
|
30
|
+
return input.valueAsNumber
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
(index) =>
|
|
34
|
+
emit('update:modelValue', sliderScale(props.min, props.max, props.step).fromNative(index)),
|
|
35
|
+
)
|
|
13
36
|
return () => {
|
|
14
37
|
const scale = sliderScale(props.min, props.max, props.step)
|
|
15
38
|
const index = scale.toNative(props.modelValue)
|
|
@@ -38,7 +61,7 @@ export const MSlider = defineComponent({
|
|
|
38
61
|
min: 0,
|
|
39
62
|
max: scale.steps,
|
|
40
63
|
step: 1,
|
|
41
|
-
value: index,
|
|
64
|
+
value: hydrationEdit() ?? index,
|
|
42
65
|
disabled: props.disabled,
|
|
43
66
|
'aria-label': props.label,
|
|
44
67
|
'aria-valuemin': props.min,
|
|
@@ -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
|
+
})
|
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
import { fontFamily } from '@getcortexlabs/mavis-core'
|
|
2
|
+
import {
|
|
3
|
+
computed,
|
|
4
|
+
KeepAlive,
|
|
5
|
+
defineComponent,
|
|
6
|
+
h,
|
|
7
|
+
mergeProps,
|
|
8
|
+
nextTick,
|
|
9
|
+
onBeforeUnmount,
|
|
10
|
+
onActivated,
|
|
11
|
+
onDeactivated,
|
|
12
|
+
onMounted,
|
|
13
|
+
ref,
|
|
14
|
+
useId,
|
|
15
|
+
watch,
|
|
16
|
+
type SlotsType,
|
|
17
|
+
} from 'vue'
|
|
18
|
+
import {
|
|
19
|
+
canChoose,
|
|
20
|
+
choiceKey,
|
|
21
|
+
tabFocusTarget,
|
|
22
|
+
validateTabs,
|
|
23
|
+
type TabOption,
|
|
24
|
+
type TabPanelProps,
|
|
25
|
+
} from '@getcortexlabs/mavis-core'
|
|
26
|
+
import { useButtonAction, tabsProps, tabsEmits, useMavisTheme } from '@getcortexlabs/mavis-core/vue'
|
|
27
|
+
import { MColumn } from './layout.js'
|
|
28
|
+
|
|
29
|
+
const TabPanel = defineComponent({
|
|
30
|
+
name: 'MTabPanel',
|
|
31
|
+
setup(_props, { slots }) {
|
|
32
|
+
useButtonAction()
|
|
33
|
+
return () => h('div', {}, slots.default?.())
|
|
34
|
+
},
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
export const MTabs = defineComponent({
|
|
38
|
+
name: 'MTabs',
|
|
39
|
+
inheritAttrs: false,
|
|
40
|
+
props: tabsProps,
|
|
41
|
+
emits: tabsEmits,
|
|
42
|
+
slots: Object as SlotsType<{ default: TabPanelProps }>,
|
|
43
|
+
setup(props, { attrs, emit, slots }) {
|
|
44
|
+
const { theme } = useMavisTheme()
|
|
45
|
+
const generated = `m-tabs-${useId()}`
|
|
46
|
+
const controls = new Map<string, HTMLButtonElement>()
|
|
47
|
+
const track = ref<HTMLElement>(),
|
|
48
|
+
scroller = ref<HTMLElement>()
|
|
49
|
+
const marker = ref<{ left: number; width: number }>()
|
|
50
|
+
const focusValue = ref(props.modelValue)
|
|
51
|
+
const selected = computed(() => {
|
|
52
|
+
validateTabs(props.tabs, props.modelValue, props.label)
|
|
53
|
+
return props.tabs.find((tab) => tab.value === props.modelValue)
|
|
54
|
+
})
|
|
55
|
+
let observer: ResizeObserver | undefined
|
|
56
|
+
let frame: number | undefined
|
|
57
|
+
let alive = false
|
|
58
|
+
function reveal(button: HTMLButtonElement) {
|
|
59
|
+
if (!scroller.value) return
|
|
60
|
+
const bounds = button.getBoundingClientRect(),
|
|
61
|
+
viewport = scroller.value.getBoundingClientRect()
|
|
62
|
+
const delta =
|
|
63
|
+
bounds.left < viewport.left
|
|
64
|
+
? bounds.left - viewport.left
|
|
65
|
+
: bounds.right > viewport.right
|
|
66
|
+
? bounds.right - viewport.right
|
|
67
|
+
: 0
|
|
68
|
+
if (delta) scroller.value.scrollBy({ left: delta, behavior: 'instant' })
|
|
69
|
+
}
|
|
70
|
+
function measure(revealSelection = false) {
|
|
71
|
+
if (!alive) return
|
|
72
|
+
if (frame !== undefined) cancelAnimationFrame(frame)
|
|
73
|
+
frame = requestAnimationFrame(() => {
|
|
74
|
+
frame = undefined
|
|
75
|
+
const button = selected.value && controls.get(choiceKey(selected.value.value))
|
|
76
|
+
marker.value = button ? { left: button.offsetLeft, width: button.offsetWidth } : undefined
|
|
77
|
+
if (button && revealSelection) reveal(button)
|
|
78
|
+
})
|
|
79
|
+
}
|
|
80
|
+
function observe() {
|
|
81
|
+
observer?.disconnect()
|
|
82
|
+
if (!alive) return
|
|
83
|
+
if (track.value) observer?.observe(track.value)
|
|
84
|
+
if (scroller.value) observer?.observe(scroller.value)
|
|
85
|
+
for (const button of controls.values()) observer?.observe(button)
|
|
86
|
+
measure(true)
|
|
87
|
+
}
|
|
88
|
+
const start = () => {
|
|
89
|
+
if (alive) return
|
|
90
|
+
alive = true
|
|
91
|
+
observer = new ResizeObserver(() => measure(true))
|
|
92
|
+
observe()
|
|
93
|
+
}
|
|
94
|
+
const stop = () => {
|
|
95
|
+
alive = false
|
|
96
|
+
observer?.disconnect()
|
|
97
|
+
if (frame !== undefined) cancelAnimationFrame(frame)
|
|
98
|
+
frame = undefined
|
|
99
|
+
}
|
|
100
|
+
onMounted(start)
|
|
101
|
+
onActivated(start)
|
|
102
|
+
onDeactivated(stop)
|
|
103
|
+
watch(
|
|
104
|
+
() => [props.modelValue, props.tabs, props.disabled],
|
|
105
|
+
() => {
|
|
106
|
+
const focused = typeof document !== 'undefined' ? document.activeElement : null
|
|
107
|
+
const ownedFocus = focused && track.value?.contains(focused)
|
|
108
|
+
focusValue.value = props.modelValue
|
|
109
|
+
void nextTick(() => {
|
|
110
|
+
observe()
|
|
111
|
+
if (!alive || !ownedFocus || props.disabled) return
|
|
112
|
+
const stillAvailable = props.tabs.some(
|
|
113
|
+
(tab) => !tab.disabled && controls.get(choiceKey(tab.value)) === focused,
|
|
114
|
+
)
|
|
115
|
+
if (stillAvailable) return
|
|
116
|
+
const next =
|
|
117
|
+
props.tabs.find((tab) => !tab.disabled && tab.value === props.modelValue) ??
|
|
118
|
+
props.tabs.find((tab) => !tab.disabled)
|
|
119
|
+
const button = next && controls.get(choiceKey(next.value))
|
|
120
|
+
button?.focus({ preventScroll: true })
|
|
121
|
+
if (button) reveal(button)
|
|
122
|
+
})
|
|
123
|
+
},
|
|
124
|
+
{ deep: true, flush: 'pre' },
|
|
125
|
+
)
|
|
126
|
+
onBeforeUnmount(() => {
|
|
127
|
+
alive = false
|
|
128
|
+
observer?.disconnect()
|
|
129
|
+
if (frame !== undefined) cancelAnimationFrame(frame)
|
|
130
|
+
controls.clear()
|
|
131
|
+
})
|
|
132
|
+
function request(tab: TabOption) {
|
|
133
|
+
if (canChoose(tab, props.modelValue, props.disabled)) emit('update:modelValue', tab.value)
|
|
134
|
+
}
|
|
135
|
+
function keydown(event: KeyboardEvent, tab: TabOption) {
|
|
136
|
+
if (props.disabled || tab.disabled || event.altKey || event.ctrlKey || event.metaKey) return
|
|
137
|
+
const rtl = track.value && getComputedStyle(track.value).direction === 'rtl'
|
|
138
|
+
const next = tabFocusTarget(props.tabs, tab.value, event.key, rtl)
|
|
139
|
+
if (!next) return
|
|
140
|
+
event.preventDefault()
|
|
141
|
+
focusValue.value = next.value
|
|
142
|
+
const button = controls.get(choiceKey(next.value))
|
|
143
|
+
button?.focus({ preventScroll: true })
|
|
144
|
+
if (button) reveal(button)
|
|
145
|
+
}
|
|
146
|
+
return () => {
|
|
147
|
+
const active = selected.value
|
|
148
|
+
const { colors, typography } = theme.value
|
|
149
|
+
const id = props.id ?? generated
|
|
150
|
+
const tabId = (tab: TabOption) => `${id}-${encodeURIComponent(choiceKey(tab.value))}`
|
|
151
|
+
const focus =
|
|
152
|
+
props.tabs.find((tab) => !tab.disabled && tab.value === focusValue.value) ??
|
|
153
|
+
props.tabs.find((tab) => !tab.disabled)
|
|
154
|
+
return h(
|
|
155
|
+
MColumn,
|
|
156
|
+
mergeProps(attrs, {
|
|
157
|
+
id,
|
|
158
|
+
width: props.width,
|
|
159
|
+
grow: props.grow,
|
|
160
|
+
shrink: props.shrink,
|
|
161
|
+
accessibilityHidden: props.accessibilityHidden,
|
|
162
|
+
gap: 'md',
|
|
163
|
+
}),
|
|
164
|
+
{
|
|
165
|
+
default: () => [
|
|
166
|
+
h(
|
|
167
|
+
'div',
|
|
168
|
+
{ ref: scroller, class: 'm-tabs-scroll', style: { '--m-focus': colors.primary } },
|
|
169
|
+
[
|
|
170
|
+
h(
|
|
171
|
+
'div',
|
|
172
|
+
{
|
|
173
|
+
ref: track,
|
|
174
|
+
class: 'm-tabs-track',
|
|
175
|
+
role: 'tablist',
|
|
176
|
+
'aria-label': props.label,
|
|
177
|
+
'aria-orientation': 'horizontal',
|
|
178
|
+
'aria-disabled': props.disabled || undefined,
|
|
179
|
+
style: {
|
|
180
|
+
borderBottomColor: colors.border,
|
|
181
|
+
fontFamily: fontFamily(theme.value.typography.body.fontFamily, 'web'),
|
|
182
|
+
fontSize: `${typography.body.fontSize}px`,
|
|
183
|
+
},
|
|
184
|
+
},
|
|
185
|
+
[
|
|
186
|
+
...props.tabs.map((tab) =>
|
|
187
|
+
h(
|
|
188
|
+
'button',
|
|
189
|
+
{
|
|
190
|
+
key: choiceKey(tab.value),
|
|
191
|
+
id: tabId(tab),
|
|
192
|
+
class: 'm-tab',
|
|
193
|
+
type: 'button',
|
|
194
|
+
role: 'tab',
|
|
195
|
+
ref: (element: unknown) => {
|
|
196
|
+
if (element)
|
|
197
|
+
controls.set(choiceKey(tab.value), element as HTMLButtonElement)
|
|
198
|
+
else controls.delete(choiceKey(tab.value))
|
|
199
|
+
},
|
|
200
|
+
disabled: props.disabled || tab.disabled,
|
|
201
|
+
tabindex: !props.disabled && focus?.value === tab.value ? 0 : -1,
|
|
202
|
+
'aria-selected': active?.value === tab.value,
|
|
203
|
+
'aria-controls': active?.value === tab.value ? `${id}-panel` : undefined,
|
|
204
|
+
style: {
|
|
205
|
+
color: active?.value === tab.value ? colors.primary : colors.muted,
|
|
206
|
+
'--m-tab-active': colors.primarySoft,
|
|
207
|
+
},
|
|
208
|
+
onFocus: () => {
|
|
209
|
+
focusValue.value = tab.value
|
|
210
|
+
},
|
|
211
|
+
onClick: () => request(tab),
|
|
212
|
+
onKeydown: (event: KeyboardEvent) => keydown(event, tab),
|
|
213
|
+
},
|
|
214
|
+
tab.label,
|
|
215
|
+
),
|
|
216
|
+
),
|
|
217
|
+
h('span', {
|
|
218
|
+
class: 'm-tabs-indicator',
|
|
219
|
+
'aria-hidden': 'true',
|
|
220
|
+
style: {
|
|
221
|
+
backgroundColor: colors.primary,
|
|
222
|
+
opacity: marker.value ? 1 : 0,
|
|
223
|
+
width: `${marker.value?.width ?? 0}px`,
|
|
224
|
+
transform: `translateX(${marker.value?.left ?? 0}px)`,
|
|
225
|
+
},
|
|
226
|
+
}),
|
|
227
|
+
],
|
|
228
|
+
),
|
|
229
|
+
],
|
|
230
|
+
),
|
|
231
|
+
props.keepAlive
|
|
232
|
+
? props.tabs.map((tab) =>
|
|
233
|
+
h(
|
|
234
|
+
KeepAlive,
|
|
235
|
+
{ key: choiceKey(tab.value), max: 1 },
|
|
236
|
+
{
|
|
237
|
+
default: () =>
|
|
238
|
+
active?.value === tab.value
|
|
239
|
+
? h(
|
|
240
|
+
TabPanel,
|
|
241
|
+
{
|
|
242
|
+
id: `${id}-panel`,
|
|
243
|
+
class: 'm-tab-panel',
|
|
244
|
+
role: 'tabpanel',
|
|
245
|
+
tabindex: 0,
|
|
246
|
+
'aria-labelledby': tabId(tab),
|
|
247
|
+
style: { '--m-focus': colors.primary },
|
|
248
|
+
},
|
|
249
|
+
{ default: () => slots.default?.({ value: tab.value }) },
|
|
250
|
+
)
|
|
251
|
+
: null,
|
|
252
|
+
},
|
|
253
|
+
),
|
|
254
|
+
)
|
|
255
|
+
: active
|
|
256
|
+
? h(
|
|
257
|
+
'div',
|
|
258
|
+
{
|
|
259
|
+
key: choiceKey(active.value),
|
|
260
|
+
id: `${id}-panel`,
|
|
261
|
+
class: 'm-tab-panel',
|
|
262
|
+
role: 'tabpanel',
|
|
263
|
+
tabindex: 0,
|
|
264
|
+
'aria-labelledby': tabId(active),
|
|
265
|
+
style: { '--m-focus': colors.primary },
|
|
266
|
+
},
|
|
267
|
+
slots.default?.({ value: active.value }),
|
|
268
|
+
)
|
|
269
|
+
: null,
|
|
270
|
+
],
|
|
271
|
+
},
|
|
272
|
+
)
|
|
273
|
+
}
|
|
274
|
+
},
|
|
275
|
+
})
|
package/src/components/MText.ts
CHANGED
|
@@ -2,11 +2,11 @@ import { defineComponent, h, mergeProps } from 'vue'
|
|
|
2
2
|
import {
|
|
3
3
|
textProps,
|
|
4
4
|
useMavisTheme,
|
|
5
|
-
|
|
5
|
+
inlineContent,
|
|
6
6
|
useDefaultShrink,
|
|
7
7
|
viewAttrs,
|
|
8
8
|
} from '@getcortexlabs/mavis-core/vue'
|
|
9
|
-
import { nonNegative } from '@getcortexlabs/mavis-core'
|
|
9
|
+
import { fontFamily, nonNegative, validateWeight } from '@getcortexlabs/mavis-core'
|
|
10
10
|
import { webAttrs } from '../style.js'
|
|
11
11
|
|
|
12
12
|
export const MText = defineComponent({
|
|
@@ -18,16 +18,22 @@ export const MText = defineComponent({
|
|
|
18
18
|
const shrink = useDefaultShrink()
|
|
19
19
|
return () => {
|
|
20
20
|
const type = theme.value.typography[props.variant]
|
|
21
|
+
const runs =
|
|
22
|
+
props.text !== undefined ? [{ text: props.text }] : inlineContent(slots.default?.())
|
|
21
23
|
return h(
|
|
22
24
|
props.as,
|
|
23
25
|
mergeProps(
|
|
24
26
|
{
|
|
27
|
+
class: 'm-text',
|
|
25
28
|
style: {
|
|
26
29
|
margin: 0,
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
30
|
+
fontFamily: `var(--m-text-font-family, ${fontFamily(type.fontFamily, 'web')})`,
|
|
31
|
+
fontSize: `var(--m-text-font-size, ${type.fontSize}px)`,
|
|
32
|
+
fontWeight: props.weight
|
|
33
|
+
? validateWeight(props.weight)
|
|
34
|
+
: `var(--m-text-font-weight, ${type.fontWeight})`,
|
|
35
|
+
letterSpacing: `var(--m-text-letter-spacing, ${type.letterSpacing}em)`,
|
|
36
|
+
lineHeight: `var(--m-text-line-height, ${type.lineHeight})`,
|
|
31
37
|
color: theme.value.colors[props.tone],
|
|
32
38
|
textAlign: props.align,
|
|
33
39
|
whiteSpace: props.wrap ? 'normal' : 'nowrap',
|
|
@@ -39,7 +45,24 @@ export const MText = defineComponent({
|
|
|
39
45
|
},
|
|
40
46
|
webAttrs({ ...attrs, ...viewAttrs(props) }),
|
|
41
47
|
),
|
|
42
|
-
|
|
48
|
+
runs.every((run) => !run.weight && !run.tone && !run.strong && !run.italic)
|
|
49
|
+
? runs.map((run) => run.text).join('')
|
|
50
|
+
: runs.map((run) => {
|
|
51
|
+
if (!run.weight && !run.tone && !run.strong && !run.italic) return run.text
|
|
52
|
+
if (run.tone && !(run.tone in theme.value.colors))
|
|
53
|
+
throw new RangeError(`Unknown text tone: ${run.tone}`)
|
|
54
|
+
const content = run.strong && run.italic ? h('em', {}, run.text) : run.text
|
|
55
|
+
return h(
|
|
56
|
+
run.strong ? 'strong' : run.italic ? 'em' : 'span',
|
|
57
|
+
{
|
|
58
|
+
style: {
|
|
59
|
+
fontWeight: run.weight ?? 'inherit',
|
|
60
|
+
color: run.tone ? theme.value.colors[run.tone] : undefined,
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
content,
|
|
64
|
+
)
|
|
65
|
+
}),
|
|
43
66
|
)
|
|
44
67
|
}
|
|
45
68
|
},
|