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