@getcortexlabs/mavis-web 0.1.0-alpha.3 → 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 +10 -1
- 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 +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 +10 -4
- package/dist/components/MSheet.d.ts.map +1 -1
- package/dist/components/MSheet.js +81 -54
- package/dist/components/MSheet.js.map +1 -1
- 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 +26 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +44 -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/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 +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 +100 -51
- 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 +66 -3
- 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 +806 -54
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
import { fontFamily } from '@getcortexlabs/mavis-core'
|
|
2
|
+
import {
|
|
3
|
+
defineComponent,
|
|
4
|
+
h,
|
|
5
|
+
mergeProps,
|
|
6
|
+
nextTick,
|
|
7
|
+
onBeforeUnmount,
|
|
8
|
+
useId,
|
|
9
|
+
watch,
|
|
10
|
+
type SlotsType,
|
|
11
|
+
} from 'vue'
|
|
12
|
+
import {
|
|
13
|
+
useButtonAction,
|
|
14
|
+
accordionProps,
|
|
15
|
+
accordionEmits,
|
|
16
|
+
useMavisTheme,
|
|
17
|
+
} from '@getcortexlabs/mavis-core/vue'
|
|
18
|
+
import {
|
|
19
|
+
choiceKey,
|
|
20
|
+
validateAccordion,
|
|
21
|
+
toggleAccordion,
|
|
22
|
+
accordionFocusTarget,
|
|
23
|
+
type AccordionItem,
|
|
24
|
+
type AccordionPanelProps,
|
|
25
|
+
} from '@getcortexlabs/mavis-core'
|
|
26
|
+
import { MColumn } from './layout.js'
|
|
27
|
+
import { MIcon } from './MIcon.js'
|
|
28
|
+
import { MReveal } from './MReveal.js'
|
|
29
|
+
import { MSeparator } from './MSeparator.js'
|
|
30
|
+
|
|
31
|
+
export const MAccordion = defineComponent({
|
|
32
|
+
name: 'MAccordion',
|
|
33
|
+
inheritAttrs: false,
|
|
34
|
+
props: accordionProps,
|
|
35
|
+
emits: accordionEmits,
|
|
36
|
+
slots: Object as SlotsType<{ default: AccordionPanelProps }>,
|
|
37
|
+
setup(props, { attrs, emit, slots }) {
|
|
38
|
+
useButtonAction()
|
|
39
|
+
const { theme } = useMavisTheme()
|
|
40
|
+
const generated = `m-accordion-${useId()}`
|
|
41
|
+
const headers = new Map<string, HTMLButtonElement>()
|
|
42
|
+
const panels = new Map<string, HTMLElement>()
|
|
43
|
+
let alive = true
|
|
44
|
+
onBeforeUnmount(() => {
|
|
45
|
+
alive = false
|
|
46
|
+
headers.clear()
|
|
47
|
+
panels.clear()
|
|
48
|
+
})
|
|
49
|
+
watch(
|
|
50
|
+
() => [props.items, props.modelValue, props.disabled],
|
|
51
|
+
() => {
|
|
52
|
+
if (typeof document === 'undefined') return
|
|
53
|
+
const focused = document.activeElement
|
|
54
|
+
if (!focused) return
|
|
55
|
+
const panel = [...panels].find(([, element]) => element.contains(focused))
|
|
56
|
+
const header = [...headers].find(([, element]) => element === focused)
|
|
57
|
+
const key = panel?.[0] ?? header?.[0]
|
|
58
|
+
if (!key) return
|
|
59
|
+
const item = props.items.find((item) => choiceKey(item.value) === key)
|
|
60
|
+
if (panel && item && props.modelValue.includes(item.value)) return
|
|
61
|
+
if (header && item && !item.disabled && !props.disabled) return
|
|
62
|
+
void nextTick(() => {
|
|
63
|
+
if (!alive || props.disabled) return
|
|
64
|
+
const target =
|
|
65
|
+
(item && !item.disabled ? item : undefined) ??
|
|
66
|
+
props.items.find((item) => !item.disabled)
|
|
67
|
+
if (target) headers.get(choiceKey(target.value))?.focus({ preventScroll: true })
|
|
68
|
+
})
|
|
69
|
+
},
|
|
70
|
+
{ deep: true, flush: 'pre' },
|
|
71
|
+
)
|
|
72
|
+
function keydown(event: KeyboardEvent, item: AccordionItem) {
|
|
73
|
+
if (props.disabled || item.disabled || event.altKey || event.ctrlKey || event.metaKey) return
|
|
74
|
+
const next = accordionFocusTarget(props.items, item.value, event.key)
|
|
75
|
+
if (!next) return
|
|
76
|
+
event.preventDefault()
|
|
77
|
+
headers.get(choiceKey(next.value))?.focus({ preventScroll: true })
|
|
78
|
+
}
|
|
79
|
+
return () => {
|
|
80
|
+
validateAccordion(
|
|
81
|
+
props.items,
|
|
82
|
+
props.modelValue,
|
|
83
|
+
props.multiple,
|
|
84
|
+
props.label,
|
|
85
|
+
props.expandedLabel,
|
|
86
|
+
props.collapsedLabel,
|
|
87
|
+
)
|
|
88
|
+
const { colors, typography, space, radius } = theme.value
|
|
89
|
+
const id = props.id ?? generated
|
|
90
|
+
return h(
|
|
91
|
+
MColumn,
|
|
92
|
+
mergeProps(attrs, {
|
|
93
|
+
id,
|
|
94
|
+
width: props.width,
|
|
95
|
+
grow: props.grow,
|
|
96
|
+
shrink: props.shrink,
|
|
97
|
+
gap: 'sm',
|
|
98
|
+
accessibilityHidden: props.accessibilityHidden,
|
|
99
|
+
class: 'm-accordion',
|
|
100
|
+
role: 'group',
|
|
101
|
+
'aria-label': props.label,
|
|
102
|
+
style: { '--m-focus': colors.primary },
|
|
103
|
+
}),
|
|
104
|
+
{
|
|
105
|
+
default: () =>
|
|
106
|
+
props.items.map((item) => {
|
|
107
|
+
const key = choiceKey(item.value),
|
|
108
|
+
expanded = props.modelValue.includes(item.value)
|
|
109
|
+
const headerId = `${id}-${encodeURIComponent(key)}`,
|
|
110
|
+
panelId = `${headerId}-panel`
|
|
111
|
+
return h(
|
|
112
|
+
MColumn,
|
|
113
|
+
{
|
|
114
|
+
key,
|
|
115
|
+
radius: 'md',
|
|
116
|
+
backgroundColor: colors.surface,
|
|
117
|
+
class: 'm-accordion-item',
|
|
118
|
+
'data-expanded': expanded,
|
|
119
|
+
style: { border: `1px solid ${expanded ? colors.primarySoft : colors.border}` },
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
default: () => [
|
|
123
|
+
h('h3', { class: 'm-accordion-heading' }, [
|
|
124
|
+
h(
|
|
125
|
+
'button',
|
|
126
|
+
{
|
|
127
|
+
id: headerId,
|
|
128
|
+
type: 'button',
|
|
129
|
+
class: 'm-accordion-trigger',
|
|
130
|
+
ref: (element: unknown) => {
|
|
131
|
+
if (element) headers.set(key, element as HTMLButtonElement)
|
|
132
|
+
else headers.delete(key)
|
|
133
|
+
},
|
|
134
|
+
disabled: props.disabled || item.disabled,
|
|
135
|
+
'aria-label': item.title,
|
|
136
|
+
'aria-describedby': item.description
|
|
137
|
+
? `${headerId}-description`
|
|
138
|
+
: undefined,
|
|
139
|
+
'aria-expanded': expanded,
|
|
140
|
+
'aria-controls': expanded ? panelId : undefined,
|
|
141
|
+
style: {
|
|
142
|
+
padding: `${space.md}px`,
|
|
143
|
+
gap: `${space.md}px`,
|
|
144
|
+
borderRadius: `${radius.md}px`,
|
|
145
|
+
color: colors.text,
|
|
146
|
+
fontFamily: fontFamily(theme.value.typography.body.fontFamily, 'web'),
|
|
147
|
+
fontSize: `${typography.body.fontSize}px`,
|
|
148
|
+
},
|
|
149
|
+
onClick() {
|
|
150
|
+
const next = toggleAccordion(
|
|
151
|
+
item,
|
|
152
|
+
props.modelValue,
|
|
153
|
+
props.multiple,
|
|
154
|
+
props.disabled,
|
|
155
|
+
)
|
|
156
|
+
if (next) emit('update:modelValue', next)
|
|
157
|
+
},
|
|
158
|
+
onKeydown: (event: KeyboardEvent) => keydown(event, item),
|
|
159
|
+
},
|
|
160
|
+
[
|
|
161
|
+
item.icon
|
|
162
|
+
? h(MIcon, {
|
|
163
|
+
name: item.icon,
|
|
164
|
+
tone: expanded ? 'primary' : 'muted',
|
|
165
|
+
style: { flexShrink: 0 },
|
|
166
|
+
})
|
|
167
|
+
: null,
|
|
168
|
+
h('span', { class: 'm-accordion-copy' }, [
|
|
169
|
+
h('span', { style: { display: 'block', fontWeight: 600 } }, item.title),
|
|
170
|
+
item.description
|
|
171
|
+
? h(
|
|
172
|
+
'span',
|
|
173
|
+
{
|
|
174
|
+
id: `${headerId}-description`,
|
|
175
|
+
style: {
|
|
176
|
+
display: 'block',
|
|
177
|
+
color: colors.muted,
|
|
178
|
+
marginTop: `${space.xs}px`,
|
|
179
|
+
fontSize: `${typography.caption.fontSize}px`,
|
|
180
|
+
},
|
|
181
|
+
},
|
|
182
|
+
item.description,
|
|
183
|
+
)
|
|
184
|
+
: null,
|
|
185
|
+
]),
|
|
186
|
+
h(MIcon, {
|
|
187
|
+
name: expanded ? 'chevron-up' : 'chevron-down',
|
|
188
|
+
size: 'sm',
|
|
189
|
+
tone: expanded ? 'primary' : 'muted',
|
|
190
|
+
style: { flexShrink: 0 },
|
|
191
|
+
}),
|
|
192
|
+
],
|
|
193
|
+
),
|
|
194
|
+
]),
|
|
195
|
+
h(
|
|
196
|
+
MReveal,
|
|
197
|
+
{
|
|
198
|
+
show: expanded,
|
|
199
|
+
padding: 'md',
|
|
200
|
+
gap: 'md',
|
|
201
|
+
style: { paddingTop: 0 },
|
|
202
|
+
accessibilityHidden: props.accessibilityHidden,
|
|
203
|
+
},
|
|
204
|
+
{
|
|
205
|
+
default: () => [
|
|
206
|
+
h(MSeparator),
|
|
207
|
+
h(
|
|
208
|
+
'div',
|
|
209
|
+
{
|
|
210
|
+
id: panelId,
|
|
211
|
+
role: 'region',
|
|
212
|
+
'aria-labelledby': headerId,
|
|
213
|
+
ref: (element: unknown) => {
|
|
214
|
+
if (element) panels.set(key, element as HTMLElement)
|
|
215
|
+
else panels.delete(key)
|
|
216
|
+
},
|
|
217
|
+
},
|
|
218
|
+
slots.default?.({ item }),
|
|
219
|
+
),
|
|
220
|
+
],
|
|
221
|
+
},
|
|
222
|
+
),
|
|
223
|
+
],
|
|
224
|
+
},
|
|
225
|
+
)
|
|
226
|
+
}),
|
|
227
|
+
},
|
|
228
|
+
)
|
|
229
|
+
}
|
|
230
|
+
},
|
|
231
|
+
})
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { defineComponent, h, mergeProps } from 'vue'
|
|
2
|
+
import { alertProps, alertEmits, useMavisTheme } from '@getcortexlabs/mavis-core/vue'
|
|
3
|
+
import { alertAppearance, checkAlertLabels } from '@getcortexlabs/mavis-core'
|
|
4
|
+
import { MBox, MColumn, MRow } from './layout.js'
|
|
5
|
+
import { MText } from './MText.js'
|
|
6
|
+
import { MIcon } from './MIcon.js'
|
|
7
|
+
import { MButton } from './MButton.js'
|
|
8
|
+
|
|
9
|
+
export const MAlert = defineComponent({
|
|
10
|
+
name: 'MAlert',
|
|
11
|
+
inheritAttrs: false,
|
|
12
|
+
props: alertProps,
|
|
13
|
+
emits: alertEmits,
|
|
14
|
+
setup(props, { attrs, slots, emit }) {
|
|
15
|
+
const { theme } = useMavisTheme()
|
|
16
|
+
return () => {
|
|
17
|
+
checkAlertLabels(props.title, props.dismissible, props.closeLabel)
|
|
18
|
+
const { colors } = theme.value
|
|
19
|
+
const appearance = alertAppearance[props.tone]
|
|
20
|
+
return h(
|
|
21
|
+
MColumn,
|
|
22
|
+
mergeProps(
|
|
23
|
+
{
|
|
24
|
+
width: props.width,
|
|
25
|
+
grow: props.grow,
|
|
26
|
+
shrink: props.shrink,
|
|
27
|
+
padding: 'md',
|
|
28
|
+
gap: 'md',
|
|
29
|
+
radius: 'md',
|
|
30
|
+
backgroundColor: colors.surface,
|
|
31
|
+
style: {
|
|
32
|
+
border: `1px solid ${colors[appearance.tone]}`,
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
attrs,
|
|
36
|
+
{
|
|
37
|
+
id: props.id,
|
|
38
|
+
accessibilityHidden: props.accessibilityHidden,
|
|
39
|
+
class: 'm-alert',
|
|
40
|
+
'data-tone': props.tone,
|
|
41
|
+
},
|
|
42
|
+
),
|
|
43
|
+
{
|
|
44
|
+
default: () => [
|
|
45
|
+
h(
|
|
46
|
+
MRow,
|
|
47
|
+
{ gap: 'sm', align: 'start' },
|
|
48
|
+
{
|
|
49
|
+
default: () => [
|
|
50
|
+
h(
|
|
51
|
+
MBox,
|
|
52
|
+
{
|
|
53
|
+
width: 32,
|
|
54
|
+
height: 32,
|
|
55
|
+
radius: 'sm',
|
|
56
|
+
shrink: 0,
|
|
57
|
+
backgroundColor: colors.elevated,
|
|
58
|
+
style: { placeItems: 'center' },
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
default: () =>
|
|
62
|
+
h(MIcon, { name: appearance.icon, tone: appearance.tone, size: 20 }),
|
|
63
|
+
},
|
|
64
|
+
),
|
|
65
|
+
h(
|
|
66
|
+
MColumn,
|
|
67
|
+
{
|
|
68
|
+
width: 0,
|
|
69
|
+
grow: 1,
|
|
70
|
+
gap: 'xs',
|
|
71
|
+
role: props.announce
|
|
72
|
+
? props.tone === 'error'
|
|
73
|
+
? 'alert'
|
|
74
|
+
: 'status'
|
|
75
|
+
: undefined,
|
|
76
|
+
'aria-atomic': props.announce ? 'true' : undefined,
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
default: () => [
|
|
80
|
+
h(MText, { text: props.title, style: { fontWeight: '600' } }),
|
|
81
|
+
props.description
|
|
82
|
+
? h(MText, { text: props.description, tone: 'muted' })
|
|
83
|
+
: null,
|
|
84
|
+
],
|
|
85
|
+
},
|
|
86
|
+
),
|
|
87
|
+
props.dismissible
|
|
88
|
+
? h(MButton, {
|
|
89
|
+
icon: 'x',
|
|
90
|
+
variant: 'ghost',
|
|
91
|
+
size: 'sm',
|
|
92
|
+
accessibilityLabel: props.closeLabel,
|
|
93
|
+
shrink: 0,
|
|
94
|
+
style: { width: '44px', paddingLeft: 0, paddingRight: 0 },
|
|
95
|
+
onClick: () => emit('close'),
|
|
96
|
+
})
|
|
97
|
+
: null,
|
|
98
|
+
],
|
|
99
|
+
},
|
|
100
|
+
),
|
|
101
|
+
slots.actions
|
|
102
|
+
? h(MRow, { gap: 'sm', wrap: true, align: 'start' }, { default: slots.actions })
|
|
103
|
+
: null,
|
|
104
|
+
],
|
|
105
|
+
},
|
|
106
|
+
)
|
|
107
|
+
}
|
|
108
|
+
},
|
|
109
|
+
})
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { fontFamily } from '@getcortexlabs/mavis-core'
|
|
2
|
+
import { defineComponent, h, mergeProps, ref, watch } from 'vue'
|
|
3
|
+
import { avatarProps, useMavisTheme } from '@getcortexlabs/mavis-core/vue'
|
|
4
|
+
import { avatarSizes, avatarInitials } from '@getcortexlabs/mavis-core'
|
|
5
|
+
import { webAttrs } from '../style.js'
|
|
6
|
+
import { MIcon } from './MIcon.js'
|
|
7
|
+
|
|
8
|
+
export const MAvatar = defineComponent({
|
|
9
|
+
name: 'MAvatar',
|
|
10
|
+
inheritAttrs: false,
|
|
11
|
+
props: avatarProps,
|
|
12
|
+
setup(props, { attrs }) {
|
|
13
|
+
const { theme } = useMavisTheme()
|
|
14
|
+
const ready = ref(false)
|
|
15
|
+
let revision = 0
|
|
16
|
+
watch(
|
|
17
|
+
() => props.src,
|
|
18
|
+
() => {
|
|
19
|
+
revision++
|
|
20
|
+
ready.value = false
|
|
21
|
+
},
|
|
22
|
+
{ flush: 'sync' },
|
|
23
|
+
)
|
|
24
|
+
return () => {
|
|
25
|
+
const size = avatarSizes[props.size]
|
|
26
|
+
const current = revision
|
|
27
|
+
const label = props.accessibilityLabel ?? props.name.trim()
|
|
28
|
+
const hidden = props.accessibilityHidden || !label
|
|
29
|
+
const initials = avatarInitials(props.name)
|
|
30
|
+
return h(
|
|
31
|
+
'span',
|
|
32
|
+
mergeProps(webAttrs(attrs), {
|
|
33
|
+
id: props.id,
|
|
34
|
+
class: 'm-avatar',
|
|
35
|
+
role: hidden ? undefined : 'img',
|
|
36
|
+
'aria-label': hidden ? undefined : label,
|
|
37
|
+
'aria-hidden': hidden ? 'true' : undefined,
|
|
38
|
+
style: {
|
|
39
|
+
display: 'inline-grid',
|
|
40
|
+
position: 'relative',
|
|
41
|
+
overflow: 'hidden',
|
|
42
|
+
width: `${size}px`,
|
|
43
|
+
height: `${size}px`,
|
|
44
|
+
flexShrink: 0,
|
|
45
|
+
alignSelf: 'flex-start',
|
|
46
|
+
borderRadius: props.shape === 'circle' ? '50%' : `${size / 4}px`,
|
|
47
|
+
placeItems: 'center',
|
|
48
|
+
color: theme.value.colors.primary,
|
|
49
|
+
backgroundColor: theme.value.colors.primarySoft,
|
|
50
|
+
fontFamily: fontFamily(theme.value.typography.body.fontFamily, 'web'),
|
|
51
|
+
fontSize: `${Math.round(size * 0.34)}px`,
|
|
52
|
+
fontWeight: 600,
|
|
53
|
+
lineHeight: 1,
|
|
54
|
+
},
|
|
55
|
+
}),
|
|
56
|
+
[
|
|
57
|
+
h(
|
|
58
|
+
'span',
|
|
59
|
+
{
|
|
60
|
+
'aria-hidden': 'true',
|
|
61
|
+
style: { gridArea: '1 / 1', visibility: ready.value ? 'hidden' : 'visible' },
|
|
62
|
+
},
|
|
63
|
+
initials ||
|
|
64
|
+
h(MIcon, { name: 'user-round', size: Math.round(size * 0.46), tone: 'primary' }),
|
|
65
|
+
),
|
|
66
|
+
props.src.trim()
|
|
67
|
+
? h('img', {
|
|
68
|
+
key: revision,
|
|
69
|
+
src: props.src.trim(),
|
|
70
|
+
alt: '',
|
|
71
|
+
'aria-hidden': 'true',
|
|
72
|
+
draggable: false,
|
|
73
|
+
ref: (element) => {
|
|
74
|
+
const image = element as HTMLImageElement | null
|
|
75
|
+
if (current === revision && image?.complete) ready.value = image.naturalWidth > 0
|
|
76
|
+
},
|
|
77
|
+
style: {
|
|
78
|
+
position: 'absolute',
|
|
79
|
+
inset: 0,
|
|
80
|
+
width: '100%',
|
|
81
|
+
height: '100%',
|
|
82
|
+
objectFit: 'cover',
|
|
83
|
+
visibility: ready.value ? 'visible' : 'hidden',
|
|
84
|
+
},
|
|
85
|
+
onLoad: () => {
|
|
86
|
+
if (current === revision) ready.value = true
|
|
87
|
+
},
|
|
88
|
+
onError: () => {
|
|
89
|
+
if (current === revision) ready.value = false
|
|
90
|
+
},
|
|
91
|
+
})
|
|
92
|
+
: null,
|
|
93
|
+
],
|
|
94
|
+
)
|
|
95
|
+
}
|
|
96
|
+
},
|
|
97
|
+
})
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { fontFamily } from '@getcortexlabs/mavis-core'
|
|
2
|
+
import { defineComponent, h, mergeProps } from 'vue'
|
|
3
|
+
import { badgeProps, useMavisTheme, viewAttrs } from '@getcortexlabs/mavis-core/vue'
|
|
4
|
+
import { badgeColors } from '@getcortexlabs/mavis-core'
|
|
5
|
+
import { webAttrs } from '../style.js'
|
|
6
|
+
|
|
7
|
+
export const MBadge = defineComponent({
|
|
8
|
+
name: 'MBadge',
|
|
9
|
+
inheritAttrs: false,
|
|
10
|
+
props: badgeProps,
|
|
11
|
+
setup(props, { attrs }) {
|
|
12
|
+
const { theme } = useMavisTheme()
|
|
13
|
+
return () =>
|
|
14
|
+
h(
|
|
15
|
+
'span',
|
|
16
|
+
mergeProps(webAttrs({ ...attrs, ...viewAttrs(props) }), {
|
|
17
|
+
class: 'm-badge',
|
|
18
|
+
role: props.accessibilityLabel ? 'img' : undefined,
|
|
19
|
+
style: {
|
|
20
|
+
...badgeColors(theme.value.colors, props.tone),
|
|
21
|
+
display: 'inline-block',
|
|
22
|
+
alignSelf: 'flex-start',
|
|
23
|
+
boxSizing: 'border-box',
|
|
24
|
+
maxWidth: '100%',
|
|
25
|
+
minWidth: props.size === 'sm' ? '22px' : '28px',
|
|
26
|
+
padding: props.size === 'sm' ? '3px 8px' : '5px 10px',
|
|
27
|
+
borderRadius: '999px',
|
|
28
|
+
fontFamily: fontFamily(theme.value.typography.body.fontFamily, 'web'),
|
|
29
|
+
fontSize: props.size === 'sm' ? '0.6875rem' : '0.8125rem',
|
|
30
|
+
fontWeight: 600,
|
|
31
|
+
lineHeight: 1.4,
|
|
32
|
+
textAlign: 'center',
|
|
33
|
+
overflowWrap: 'anywhere',
|
|
34
|
+
whiteSpace: 'normal',
|
|
35
|
+
},
|
|
36
|
+
}),
|
|
37
|
+
String(props.text),
|
|
38
|
+
)
|
|
39
|
+
},
|
|
40
|
+
})
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
import { defineComponent, h, mergeProps } from 'vue'
|
|
1
|
+
import { defineComponent, h, mergeProps, type VNode, type SlotsType } from 'vue'
|
|
2
2
|
import {
|
|
3
|
+
useButtonAction,
|
|
3
4
|
buttonProps,
|
|
5
|
+
buttonContent,
|
|
6
|
+
ButtonAdornment,
|
|
4
7
|
useMavisTheme,
|
|
5
8
|
actionEmits,
|
|
6
9
|
textContent,
|
|
@@ -8,6 +11,9 @@ import {
|
|
|
8
11
|
viewAttrs,
|
|
9
12
|
} from '@getcortexlabs/mavis-core/vue'
|
|
10
13
|
import {
|
|
14
|
+
fontFamily,
|
|
15
|
+
resolveRadius,
|
|
16
|
+
shadowStyle,
|
|
11
17
|
nonNegative,
|
|
12
18
|
iconGlyph,
|
|
13
19
|
iconFontFamily,
|
|
@@ -15,23 +21,40 @@ import {
|
|
|
15
21
|
checkIconOnly,
|
|
16
22
|
} from '@getcortexlabs/mavis-core'
|
|
17
23
|
import { webAttrs } from '../style.js'
|
|
24
|
+
import { usePressFeedback } from '../motion.js'
|
|
18
25
|
|
|
19
26
|
export const MButton = defineComponent({
|
|
20
27
|
name: 'MButton',
|
|
21
28
|
inheritAttrs: false,
|
|
22
29
|
props: buttonProps,
|
|
23
30
|
emits: actionEmits,
|
|
31
|
+
slots: Object as SlotsType<{
|
|
32
|
+
default?: () => VNode[]
|
|
33
|
+
leading?: () => VNode[]
|
|
34
|
+
trailing?: () => VNode[]
|
|
35
|
+
}>,
|
|
24
36
|
setup(props, { attrs, slots, emit }) {
|
|
37
|
+
useButtonAction()
|
|
25
38
|
const { theme } = useMavisTheme()
|
|
39
|
+
const lifecycle = usePressFeedback(
|
|
40
|
+
() => !props.disabled && !props.loading,
|
|
41
|
+
theme,
|
|
42
|
+
() => props.motionSurface,
|
|
43
|
+
)
|
|
26
44
|
const shrink = useDefaultShrink()
|
|
27
45
|
return () => {
|
|
28
|
-
const { colors, control
|
|
46
|
+
const { colors, control } = theme.value
|
|
47
|
+
const tokens = theme.value.components.button
|
|
48
|
+
const family = fontFamily(tokens.fontFamily ?? theme.value.typography.body.fontFamily, 'web')
|
|
29
49
|
const size = control[props.size]
|
|
30
50
|
const primary = props.variant === 'primary'
|
|
31
51
|
const text = props.loading
|
|
32
52
|
? props.loadingText
|
|
33
53
|
: (props.text ?? textContent(slots.default?.()))
|
|
34
|
-
const
|
|
54
|
+
const leading = buttonContent(slots.leading?.())
|
|
55
|
+
const trailing = buttonContent(slots.trailing?.())
|
|
56
|
+
const composed = Boolean(slots.leading || slots.trailing)
|
|
57
|
+
const hasIcon = Boolean(composed || props.icon || props.trailingIcon)
|
|
35
58
|
checkIconOnly(text, hasIcon, props.accessibilityLabel)
|
|
36
59
|
const iconSize = iconSizes[props.size]
|
|
37
60
|
const paddingX = hasIcon && !text ? Math.round((size.height - iconSize) / 2) : size.padding
|
|
@@ -60,50 +83,80 @@ export const MButton = defineComponent({
|
|
|
60
83
|
return h(
|
|
61
84
|
'button',
|
|
62
85
|
mergeProps(
|
|
86
|
+
lifecycle,
|
|
63
87
|
{
|
|
64
88
|
class: 'm-button',
|
|
65
89
|
style: {
|
|
66
90
|
boxSizing: 'border-box',
|
|
67
91
|
display: 'inline-flex',
|
|
92
|
+
flexWrap: composed ? 'wrap' : undefined,
|
|
68
93
|
alignItems: 'center',
|
|
69
94
|
justifyContent: 'center',
|
|
70
95
|
gap: hasIcon ? '8px' : undefined,
|
|
71
96
|
minHeight: `${size.height}px`,
|
|
72
|
-
padding: `
|
|
73
|
-
fontSize:
|
|
74
|
-
fontWeight:
|
|
75
|
-
fontFamily:
|
|
76
|
-
lineHeight:
|
|
97
|
+
padding: `var(--m-button-padding-y, ${tokens.paddingY}px) var(--m-button-padding-x, ${paddingX}px)`,
|
|
98
|
+
fontSize: `var(--m-button-font-size, ${size.fontSize}px)`,
|
|
99
|
+
fontWeight: `var(--m-button-font-weight, ${tokens.fontWeight})`,
|
|
100
|
+
fontFamily: `var(--m-button-font-family, ${family})`,
|
|
101
|
+
lineHeight: `var(--m-button-line-height, ${tokens.lineHeight})`,
|
|
77
102
|
backgroundColor: primary
|
|
78
103
|
? colors.primary
|
|
79
104
|
: props.variant === 'secondary'
|
|
80
105
|
? colors.elevated
|
|
81
106
|
: 'transparent',
|
|
82
107
|
color: primary ? colors.onPrimary : colors.text,
|
|
83
|
-
borderRadius:
|
|
108
|
+
borderRadius: `var(--m-button-radius, ${resolveRadius(theme.value, tokens.radius)}px)`,
|
|
109
|
+
boxShadow: `var(--m-button-shadow, ${shadowStyle(theme.value.elevation[tokens.elevation])})`,
|
|
84
110
|
border: 0,
|
|
85
111
|
margin: 0,
|
|
86
|
-
|
|
112
|
+
filter: props.disabled ? 'opacity(0.45)' : undefined,
|
|
87
113
|
flexGrow: nonNegative(props.grow, 'grow'),
|
|
88
114
|
flexShrink: nonNegative(props.shrink ?? shrink, 'shrink'),
|
|
89
115
|
minWidth: '44px',
|
|
90
|
-
'--m-press-scale': motion.pressScale,
|
|
91
116
|
'--m-focus': colors.primary,
|
|
92
117
|
},
|
|
93
118
|
},
|
|
94
119
|
webAttrs({ ...attrs, ...viewAttrs(props) }),
|
|
95
120
|
{
|
|
96
|
-
type:
|
|
121
|
+
type: props.type,
|
|
122
|
+
name: props.name,
|
|
123
|
+
value: props.value,
|
|
124
|
+
form: props.form,
|
|
97
125
|
disabled: props.disabled,
|
|
98
126
|
'aria-disabled': props.disabled || props.loading || undefined,
|
|
99
127
|
'aria-busy': props.loading || undefined,
|
|
100
|
-
onClick: () => {
|
|
101
|
-
if (
|
|
128
|
+
onClick: (event: MouseEvent) => {
|
|
129
|
+
if (props.disabled || props.loading) {
|
|
130
|
+
event.preventDefault()
|
|
131
|
+
return
|
|
132
|
+
}
|
|
133
|
+
emit('click')
|
|
102
134
|
},
|
|
103
135
|
},
|
|
104
136
|
),
|
|
105
137
|
hasIcon
|
|
106
|
-
? [
|
|
138
|
+
? [
|
|
139
|
+
slots.leading
|
|
140
|
+
? h('span', { class: 'm-button-adornment', 'aria-hidden': 'true', inert: '' }, [
|
|
141
|
+
h(ButtonAdornment, {}, { default: () => leading }),
|
|
142
|
+
])
|
|
143
|
+
: span(props.icon),
|
|
144
|
+
text
|
|
145
|
+
? h(
|
|
146
|
+
'span',
|
|
147
|
+
{
|
|
148
|
+
class: 'm-button-label',
|
|
149
|
+
style: { minWidth: 0, maxWidth: '100%', overflowWrap: 'break-word' },
|
|
150
|
+
},
|
|
151
|
+
text,
|
|
152
|
+
)
|
|
153
|
+
: null,
|
|
154
|
+
slots.trailing
|
|
155
|
+
? h('span', { class: 'm-button-adornment', 'aria-hidden': 'true', inert: '' }, [
|
|
156
|
+
h(ButtonAdornment, {}, { default: () => trailing }),
|
|
157
|
+
])
|
|
158
|
+
: span(props.trailingIcon),
|
|
159
|
+
]
|
|
107
160
|
: text,
|
|
108
161
|
)
|
|
109
162
|
}
|