@getcortexlabs/mavis-web 0.1.0-alpha.2 → 0.1.0-alpha.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (171) hide show
  1. package/README.md +4 -4
  2. package/dist/components/MAccordion.d.ts +109 -0
  3. package/dist/components/MAccordion.d.ts.map +1 -0
  4. package/dist/components/MAccordion.js +180 -0
  5. package/dist/components/MAccordion.js.map +1 -0
  6. package/dist/components/MAlert.d.ts +99 -0
  7. package/dist/components/MAlert.d.ts.map +1 -0
  8. package/dist/components/MAlert.js +88 -0
  9. package/dist/components/MAlert.js.map +1 -0
  10. package/dist/components/MAvatar.d.ts +74 -0
  11. package/dist/components/MAvatar.d.ts.map +1 -0
  12. package/dist/components/MAvatar.js +88 -0
  13. package/dist/components/MAvatar.js.map +1 -0
  14. package/dist/components/MBadge.d.ts +64 -0
  15. package/dist/components/MBadge.d.ts.map +1 -0
  16. package/dist/components/MBadge.js +35 -0
  17. package/dist/components/MBadge.js.map +1 -0
  18. package/dist/components/MButton.d.ts +59 -7
  19. package/dist/components/MButton.d.ts.map +1 -1
  20. package/dist/components/MButton.js +51 -18
  21. package/dist/components/MButton.js.map +1 -1
  22. package/dist/components/MCard.d.ts +23 -5
  23. package/dist/components/MCard.d.ts.map +1 -1
  24. package/dist/components/MCard.js +28 -6
  25. package/dist/components/MCard.js.map +1 -1
  26. package/dist/components/MCheckbox.d.ts +93 -0
  27. package/dist/components/MCheckbox.d.ts.map +1 -0
  28. package/dist/components/MCheckbox.js +108 -0
  29. package/dist/components/MCheckbox.js.map +1 -0
  30. package/dist/components/MChip.d.ts +107 -0
  31. package/dist/components/MChip.d.ts.map +1 -0
  32. package/dist/components/MChip.js +103 -0
  33. package/dist/components/MChip.js.map +1 -0
  34. package/dist/components/MDialog.d.ts +94 -0
  35. package/dist/components/MDialog.d.ts.map +1 -0
  36. package/dist/components/MDialog.js +214 -0
  37. package/dist/components/MDialog.js.map +1 -0
  38. package/dist/components/MEmptyState.d.ts +107 -0
  39. package/dist/components/MEmptyState.d.ts.map +1 -0
  40. package/dist/components/MEmptyState.js +79 -0
  41. package/dist/components/MEmptyState.js.map +1 -0
  42. package/dist/components/MIcon.d.ts +1 -1
  43. package/dist/components/MInput.d.ts +66 -8
  44. package/dist/components/MInput.d.ts.map +1 -1
  45. package/dist/components/MInput.js +96 -20
  46. package/dist/components/MInput.js.map +1 -1
  47. package/dist/components/MListItem.d.ts +92 -0
  48. package/dist/components/MListItem.d.ts.map +1 -0
  49. package/dist/components/MListItem.js +53 -0
  50. package/dist/components/MListItem.js.map +1 -0
  51. package/dist/components/MProgress.d.ts +112 -0
  52. package/dist/components/MProgress.d.ts.map +1 -0
  53. package/dist/components/MProgress.js +69 -0
  54. package/dist/components/MProgress.js.map +1 -0
  55. package/dist/components/MRadioGroup.d.ts +94 -0
  56. package/dist/components/MRadioGroup.d.ts.map +1 -0
  57. package/dist/components/MRadioGroup.js +167 -0
  58. package/dist/components/MRadioGroup.js.map +1 -0
  59. package/dist/components/MReveal.d.ts.map +1 -1
  60. package/dist/components/MReveal.js +28 -3
  61. package/dist/components/MReveal.js.map +1 -1
  62. package/dist/components/MScreen.d.ts +19 -1
  63. package/dist/components/MScreen.d.ts.map +1 -1
  64. package/dist/components/MScreen.js +30 -1
  65. package/dist/components/MScreen.js.map +1 -1
  66. package/dist/components/MSegmentedControl.d.ts +85 -0
  67. package/dist/components/MSegmentedControl.d.ts.map +1 -0
  68. package/dist/components/MSegmentedControl.js +128 -0
  69. package/dist/components/MSegmentedControl.js.map +1 -0
  70. package/dist/components/MSelect.d.ts +130 -0
  71. package/dist/components/MSelect.d.ts.map +1 -0
  72. package/dist/components/MSelect.js +308 -0
  73. package/dist/components/MSelect.js.map +1 -0
  74. package/dist/components/MSeparator.d.ts +54 -0
  75. package/dist/components/MSeparator.d.ts.map +1 -0
  76. package/dist/components/MSeparator.js +36 -0
  77. package/dist/components/MSeparator.js.map +1 -0
  78. package/dist/components/MSheet.d.ts +102 -0
  79. package/dist/components/MSheet.d.ts.map +1 -0
  80. package/dist/components/MSheet.js +265 -0
  81. package/dist/components/MSheet.js.map +1 -0
  82. package/dist/components/MSkeleton.d.ts +70 -0
  83. package/dist/components/MSkeleton.d.ts.map +1 -0
  84. package/dist/components/MSkeleton.js +43 -0
  85. package/dist/components/MSkeleton.js.map +1 -0
  86. package/dist/components/MSlider.d.ts +1 -1
  87. package/dist/components/MSlider.d.ts.map +1 -1
  88. package/dist/components/MSlider.js +2 -1
  89. package/dist/components/MSlider.js.map +1 -1
  90. package/dist/components/MSwitch.d.ts +79 -0
  91. package/dist/components/MSwitch.d.ts.map +1 -0
  92. package/dist/components/MSwitch.js +87 -0
  93. package/dist/components/MSwitch.js.map +1 -0
  94. package/dist/components/MTabs.d.ts +91 -0
  95. package/dist/components/MTabs.d.ts.map +1 -0
  96. package/dist/components/MTabs.js +228 -0
  97. package/dist/components/MTabs.js.map +1 -0
  98. package/dist/components/MText.d.ts +18 -9
  99. package/dist/components/MText.d.ts.map +1 -1
  100. package/dist/components/MText.js +26 -7
  101. package/dist/components/MText.js.map +1 -1
  102. package/dist/components/MToast.d.ts +24 -0
  103. package/dist/components/MToast.d.ts.map +1 -0
  104. package/dist/components/MToast.js +196 -0
  105. package/dist/components/MToast.js.map +1 -0
  106. package/dist/index.d.ts +27 -4
  107. package/dist/index.d.ts.map +1 -1
  108. package/dist/index.js +46 -4
  109. package/dist/index.js.map +1 -1
  110. package/dist/input-attrs.d.ts +15 -0
  111. package/dist/input-attrs.d.ts.map +1 -0
  112. package/dist/input-attrs.js +18 -0
  113. package/dist/input-attrs.js.map +1 -0
  114. package/dist/motion-surface.d.ts +8 -0
  115. package/dist/motion-surface.d.ts.map +1 -0
  116. package/dist/motion-surface.js +79 -0
  117. package/dist/motion-surface.js.map +1 -0
  118. package/dist/motion.d.ts +20 -0
  119. package/dist/motion.d.ts.map +1 -0
  120. package/dist/motion.js +227 -0
  121. package/dist/motion.js.map +1 -0
  122. package/dist/screen-viewport.d.ts.map +1 -1
  123. package/dist/screen-viewport.js +3 -0
  124. package/dist/screen-viewport.js.map +1 -1
  125. package/dist/scroll-motion.d.ts +5 -0
  126. package/dist/scroll-motion.d.ts.map +1 -0
  127. package/dist/scroll-motion.js +69 -0
  128. package/dist/scroll-motion.js.map +1 -0
  129. package/dist/sheet-motion.d.ts +8 -0
  130. package/dist/sheet-motion.d.ts.map +1 -0
  131. package/dist/sheet-motion.js +148 -0
  132. package/dist/sheet-motion.js.map +1 -0
  133. package/dist/style.d.ts.map +1 -1
  134. package/dist/style.js +24 -9
  135. package/dist/style.js.map +1 -1
  136. package/package.json +4 -3
  137. package/src/components/MAccordion.ts +231 -0
  138. package/src/components/MAlert.ts +109 -0
  139. package/src/components/MAvatar.ts +97 -0
  140. package/src/components/MBadge.ts +40 -0
  141. package/src/components/MButton.ts +68 -15
  142. package/src/components/MCard.ts +43 -5
  143. package/src/components/MCheckbox.ts +127 -0
  144. package/src/components/MChip.ts +109 -0
  145. package/src/components/MDialog.ts +245 -0
  146. package/src/components/MEmptyState.ts +96 -0
  147. package/src/components/MInput.ts +166 -71
  148. package/src/components/MListItem.ts +66 -0
  149. package/src/components/MProgress.ts +82 -0
  150. package/src/components/MRadioGroup.ts +184 -0
  151. package/src/components/MReveal.ts +40 -3
  152. package/src/components/MScreen.ts +31 -1
  153. package/src/components/MSegmentedControl.ts +151 -0
  154. package/src/components/MSelect.ts +362 -0
  155. package/src/components/MSeparator.ts +40 -0
  156. package/src/components/MSheet.ts +317 -0
  157. package/src/components/MSkeleton.ts +52 -0
  158. package/src/components/MSlider.ts +7 -1
  159. package/src/components/MSwitch.ts +108 -0
  160. package/src/components/MTabs.ts +275 -0
  161. package/src/components/MText.ts +30 -7
  162. package/src/components/MToast.ts +241 -0
  163. package/src/index.ts +82 -4
  164. package/src/input-attrs.ts +41 -0
  165. package/src/motion-surface.ts +86 -0
  166. package/src/motion.ts +275 -0
  167. package/src/screen-viewport.ts +2 -0
  168. package/src/scroll-motion.ts +75 -0
  169. package/src/sheet-motion.ts +152 -0
  170. package/src/style.css +861 -39
  171. package/src/style.ts +20 -9
@@ -1,5 +1,7 @@
1
1
  import {
2
2
  defineComponent,
3
+ getCurrentInstance,
4
+ nextTick,
3
5
  h,
4
6
  mergeProps,
5
7
  onBeforeUnmount,
@@ -10,32 +12,60 @@ import {
10
12
  watch,
11
13
  } from 'vue'
12
14
  import {
15
+ useButtonAction,
13
16
  inputProps,
14
17
  inputEmits,
15
18
  useMavisTheme,
16
19
  useDefaultShrink,
17
20
  } from '@getcortexlabs/mavis-core/vue'
18
21
  import {
22
+ fontFamily,
23
+ resolveRadius,
19
24
  nonNegative,
20
25
  resolveDimension,
21
26
  validateInput,
22
27
  iconSizes,
28
+ inputActionSize,
23
29
  type InputHandle,
24
30
  } from '@getcortexlabs/mavis-core'
25
31
  import { length, webAttrs } from '../style.js'
26
32
  import { MIcon } from './MIcon.js'
33
+ import { MButton } from './MButton.js'
34
+ import { inputAttrs, describedBy, type InputEditorAttributes } from '../input-attrs.js'
27
35
 
28
- export const MInput = defineComponent({
36
+ const Input = defineComponent({
29
37
  name: 'MInput',
30
38
  inheritAttrs: false,
31
39
  props: inputProps,
32
40
  emits: inputEmits,
33
41
  setup(props, { attrs, emit, expose }) {
42
+ useButtonAction()
43
+ const instance = getCurrentInstance()!
34
44
  const { theme } = useMavisTheme()
35
45
  const shrink = useDefaultShrink()
36
46
  const generatedId = `m-input-${useId()}`
37
47
  const editor = ref<HTMLInputElement | HTMLTextAreaElement>()
38
48
  const focused = ref(false)
49
+ watch(
50
+ () => props.type,
51
+ () => {
52
+ const field = editor.value
53
+ if (!field || document.activeElement !== field || field.selectionStart === null) return
54
+ const start = field.selectionStart,
55
+ end = field.selectionEnd!,
56
+ direction = field.selectionDirection
57
+ void nextTick(() => {
58
+ if (
59
+ editor.value !== field ||
60
+ document.activeElement !== field ||
61
+ field.selectionStart === null
62
+ )
63
+ return
64
+ field.setSelectionRange(start, end, direction ?? undefined)
65
+ })
66
+ },
67
+ { flush: 'pre' },
68
+ )
39
69
  let observer: ResizeObserver | undefined
40
70
  let observed: HTMLElement | undefined
41
71
  let width = 0
@@ -49,6 +79,7 @@ export const MInput = defineComponent({
49
79
  field.clientWidth,
50
80
  props.rows,
51
81
  theme.value.typography.body.fontSize,
82
+ theme.value.components.input,
52
83
  ])
53
84
  // Resetting height can move Safari's scroll position while a pointer is
54
85
  // down. Focus/blur renders do not need to measure unchanged content.
@@ -58,6 +89,9 @@ export const MInput = defineComponent({
58
89
  field.style.height = `${field.scrollHeight + 2}px`
59
90
  }
60
91
  function observe() {
92
+ // HTML reset must not replace a controlled value behind the application's back.
93
+ // Applications reset their models in @reset.prevent; ordinary reset keeps them intact.
94
+ if (editor.value) editor.value.defaultValue = props.modelValue
61
95
  if (editor.value !== observed) {
62
96
  observer?.disconnect()
63
97
  observed = editor.value
@@ -98,9 +132,13 @@ export const MInput = defineComponent({
98
132
  const { colors, radius, typography, control, space } = theme.value
99
133
  const id = props.id ?? generatedId
100
134
  const message = props.error || props.helperText
135
+ const forwarded = inputAttrs(attrs)
101
136
  const text = props.type === 'text' || props.type === 'search'
102
137
  const border = props.error ? colors.danger : focused.value ? colors.primary : colors.border
103
- const inset = 16 + iconSizes.md + 10
138
+ const tokens = theme.value.components.input
139
+ const fontSize = tokens.fontSize ?? typography.body.fontSize
140
+ const family = fontFamily(tokens.fontFamily ?? typography.body.fontFamily, 'web')
141
+ const action = props.trailingAction
104
142
  const icon = (name: typeof props.icon, trailing: boolean) =>
105
143
  name
106
144
  ? h(MIcon, {
@@ -109,8 +147,8 @@ export const MInput = defineComponent({
109
147
  tone: props.error ? 'danger' : 'muted',
110
148
  style: {
111
149
  position: 'absolute',
112
- [trailing ? 'right' : 'left']: '16px',
113
- top: props.multiline ? '16px' : '50%',
150
+ [trailing ? 'right' : 'left']: `var(--m-input-padding-x, ${tokens.paddingX}px)`,
151
+ top: props.multiline ? `var(--m-input-padding-y, ${tokens.paddingY}px)` : '50%',
114
152
  transform: props.multiline ? undefined : 'translateY(-50%)',
115
153
  pointerEvents: 'none',
116
154
  },
@@ -126,6 +164,7 @@ export const MInput = defineComponent({
126
164
  flexDirection: 'column',
127
165
  gap: `${space.sm}px`,
128
166
  minWidth: 0,
167
+ fontFamily: fontFamily(typography.body.fontFamily, 'web'),
129
168
  flexGrow: nonNegative(props.grow, 'grow'),
130
169
  flexShrink: nonNegative(props.shrink ?? shrink, 'shrink'),
131
170
  width: length(resolveDimension(props.width)),
@@ -133,7 +172,7 @@ export const MInput = defineComponent({
133
172
  '--m-input-placeholder': colors.muted,
134
173
  },
135
174
  },
136
- webAttrs({ ...attrs, accessibilityHidden: props.accessibilityHidden }),
175
+ webAttrs({ ...forwarded.wrapper, accessibilityHidden: props.accessibilityHidden }),
137
176
  ),
138
177
  [
139
178
  h(
@@ -150,74 +189,125 @@ export const MInput = defineComponent({
150
189
  props.label,
151
190
  ),
152
191
  h('div', { class: 'm-input-field', style: { position: 'relative', display: 'flex' } }, [
153
- h(props.multiline ? 'textarea' : 'input', {
154
- ref: editor,
155
- id,
156
- class: 'm-input-editor',
157
- type: props.multiline ? undefined : props.type,
158
- rows: props.multiline ? props.rows : undefined,
159
- value: props.modelValue,
160
- placeholder: props.placeholder,
161
- disabled: props.disabled,
162
- readonly: props.readonly,
163
- maxlength: props.maxLength,
164
- autocapitalize: props.autocapitalize ?? (text ? 'sentences' : 'none'),
165
- autocorrect: (props.autocorrect ?? text) ? 'on' : 'off',
166
- spellcheck: props.autocorrect ?? text,
167
- enterkeyhint: props.multiline ? 'enter' : props.returnKey,
168
- 'aria-invalid': props.error ? 'true' : undefined,
169
- 'aria-describedby': message ? `${id}-message` : undefined,
170
- style: {
171
- boxSizing: 'border-box',
172
- width: '100%',
173
- minWidth: 0,
174
- minHeight: `${props.multiline ? props.rows * typography.body.fontSize * 1.5 + 30 : control.md.height}px`,
175
- margin: 0,
176
- padding: '14px 16px',
177
- paddingLeft: props.icon ? `${inset}px` : undefined,
178
- paddingRight: props.trailingIcon ? `${inset}px` : undefined,
179
- border: `1px solid ${border}`,
180
- borderRadius: `${radius.md}px`,
181
- outline: 'none',
182
- boxShadow: focused.value ? `0 0 0 2px ${border}` : 'none',
183
- fontFamily: 'inherit',
184
- fontSize: `${typography.body.fontSize}px`,
185
- lineHeight: '1.5',
186
- backgroundColor: props.readonly ? colors.elevated : colors.surface,
187
- color: colors.text,
188
- caretColor: colors.primary,
189
- resize: 'none',
190
- overflow: props.multiline ? 'hidden' : undefined,
191
- },
192
- onInput: (event: Event) => {
193
- if (props.disabled || props.readonly) return
194
- const value = (event.target as HTMLInputElement).value
195
- if (value !== props.modelValue) emit('update:modelValue', value)
196
- resize()
197
- },
198
- onFocus: () => {
199
- focused.value = true
200
- emit('focus')
201
- },
202
- onBlur: () => {
203
- focused.value = false
204
- emit('blur')
205
- },
206
- onKeydown: (event: KeyboardEvent) => {
207
- if (
208
- event.key !== 'Enter' ||
209
- event.isComposing ||
210
- event.keyCode === 229 ||
211
- props.multiline
212
- )
213
- return
214
- event.preventDefault()
215
- if (!props.disabled && !props.readonly)
216
- emit('submit', (event.target as HTMLInputElement).value)
217
- },
218
- }),
192
+ h(
193
+ props.multiline ? 'textarea' : 'input',
194
+ mergeProps(forwarded.editor, {
195
+ ref: editor,
196
+ id,
197
+ class: 'm-input-editor',
198
+ type: props.multiline ? undefined : props.type,
199
+ rows: props.multiline ? props.rows : undefined,
200
+ value: props.modelValue,
201
+ name: props.name,
202
+ autocomplete: props.autocomplete,
203
+ required: props.required,
204
+ inputmode: props.inputmode,
205
+ form: props.form,
206
+ placeholder: props.placeholder,
207
+ disabled: props.disabled,
208
+ readonly: props.readonly,
209
+ maxlength: props.maxLength,
210
+ autocapitalize: props.autocapitalize ?? (text ? 'sentences' : 'none'),
211
+ autocorrect: (props.autocorrect ?? text) ? 'on' : 'off',
212
+ spellcheck: props.autocorrect ?? text,
213
+ enterkeyhint: props.multiline ? 'enter' : props.returnKey,
214
+ 'aria-invalid': props.error ? 'true' : forwarded.editor['aria-invalid'],
215
+ 'aria-describedby': describedBy(
216
+ forwarded.editor['aria-describedby'],
217
+ message ? `${id}-message` : undefined,
218
+ ),
219
+ style: {
220
+ boxSizing: 'border-box',
221
+ width: '100%',
222
+ minWidth: 0,
223
+ minHeight: `${props.multiline ? props.rows * fontSize * tokens.lineHeight + tokens.paddingY * 2 + 2 : Math.max(control.md.height, action ? inputActionSize + 8 : 0)}px`,
224
+ margin: 0,
225
+ paddingTop: `var(--m-input-padding-y, ${tokens.paddingY}px)`,
226
+ paddingBottom: `var(--m-input-padding-y, ${tokens.paddingY}px)`,
227
+ paddingLeft: props.icon
228
+ ? `calc(var(--m-input-padding-x, ${tokens.paddingX}px) + ${iconSizes.md + 10}px)`
229
+ : `var(--m-input-padding-x, ${tokens.paddingX}px)`,
230
+ paddingRight: action
231
+ ? `max(var(--m-input-padding-x, ${tokens.paddingX}px), ${inputActionSize + 12}px)`
232
+ : props.trailingIcon
233
+ ? `calc(var(--m-input-padding-x, ${tokens.paddingX}px) + ${iconSizes.md + 10}px)`
234
+ : `var(--m-input-padding-x, ${tokens.paddingX}px)`,
235
+ border: `1px solid ${border}`,
236
+ borderRadius: `var(--m-input-radius, ${resolveRadius(theme.value, tokens.radius)}px)`,
237
+ outline: 'none',
238
+ boxShadow: focused.value ? `0 0 0 2px ${border}` : 'none',
239
+ fontFamily: `var(--m-input-font-family, ${family})`,
240
+ fontSize: `var(--m-input-font-size, ${fontSize}px)`,
241
+ fontWeight: `var(--m-input-font-weight, ${tokens.fontWeight})`,
242
+ lineHeight: `var(--m-input-line-height, ${tokens.lineHeight})`,
243
+ backgroundColor: props.readonly ? colors.elevated : colors.surface,
244
+ color: colors.text,
245
+ caretColor: colors.primary,
246
+ resize: 'none',
247
+ overflow: props.multiline ? 'hidden' : undefined,
248
+ },
249
+ onInput: (event: Event) => {
250
+ if (props.disabled || props.readonly) return
251
+ const value = (event.target as HTMLInputElement).value
252
+ if (value !== props.modelValue) emit('update:modelValue', value)
253
+ resize()
254
+ },
255
+ onFocus: () => {
256
+ focused.value = true
257
+ emit('focus')
258
+ },
259
+ onBlur: () => {
260
+ focused.value = false
261
+ emit('blur')
262
+ },
263
+ onKeydown: (event: KeyboardEvent) => {
264
+ if (
265
+ event.key !== 'Enter' ||
266
+ event.defaultPrevented ||
267
+ event.isComposing ||
268
+ event.keyCode === 229 ||
269
+ props.multiline
270
+ )
271
+ return
272
+ // An existing component handler owns this action (for example, focus next).
273
+ // Without one, leave implicit submission and validation to the HTML form.
274
+ const listeners = instance.vnode.props
275
+ if (!listeners?.onSubmit && !listeners?.onSubmitOnce && editor.value?.form) return
276
+ event.preventDefault()
277
+ if (!props.disabled && !props.readonly)
278
+ emit('submit', (event.target as HTMLInputElement).value)
279
+ },
280
+ }),
281
+ ),
219
282
  icon(props.icon, false),
220
283
  icon(props.trailingIcon, true),
284
+ action
285
+ ? h(MButton, {
286
+ class: 'm-input-action',
287
+ type: 'button',
288
+ icon: action.icon,
289
+ accessibilityLabel: action.label,
290
+ variant: 'ghost',
291
+ disabled: props.disabled || props.readonly || action.disabled,
292
+ style: {
293
+ position: 'absolute',
294
+ right: '4px',
295
+ // Positioning must not overwrite the Button's Jolt-owned transform on updates.
296
+ top: props.multiline ? '4px' : `calc(50% - ${inputActionSize / 2}px)`,
297
+ height: `${inputActionSize}px`,
298
+ width: `${inputActionSize}px`,
299
+ minHeight: `${inputActionSize}px`,
300
+ padding: 0,
301
+ },
302
+ onPointerdown: (event: PointerEvent) => {
303
+ if (event.button === 0 && document.activeElement === editor.value)
304
+ event.preventDefault()
305
+ },
306
+ onClick: () => {
307
+ if (!props.disabled && !props.readonly && !action.disabled) emit('action')
308
+ },
309
+ })
310
+ : null,
221
311
  ]),
222
312
  message
223
313
  ? h(
@@ -239,3 +329,8 @@ export const MInput = defineComponent({
239
329
  }
240
330
  },
241
331
  })
332
+
333
+ // Vue's options overload does not infer setupContext.expose() in its constructor type.
334
+ export const MInput = Input as typeof Input & {
335
+ new (): InstanceType<typeof Input> & InputHandle & { $props: InputEditorAttributes }
336
+ }
@@ -0,0 +1,66 @@
1
+ import { defineComponent, h, mergeProps, type SlotsType, type VNode } from 'vue'
2
+ import { listItemProps, actionEmits } from '@getcortexlabs/mavis-core/vue'
3
+ import { listItemLabel } from '@getcortexlabs/mavis-core'
4
+ import { MCard } from './MCard.js'
5
+ import { MRow, MColumn } from './layout.js'
6
+ import { MText } from './MText.js'
7
+ import { MIcon } from './MIcon.js'
8
+
9
+ export const MListItem = defineComponent({
10
+ name: 'MListItem',
11
+ inheritAttrs: false,
12
+ props: listItemProps,
13
+ emits: actionEmits,
14
+ slots: Object as SlotsType<{ leading?: () => VNode[]; trailing?: () => VNode[] }>,
15
+ setup(props, { attrs, slots, emit }) {
16
+ return () => {
17
+ const label = listItemLabel(props.title, props.description, props.accessibilityLabel)
18
+ return h(
19
+ MCard,
20
+ mergeProps(attrs, {
21
+ id: props.id,
22
+ width: props.width,
23
+ grow: props.grow,
24
+ shrink: props.shrink,
25
+ padding: 'md',
26
+ radius: 'md',
27
+ interactive: props.interactive,
28
+ disabled: props.disabled,
29
+ accessibilityHidden: props.accessibilityHidden,
30
+ accessibilityLabel: props.interactive ? label : undefined,
31
+ style: { borderWidth: '0' },
32
+ onClick: () => emit('click'),
33
+ }),
34
+ {
35
+ default: () =>
36
+ h(
37
+ MRow,
38
+ { gap: 'md' },
39
+ {
40
+ default: () => [
41
+ slots.leading ? h(MColumn, { shrink: 0 }, { default: slots.leading }) : null,
42
+ h(
43
+ MColumn,
44
+ { width: 0, grow: 1, gap: 'xs' },
45
+ {
46
+ default: () => [
47
+ h(MText, { text: props.title, style: { fontWeight: '600' } }),
48
+ props.description
49
+ ? h(MText, { text: props.description, variant: 'caption', tone: 'muted' })
50
+ : null,
51
+ ],
52
+ },
53
+ ),
54
+ slots.trailing
55
+ ? h(MColumn, { shrink: 1, align: 'end' }, { default: slots.trailing })
56
+ : props.interactive
57
+ ? h(MIcon, { name: 'chevron-right', size: 'sm', tone: 'muted' })
58
+ : null,
59
+ ],
60
+ },
61
+ ),
62
+ },
63
+ )
64
+ }
65
+ },
66
+ })
@@ -0,0 +1,82 @@
1
+ import { defineComponent, h, mergeProps, onBeforeUnmount, onMounted, ref } from 'vue'
2
+ import { progressProps, useMavisTheme } from '@getcortexlabs/mavis-core/vue'
3
+ import {
4
+ progressSizes,
5
+ progressMotion,
6
+ progressState,
7
+ checkProgressLabels,
8
+ } from '@getcortexlabs/mavis-core'
9
+ import { MBox } from './layout.js'
10
+
11
+ export const MProgress = defineComponent({
12
+ name: 'MProgress',
13
+ inheritAttrs: false,
14
+ props: progressProps,
15
+ setup(props, { attrs }) {
16
+ const { theme } = useMavisTheme()
17
+ const hidden = ref(false)
18
+ function visibility() {
19
+ hidden.value = document.hidden
20
+ }
21
+ onMounted(() => {
22
+ if (typeof document === 'undefined') return
23
+ visibility()
24
+ document.addEventListener('visibilitychange', visibility)
25
+ })
26
+ onBeforeUnmount(() => {
27
+ if (typeof document !== 'undefined')
28
+ document.removeEventListener('visibilitychange', visibility)
29
+ })
30
+ return () => {
31
+ checkProgressLabels(props.label, props.indeterminateLabel)
32
+ const reading = progressState(props.value, props.max)
33
+ const fraction = props.indeterminate ? progressMotion.segment : reading.ratio
34
+ return h(
35
+ MBox,
36
+ mergeProps(
37
+ {
38
+ width: props.width,
39
+ height: progressSizes[props.size],
40
+ grow: props.grow,
41
+ shrink: props.shrink,
42
+ radius: 'full',
43
+ backgroundColor: theme.value.colors.border,
44
+ },
45
+ attrs,
46
+ {
47
+ id: props.id,
48
+ accessibilityHidden: props.accessibilityHidden,
49
+ class: 'm-progress',
50
+ role: 'progressbar',
51
+ 'aria-label': props.label,
52
+ 'aria-valuemin': 0,
53
+ 'aria-valuemax': props.max,
54
+ 'aria-valuenow': props.indeterminate ? undefined : reading.value,
55
+ 'aria-valuetext': props.indeterminate ? props.indeterminateLabel : reading.text,
56
+ 'data-indeterminate': props.indeterminate,
57
+ style: {
58
+ '--m-progress-duration': `${progressMotion.duration}ms`,
59
+ '--m-progress-travel': `${((1 - progressMotion.segment) / progressMotion.segment) * 100}%`,
60
+ '--m-progress-rest': `${((1 - progressMotion.segment) / progressMotion.segment) * 50}%`,
61
+ overflow: 'hidden',
62
+ },
63
+ },
64
+ ),
65
+ {
66
+ default: () =>
67
+ h('div', {
68
+ class: 'm-progress-fill',
69
+ 'aria-hidden': 'true',
70
+ style: {
71
+ width: `${fraction * 100}%`,
72
+ height: '100%',
73
+ borderRadius: 'inherit',
74
+ backgroundColor: theme.value.colors[props.tone],
75
+ animationPlayState: hidden.value ? 'paused' : 'running',
76
+ },
77
+ }),
78
+ },
79
+ )
80
+ }
81
+ },
82
+ })
@@ -0,0 +1,184 @@
1
+ import { fontFamily } from '@getcortexlabs/mavis-core'
2
+ import { computed, defineComponent, h, mergeProps, nextTick, onBeforeUnmount, useId } from 'vue'
3
+ import { choiceKey, validateChoices, canChoose, type ChoiceOption } from '@getcortexlabs/mavis-core'
4
+ import {
5
+ useButtonAction,
6
+ radioGroupProps,
7
+ radioGroupEmits,
8
+ useMavisTheme,
9
+ } from '@getcortexlabs/mavis-core/vue'
10
+ import { MColumn } from './layout.js'
11
+ import { MText } from './MText.js'
12
+
13
+ export const MRadioGroup = defineComponent({
14
+ name: 'MRadioGroup',
15
+ inheritAttrs: false,
16
+ props: radioGroupProps,
17
+ emits: radioGroupEmits,
18
+ setup(props, { attrs, emit }) {
19
+ useButtonAction()
20
+ const { theme } = useMavisTheme()
21
+ const generatedId = `m-radio-${useId()}`
22
+ const controls = new Map<string, HTMLInputElement>()
23
+ let alive = true
24
+ onBeforeUnmount(() => {
25
+ alive = false
26
+ controls.clear()
27
+ })
28
+ const options = computed(() => {
29
+ validateChoices(props.options, props.modelValue)
30
+ return props.options
31
+ })
32
+ function request(option: ChoiceOption) {
33
+ if (canChoose(option, props.modelValue, props.disabled))
34
+ emit('update:modelValue', option.value)
35
+ // A radio click changes the entire browser group before Vue updates.
36
+ void nextTick(() => {
37
+ if (!alive) return
38
+ for (const item of props.options) {
39
+ const input = controls.get(choiceKey(item.value))
40
+ if (input) input.checked = item.value === props.modelValue
41
+ }
42
+ })
43
+ }
44
+ function keydown(event: KeyboardEvent, option: ChoiceOption) {
45
+ if (props.disabled || option.disabled || event.altKey || event.ctrlKey || event.metaKey)
46
+ return
47
+ const direction = { ArrowDown: 1, ArrowRight: 1, ArrowUp: -1, ArrowLeft: -1 }[event.key]
48
+ if (!direction && event.key !== 'Home' && event.key !== 'End') return
49
+ event.preventDefault()
50
+ const enabled = options.value.filter((item) => !item.disabled)
51
+ const current = enabled.findIndex((item) => item.value === option.value)
52
+ const index =
53
+ event.key === 'Home'
54
+ ? 0
55
+ : event.key === 'End'
56
+ ? enabled.length - 1
57
+ : (current + direction! + enabled.length) % enabled.length
58
+ const next = enabled[index]
59
+ if (!next) return
60
+ controls.get(choiceKey(next.value))?.focus()
61
+ request(next)
62
+ }
63
+ return () => {
64
+ const { colors, typography, space } = theme.value
65
+ const id = props.id ?? generatedId
66
+ const enabled = options.value.filter((option) => !option.disabled)
67
+ const tabValue =
68
+ enabled.find((option) => option.value === props.modelValue)?.value ?? enabled[0]?.value
69
+ return h(
70
+ MColumn,
71
+ mergeProps(attrs, {
72
+ id,
73
+ width: props.width,
74
+ grow: props.grow,
75
+ shrink: props.shrink,
76
+ gap: 'sm',
77
+ accessibilityHidden: props.accessibilityHidden,
78
+ role: 'radiogroup',
79
+ 'aria-labelledby': `${id}-label`,
80
+ 'aria-describedby': props.helperText ? `${id}-help` : undefined,
81
+ 'aria-disabled': props.disabled || undefined,
82
+ }),
83
+ {
84
+ default: () => [
85
+ h(MText, { id: `${id}-label`, text: props.label, style: { fontWeight: 600 } }),
86
+ props.helperText
87
+ ? h(MText, {
88
+ id: `${id}-help`,
89
+ text: props.helperText,
90
+ variant: 'caption',
91
+ tone: 'muted',
92
+ })
93
+ : null,
94
+ ...options.value.map((option) => {
95
+ const key = choiceKey(option.value)
96
+ const optionId = `${id}-${encodeURIComponent(key)}`
97
+ const disabled = props.disabled || option.disabled
98
+ const selected = option.value === props.modelValue
99
+ return h(
100
+ 'label',
101
+ {
102
+ key,
103
+ class: 'm-radio-option',
104
+ style: {
105
+ fontFamily: fontFamily(theme.value.typography.body.fontFamily, 'web'),
106
+ position: 'relative',
107
+ display: 'flex',
108
+ flexWrap: 'wrap',
109
+ alignItems: 'center',
110
+ minWidth: 0,
111
+ minHeight: '48px',
112
+ boxSizing: 'border-box',
113
+ borderRadius: '10px',
114
+ gap: `${space.md}px`,
115
+ padding: `${space.sm}px 2px`,
116
+ color: colors.text,
117
+ opacity: disabled ? 0.45 : 1,
118
+ fontSize: `${typography.body.fontSize}px`,
119
+ lineHeight: 1.5,
120
+ '--m-focus': colors.primary,
121
+ '--m-radio-border': colors.muted,
122
+ '--m-radio-fill': colors.primary,
123
+ },
124
+ },
125
+ [
126
+ h('input', {
127
+ ref: (element: unknown) => {
128
+ if (element) controls.set(key, element as HTMLInputElement)
129
+ else controls.delete(key)
130
+ },
131
+ id: optionId,
132
+ name: generatedId,
133
+ type: 'radio',
134
+ class: 'm-radio-input',
135
+ checked: selected,
136
+ disabled,
137
+ tabindex: !disabled && option.value === tabValue ? 0 : -1,
138
+ 'aria-label': option.label,
139
+ 'aria-checked': selected,
140
+ 'aria-describedby': option.helperText ? `${optionId}-help` : undefined,
141
+ onChange: () => request(option),
142
+ onKeydown: (event: KeyboardEvent) => keydown(event, option),
143
+ }),
144
+ h('span', { class: 'm-radio-indicator', 'aria-hidden': 'true' }, [
145
+ h('span', { class: 'm-radio-dot' }),
146
+ ]),
147
+ h(
148
+ 'span',
149
+ {
150
+ style: {
151
+ flex: '1 1 min-content',
152
+ minWidth: 0,
153
+ overflowWrap: 'break-word',
154
+ maxWidth: '100%',
155
+ },
156
+ },
157
+ [
158
+ h('span', { style: { display: 'block', fontWeight: 600 } }, option.label),
159
+ option.helperText
160
+ ? h(
161
+ 'span',
162
+ {
163
+ id: `${optionId}-help`,
164
+ style: {
165
+ display: 'block',
166
+ color: colors.muted,
167
+ fontSize: `${typography.caption.fontSize}px`,
168
+ marginTop: `${space.xs}px`,
169
+ },
170
+ },
171
+ option.helperText,
172
+ )
173
+ : null,
174
+ ],
175
+ ),
176
+ ],
177
+ )
178
+ }),
179
+ ],
180
+ },
181
+ )
182
+ }
183
+ },
184
+ })