@m3ui-vue/m3ui-vue 0.8.0 → 0.8.2

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 (67) hide show
  1. package/README.md +9 -1
  2. package/dist/{MMenuItem-vSLbJGqe.js → MMenuItem-BAWmUTT3.js} +367 -189
  3. package/dist/MMenuItem-BAWmUTT3.js.map +1 -0
  4. package/dist/code-editor.js +1 -1
  5. package/dist/code-editor.js.map +1 -1
  6. package/dist/components/MButton.vue.d.ts +7 -0
  7. package/dist/components/MCalendar.vue.d.ts +0 -1
  8. package/dist/components/MCarousel.vue.d.ts +12 -14
  9. package/dist/components/MContextMenu.vue.d.ts +25 -4
  10. package/dist/components/MDatePicker.vue.d.ts +1 -3
  11. package/dist/components/MDatePickerModal.vue.d.ts +0 -1
  12. package/dist/components/MDateRangePicker.vue.d.ts +1 -3
  13. package/dist/components/MDateRangePickerModal.vue.d.ts +0 -1
  14. package/dist/components/MKanban.vue.d.ts +1 -0
  15. package/dist/components/MMenu.vue.d.ts +20 -2
  16. package/dist/components/MMenuDivider.vue.d.ts +13 -1
  17. package/dist/components/MMenuItem.vue.d.ts +3 -0
  18. package/dist/components/MScheduler.vue.d.ts +0 -1
  19. package/dist/components/MShape.vue.d.ts +51 -0
  20. package/dist/components/MShortNavigationBar.vue.d.ts +34 -0
  21. package/dist/components/MSimpleCarousel.vue.d.ts +45 -0
  22. package/dist/components/MToggleButton.vue.d.ts +29 -0
  23. package/dist/components/MTree.vue.d.ts +0 -1
  24. package/dist/components/MTreeTable.vue.d.ts +1 -0
  25. package/dist/index.d.ts +8 -1
  26. package/dist/m3ui-vue.css +1 -1
  27. package/dist/m3ui.js +5599 -3973
  28. package/dist/m3ui.js.map +1 -1
  29. package/dist/rich-text-editor.js +8 -8
  30. package/dist/styles/palettes.css +22 -22
  31. package/dist/styles.css +1 -1
  32. package/package.json +4 -1
  33. package/src/__tests__/MCarousel.test.ts +33 -0
  34. package/src/__tests__/MShape.test.ts +36 -0
  35. package/src/__tests__/MToggleButton.test.ts +27 -0
  36. package/src/components/MAutocomplete.vue +5 -1
  37. package/src/components/MButton.vue +15 -2
  38. package/src/components/MCalendar.vue +9 -5
  39. package/src/components/MCarousel.vue +123 -173
  40. package/src/components/MCodeEditor.vue +6 -1
  41. package/src/components/MCommandPalette.vue +4 -0
  42. package/src/components/MContextMenu.vue +287 -13
  43. package/src/components/MDatePicker.vue +12 -9
  44. package/src/components/MDatePickerModal.vue +9 -4
  45. package/src/components/MDateRangePicker.vue +12 -9
  46. package/src/components/MDateRangePickerModal.vue +9 -4
  47. package/src/components/MKanban.vue +5 -1
  48. package/src/components/MMenu.vue +308 -20
  49. package/src/components/MMenuDivider.vue +16 -0
  50. package/src/components/MMenuItem.vue +60 -18
  51. package/src/components/MMultiAutocomplete.vue +5 -1
  52. package/src/components/MMultiSelect.vue +5 -1
  53. package/src/components/MScheduler.vue +10 -6
  54. package/src/components/MSearchBar.vue +5 -1
  55. package/src/components/MSelect.vue +5 -1
  56. package/src/components/MShape.vue +107 -0
  57. package/src/components/MShortNavigationBar.vue +113 -0
  58. package/src/components/MSimpleCarousel.vue +325 -0
  59. package/src/components/MSpotlightSearch.vue +6 -0
  60. package/src/components/MToggleButton.vue +188 -0
  61. package/src/components/MTopAppBar.vue +6 -2
  62. package/src/components/MTree.vue +4 -2
  63. package/src/components/MTreeTable.vue +5 -1
  64. package/src/composables/useColorPalette.ts +1 -1
  65. package/src/index.ts +8 -1
  66. package/src/styles/palettes.css +22 -22
  67. package/dist/MMenuItem-vSLbJGqe.js.map +0 -1
@@ -1,12 +1,244 @@
1
1
  <script setup lang="ts">
2
- import { nextTick, onMounted, onUnmounted, provide, ref } from 'vue'
2
+ import { computed, Fragment, inject, nextTick, onMounted, onUnmounted, provide, ref, useSlots, watch, type VNode } from 'vue'
3
+ import MIcon from './MIcon.vue'
4
+ import MMenuDivider from './MMenuDivider.vue'
5
+
6
+ const props = withDefaults(
7
+ defineProps<{
8
+ /**
9
+ * How items with a `#children` slot behave.
10
+ * `'flyout'` opens a hover-positioned side panel (desktop).
11
+ * `'push'` replaces the panel's own content with the submenu and a
12
+ * back header — no positioning math, works with touch. Useful for mobile.
13
+ */
14
+ submenuMode?: 'flyout' | 'push'
15
+ /**
16
+ * `'standard'` is M3's baseline menu — square-ish 4dp corners
17
+ * (`MenuTokens.ContainerShape`/`CornerExtraSmall`).
18
+ * `'expressive'` is M3's rounder "vertical menu" styling — 16dp corners
19
+ * (`SegmentedMenuTokens.ContainerShape`/`CornerLarge`). Combine with
20
+ * `<MMenuDivider gap />` to split the panel into independently-rounded
21
+ * groups with a visible gap between them, instead of a plain line.
22
+ */
23
+ variant?: 'standard' | 'expressive'
24
+ }>(),
25
+ { submenuMode: 'flyout', variant: 'standard' },
26
+ )
27
+
28
+ const slots = useSlots()
29
+
30
+ function flattenVNodes(vnodes: VNode[]): VNode[] {
31
+ const out: VNode[] = []
32
+ for (const vnode of vnodes) {
33
+ if (vnode.type === Fragment && Array.isArray(vnode.children)) {
34
+ out.push(...flattenVNodes(vnode.children as VNode[]))
35
+ } else {
36
+ out.push(vnode)
37
+ }
38
+ }
39
+ return out
40
+ }
41
+
42
+ function isGapDivider(vnode: VNode): boolean {
43
+ if (vnode.type !== MMenuDivider) return false
44
+ const gap = (vnode.props as { gap?: unknown } | null)?.gap
45
+ return gap === '' || gap === true || gap === 'true'
46
+ }
47
+
48
+ // See MMenu.vue for the same mechanism: splits the default slot's content
49
+ // into groups at each `<MMenuDivider gap />`, for the 'expressive' variant's
50
+ // independently-rounded group boxes.
51
+ const groups = computed(() => {
52
+ if (props.variant !== 'expressive') return null
53
+ const raw = flattenVNodes((slots.default?.() ?? []) as VNode[])
54
+ const result: VNode[][] = [[]]
55
+ for (const vnode of raw) {
56
+ if (isGapDivider(vnode)) result.push([])
57
+ else result[result.length - 1]!.push(vnode)
58
+ }
59
+ return result.filter(g => g.length > 0)
60
+ })
61
+ const isGrouped = computed(() => !!groups.value && groups.value.length > 1)
3
62
 
4
63
  const visible = ref(false)
5
64
  const adjustedPos = ref({ x: 0, y: 0 })
6
65
  const panelEl = ref<HTMLElement | null>(null)
7
66
 
67
+ // See MMenu.vue for why this is needed: a menu nested inside another
68
+ // MMenu/MContextMenu's slot Teleports to <body> independently, so the
69
+ // ancestor's outside-click check needs a shared registry of open panel
70
+ // elements (across the logical component tree, not the DOM tree) instead of
71
+ // checking only its own panel.
72
+ const panelRegistry = inject<Set<HTMLElement>>('m-menu-panel-registry', new Set())
73
+ provide('m-menu-panel-registry', panelRegistry)
74
+
75
+ watch(panelEl, (el, oldEl) => {
76
+ if (oldEl) panelRegistry.delete(oldEl)
77
+ if (el) panelRegistry.add(el)
78
+ })
79
+
80
+ onUnmounted(() => {
81
+ if (panelEl.value) panelRegistry.delete(panelEl.value)
82
+ })
83
+
84
+ // See MMenu.vue for why this is separate from panelRegistry: keeps at most
85
+ // one of this menu's *direct* siblings-under-the-same-parent open at a time.
86
+ const siblingGroup = inject<{ current: (() => void) | null } | null>('m-menu-sibling-group', null)
87
+ provide('m-menu-sibling-group', { current: null })
88
+
89
+ type NavEntry = { icon?: string, header?: () => any, content?: () => any }
90
+ const navStack = ref<NavEntry[]>([])
91
+ const currentNav = computed(() => navStack.value[navStack.value.length - 1])
92
+ const navDirection = ref<'forward' | 'backward'>('forward')
93
+
94
+ // See MMenu.vue: driven by the Web Animations API rather than Vue's
95
+ // CSS-class transition hooks, which never reliably completed here with
96
+ // dynamic (direction-dependent) enter/leave classes on a mode-less Transition.
97
+ const slideDuration = 220
98
+ function navSlideEnter(el: Element, done: () => void) {
99
+ const dir = navDirection.value === 'forward' ? 1 : -1
100
+ const anim = (el as HTMLElement).animate(
101
+ [
102
+ { transform: `translateX(${dir * 100}%)`, opacity: 0.4 },
103
+ { transform: 'translateX(0%)', opacity: 1 },
104
+ ],
105
+ { duration: slideDuration, easing: 'cubic-bezier(0.05,0.7,0.1,1)' },
106
+ )
107
+ anim.onfinish = done
108
+ }
109
+ function navSlideLeave(el: Element, done: () => void) {
110
+ const dir = navDirection.value === 'forward' ? -1 : 1
111
+ const htmlEl = el as HTMLElement
112
+ htmlEl.style.position = 'absolute'
113
+ htmlEl.style.insetInline = '0'
114
+ htmlEl.style.top = '0'
115
+ const anim = htmlEl.animate(
116
+ [
117
+ { transform: 'translateX(0%)', opacity: 1 },
118
+ { transform: `translateX(${dir * 100}%)`, opacity: 0.4 },
119
+ ],
120
+ { duration: slideDuration, easing: 'cubic-bezier(0.3,0,0.8,0.15)' },
121
+ )
122
+ anim.onfinish = done
123
+ }
124
+
125
+ // See MMenu.vue: the real Menu.kt animates the panel's scale/alpha with
126
+ // actual springs (StandardMotionTokens: scale dampingRatio 0.9/stiffness
127
+ // 1400, alpha dampingRatio 1.0/stiffness 3800), not a duration+easing tween.
128
+ // Running close as its own forward spring toward the reversed targets isn't
129
+ // right either — alpha (stiffness 3800) settles much faster than scale
130
+ // (stiffness 1400), so the panel fades to invisible before it finishes
131
+ // shrinking and you never see the shrink. Close needs to be the literal
132
+ // time-reverse of open instead: simulated once (open direction only) and
133
+ // played back forwards for enter, backwards for leave.
134
+ //
135
+ // A damped spring approaches its target exponentially, so it keeps "settling"
136
+ // long after the motion is visually done — with a tight (0.001) tolerance on
137
+ // both position *and* velocity, roughly the last third of the recorded
138
+ // trajectory is values within a fraction of a percent of the target, visually
139
+ // indistinguishable from it. Reversed for close, that flat tail lands at the
140
+ // *start* instead, so nothing visibly happens for the first ~80ms before the
141
+ // close animation actually appears to begin. Trimmed on position alone with a
142
+ // much looser tolerance instead, since that's what's actually visible.
143
+ let cachedTrajectory: { scale: number, alpha: number }[] | null = null
144
+ const trajectoryStep = 1 / 240
145
+ function openTrajectory() {
146
+ if (cachedTrajectory) return cachedTrajectory
147
+ const samples: { scale: number, alpha: number }[] = []
148
+ let scale = 0.8
149
+ let scaleVel = 0
150
+ let alpha = 0
151
+ let alphaVel = 0
152
+ const scaleDamping = 0.9
153
+ const scaleStiffness = 1400
154
+ const alphaDamping = 1.0
155
+ const alphaStiffness = 3800
156
+ for (let t = 0; t < 1; t += trajectoryStep) {
157
+ samples.push({ scale, alpha })
158
+ scaleVel += (-scaleStiffness * (scale - 1) - 2 * scaleDamping * Math.sqrt(scaleStiffness) * scaleVel) * trajectoryStep
159
+ scale += scaleVel * trajectoryStep
160
+ alphaVel += (-alphaStiffness * (alpha - 1) - 2 * alphaDamping * Math.sqrt(alphaStiffness) * alphaVel) * trajectoryStep
161
+ alpha += alphaVel * trajectoryStep
162
+ const visuallySettled = Math.abs(scale - 1) < 0.003 && Math.abs(alpha - 1) < 0.003
163
+ if (visuallySettled) break
164
+ }
165
+ samples.push({ scale: 1, alpha: 1 })
166
+ cachedTrajectory = samples
167
+ return samples
168
+ }
169
+
170
+ // Vue interrupts and reverses this mid-flight when the menu is toggled
171
+ // quickly (close while still opening, or vice versa) — it calls the other
172
+ // hook on the same still-mounted element without waiting for `done()`. Both
173
+ // `currentIdx` (how far along the trajectory we are, so a reversal continues
174
+ // smoothly from wherever it currently is instead of snapping back to a fixed
175
+ // start) and `cancelActive` (so the previous rAF loop actually stops instead
176
+ // of running alongside the new one, fighting over the same style every
177
+ // frame) have to live outside this function to survive that interruption.
178
+ let currentIdx = 0
179
+ let cancelActive: (() => void) | null = null
180
+
181
+ function playTrajectory(el: Element, done: () => void, opening: boolean) {
182
+ cancelActive?.()
183
+ const htmlEl = el as HTMLElement
184
+ const samples = openTrajectory()
185
+ const last = samples.length - 1
186
+ const direction = opening ? 1 : -1
187
+ const target = opening ? last : 0
188
+ let lastTime = 0
189
+ let rafId = 0
190
+ let cancelled = false
191
+
192
+ function apply(idx: number) {
193
+ const sample = samples[Math.round(Math.max(0, Math.min(last, idx)))]!
194
+ htmlEl.style.transform = `scale(${sample.scale})`
195
+ htmlEl.style.opacity = String(Math.min(1, Math.max(0, sample.alpha)))
196
+ }
197
+
198
+ function step(now: number) {
199
+ if (cancelled) return
200
+ const dtSteps = lastTime ? (now - lastTime) / 1000 / trajectoryStep : 1
201
+ lastTime = now
202
+ currentIdx = Math.max(0, Math.min(last, currentIdx + direction * dtSteps))
203
+ apply(currentIdx)
204
+ if ((opening && currentIdx >= target) || (!opening && currentIdx <= target)) {
205
+ cancelActive = null
206
+ done()
207
+ return
208
+ }
209
+ rafId = requestAnimationFrame(step)
210
+ }
211
+
212
+ cancelActive = () => { cancelled = true; cancelAnimationFrame(rafId) }
213
+ apply(currentIdx)
214
+ rafId = requestAnimationFrame(step)
215
+ }
216
+ function panelEnter(el: Element, done: () => void) {
217
+ playTrajectory(el, done, true)
218
+ }
219
+ function panelLeave(el: Element, done: () => void) {
220
+ playTrajectory(el, done, false)
221
+ }
222
+
223
+ function pushNav(entry: NavEntry) {
224
+ navDirection.value = 'forward'
225
+ navStack.value.push(entry)
226
+ nextTick(() => focusableItems()[0]?.focus())
227
+ }
228
+
229
+ function popNav() {
230
+ navDirection.value = 'backward'
231
+ navStack.value.pop()
232
+ nextTick(() => focusableItems()[0]?.focus())
233
+ }
234
+
8
235
  async function showAt(x: number, y: number) {
236
+ if (siblingGroup && siblingGroup.current && siblingGroup.current !== hide) {
237
+ siblingGroup.current()
238
+ }
239
+ if (siblingGroup) siblingGroup.current = hide
9
240
  adjustedPos.value = { x, y }
241
+ navStack.value = []
10
242
  visible.value = true
11
243
  await nextTick()
12
244
  if (!panelEl.value) return
@@ -41,22 +273,30 @@ function show(e: MouseEvent) {
41
273
  }
42
274
 
43
275
  function hide() {
276
+ if (siblingGroup?.current === hide) siblingGroup.current = null
44
277
  visible.value = false
45
278
  }
46
279
 
47
280
  provide('m-menu-close', hide)
281
+ provide('m-menu-nav', { mode: props.submenuMode, push: pushNav })
48
282
  defineExpose({ show, showAt, hide })
49
283
 
50
284
  function onDocMouseDown(e: MouseEvent) {
51
285
  if (!visible.value) return
52
286
  const t = e.target as Node
53
- if (panelEl.value?.contains(t)) return
287
+ for (const panel of panelRegistry) {
288
+ if (panel.contains(t)) return
289
+ }
54
290
  if ((t as Element).closest?.('.m3-submenu')) return
55
291
  hide()
56
292
  }
57
293
 
58
294
  function onKeydown(e: KeyboardEvent) {
59
- if (e.key === 'Escape') { hide(); return }
295
+ if (e.key === 'Escape') {
296
+ if (navStack.value.length) popNav()
297
+ else hide()
298
+ return
299
+ }
60
300
  if (!visible.value) return
61
301
  if (e.key === 'ArrowDown') { e.preventDefault(); moveFocus(1) }
62
302
  else if (e.key === 'ArrowUp') { e.preventDefault(); moveFocus(-1) }
@@ -76,6 +316,7 @@ onUnmounted(() => {
76
316
  document.removeEventListener('mousedown', onDocMouseDown)
77
317
  document.removeEventListener('keydown', onKeydown)
78
318
  window.removeEventListener('scroll', onScroll, true)
319
+ cancelActive?.()
79
320
  })
80
321
  </script>
81
322
 
@@ -85,22 +326,55 @@ onUnmounted(() => {
85
326
  </div>
86
327
 
87
328
  <Teleport to="body">
88
- <Transition
89
- enter-active-class="transition-[opacity,transform] duration-100 ease-out"
90
- enter-from-class="opacity-0 scale-95"
91
- enter-to-class="opacity-100 scale-100"
92
- leave-active-class="transition-[opacity,transform] duration-75 ease-in"
93
- leave-from-class="opacity-100 scale-100"
94
- leave-to-class="opacity-0 scale-95"
95
- >
329
+ <Transition :css="false" @enter="panelEnter" @leave="panelLeave">
96
330
  <div
97
331
  v-if="visible"
98
332
  ref="panelEl"
99
- class="fixed z-[500] min-w-48 overflow-hidden rounded-xs bg-surface-container py-1 shadow-elevation-2"
333
+ class="fixed z-[500] min-w-48"
334
+ :class="[
335
+ variant === 'expressive' ? 'rounded-lg' : 'rounded-xs',
336
+ isGrouped ? '' : 'shadow-elevation-2',
337
+ ]"
100
338
  :style="{ left: `${adjustedPos.x}px`, top: `${adjustedPos.y}px`, transformOrigin: 'top left' }"
101
339
  @contextmenu.prevent
102
340
  >
103
- <slot />
341
+ <!-- overflow-hidden (for the rounded-corner clip and to clip the push
342
+ submenu's slide) lives on this inner wrapper, never together with
343
+ shadow-elevation-2 on the same box — overflow-hidden clips an
344
+ element's own box-shadow too, so the two have to be on separate
345
+ elements or the shadow gets cut off -->
346
+ <div
347
+ class="overflow-hidden py-1"
348
+ :class="[
349
+ variant === 'expressive' ? 'rounded-lg' : 'rounded-xs',
350
+ isGrouped ? '' : 'bg-surface-container',
351
+ ]"
352
+ >
353
+ <Transition :css="false" @enter="navSlideEnter" @leave="navSlideLeave">
354
+ <div v-if="currentNav" :key="navStack.length">
355
+ <button
356
+ type="button"
357
+ class="flex w-full items-center gap-3 border-b border-outline-variant px-4 py-2.5 text-left text-body-large text-on-surface outline-none transition-colors hover:bg-on-surface/8 focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-secondary"
358
+ @click="popNav"
359
+ >
360
+ <MIcon name="chevron_left" :size="20" class="shrink-0 text-on-surface-variant" />
361
+ <MIcon v-if="currentNav.icon" :name="currentNav.icon" :size="20" class="shrink-0 text-on-surface-variant" />
362
+ <span class="flex-1 truncate"><component :is="() => currentNav?.header?.()" /></span>
363
+ </button>
364
+ <component :is="() => currentNav?.content?.()" />
365
+ </div>
366
+ <div v-else key="root">
367
+ <div v-if="isGrouped" class="flex flex-col gap-1 px-1.5">
368
+ <div v-for="(group, i) in groups" :key="i" class="rounded-lg shadow-elevation-2">
369
+ <div class="overflow-hidden rounded-lg bg-surface-container">
370
+ <component :is="() => group" />
371
+ </div>
372
+ </div>
373
+ </div>
374
+ <slot v-else />
375
+ </div>
376
+ </Transition>
377
+ </div>
104
378
  </div>
105
379
  </Transition>
106
380
  </Teleport>
@@ -5,7 +5,7 @@ import MIconButton from './MIconButton.vue'
5
5
  import { useFieldBg } from '../composables/useFieldBg'
6
6
  import { useLocale } from '../composables/useLocale'
7
7
 
8
- const props = withDefaults(defineProps<{
8
+ const props = defineProps<{
9
9
  modelValue: string | null
10
10
  label?: string
11
11
  placeholder?: string
@@ -19,12 +19,15 @@ const props = withDefaults(defineProps<{
19
19
  fieldBg?: string
20
20
  prevMonthLabel?: string
21
21
  nextMonthLabel?: string
22
- }>(), {
23
- locale: 'es-ES',
24
- })
22
+ }>()
25
23
 
26
24
  const localeStrings = useLocale()
27
25
 
26
+ // Falls back to the app's own configured locale (via createM3UI/useLocale) rather than a
27
+ // fixed default, matching the pattern MRelativeTime already uses — previously this defaulted
28
+ // to a hardcoded 'es-ES' regardless of what locale the app actually provided.
29
+ const resolvedLocale = computed(() => props.locale ?? localeStrings.lang)
30
+
28
31
  const emit = defineEmits<{ 'update:modelValue': [string | null] }>()
29
32
 
30
33
  const open = ref(false)
@@ -38,16 +41,16 @@ watch(() => props.modelValue, (v) => {
38
41
  if (v) viewDate.value = new Date(v + 'T00:00:00')
39
42
  })
40
43
 
41
- const WEEKDAYS = (() => {
42
- const f = new Intl.DateTimeFormat(props.locale, { weekday: 'narrow' })
44
+ const WEEKDAYS = computed(() => {
45
+ const f = new Intl.DateTimeFormat(resolvedLocale.value, { weekday: 'narrow' })
43
46
  return Array.from({ length: 7 }, (_, i) => {
44
47
  const d = new Date(2024, 0, i + 1) // Mon=1 Jan 2024
45
48
  return f.format(d)
46
49
  })
47
- })()
50
+ })
48
51
 
49
52
  const monthLabel = computed(() => {
50
- const f = new Intl.DateTimeFormat(props.locale, { month: 'long', year: 'numeric' })
53
+ const f = new Intl.DateTimeFormat(resolvedLocale.value, { month: 'long', year: 'numeric' })
51
54
  return f.format(viewDate.value)
52
55
  })
53
56
 
@@ -117,7 +120,7 @@ function clear() {
117
120
  const displayValue = computed(() => {
118
121
  if (!props.modelValue) return ''
119
122
  const d = new Date(props.modelValue + 'T00:00:00')
120
- return new Intl.DateTimeFormat(props.locale, { day: 'numeric', month: 'short', year: 'numeric' }).format(d)
123
+ return new Intl.DateTimeFormat(resolvedLocale.value, { day: 'numeric', month: 'short', year: 'numeric' }).format(d)
121
124
  })
122
125
 
123
126
  function computeDropPos() {
@@ -15,10 +15,15 @@ const props = withDefaults(defineProps<{
15
15
  }>(), {
16
16
  modelValue: null,
17
17
  show: false,
18
- locale: 'es-ES',
19
18
  })
20
19
 
21
20
  const locale = useLocale()
21
+
22
+ // Falls back to the app's own configured locale (via createM3UI/useLocale) rather than a
23
+ // fixed default, matching the pattern MRelativeTime already uses — previously this defaulted
24
+ // to a hardcoded 'es-ES' regardless of what locale the app actually provided.
25
+ const resolvedLocale = computed(() => props.locale ?? locale.lang)
26
+
22
27
  const emit = defineEmits<{
23
28
  'update:modelValue': [string | null]
24
29
  'update:show': [boolean]
@@ -45,12 +50,12 @@ watch(() => props.show, (open) => {
45
50
 
46
51
  // ── Calendar logic ─────────────────────────────────────────────────
47
52
  const WEEKDAYS = computed(() => {
48
- const f = new Intl.DateTimeFormat(props.locale, { weekday: 'narrow' })
53
+ const f = new Intl.DateTimeFormat(resolvedLocale.value, { weekday: 'narrow' })
49
54
  return Array.from({ length: 7 }, (_, i) => f.format(new Date(2024, 0, i + 1)))
50
55
  })
51
56
 
52
57
  const monthLabel = computed(() =>
53
- new Intl.DateTimeFormat(props.locale, { month: 'long', year: 'numeric' }).format(viewDate.value),
58
+ new Intl.DateTimeFormat(resolvedLocale.value, { month: 'long', year: 'numeric' }).format(viewDate.value),
54
59
  )
55
60
 
56
61
  const calendarDays = computed(() => {
@@ -112,7 +117,7 @@ function selectDay(day: typeof calendarDays.value[0]) {
112
117
  const headerDate = computed(() => {
113
118
  if (!selected.value) return '—'
114
119
  const d = new Date(selected.value + 'T00:00:00')
115
- return new Intl.DateTimeFormat(props.locale, { weekday: 'short', month: 'short', day: 'numeric' }).format(d)
120
+ return new Intl.DateTimeFormat(resolvedLocale.value, { weekday: 'short', month: 'short', day: 'numeric' }).format(d)
116
121
  })
117
122
 
118
123
  // ── Input mode ─────────────────────────────────────────────────────
@@ -10,7 +10,7 @@ export interface DateRange {
10
10
  end: string | null
11
11
  }
12
12
 
13
- const props = withDefaults(defineProps<{
13
+ const props = defineProps<{
14
14
  modelValue: DateRange
15
15
  label?: string
16
16
  placeholder?: string
@@ -26,12 +26,15 @@ const props = withDefaults(defineProps<{
26
26
  nextMonthLabel?: string
27
27
  pickStartText?: string
28
28
  pickEndText?: string
29
- }>(), {
30
- locale: 'es-ES',
31
- })
29
+ }>()
32
30
 
33
31
  const localeStrings = useLocale()
34
32
 
33
+ // Falls back to the app's own configured locale (via createM3UI/useLocale) rather than a
34
+ // fixed default, matching the pattern MRelativeTime already uses — previously this defaulted
35
+ // to a hardcoded 'es-ES' regardless of what locale the app actually provided.
36
+ const resolvedLocale = computed(() => props.locale ?? localeStrings.lang)
37
+
35
38
  const emit = defineEmits<{ 'update:modelValue': [DateRange] }>()
36
39
 
37
40
  const open = ref(false)
@@ -49,13 +52,13 @@ watch(() => props.modelValue.start, (v) => {
49
52
  if (v) viewDate.value = new Date(v + 'T00:00:00')
50
53
  })
51
54
 
52
- const WEEKDAYS = (() => {
53
- const f = new Intl.DateTimeFormat(props.locale, { weekday: 'narrow' })
55
+ const WEEKDAYS = computed(() => {
56
+ const f = new Intl.DateTimeFormat(resolvedLocale.value, { weekday: 'narrow' })
54
57
  return Array.from({ length: 7 }, (_, i) => f.format(new Date(2024, 0, i + 1)))
55
- })()
58
+ })
56
59
 
57
60
  const monthLabel = computed(() =>
58
- new Intl.DateTimeFormat(props.locale, { month: 'long', year: 'numeric' }).format(viewDate.value)
61
+ new Intl.DateTimeFormat(resolvedLocale.value, { month: 'long', year: 'numeric' }).format(viewDate.value)
59
62
  )
60
63
 
61
64
  const calendarDays = computed(() => {
@@ -125,7 +128,7 @@ function prevMonth() { const d = new Date(viewDate.value); d.setMonth(d.getMonth
125
128
  function nextMonth() { const d = new Date(viewDate.value); d.setMonth(d.getMonth() + 1); viewDate.value = d }
126
129
 
127
130
  const displayValue = computed(() => {
128
- const f = new Intl.DateTimeFormat(props.locale, { day: 'numeric', month: 'short' })
131
+ const f = new Intl.DateTimeFormat(resolvedLocale.value, { day: 'numeric', month: 'short' })
129
132
  const s = props.modelValue.start ? f.format(new Date(props.modelValue.start + 'T00:00:00')) : '—'
130
133
  const e = props.modelValue.end ? f.format(new Date(props.modelValue.end + 'T00:00:00')) : '—'
131
134
  if (!props.modelValue.start && !props.modelValue.end) return ''
@@ -18,10 +18,15 @@ const props = withDefaults(defineProps<{
18
18
  title?: string
19
19
  }>(), {
20
20
  show: false,
21
- locale: 'es-ES',
22
21
  })
23
22
 
24
23
  const locale = useLocale()
24
+
25
+ // Falls back to the app's own configured locale (via createM3UI/useLocale) rather than a
26
+ // fixed default, matching the pattern MRelativeTime already uses — previously this defaulted
27
+ // to a hardcoded 'es-ES' regardless of what locale the app actually provided.
28
+ const resolvedLocale = computed(() => props.locale ?? locale.lang)
29
+
25
30
  const emit = defineEmits<{
26
31
  'update:modelValue': [DateRange]
27
32
  'update:show': [boolean]
@@ -51,12 +56,12 @@ watch(() => props.show, (open) => {
51
56
 
52
57
  // ── Calendar logic ─────────────────────────────────────────────────
53
58
  const WEEKDAYS = computed(() => {
54
- const f = new Intl.DateTimeFormat(props.locale, { weekday: 'narrow' })
59
+ const f = new Intl.DateTimeFormat(resolvedLocale.value, { weekday: 'narrow' })
55
60
  return Array.from({ length: 7 }, (_, i) => f.format(new Date(2024, 0, i + 1)))
56
61
  })
57
62
 
58
63
  const monthLabel = computed(() =>
59
- new Intl.DateTimeFormat(props.locale, { month: 'long', year: 'numeric' }).format(viewDate.value),
64
+ new Intl.DateTimeFormat(resolvedLocale.value, { month: 'long', year: 'numeric' }).format(viewDate.value),
60
65
  )
61
66
 
62
67
  const calendarDays = computed(() => {
@@ -138,7 +143,7 @@ function isInRange(iso: string) {
138
143
  const fmtDisplay = (iso: string | null) => {
139
144
  if (!iso) return '—'
140
145
  const d = new Date(iso + 'T00:00:00')
141
- return new Intl.DateTimeFormat(props.locale, { month: 'short', day: 'numeric' }).format(d)
146
+ return new Intl.DateTimeFormat(resolvedLocale.value, { month: 'short', day: 'numeric' }).format(d)
142
147
  }
143
148
 
144
149
  // ── Actions ────────────────────────────────────────────────────────
@@ -2,6 +2,7 @@
2
2
  import { ref } from 'vue'
3
3
  import MIcon from './MIcon.vue'
4
4
  import MIconButton from './MIconButton.vue'
5
+ import { useLocale } from '../composables/useLocale'
5
6
 
6
7
  export interface KanbanCard {
7
8
  id: string | number
@@ -17,8 +18,11 @@ export interface KanbanColumn {
17
18
 
18
19
  const props = defineProps<{
19
20
  modelValue: KanbanColumn[]
21
+ emptyText?: string
20
22
  }>()
21
23
 
24
+ const locale = useLocale()
25
+
22
26
  const emit = defineEmits<{
23
27
  'update:modelValue': [KanbanColumn[]]
24
28
  cardMove: [{ cardId: string | number; fromColumn: string | number; toColumn: string | number; toIndex: number }]
@@ -139,7 +143,7 @@ function reset() {
139
143
  v-if="column.cards.length === 0"
140
144
  class="flex flex-1 items-center justify-center rounded-lg border border-dashed border-outline-variant/50 p-4"
141
145
  >
142
- <p class="text-body-small text-on-surface-variant/60">Sin tarjetas</p>
146
+ <p class="text-body-small text-on-surface-variant/60">{{ emptyText ?? locale.noItems }}</p>
143
147
  </div>
144
148
  </div>
145
149
  </div>