@m3ui-vue/m3ui-vue 0.7.1 → 0.8.1
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 +14 -6
- package/dist/{MMenuItem-xQ1x6-DH.js → MMenuItem-CDWfeU4F.js} +331 -252
- package/dist/MMenuItem-CDWfeU4F.js.map +1 -0
- package/dist/code-editor.d.ts +1 -0
- package/dist/code-editor.js +22 -7
- package/dist/code-editor.js.map +1 -1
- package/dist/components/MButton.vue.d.ts +7 -0
- package/dist/components/MCalendar.vue.d.ts +0 -1
- package/dist/components/MCard.vue.d.ts +2 -0
- package/dist/components/MCarousel.vue.d.ts +12 -14
- package/dist/components/MChatBubble.vue.d.ts +0 -1
- package/dist/components/MCircleProgressBar.vue.d.ts +0 -1
- package/dist/components/MCodeEditor.vue.d.ts +1 -1
- package/dist/components/MConfirmDialog.vue.d.ts +3 -0
- package/dist/components/MDatePicker.vue.d.ts +1 -3
- package/dist/components/MDatePickerModal.vue.d.ts +0 -1
- package/dist/components/MDateRangePicker.vue.d.ts +1 -3
- package/dist/components/MDateRangePickerModal.vue.d.ts +0 -1
- package/dist/components/MDialog.vue.d.ts +23 -7
- package/dist/components/MFab.vue.d.ts +2 -2
- package/dist/components/MKanban.vue.d.ts +1 -0
- package/dist/components/MListItem.vue.d.ts +11 -6
- package/dist/components/MNavigationRail.vue.d.ts +17 -1
- package/dist/components/MScheduler.vue.d.ts +0 -1
- package/dist/components/MSelect.vue.d.ts +1 -0
- package/dist/components/MShape.vue.d.ts +51 -0
- package/dist/components/MShortNavigationBar.vue.d.ts +34 -0
- package/dist/components/MSimpleCarousel.vue.d.ts +45 -0
- package/dist/components/MSwitch.vue.d.ts +8 -0
- package/dist/components/MTabs.vue.d.ts +3 -0
- package/dist/components/MToggleButton.vue.d.ts +29 -0
- package/dist/components/MTree.vue.d.ts +0 -1
- package/dist/components/MTreeTable.vue.d.ts +1 -0
- package/dist/index.d.ts +9 -1
- package/dist/m3ui-vue.css +1 -1
- package/dist/m3ui.js +4387 -2525
- package/dist/m3ui.js.map +1 -1
- package/dist/rich-text-editor.js +1 -1
- package/dist/styles/palettes.css +659 -0
- package/dist/styles/theme.css +1 -0
- package/dist/styles.css +1 -1
- package/package.json +16 -1
- package/src/__tests__/MCarousel.test.ts +33 -0
- package/src/__tests__/MShape.test.ts +36 -0
- package/src/__tests__/MToggleButton.test.ts +27 -0
- package/src/__tests__/useColorPalette.test.ts +2 -2
- package/src/code-editor.ts +1 -0
- package/src/components/MAutocomplete.vue +40 -27
- package/src/components/MBadge.vue +1 -1
- package/src/components/MBottomSheet.vue +4 -4
- package/src/components/MButton.vue +51 -21
- package/src/components/MButtonGroup.vue +2 -2
- package/src/components/MCalendar.vue +9 -5
- package/src/components/MCard.vue +76 -11
- package/src/components/MCarousel.vue +123 -173
- package/src/components/MChatBubble.vue +0 -1
- package/src/components/MCheckbox.vue +58 -13
- package/src/components/MChip.vue +26 -6
- package/src/components/MCircleProgressBar.vue +7 -4
- package/src/components/MCodeEditor.vue +60 -9
- package/src/components/MColorPicker.vue +9 -8
- package/src/components/MColorPickerModal.vue +2 -2
- package/src/components/MCommandPalette.vue +1 -1
- package/src/components/MConfirmDialog.vue +4 -0
- package/src/components/MContextMenu.vue +27 -6
- package/src/components/MDatePicker.vue +23 -20
- package/src/components/MDatePickerModal.vue +14 -9
- package/src/components/MDateRangePicker.vue +24 -21
- package/src/components/MDateRangePickerModal.vue +12 -7
- package/src/components/MDialog.vue +103 -12
- package/src/components/MFab.vue +10 -7
- package/src/components/MFabMenu.vue +1 -1
- package/src/components/MIconButton.vue +41 -19
- package/src/components/MKanban.vue +5 -1
- package/src/components/MListItem.vue +35 -17
- package/src/components/MLoadingIndicator.vue +14 -7
- package/src/components/MMaskField.vue +14 -6
- package/src/components/MMenu.vue +32 -7
- package/src/components/MMenuItem.vue +2 -2
- package/src/components/MMultiAutocomplete.vue +46 -27
- package/src/components/MMultiSelect.vue +45 -23
- package/src/components/MNavigationBar.vue +5 -10
- package/src/components/MNavigationDrawer.vue +10 -9
- package/src/components/MNavigationRail.vue +335 -22
- package/src/components/MNumberField.vue +14 -6
- package/src/components/MOverlay.vue +1 -1
- package/src/components/MPinInput.vue +7 -4
- package/src/components/MProgressBar.vue +16 -10
- package/src/components/MRadio.vue +54 -12
- package/src/components/MScheduler.vue +10 -6
- package/src/components/MSearchBar.vue +8 -3
- package/src/components/MSegmentedButton.vue +14 -9
- package/src/components/MSelect.vue +49 -33
- package/src/components/MShape.vue +107 -0
- package/src/components/MShortNavigationBar.vue +113 -0
- package/src/components/MSideSheet.vue +1 -1
- package/src/components/MSimpleCarousel.vue +325 -0
- package/src/components/MSnackbar.vue +4 -4
- package/src/components/MSplitButton.vue +32 -17
- package/src/components/MSpotlightSearch.vue +1 -1
- package/src/components/MSwitch.vue +96 -18
- package/src/components/MTabs.vue +16 -12
- package/src/components/MTagInput.vue +33 -22
- package/src/components/MTextField.vue +14 -6
- package/src/components/MTimePicker.vue +9 -9
- package/src/components/MTimePickerModal.vue +16 -16
- package/src/components/MToggleButton.vue +188 -0
- package/src/components/MToolbar.vue +5 -3
- package/src/components/MTooltip.vue +4 -4
- package/src/components/MTopAppBar.vue +19 -7
- package/src/components/MTour.vue +1 -1
- package/src/components/MTree.vue +4 -2
- package/src/components/MTreeTable.vue +5 -1
- package/src/composables/useColorPalette.ts +10 -0
- package/src/index.ts +9 -1
- package/src/styles/palettes.css +659 -0
- package/src/styles/theme.css +1 -0
- package/dist/MMenuItem-xQ1x6-DH.js.map +0 -1
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { ref, watch, onMounted, onBeforeUnmount, computed } from 'vue'
|
|
3
3
|
import MIcon from './MIcon.vue'
|
|
4
4
|
|
|
5
|
-
type Language = 'javascript' | 'typescript' | 'json' | 'html' | 'css' | 'python' | 'vue' | 'plain'
|
|
5
|
+
type Language = 'javascript' | 'typescript' | 'json' | 'html' | 'css' | 'python' | 'vue' | 'c' | 'cpp' | 'rust' | 'asm' | 'plain'
|
|
6
6
|
|
|
7
7
|
const props = withDefaults(
|
|
8
8
|
defineProps<{
|
|
@@ -49,6 +49,10 @@ const langLabel = computed(() => {
|
|
|
49
49
|
css: 'CSS',
|
|
50
50
|
python: 'Python',
|
|
51
51
|
vue: 'Vue',
|
|
52
|
+
c: 'C',
|
|
53
|
+
cpp: 'C++',
|
|
54
|
+
rust: 'Rust',
|
|
55
|
+
asm: 'Assembly',
|
|
52
56
|
plain: 'Texto',
|
|
53
57
|
}
|
|
54
58
|
return labels[props.language]
|
|
@@ -57,7 +61,7 @@ const langLabel = computed(() => {
|
|
|
57
61
|
async function loadModules() {
|
|
58
62
|
if (cmModules) return cmModules
|
|
59
63
|
|
|
60
|
-
const [viewMod, stateMod, commandsMod, languageMod, highlightMod, oneDarkMod, jsMod, jsonMod, htmlMod, cssMod, pyMod, vueMod] = await Promise.all([
|
|
64
|
+
const [viewMod, stateMod, commandsMod, languageMod, highlightMod, oneDarkMod, jsMod, jsonMod, htmlMod, cssMod, pyMod, vueMod, cppMod, rustMod, asmMod] = await Promise.all([
|
|
61
65
|
import('@codemirror/view'),
|
|
62
66
|
import('@codemirror/state'),
|
|
63
67
|
import('@codemirror/commands'),
|
|
@@ -70,9 +74,12 @@ async function loadModules() {
|
|
|
70
74
|
import('@codemirror/lang-css'),
|
|
71
75
|
import('@codemirror/lang-python'),
|
|
72
76
|
import('@codemirror/lang-vue'),
|
|
77
|
+
import('@codemirror/lang-cpp'),
|
|
78
|
+
import('@codemirror/lang-rust'),
|
|
79
|
+
import('@codemirror/legacy-modes/mode/gas'),
|
|
73
80
|
])
|
|
74
81
|
|
|
75
|
-
cmModules = { viewMod, stateMod, commandsMod, languageMod, highlightMod, oneDarkMod, jsMod, jsonMod, htmlMod, cssMod, pyMod, vueMod }
|
|
82
|
+
cmModules = { viewMod, stateMod, commandsMod, languageMod, highlightMod, oneDarkMod, jsMod, jsonMod, htmlMod, cssMod, pyMod, vueMod, cppMod, rustMod, asmMod }
|
|
76
83
|
return cmModules
|
|
77
84
|
}
|
|
78
85
|
|
|
@@ -131,6 +138,9 @@ function getLangExtension(mods: any) {
|
|
|
131
138
|
case 'css': return mods.cssMod.css()
|
|
132
139
|
case 'python': return mods.pyMod.python()
|
|
133
140
|
case 'vue': return mods.vueMod.vue()
|
|
141
|
+
case 'c': case 'cpp': return mods.cppMod.cpp()
|
|
142
|
+
case 'rust': return mods.rustMod.rust()
|
|
143
|
+
case 'asm': return mods.languageMod.StreamLanguage.define(mods.asmMod.gas)
|
|
134
144
|
default: return []
|
|
135
145
|
}
|
|
136
146
|
}
|
|
@@ -161,6 +171,7 @@ function buildExtensions(mods: any) {
|
|
|
161
171
|
if (props.wrap) exts.push(viewMod.EditorView.lineWrapping)
|
|
162
172
|
if (props.lineNumbers) exts.push(viewMod.lineNumbers())
|
|
163
173
|
if (props.theme === 'dark') exts.push(oneDarkMod.oneDark)
|
|
174
|
+
if (props.placeholder) exts.push(viewMod.placeholder(props.placeholder))
|
|
164
175
|
|
|
165
176
|
return exts
|
|
166
177
|
}
|
|
@@ -189,13 +200,13 @@ watch(() => props.modelValue, (val) => {
|
|
|
189
200
|
}
|
|
190
201
|
})
|
|
191
202
|
|
|
192
|
-
watch([() => props.language, () => props.theme, () => props.readonly, () => props.lineNumbers, () => props.wrap], createEditor)
|
|
203
|
+
watch([() => props.language, () => props.theme, () => props.readonly, () => props.lineNumbers, () => props.wrap, () => props.placeholder], createEditor)
|
|
193
204
|
|
|
194
205
|
onBeforeUnmount(() => view?.destroy())
|
|
195
206
|
</script>
|
|
196
207
|
|
|
197
208
|
<template>
|
|
198
|
-
<div class="overflow-hidden rounded-lg border border-outline-variant">
|
|
209
|
+
<div class="flex flex-col overflow-hidden rounded-lg border border-outline-variant">
|
|
199
210
|
<!-- Header bar -->
|
|
200
211
|
<div class="flex items-center justify-between border-b border-outline-variant bg-surface-container px-4 py-2">
|
|
201
212
|
<span class="text-label-medium text-on-surface-variant">{{ langLabel }}</span>
|
|
@@ -223,9 +234,27 @@ onBeforeUnmount(() => view?.destroy())
|
|
|
223
234
|
</template>
|
|
224
235
|
|
|
225
236
|
<style scoped>
|
|
237
|
+
.code-editor-container {
|
|
238
|
+
/* .cm-editor/.cm-scroller/.cm-gutters all use height:100%, which only ever
|
|
239
|
+
resolves against a genuinely definite ancestor height — a min-height (what
|
|
240
|
+
this container has, so it can grow with content up to maxHeight) doesn't
|
|
241
|
+
count as definite for that percentage chain, so .cm-gutters silently fell
|
|
242
|
+
back to sizing off its own content instead of the real editor height.
|
|
243
|
+
Making this a flex column and letting .cm-editor grow via flex instead of
|
|
244
|
+
a % height gives the whole chain a real definite size to resolve against. */
|
|
245
|
+
display: flex;
|
|
246
|
+
flex-direction: column;
|
|
247
|
+
/* Also grow to fill the outer wrapper (see the root element's own flex-col
|
|
248
|
+
above) rather than just sitting at minHeight, whenever a consumer stretches
|
|
249
|
+
the whole component taller than that — e.g. `class="h-full"` in a grid
|
|
250
|
+
cell next to taller content. Still hard-capped by maxHeight either way. */
|
|
251
|
+
flex: 1 1 auto;
|
|
252
|
+
min-height: 0;
|
|
253
|
+
}
|
|
254
|
+
|
|
226
255
|
.code-editor-container :deep(.cm-editor) {
|
|
227
|
-
|
|
228
|
-
min-height:
|
|
256
|
+
flex: 1;
|
|
257
|
+
min-height: 0;
|
|
229
258
|
font-family: 'Roboto Mono', 'Fira Code', 'Consolas', monospace;
|
|
230
259
|
font-size: 0.8125rem;
|
|
231
260
|
line-height: 1.6;
|
|
@@ -236,7 +265,18 @@ onBeforeUnmount(() => view?.destroy())
|
|
|
236
265
|
}
|
|
237
266
|
|
|
238
267
|
.code-editor-container :deep(.cm-scroller) {
|
|
239
|
-
|
|
268
|
+
/* .cm-scroller normally sizes itself off a height:100% against .cm-editor,
|
|
269
|
+
but that's a percentage-height-in-nested-flex-column case that browsers
|
|
270
|
+
don't reliably resolve — grow it directly instead so it has a real,
|
|
271
|
+
laid-out height for .cm-gutters to stretch against below. */
|
|
272
|
+
flex: 1 !important;
|
|
273
|
+
min-height: 0;
|
|
274
|
+
/* .cm-scroller lays out .cm-gutters/.cm-content in a row (gutter | content),
|
|
275
|
+
so .cm-gutters' height comes from cross-axis stretch, not flex-grow —
|
|
276
|
+
CodeMirror's own base theme sets align-items: flex-start !important here,
|
|
277
|
+
which is exactly what stops the gutter from stretching to full height in
|
|
278
|
+
the first place. */
|
|
279
|
+
align-items: stretch !important;
|
|
240
280
|
}
|
|
241
281
|
|
|
242
282
|
.code-editor-container :deep(.cm-content) {
|
|
@@ -253,6 +293,12 @@ onBeforeUnmount(() => view?.destroy())
|
|
|
253
293
|
color: var(--color-outline);
|
|
254
294
|
font-size: 0.75rem;
|
|
255
295
|
padding: 0 4px;
|
|
296
|
+
/* .cm-gutters ships with an explicit height:100% rather than auto, so the
|
|
297
|
+
align-items:stretch above (on .cm-scroller) never actually kicks in —
|
|
298
|
+
stretch only applies to items whose cross-size computes to auto. Forcing
|
|
299
|
+
height back to auto here is what makes that stretch take effect. */
|
|
300
|
+
height: auto !important;
|
|
301
|
+
align-self: stretch !important;
|
|
256
302
|
}
|
|
257
303
|
|
|
258
304
|
.code-editor-container :deep(.cm-activeLineGutter) {
|
|
@@ -261,7 +307,12 @@ onBeforeUnmount(() => view?.destroy())
|
|
|
261
307
|
}
|
|
262
308
|
|
|
263
309
|
.code-editor-container :deep(.cm-activeLine) {
|
|
264
|
-
|
|
310
|
+
/* CodeMirror renders the selection highlight on a layer with z-index: -1
|
|
311
|
+
(@codemirror/view's selectionLayer has `above: false` by design, so it always
|
|
312
|
+
sits behind the line content). An opaque active-line background would paint
|
|
313
|
+
straight over it and hide the selection on the current line — this needs to
|
|
314
|
+
stay a translucent tint so a selection underneath still shows through. */
|
|
315
|
+
background: color-mix(in srgb, var(--color-on-surface) 5%, transparent);
|
|
265
316
|
}
|
|
266
317
|
|
|
267
318
|
.code-editor-container :deep(.cm-selectionBackground) {
|
|
@@ -172,26 +172,27 @@ onUnmounted(() => {
|
|
|
172
172
|
<div ref="triggerEl" class="relative mt-2" :style="{ '--field-bg': resolvedFieldBg }">
|
|
173
173
|
<button
|
|
174
174
|
type="button"
|
|
175
|
-
class="flex h-14 w-full items-center gap-3 rounded-
|
|
175
|
+
class="flex h-14 w-full items-center gap-3 rounded-xs border bg-transparent px-4 text-left text-body-large transition-[border-color,border-width] duration-150"
|
|
176
176
|
:class="[
|
|
177
|
-
disabled ? 'pointer-events-none
|
|
178
|
-
open
|
|
177
|
+
disabled ? 'pointer-events-none cursor-not-allowed border-on-surface/12' : 'cursor-pointer',
|
|
178
|
+
!disabled && (open
|
|
179
179
|
? error ? 'border-2 border-error' : 'border-2 border-primary'
|
|
180
|
-
: error ? 'border-error' : 'border-outline hover:border-on-surface',
|
|
180
|
+
: error ? 'border-error' : 'border-outline hover:border-on-surface'),
|
|
181
181
|
]"
|
|
182
182
|
@click="!disabled && (open = !open)"
|
|
183
183
|
>
|
|
184
184
|
<span
|
|
185
185
|
class="h-6 w-6 shrink-0 rounded-full border border-outline-variant"
|
|
186
|
+
:class="disabled ? 'opacity-38' : ''"
|
|
186
187
|
:style="{ backgroundColor: modelValue }"
|
|
187
188
|
/>
|
|
188
|
-
<span class="flex-1 font-mono text-on-surface">{{ modelValue }}</span>
|
|
189
|
-
<MIcon name="palette" :size="
|
|
189
|
+
<span class="flex-1 font-mono" :class="disabled ? 'text-on-surface/38' : 'text-on-surface'">{{ modelValue }}</span>
|
|
190
|
+
<MIcon name="palette" :size="24" class="shrink-0" :class="disabled ? 'text-on-surface/38' : 'text-on-surface-variant'" />
|
|
190
191
|
</button>
|
|
191
192
|
<label
|
|
192
193
|
v-if="label"
|
|
193
194
|
class="pointer-events-none absolute -top-2.5 left-3 bg-(--field-bg) px-1 text-label-small transition-colors"
|
|
194
|
-
:class="open ? (error ? 'text-error' : 'text-primary') : error ? 'text-error' : 'text-on-surface-variant'"
|
|
195
|
+
:class="disabled ? 'text-on-surface/38' : open ? (error ? 'text-error' : 'text-primary') : error ? 'text-error' : 'text-on-surface-variant'"
|
|
195
196
|
>
|
|
196
197
|
{{ label }}
|
|
197
198
|
</label>
|
|
@@ -254,7 +255,7 @@ onUnmounted(() => {
|
|
|
254
255
|
type="text"
|
|
255
256
|
:value="modelValue"
|
|
256
257
|
maxlength="7"
|
|
257
|
-
class="flex-1 rounded-
|
|
258
|
+
class="flex-1 rounded-xs border border-outline bg-transparent px-3 py-2 font-mono text-body-medium text-on-surface outline-none caret-primary transition-colors focus:border-primary"
|
|
258
259
|
@input="onHexInput"
|
|
259
260
|
/>
|
|
260
261
|
</div>
|
|
@@ -150,7 +150,7 @@ function onKeydown(e: KeyboardEvent) { if (e.key === 'Escape') cancel() }
|
|
|
150
150
|
<Transition name="m3-cp-modal">
|
|
151
151
|
<div
|
|
152
152
|
v-if="show"
|
|
153
|
-
class="fixed inset-0 z-50 flex items-center justify-center bg-scrim/
|
|
153
|
+
class="fixed inset-0 z-50 flex items-center justify-center bg-scrim/32 p-4"
|
|
154
154
|
@click.self="cancel"
|
|
155
155
|
>
|
|
156
156
|
<div class="cp-box w-[328px] rounded-[28px] bg-surface-container-high px-6 pt-6 pb-4 shadow-elevation-3">
|
|
@@ -205,7 +205,7 @@ function onKeydown(e: KeyboardEvent) { if (e.key === 'Escape') cancel() }
|
|
|
205
205
|
type="text"
|
|
206
206
|
:value="hexInput"
|
|
207
207
|
maxlength="7"
|
|
208
|
-
class="w-full rounded-
|
|
208
|
+
class="w-full rounded-xs border border-outline bg-transparent px-3 py-2 font-mono text-body-medium text-on-surface caret-primary outline-none transition-colors focus:border-primary"
|
|
209
209
|
@input="onHexFieldInput"
|
|
210
210
|
/>
|
|
211
211
|
</div>
|
|
@@ -129,7 +129,7 @@ onBeforeUnmount(() => document.removeEventListener('keydown', onGlobalKeydown))
|
|
|
129
129
|
<Transition name="m3-cmd">
|
|
130
130
|
<div
|
|
131
131
|
v-if="modelValue"
|
|
132
|
-
class="fixed inset-0 z-50 flex items-start justify-center bg-scrim/
|
|
132
|
+
class="fixed inset-0 z-50 flex items-start justify-center bg-scrim/32 pt-[15vh]"
|
|
133
133
|
@click.self="close"
|
|
134
134
|
>
|
|
135
135
|
<div class="cmd-box flex w-full max-w-lg flex-col overflow-hidden rounded-xl bg-surface-container-high shadow-elevation-3">
|
|
@@ -12,10 +12,13 @@ const props = withDefaults(
|
|
|
12
12
|
cancelLabel?: string
|
|
13
13
|
danger?: boolean
|
|
14
14
|
loading?: boolean
|
|
15
|
+
/** Passed straight through to MDialog's `closable` — show/hide the header close (X) button. */
|
|
16
|
+
closable?: boolean
|
|
15
17
|
}>(),
|
|
16
18
|
{
|
|
17
19
|
danger: false,
|
|
18
20
|
loading: false,
|
|
21
|
+
closable: true,
|
|
19
22
|
},
|
|
20
23
|
)
|
|
21
24
|
|
|
@@ -29,6 +32,7 @@ const emit = defineEmits<{ 'update:modelValue': [boolean]; confirm: [] }>()
|
|
|
29
32
|
:model-value="modelValue"
|
|
30
33
|
:title="title"
|
|
31
34
|
max-width="max-w-sm"
|
|
35
|
+
:closable="closable"
|
|
32
36
|
@update:model-value="emit('update:modelValue', $event)"
|
|
33
37
|
>
|
|
34
38
|
<p class="text-body-medium text-on-surface-variant">{{ message }}</p>
|
|
@@ -15,6 +15,24 @@ async function showAt(x: number, y: number) {
|
|
|
15
15
|
x: Math.min(x, window.innerWidth - el.offsetWidth - 8),
|
|
16
16
|
y: Math.min(y, window.innerHeight - el.offsetHeight - 8),
|
|
17
17
|
}
|
|
18
|
+
focusableItems()[0]?.focus()
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function focusableItems() {
|
|
22
|
+
if (!panelEl.value) return []
|
|
23
|
+
return Array.from(
|
|
24
|
+
panelEl.value.querySelectorAll<HTMLElement>('button:not(:disabled), a[href]'),
|
|
25
|
+
)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function moveFocus(dir: 1 | -1) {
|
|
29
|
+
const items = focusableItems()
|
|
30
|
+
if (!items.length) return
|
|
31
|
+
const idx = items.indexOf(document.activeElement as HTMLElement)
|
|
32
|
+
const next = idx === -1
|
|
33
|
+
? (dir === 1 ? items[0] : items[items.length - 1])
|
|
34
|
+
: items[(idx + dir + items.length) % items.length]
|
|
35
|
+
next?.focus()
|
|
18
36
|
}
|
|
19
37
|
|
|
20
38
|
function show(e: MouseEvent) {
|
|
@@ -38,7 +56,10 @@ function onDocMouseDown(e: MouseEvent) {
|
|
|
38
56
|
}
|
|
39
57
|
|
|
40
58
|
function onKeydown(e: KeyboardEvent) {
|
|
41
|
-
if (e.key === 'Escape') hide()
|
|
59
|
+
if (e.key === 'Escape') { hide(); return }
|
|
60
|
+
if (!visible.value) return
|
|
61
|
+
if (e.key === 'ArrowDown') { e.preventDefault(); moveFocus(1) }
|
|
62
|
+
else if (e.key === 'ArrowUp') { e.preventDefault(); moveFocus(-1) }
|
|
42
63
|
}
|
|
43
64
|
|
|
44
65
|
function onScroll() {
|
|
@@ -65,17 +86,17 @@ onUnmounted(() => {
|
|
|
65
86
|
|
|
66
87
|
<Teleport to="body">
|
|
67
88
|
<Transition
|
|
68
|
-
enter-active-class="transition-[opacity,transform] duration-
|
|
69
|
-
enter-from-class="opacity-0 scale-
|
|
89
|
+
enter-active-class="transition-[opacity,transform] duration-150 ease-[cubic-bezier(0.05,0.7,0.1,1)]"
|
|
90
|
+
enter-from-class="opacity-0 scale-[0.8]"
|
|
70
91
|
enter-to-class="opacity-100 scale-100"
|
|
71
|
-
leave-active-class="transition-[opacity,transform] duration-
|
|
92
|
+
leave-active-class="transition-[opacity,transform] duration-150 ease-[cubic-bezier(0.3,0,0.8,0.15)]"
|
|
72
93
|
leave-from-class="opacity-100 scale-100"
|
|
73
|
-
leave-to-class="opacity-0 scale-
|
|
94
|
+
leave-to-class="opacity-0 scale-[0.8]"
|
|
74
95
|
>
|
|
75
96
|
<div
|
|
76
97
|
v-if="visible"
|
|
77
98
|
ref="panelEl"
|
|
78
|
-
class="fixed z-[500] min-w-48 overflow-hidden rounded-
|
|
99
|
+
class="fixed z-[500] min-w-48 overflow-hidden rounded-xs bg-surface-container py-1 shadow-elevation-2"
|
|
79
100
|
:style="{ left: `${adjustedPos.x}px`, top: `${adjustedPos.y}px`, transformOrigin: 'top left' }"
|
|
80
101
|
@contextmenu.prevent
|
|
81
102
|
>
|
|
@@ -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 =
|
|
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(
|
|
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(
|
|
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(
|
|
123
|
+
return new Intl.DateTimeFormat(resolvedLocale.value, { day: 'numeric', month: 'short', year: 'numeric' }).format(d)
|
|
121
124
|
})
|
|
122
125
|
|
|
123
126
|
function computeDropPos() {
|
|
@@ -167,18 +170,18 @@ onUnmounted(() => {
|
|
|
167
170
|
<div ref="triggerEl" class="relative mt-2" :style="{ '--field-bg': resolvedFieldBg }">
|
|
168
171
|
<button
|
|
169
172
|
type="button"
|
|
170
|
-
class="flex h-14 w-full items-center gap-2 rounded-
|
|
173
|
+
class="flex h-14 w-full items-center gap-2 rounded-xs border bg-transparent px-4 text-left text-body-large transition-[border-color,border-width] duration-150"
|
|
171
174
|
:class="[
|
|
172
|
-
disabled ? 'pointer-events-none
|
|
173
|
-
open
|
|
175
|
+
disabled ? 'pointer-events-none cursor-not-allowed border-on-surface/12' : 'cursor-pointer',
|
|
176
|
+
!disabled && (open
|
|
174
177
|
? error ? 'border-2 border-error' : 'border-2 border-primary'
|
|
175
|
-
: error ? 'border-error' : 'border-outline hover:border-on-surface',
|
|
178
|
+
: error ? 'border-error' : 'border-outline hover:border-on-surface'),
|
|
176
179
|
]"
|
|
177
180
|
@click="!disabled && (open = !open)"
|
|
178
181
|
>
|
|
179
|
-
<MIcon name="calendar_today" :size="
|
|
180
|
-
<span v-if="displayValue" class="flex-1 text-on-surface">{{ displayValue }}</span>
|
|
181
|
-
<span v-else class="flex-1 text-on-surface-variant">{{ placeholder || label || localeStrings.selectDate }}</span>
|
|
182
|
+
<MIcon name="calendar_today" :size="24" class="shrink-0" :class="disabled ? 'text-on-surface/38' : 'text-on-surface-variant'" />
|
|
183
|
+
<span v-if="displayValue" class="flex-1" :class="disabled ? 'text-on-surface/38' : 'text-on-surface'">{{ displayValue }}</span>
|
|
184
|
+
<span v-else class="flex-1" :class="disabled ? 'text-on-surface/38' : 'text-on-surface-variant'">{{ placeholder || label || localeStrings.selectDate }}</span>
|
|
182
185
|
<MIcon
|
|
183
186
|
v-if="modelValue"
|
|
184
187
|
name="close"
|
|
@@ -190,7 +193,7 @@ onUnmounted(() => {
|
|
|
190
193
|
<label
|
|
191
194
|
v-if="label"
|
|
192
195
|
class="pointer-events-none absolute -top-2.5 left-3 bg-(--field-bg) px-1 text-label-small transition-colors"
|
|
193
|
-
:class="open ? (error ? 'text-error' : 'text-primary') : error ? 'text-error' : 'text-on-surface-variant'"
|
|
196
|
+
:class="disabled ? 'text-on-surface/38' : open ? (error ? 'text-error' : 'text-primary') : error ? 'text-error' : 'text-on-surface-variant'"
|
|
194
197
|
>
|
|
195
198
|
{{ label }}
|
|
196
199
|
</label>
|
|
@@ -210,7 +213,7 @@ onUnmounted(() => {
|
|
|
210
213
|
<div
|
|
211
214
|
v-if="open"
|
|
212
215
|
ref="panelEl"
|
|
213
|
-
class="fixed z-500 w-[
|
|
216
|
+
class="fixed z-500 w-[360px] rounded-[28px] bg-surface-container-high p-4 shadow-elevation-3"
|
|
214
217
|
:style="dropPos"
|
|
215
218
|
>
|
|
216
219
|
<!-- Header -->
|
|
@@ -222,7 +225,7 @@ onUnmounted(() => {
|
|
|
222
225
|
|
|
223
226
|
<!-- Weekday headers -->
|
|
224
227
|
<div class="mb-1 grid grid-cols-7 gap-0.5 text-center">
|
|
225
|
-
<span v-for="wd in WEEKDAYS" :key="wd" class="py-1 text-
|
|
228
|
+
<span v-for="wd in WEEKDAYS" :key="wd" class="py-1 text-body-large font-medium text-on-surface">
|
|
226
229
|
{{ wd }}
|
|
227
230
|
</span>
|
|
228
231
|
</div>
|
|
@@ -233,7 +236,7 @@ onUnmounted(() => {
|
|
|
233
236
|
v-for="(day, i) in calendarDays"
|
|
234
237
|
:key="i"
|
|
235
238
|
type="button"
|
|
236
|
-
class="flex h-
|
|
239
|
+
class="flex h-10 w-full items-center justify-center rounded-full text-body-medium transition-colors duration-100"
|
|
237
240
|
:class="[
|
|
238
241
|
day.disabled
|
|
239
242
|
? 'cursor-not-allowed text-on-surface/25'
|
|
@@ -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(
|
|
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(
|
|
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(
|
|
120
|
+
return new Intl.DateTimeFormat(resolvedLocale.value, { weekday: 'short', month: 'short', day: 'numeric' }).format(d)
|
|
116
121
|
})
|
|
117
122
|
|
|
118
123
|
// ── Input mode ─────────────────────────────────────────────────────
|
|
@@ -155,17 +160,17 @@ function onKeydown(e: KeyboardEvent) { if (e.key === 'Escape') cancel() }
|
|
|
155
160
|
<Transition name="m3-dp-modal">
|
|
156
161
|
<div
|
|
157
162
|
v-if="show"
|
|
158
|
-
class="fixed inset-0 z-50 flex items-center justify-center bg-scrim/
|
|
163
|
+
class="fixed inset-0 z-50 flex items-center justify-center bg-scrim/32 p-4"
|
|
159
164
|
@click.self="cancel"
|
|
160
165
|
>
|
|
161
166
|
<div class="dp-box w-[360px] rounded-[28px] bg-surface-container-high shadow-elevation-3">
|
|
162
167
|
<!-- Header -->
|
|
163
168
|
<div class="px-6 pt-6 pb-4">
|
|
164
|
-
<p class="mb-3 text-label-
|
|
169
|
+
<p class="mb-3 text-label-large text-on-surface-variant">
|
|
165
170
|
{{ title || locale.selectDate }}
|
|
166
171
|
</p>
|
|
167
172
|
<div class="flex items-center justify-between">
|
|
168
|
-
<span class="text-headline-
|
|
173
|
+
<span class="text-headline-large font-medium capitalize text-on-surface-variant">
|
|
169
174
|
{{ headerDate }}
|
|
170
175
|
</span>
|
|
171
176
|
<MIconButton
|
|
@@ -189,7 +194,7 @@ function onKeydown(e: KeyboardEvent) { if (e.key === 'Escape') cancel() }
|
|
|
189
194
|
|
|
190
195
|
<!-- Weekday headers -->
|
|
191
196
|
<div class="mb-1 grid grid-cols-7 gap-0.5 text-center">
|
|
192
|
-
<span v-for="wd in WEEKDAYS" :key="wd" class="py-1 text-
|
|
197
|
+
<span v-for="wd in WEEKDAYS" :key="wd" class="py-1 text-body-large font-medium text-on-surface">
|
|
193
198
|
{{ wd }}
|
|
194
199
|
</span>
|
|
195
200
|
</div>
|
|
@@ -228,7 +233,7 @@ function onKeydown(e: KeyboardEvent) { if (e.key === 'Escape') cancel() }
|
|
|
228
233
|
type="text"
|
|
229
234
|
placeholder="23/06/2026"
|
|
230
235
|
maxlength="10"
|
|
231
|
-
class="h-14 w-full rounded-
|
|
236
|
+
class="h-14 w-full rounded-xs border border-outline bg-transparent px-4 text-body-large text-on-surface caret-primary outline-none transition-colors focus:border-2 focus:border-primary"
|
|
232
237
|
@keydown.enter="applyInput"
|
|
233
238
|
@blur="applyInput"
|
|
234
239
|
/>
|
|
@@ -10,7 +10,7 @@ export interface DateRange {
|
|
|
10
10
|
end: string | null
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
const props =
|
|
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(
|
|
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(
|
|
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(
|
|
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 ''
|
|
@@ -181,18 +184,18 @@ onUnmounted(() => {
|
|
|
181
184
|
<div ref="triggerEl" class="relative mt-2" :style="{ '--field-bg': resolvedFieldBg }">
|
|
182
185
|
<button
|
|
183
186
|
type="button"
|
|
184
|
-
class="flex h-14 w-full items-center gap-2 rounded-
|
|
187
|
+
class="flex h-14 w-full items-center gap-2 rounded-xs border bg-transparent px-4 text-left text-body-large transition-[border-color,border-width] duration-150"
|
|
185
188
|
:class="[
|
|
186
|
-
disabled ? 'pointer-events-none
|
|
187
|
-
open
|
|
189
|
+
disabled ? 'pointer-events-none cursor-not-allowed border-on-surface/12' : 'cursor-pointer',
|
|
190
|
+
!disabled && (open
|
|
188
191
|
? error ? 'border-2 border-error' : 'border-2 border-primary'
|
|
189
|
-
: error ? 'border-error' : 'border-outline hover:border-on-surface',
|
|
192
|
+
: error ? 'border-error' : 'border-outline hover:border-on-surface'),
|
|
190
193
|
]"
|
|
191
194
|
@click="!disabled && (open = !open)"
|
|
192
195
|
>
|
|
193
|
-
<MIcon name="date_range" :size="
|
|
194
|
-
<span v-if="displayValue" class="flex-1 text-on-surface">{{ displayValue }}</span>
|
|
195
|
-
<span v-else class="flex-1 text-on-surface-variant">{{ label || placeholder || localeStrings.selectRange }}</span>
|
|
196
|
+
<MIcon name="date_range" :size="24" class="shrink-0" :class="disabled ? 'text-on-surface/38' : 'text-on-surface-variant'" />
|
|
197
|
+
<span v-if="displayValue" class="flex-1" :class="disabled ? 'text-on-surface/38' : 'text-on-surface'">{{ displayValue }}</span>
|
|
198
|
+
<span v-else class="flex-1" :class="disabled ? 'text-on-surface/38' : 'text-on-surface-variant'">{{ label || placeholder || localeStrings.selectRange }}</span>
|
|
196
199
|
<MIcon
|
|
197
200
|
v-if="modelValue.start || modelValue.end"
|
|
198
201
|
name="close"
|
|
@@ -204,7 +207,7 @@ onUnmounted(() => {
|
|
|
204
207
|
<label
|
|
205
208
|
v-if="label"
|
|
206
209
|
class="pointer-events-none absolute -top-2.5 left-3 bg-(--field-bg) px-1 text-label-small transition-colors"
|
|
207
|
-
:class="open ? (error ? 'text-error' : 'text-primary') : error ? 'text-error' : 'text-on-surface-variant'"
|
|
210
|
+
:class="disabled ? 'text-on-surface/38' : open ? (error ? 'text-error' : 'text-primary') : error ? 'text-error' : 'text-on-surface-variant'"
|
|
208
211
|
>
|
|
209
212
|
{{ label }}
|
|
210
213
|
</label>
|
|
@@ -223,10 +226,10 @@ onUnmounted(() => {
|
|
|
223
226
|
<div
|
|
224
227
|
v-if="open"
|
|
225
228
|
ref="panelEl"
|
|
226
|
-
class="fixed z-500 w-[
|
|
229
|
+
class="fixed z-500 w-[360px] rounded-[28px] bg-surface-container-high p-4 shadow-elevation-3"
|
|
227
230
|
:style="dropPos"
|
|
228
231
|
>
|
|
229
|
-
<p class="mb-2 text-center text-label-
|
|
232
|
+
<p class="mb-2 text-center text-label-large text-on-surface-variant">
|
|
230
233
|
{{ picking === 'start' ? (pickStartText ?? localeStrings.pickStart) : (pickEndText ?? localeStrings.pickEnd) }}
|
|
231
234
|
</p>
|
|
232
235
|
|
|
@@ -237,7 +240,7 @@ onUnmounted(() => {
|
|
|
237
240
|
</div>
|
|
238
241
|
|
|
239
242
|
<div class="mb-1 grid grid-cols-7 gap-0.5 text-center">
|
|
240
|
-
<span v-for="wd in WEEKDAYS" :key="wd" class="py-1 text-
|
|
243
|
+
<span v-for="wd in WEEKDAYS" :key="wd" class="py-1 text-body-large font-medium text-on-surface">{{ wd }}</span>
|
|
241
244
|
</div>
|
|
242
245
|
|
|
243
246
|
<div class="grid grid-cols-7 gap-0.5">
|
|
@@ -245,7 +248,7 @@ onUnmounted(() => {
|
|
|
245
248
|
v-for="(day, i) in calendarDays"
|
|
246
249
|
:key="i"
|
|
247
250
|
type="button"
|
|
248
|
-
class="flex h-
|
|
251
|
+
class="flex h-10 w-full items-center justify-center text-body-medium transition-colors duration-100"
|
|
249
252
|
:class="[
|
|
250
253
|
day.disabled
|
|
251
254
|
? 'cursor-not-allowed text-on-surface/25 rounded-full'
|