@m3ui-vue/m3ui-vue 0.8.6 → 0.8.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/README.md +4 -0
  2. package/dist/{MMenuItem-BmPLAyv5.js → MMenuItem-DmrsQrK7.js} +2 -2
  3. package/dist/{MMenuItem-BmPLAyv5.js.map → MMenuItem-DmrsQrK7.js.map} +1 -1
  4. package/dist/chart.js +5 -1
  5. package/dist/chart.js.map +1 -1
  6. package/dist/code-editor.js +1 -1
  7. package/dist/components/MBottomSheet.vue.d.ts +3 -3
  8. package/dist/components/MListDetail.vue.d.ts +31 -0
  9. package/dist/components/MNavigationRail.vue.d.ts +6 -3
  10. package/dist/components/MNavigationSuite.vue.d.ts +46 -0
  11. package/dist/components/MShortNavigationBar.vue.d.ts +6 -1
  12. package/dist/components/MSideSheet.vue.d.ts +4 -4
  13. package/dist/components/MSupportingPane.vue.d.ts +34 -0
  14. package/dist/components/MTransferList.vue.d.ts +55 -34
  15. package/dist/components/MWindow.vue.d.ts +39 -1
  16. package/dist/components/_MTransferPane.vue.d.ts +10 -3
  17. package/dist/composables/_useItemLink.d.ts +30 -0
  18. package/dist/composables/_useSheetMotion.d.ts +7 -0
  19. package/dist/composables/useLocale.d.ts +3 -0
  20. package/dist/composables/useWindowSizeClass.d.ts +19 -0
  21. package/dist/index.d.ts +6 -0
  22. package/dist/locales/index.js +28 -7
  23. package/dist/locales/index.js.map +1 -1
  24. package/dist/m3ui-vue.css +1 -1
  25. package/dist/m3ui.js +2357 -1868
  26. package/dist/m3ui.js.map +1 -1
  27. package/dist/rich-text-editor.js +2 -2
  28. package/dist/styles.css +1 -1
  29. package/dist/{useLocale-4afAzuuP.js → useLocale-Bircp823.js} +5 -2
  30. package/dist/useLocale-Bircp823.js.map +1 -0
  31. package/package.json +1 -1
  32. package/src/__tests__/MChart.test.ts +28 -0
  33. package/src/__tests__/MShortNavigationBar.test.ts +25 -0
  34. package/src/__tests__/MTransferList.test.ts +73 -0
  35. package/src/__tests__/MWindow.test.ts +258 -0
  36. package/src/__tests__/adaptiveLayouts.test.ts +191 -0
  37. package/src/__tests__/sheets.test.ts +76 -0
  38. package/src/components/MBottomSheet.vue +11 -57
  39. package/src/components/MChart.vue +2 -1
  40. package/src/components/MListDetail.vue +103 -0
  41. package/src/components/MNavigationRail.vue +13 -8
  42. package/src/components/MNavigationSuite.vue +89 -0
  43. package/src/components/MShortNavigationBar.vue +37 -17
  44. package/src/components/MSideSheet.vue +11 -56
  45. package/src/components/MSupportingPane.vue +70 -0
  46. package/src/components/MTransferList.vue +43 -9
  47. package/src/components/MWindow.vue +507 -108
  48. package/src/components/_MTransferPane.vue +113 -35
  49. package/src/composables/_useItemLink.ts +19 -0
  50. package/src/composables/_useSheetMotion.ts +181 -0
  51. package/src/composables/useLocale.ts +7 -0
  52. package/src/composables/useWindowSizeClass.ts +93 -0
  53. package/src/index.ts +6 -0
  54. package/src/locales/de.ts +3 -0
  55. package/src/locales/es.ts +3 -0
  56. package/src/locales/fr.ts +3 -0
  57. package/src/locales/ja.ts +3 -0
  58. package/src/locales/ko.ts +3 -0
  59. package/src/locales/pt.ts +3 -0
  60. package/src/locales/zh.ts +3 -0
  61. package/dist/useLocale-4afAzuuP.js.map +0 -1
@@ -2,6 +2,7 @@
2
2
  import { computed } from 'vue'
3
3
  import MIcon from './MIcon.vue'
4
4
  import MBadge from './MBadge.vue'
5
+ import { useItemLink, type ItemLink } from '../composables/_useItemLink'
5
6
 
6
7
  export interface ShortNavBarItem {
7
8
  value: string | number
@@ -9,6 +10,10 @@ export interface ShortNavBarItem {
9
10
  icon: string
10
11
  badge?: number
11
12
  badgeDot?: boolean
13
+ /** Not selectable: icon and label at 38% of the unselected color, no hover. */
14
+ disabled?: boolean
15
+ /** Makes the item a link: a vue-router location (rendered as RouterLink), or a URL without vue-router. */
16
+ to?: ItemLink
12
17
  }
13
18
 
14
19
  const props = withDefaults(
@@ -37,6 +42,28 @@ const props = withDefaults(
37
42
 
38
43
  defineEmits<{ 'update:modelValue': [string | number] }>()
39
44
 
45
+ const itemLink = useItemLink()
46
+
47
+ // ShortNavigationBarItemDefaults.colors(): disabled icon/text = unselected color at
48
+ // DisabledAlpha (0.38), whether or not the item is selected; no hover state layer.
49
+ const DISABLED = 'text-on-surface-variant/38'
50
+ function topPillClass(item: ShortNavBarItem) {
51
+ const selected = item.value === props.modelValue
52
+ if (item.disabled) return selected ? `w-14 bg-secondary-container ${DISABLED}` : `w-0 ${DISABLED}`
53
+ return selected
54
+ ? 'w-14 bg-secondary-container text-on-secondary-container'
55
+ : 'w-0 bg-secondary-container/0 text-on-surface-variant group-hover:w-14 group-hover:bg-on-surface/8'
56
+ }
57
+ function labelClass(item: ShortNavBarItem) {
58
+ if (item.disabled) return DISABLED
59
+ return item.value === props.modelValue ? 'text-secondary' : 'text-on-surface-variant'
60
+ }
61
+ function startPillClass(item: ShortNavBarItem) {
62
+ const selected = item.value === props.modelValue
63
+ if (item.disabled) return selected ? `bg-secondary-container ${DISABLED}` : DISABLED
64
+ return selected ? 'bg-secondary-container text-on-secondary-container' : 'text-on-surface-variant group-hover:bg-on-surface/8'
65
+ }
66
+
40
67
  // calculateCenteredContentHorizontalPadding: 3 items -> 20% each side, 4 -> 15%, 5 -> 10%,
41
68
  // 6 -> 5%, 7+ -> 0. Matches the real formula verbatim: ((100 - 10*(n+3)) / 2) / 100.
42
69
  const centeredPadding = computed(() => {
@@ -51,23 +78,20 @@ const centeredPadding = computed(() => {
51
78
  class="flex h-16 w-full items-center border-t border-outline-variant bg-surface-container shadow-elevation-2"
52
79
  :style="arrangement === 'centered' ? { paddingLeft: `${centeredPadding}%`, paddingRight: `${centeredPadding}%` } : undefined"
53
80
  >
54
- <button
81
+ <component
82
+ :is="itemLink(item).tag"
55
83
  v-for="item in items"
56
84
  :key="item.value"
57
- type="button"
58
- class="group flex flex-1 cursor-pointer items-center justify-center self-stretch transition-colors focus-visible:outline-none"
59
- :class="iconPosition === 'top' ? 'flex-col gap-1' : 'flex-row gap-1 py-1.5'"
60
- @click="$emit('update:modelValue', item.value)"
85
+ v-bind="itemLink(item).attrs"
86
+ class="group flex flex-1 items-center justify-center self-stretch transition-colors focus-visible:outline-none"
87
+ :class="[iconPosition === 'top' ? 'flex-col gap-1' : 'flex-row gap-1 py-1.5', item.disabled ? 'cursor-not-allowed' : 'cursor-pointer']"
88
+ @click="!item.disabled && $emit('update:modelValue', item.value)"
61
89
  >
62
90
  <template v-if="iconPosition === 'top'">
63
91
  <!-- Top icon position: 56x32dp pill above a separate label, matching MNavigationBar -->
64
92
  <span
65
93
  class="inline-flex h-8 items-center justify-center rounded-2xl transition-all duration-200"
66
- :class="
67
- item.value === modelValue
68
- ? 'w-14 bg-secondary-container text-on-secondary-container'
69
- : 'w-0 bg-secondary-container/0 text-on-surface-variant group-hover:w-14 group-hover:bg-on-surface/8'
70
- "
94
+ :class="topPillClass(item)"
71
95
  >
72
96
  <MBadge v-if="item.badge != null" :count="item.badge">
73
97
  <MIcon :name="item.icon" :size="24" />
@@ -79,7 +103,7 @@ const centeredPadding = computed(() => {
79
103
  </span>
80
104
  <span
81
105
  class="text-label-medium font-medium"
82
- :class="item.value === modelValue ? 'text-secondary' : 'text-on-surface-variant'"
106
+ :class="labelClass(item)"
83
107
  >
84
108
  {{ item.label }}
85
109
  </span>
@@ -92,11 +116,7 @@ const centeredPadding = computed(() => {
92
116
  separate Secondary label color (ShortNavigationBarItemDefaults.colors() doc comment). -->
93
117
  <span
94
118
  class="inline-flex h-10 items-center justify-center gap-1 rounded-2xl px-4 transition-colors duration-200"
95
- :class="
96
- item.value === modelValue
97
- ? 'bg-secondary-container text-on-secondary-container'
98
- : 'text-on-surface-variant group-hover:bg-on-surface/8'
99
- "
119
+ :class="startPillClass(item)"
100
120
  >
101
121
  <MBadge v-if="item.badge != null" :count="item.badge">
102
122
  <MIcon :name="item.icon" :size="24" />
@@ -108,6 +128,6 @@ const centeredPadding = computed(() => {
108
128
  <span class="text-label-medium font-medium">{{ item.label }}</span>
109
129
  </span>
110
130
  </template>
111
- </button>
131
+ </component>
112
132
  </nav>
113
133
  </template>
@@ -1,6 +1,6 @@
1
1
  <script setup lang="ts">
2
- import { computed, ref } from 'vue'
3
2
  import MIcon from './MIcon.vue'
3
+ import { useSheetMotion } from '../composables/_useSheetMotion'
4
4
 
5
5
  withDefaults(defineProps<{
6
6
  modelValue: boolean
@@ -11,51 +11,30 @@ withDefaults(defineProps<{
11
11
  const emit = defineEmits<{ 'update:modelValue': [boolean] }>()
12
12
  const close = () => emit('update:modelValue', false)
13
13
 
14
- const dragX = ref(0)
15
- const dragging = ref(false)
16
- let startX = 0
17
-
18
- function onEdgePointerDown(e: PointerEvent) {
19
- dragging.value = true
20
- startX = e.clientX
21
- dragX.value = 0
22
- ;(e.currentTarget as HTMLElement).setPointerCapture(e.pointerId)
23
- }
24
- function onEdgePointerMove(e: PointerEvent) {
25
- if (!dragging.value) return
26
- dragX.value = Math.max(0, e.clientX - startX)
27
- }
28
- function onEdgePointerUp() {
29
- if (dragX.value > 100) close()
30
- dragging.value = false
31
- dragX.value = 0
32
- }
33
-
34
- const panelStyle = computed(() => ({
35
- transform: `translateX(${dragX.value}px)`,
36
- transition: dragging.value ? 'none' : undefined,
37
- }))
14
+ // Slide in/out and drag-to-dismiss, as springs (see _useSheetMotion).
15
+ const motion = useSheetMotion('x', close)
38
16
  </script>
39
17
 
40
18
  <template>
41
19
  <Teleport to="body">
42
- <Transition name="ss" :duration="{ enter: 320, leave: 280 }">
20
+ <Transition :css="false" @enter="motion.onEnter" @leave="motion.onLeave">
43
21
  <div v-if="modelValue" class="fixed inset-0 z-200 flex justify-end">
44
22
  <!-- Scrim -->
45
- <div class="ss-scrim absolute inset-0 bg-scrim/32" @click="close" />
23
+ <div data-sheet-scrim class="absolute inset-0 bg-scrim/32" @click="close" />
46
24
 
47
25
  <!-- Panel -->
48
26
  <aside
49
- class="ss-panel relative flex h-full flex-col bg-surface-container-low shadow-elevation-3"
27
+ data-sheet-panel
28
+ class="relative flex h-full flex-col bg-surface-container-low shadow-elevation-3"
50
29
  :class="[width, 'max-w-[90vw]']"
51
- :style="panelStyle"
52
30
  >
53
31
  <!-- Drag edge -->
54
32
  <div
55
33
  class="absolute top-0 left-0 h-full w-3 cursor-ew-resize touch-none"
56
- @pointerdown="onEdgePointerDown"
57
- @pointermove="onEdgePointerMove"
58
- @pointerup="onEdgePointerUp"
34
+ @pointerdown="motion.onDragStart"
35
+ @pointermove="motion.onDragMove"
36
+ @pointerup="motion.onDragEnd"
37
+ @pointercancel="motion.onDragEnd"
59
38
  />
60
39
 
61
40
  <!-- Header -->
@@ -86,27 +65,3 @@ const panelStyle = computed(() => ({
86
65
  </Transition>
87
66
  </Teleport>
88
67
  </template>
89
-
90
- <style scoped>
91
- .ss-scrim {
92
- transition: opacity 280ms ease;
93
- }
94
- .ss-enter-from .ss-scrim,
95
- .ss-leave-to .ss-scrim {
96
- opacity: 0;
97
- }
98
-
99
- .ss-panel {
100
- transition:
101
- transform 320ms cubic-bezier(0.2, 0, 0, 1),
102
- opacity 240ms ease;
103
- }
104
- .ss-enter-from .ss-panel {
105
- transform: translateX(40%);
106
- opacity: 0;
107
- }
108
- .ss-leave-to .ss-panel {
109
- transform: translateX(100%) !important;
110
- opacity: 0;
111
- }
112
- </style>
@@ -0,0 +1,70 @@
1
+ <script setup lang="ts">
2
+ import { computed, ref, watch } from 'vue'
3
+ import MBottomSheet from './MBottomSheet.vue'
4
+ import { useWindowSizeClass } from '../composables/useWindowSizeClass'
5
+
6
+ /*
7
+ * M3 supporting-pane canonical layout, after androidx SupportingPaneScaffold: from the
8
+ * expanded width class (840px) up, the supporting pane sits beside the main one with a 24dp
9
+ * spacer at its preferred width (360dp, 412dp from large). Below that, its default adapt
10
+ * strategy is `Reflow(Main)`: it moves under the main pane ('below' here). 'sheet' follows
11
+ * the `Levitate` bottom-sheet sample instead: hidden until opened, then in a bottom sheet.
12
+ * Measured on the component itself, not the window.
13
+ */
14
+ const props = withDefaults(defineProps<{
15
+ /** Where the supporting pane goes when there's room for only one pane. */
16
+ singlePane?: 'below' | 'sheet'
17
+ /** With `singlePane="sheet"`: whether the sheet is open (v-model:open). */
18
+ open?: boolean
19
+ /** With `singlePane="sheet"`: the sheet's title. */
20
+ sheetTitle?: string
21
+ /** Supporting pane width in the two-pane layout. Defaults to M3's 360px (412px from the large width class). */
22
+ supportingWidth?: string
23
+ }>(), { singlePane: 'below', open: false })
24
+
25
+ const emit = defineEmits<{ 'update:open': [boolean] }>()
26
+
27
+ defineSlots<{
28
+ main?: (props: { twoPane: boolean }) => unknown
29
+ supporting?: (props: { twoPane: boolean }) => unknown
30
+ }>()
31
+
32
+ const root = ref<HTMLElement>()
33
+ const { widthClass } = useWindowSizeClass(root)
34
+ const twoPane = computed(() => widthClass.value !== 'compact' && widthClass.value !== 'medium')
35
+ const width = computed(() =>
36
+ props.supportingWidth ?? (widthClass.value === 'large' || widthClass.value === 'extra-large' ? '412px' : '360px'),
37
+ )
38
+ const inSheet = computed(() => !twoPane.value && props.singlePane === 'sheet')
39
+ // Once the pane fits beside the main one, an open sheet would pop back up on the next narrowing.
40
+ watch(twoPane, (two) => {
41
+ if (two && props.open) emit('update:open', false)
42
+ })
43
+ </script>
44
+
45
+ <template>
46
+ <div ref="root" class="flex gap-6" :class="twoPane ? 'overflow-hidden' : 'flex-col overflow-y-auto'">
47
+ <!--
48
+ Two panes: each scrolls on its own (give the component a height). One pane, 'below': the
49
+ whole thing scrolls as a single column.
50
+ -->
51
+ <div class="min-w-0" :class="twoPane ? 'min-h-0 flex-1 overflow-auto' : 'shrink-0'">
52
+ <slot name="main" :two-pane="twoPane" />
53
+ </div>
54
+ <div
55
+ v-if="!inSheet"
56
+ :class="twoPane ? 'min-h-0 shrink-0 overflow-auto' : 'shrink-0'"
57
+ :style="twoPane ? { width } : undefined"
58
+ >
59
+ <slot name="supporting" :two-pane="twoPane" />
60
+ </div>
61
+ <MBottomSheet
62
+ v-else
63
+ :model-value="open"
64
+ :title="sheetTitle"
65
+ @update:model-value="emit('update:open', $event)"
66
+ >
67
+ <slot name="supporting" :two-pane="false" />
68
+ </MBottomSheet>
69
+ </div>
70
+ </template>
@@ -1,11 +1,4 @@
1
- <script setup lang="ts">
2
- import { computed, ref } from 'vue'
3
- import MIconButton from './MIconButton.vue'
4
- import MTransferPane from './_MTransferPane.vue'
5
- import { useLocale } from '../composables/useLocale'
6
-
7
- const locale = useLocale()
8
-
1
+ <script lang="ts">
9
2
  export interface TransferItem {
10
3
  value: string | number
11
4
  label: string
@@ -13,12 +6,21 @@ export interface TransferItem {
13
6
  /** Optional second line under the label (an email, a role, a short description). */
14
7
  description?: string
15
8
  }
9
+ </script>
10
+
11
+ <script setup lang="ts" generic="T extends TransferItem = TransferItem">
12
+ import { computed, ref } from 'vue'
13
+ import MIconButton from './MIconButton.vue'
14
+ import MTransferPane from './_MTransferPane.vue'
15
+ import { useLocale } from '../composables/useLocale'
16
+
17
+ const locale = useLocale()
16
18
 
17
19
  type Value = string | number
18
20
 
19
21
  const props = withDefaults(defineProps<{
20
22
  modelValue: Value[]
21
- items: TransferItem[]
23
+ items: T[]
22
24
  sourceTitle?: string
23
25
  targetTitle?: string
24
26
  filterable?: boolean
@@ -30,11 +32,39 @@ const props = withDefaults(defineProps<{
30
32
  moveAllLeftLabel?: string
31
33
  /** Height of each list's scroll area (any CSS length). */
32
34
  listHeight?: string
35
+ /**
36
+ * Fully custom rows: the `#item` slot draws the whole row (no checkbox, padding, min height
37
+ * or background). The row stays clickable, focusable (Space checks it, Enter moves it) and
38
+ * animated; use the slot's `checked` to style the checked state.
39
+ */
40
+ bare?: boolean
33
41
  }>(), {
34
42
  filterable: false,
35
43
  listHeight: '280px',
44
+ bare: false,
36
45
  })
37
46
 
47
+ defineSlots<{
48
+ /**
49
+ * Custom row content. Without `bare` it replaces the icon and text, keeping the checkbox,
50
+ * highlight and hover. Buttons, links, fields and `[data-transfer-action]` elements inside
51
+ * keep their own clicks instead of checking the row.
52
+ */
53
+ item?: (props: {
54
+ /** Your item, with any extra fields it carries. */
55
+ item: T
56
+ checked: boolean
57
+ /** Which pane the row is in. */
58
+ side: 'source' | 'target'
59
+ /** Check or uncheck the row. */
60
+ toggle: () => void
61
+ /** Send just this row to the other pane. */
62
+ move: () => void
63
+ }) => unknown
64
+ 'source-empty'?: () => unknown
65
+ 'target-empty'?: () => unknown
66
+ }>()
67
+
38
68
  const emit = defineEmits<{ 'update:modelValue': [Value[]] }>()
39
69
 
40
70
  const checkedSource = ref<Set<Value>>(new Set())
@@ -131,11 +161,13 @@ function activateTarget(value: Value) {
131
161
  enter-from="end"
132
162
  :select-all-label="locale.selectAll"
133
163
  :clear-search-label="locale.clearSearch"
164
+ :bare="bare"
134
165
  @toggle="toggleSource"
135
166
  @toggle-all="toggleAllSource"
136
167
  @activate="activateSource"
137
168
  @update:search="sourceSearch = $event"
138
169
  >
170
+ <template v-if="$slots.item" #item="row"><slot name="item" v-bind="row" :item="row.item as T" side="source" /></template>
139
171
  <template v-if="$slots['source-empty']" #empty><slot name="source-empty" /></template>
140
172
  </MTransferPane>
141
173
 
@@ -187,11 +219,13 @@ function activateTarget(value: Value) {
187
219
  enter-from="start"
188
220
  :select-all-label="locale.selectAll"
189
221
  :clear-search-label="locale.clearSearch"
222
+ :bare="bare"
190
223
  @toggle="toggleTarget"
191
224
  @toggle-all="toggleAllTarget"
192
225
  @activate="activateTarget"
193
226
  @update:search="targetSearch = $event"
194
227
  >
228
+ <template v-if="$slots.item" #item="row"><slot name="item" v-bind="row" :item="row.item as T" side="target" /></template>
195
229
  <template v-if="$slots['target-empty']" #empty><slot name="target-empty" /></template>
196
230
  </MTransferPane>
197
231
  </div>