@m3ui-vue/m3ui-vue 1.6.2 → 1.7.0
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/dist/API.md +649 -28
- package/dist/{MButton-OQ4wIERQ.js → MButton-CN3wYwIG.js} +2 -2
- package/dist/{MButton-OQ4wIERQ.js.map → MButton-CN3wYwIG.js.map} +1 -1
- package/dist/{MColorPickerModal-NtkihoK6.js → MColorPickerModal-BKM1CHxr.js} +4 -4
- package/dist/{MColorPickerModal-NtkihoK6.js.map → MColorPickerModal-BKM1CHxr.js.map} +1 -1
- package/dist/{MDialog-DYMnaBlt.js → MDialog-1LAk9WAO.js} +2 -2
- package/dist/{MDialog-DYMnaBlt.js.map → MDialog-1LAk9WAO.js.map} +1 -1
- package/dist/{MListItem-D2cNUyzP.js → MListItem-BU5KDRCB.js} +376 -270
- package/dist/MListItem-BU5KDRCB.js.map +1 -0
- package/dist/{MLoadingIndicator-DWUj0BAB.js → MLoadingIndicator-RykOo5tf.js} +2 -2
- package/dist/{MLoadingIndicator-DWUj0BAB.js.map → MLoadingIndicator-RykOo5tf.js.map} +1 -1
- package/dist/{MSeekBar-C4cn9RIF.js → MSeekBar-B_Y3MpVz.js} +2 -2
- package/dist/{MSeekBar-C4cn9RIF.js.map → MSeekBar-B_Y3MpVz.js.map} +1 -1
- package/dist/MSegmentedButton-CiOOY1-N.js +105 -0
- package/dist/MSegmentedButton-CiOOY1-N.js.map +1 -0
- package/dist/MSlider-BCeVIxcq.js +739 -0
- package/dist/MSlider-BCeVIxcq.js.map +1 -0
- package/dist/{MSpinner-DZkXZJpc.js → MSpinner-Cs03qoqE.js} +2 -2
- package/dist/{MSpinner-DZkXZJpc.js.map → MSpinner-Cs03qoqE.js.map} +1 -1
- package/dist/{MTextField-CNH-byir.js → MTextField-NaFbMkjv.js} +162 -115
- package/dist/MTextField-NaFbMkjv.js.map +1 -0
- package/dist/_useFieldValidation-Bz34IAQY.js +191 -0
- package/dist/_useFieldValidation-Bz34IAQY.js.map +1 -0
- package/dist/api.json +1 -1
- package/dist/code-editor.js +184 -103
- package/dist/code-editor.js.map +1 -1
- package/dist/components/MAddressField.vue.d.ts +18 -3
- package/dist/components/MAppBarWithSearch.vue.d.ts +1 -1
- package/dist/components/MAudioRecorder.vue.d.ts +2 -2
- package/dist/components/MAutocomplete.vue.d.ts +22 -3
- package/dist/components/MCheckbox.vue.d.ts +23 -1
- package/dist/components/MCodeEditor.vue.d.ts +23 -1
- package/dist/components/MColorPicker.vue.d.ts +24 -3
- package/dist/components/MConfirmDialog.vue.d.ts +2 -2
- package/dist/components/MCountrySelect.vue.d.ts +13 -2
- package/dist/components/MCreditCardInput.vue.d.ts +33 -0
- package/dist/components/MCronField.vue.d.ts +23 -1
- package/dist/components/MDataTable.vue.d.ts +1 -1
- package/dist/components/MDatePicker.vue.d.ts +24 -3
- package/dist/components/MDateRangePicker.vue.d.ts +24 -3
- package/dist/components/MFileUpload.vue.d.ts +23 -2
- package/dist/components/MForm.vue.d.ts +61 -0
- package/dist/components/MJsonEditor.vue.d.ts +23 -1
- package/dist/components/MMapRoute.vue.d.ts +168 -0
- package/dist/components/MMaskField.vue.d.ts +20 -2
- package/dist/components/MMentionField.vue.d.ts +13 -2
- package/dist/components/MMultiAutocomplete.vue.d.ts +22 -3
- package/dist/components/MMultiSelect.vue.d.ts +22 -3
- package/dist/components/MNavigationRail.vue.d.ts +1 -1
- package/dist/components/MNotificationCenter.vue.d.ts +2 -2
- package/dist/components/MNumberField.vue.d.ts +20 -2
- package/dist/components/MPhoneInput.vue.d.ts +19 -4
- package/dist/components/MPinInput.vue.d.ts +24 -3
- package/dist/components/MPosKeypad.vue.d.ts +2 -2
- package/dist/components/MRadioGroup.vue.d.ts +23 -1
- package/dist/components/MRating.vue.d.ts +23 -1
- package/dist/components/MRichTextEditor.vue.d.ts +23 -1
- package/dist/components/MSearchBar.vue.d.ts +1 -1
- package/dist/components/MSegmentedButton.vue.d.ts +23 -2
- package/dist/components/MSelect.vue.d.ts +22 -3
- package/dist/components/MSignaturePad.vue.d.ts +19 -0
- package/dist/components/MSlider.vue.d.ts +23 -1
- package/dist/components/MSwitch.vue.d.ts +23 -1
- package/dist/components/MTable.vue.d.ts +1 -1
- package/dist/components/MTagInput.vue.d.ts +20 -2
- package/dist/components/MText.vue.d.ts +1 -1
- package/dist/components/MTextField.vue.d.ts +26 -3
- package/dist/components/MTimePicker.vue.d.ts +24 -3
- package/dist/components/MTimezoneSelect.vue.d.ts +13 -2
- package/dist/components/MTour.vue.d.ts +2 -2
- package/dist/components/MTrackingTimeline.vue.d.ts +75 -0
- package/dist/components/MWindow.vue.d.ts +2 -2
- package/dist/composables/_routeGeometry.d.ts +26 -0
- package/dist/composables/_useFieldValidation.d.ts +91 -0
- package/dist/composables/mapRouting.d.ts +35 -0
- package/dist/composables/useLocale.d.ts +23 -0
- package/dist/composables/validation.d.ts +82 -0
- package/dist/draw.js +2 -2
- package/dist/flow.js +1 -1
- package/dist/gantt.js +2 -2
- package/dist/index.d.ts +5 -0
- package/dist/locales/index.js +154 -7
- package/dist/locales/index.js.map +1 -1
- package/dist/m3ui-vue.css +1 -1
- package/dist/m3ui.js +6768 -5602
- package/dist/m3ui.js.map +1 -1
- package/dist/map.d.ts +4 -0
- package/dist/map.js +1230 -784
- package/dist/map.js.map +1 -1
- package/dist/media.js +4 -4
- package/dist/pdf.js +4 -4
- package/dist/rich-text-editor.js +189 -146
- package/dist/rich-text-editor.js.map +1 -1
- package/dist/styles.css +1 -1
- package/dist/{useLocale-DaVSTdm0.js → useLocale-Dh1xZZ8i.js} +22 -1
- package/dist/useLocale-Dh1xZZ8i.js.map +1 -0
- package/package.json +1 -1
- package/src/__tests__/MForm.test.ts +325 -0
- package/src/__tests__/MMapRoute.test.ts +384 -0
- package/src/__tests__/MPhoneInput.test.ts +5 -2
- package/src/__tests__/MRichTextEditor.test.ts +2 -1
- package/src/__tests__/MTrackingTimeline.test.ts +66 -0
- package/src/__tests__/_fakeMaplibre.ts +4 -1
- package/src/__tests__/_osrmRoutes.ts +10 -0
- package/src/__tests__/attrsFallthrough.test.ts +11 -0
- package/src/__tests__/fieldsValidation.test.ts +229 -0
- package/src/__tests__/ssr.test.ts +1 -0
- package/src/__tests__/validation.test.ts +77 -0
- package/src/components/MAddressField.vue +45 -8
- package/src/components/MAutocomplete.vue +69 -23
- package/src/components/MCheckbox.vue +80 -17
- package/src/components/MCodeEditor.vue +59 -2
- package/src/components/MColorPicker.vue +65 -16
- package/src/components/MCountrySelect.vue +17 -3
- package/src/components/MCreditCardInput.vue +76 -7
- package/src/components/MCronField.vue +60 -10
- package/src/components/MDatePicker.vue +65 -16
- package/src/components/MDateRangePicker.vue +66 -16
- package/src/components/MFileUpload.vue +71 -8
- package/src/components/MForm.vue +208 -0
- package/src/components/MJsonEditor.vue +57 -3
- package/src/components/MMapRoute.vue +470 -0
- package/src/components/MMaskField.vue +55 -13
- package/src/components/MMentionField.vue +17 -2
- package/src/components/MMultiAutocomplete.vue +70 -23
- package/src/components/MMultiSelect.vue +70 -23
- package/src/components/MNumberField.vue +58 -16
- package/src/components/MPhoneInput.vue +60 -18
- package/src/components/MPinInput.vue +58 -10
- package/src/components/MRadioGroup.vue +65 -4
- package/src/components/MRating.vue +62 -6
- package/src/components/MRichTextEditor.vue +64 -4
- package/src/components/MSegmentedButton.vue +59 -2
- package/src/components/MSelect.vue +72 -26
- package/src/components/MSignaturePad.vue +71 -6
- package/src/components/MSlider.vue +61 -10
- package/src/components/MSwitch.vue +63 -8
- package/src/components/MTagInput.vue +67 -25
- package/src/components/MTextField.vue +68 -14
- package/src/components/MTimePicker.vue +65 -16
- package/src/components/MTimezoneSelect.vue +17 -3
- package/src/components/MTrackingTimeline.vue +257 -0
- package/src/composables/_routeGeometry.ts +140 -0
- package/src/composables/_useFieldValidation.ts +287 -0
- package/src/composables/mapRouting.ts +55 -0
- package/src/composables/useLocale.ts +46 -0
- package/src/composables/validation.ts +178 -0
- package/src/index.ts +5 -0
- package/src/locales/de.ts +21 -0
- package/src/locales/es.ts +28 -7
- package/src/locales/fr.ts +21 -0
- package/src/locales/ja.ts +21 -0
- package/src/locales/ko.ts +21 -0
- package/src/locales/pt.ts +21 -0
- package/src/locales/zh.ts +21 -0
- package/src/map.ts +4 -0
- package/dist/MListItem-D2cNUyzP.js.map +0 -1
- package/dist/MSegmentedButton-BEB4gXLA.js +0 -64
- package/dist/MSegmentedButton-BEB4gXLA.js.map +0 -1
- package/dist/MSlider-BIkA6DiE.js +0 -690
- package/dist/MSlider-BIkA6DiE.js.map +0 -1
- package/dist/MTextField-CNH-byir.js.map +0 -1
- package/dist/useLocale-DaVSTdm0.js.map +0 -1
|
@@ -3,9 +3,12 @@
|
|
|
3
3
|
* A toggle switch with an optional label, 4 semantic colors, and both M3 icon variants.
|
|
4
4
|
*
|
|
5
5
|
* @event update:modelValue Emitted with the new on/off state.
|
|
6
|
+
* @event blur Emitted when the switch loses focus
|
|
6
7
|
*/
|
|
7
8
|
import { computed, ref } from 'vue'
|
|
8
9
|
import MIcon from './MIcon.vue'
|
|
10
|
+
import { useFieldValidation } from '../composables/_useFieldValidation'
|
|
11
|
+
import type { ValidateOn, ValidationRule } from '../composables/validation'
|
|
9
12
|
|
|
10
13
|
const props = withDefaults(
|
|
11
14
|
defineProps<{
|
|
@@ -23,11 +26,45 @@ const props = withDefaults(
|
|
|
23
26
|
// defaults to `null`). Defaults to `true` here to keep this component's existing look;
|
|
24
27
|
// pass `false` for the plain/no-icon variant.
|
|
25
28
|
icon?: boolean
|
|
29
|
+
/** Error state. A string is also the message */
|
|
30
|
+
error?: boolean | string
|
|
31
|
+
/** Error message shown when `error` is true */
|
|
32
|
+
errorLabel?: string
|
|
33
|
+
/** Must be on, inside an `MForm` or with `rules` */
|
|
34
|
+
required?: boolean
|
|
35
|
+
/** Validation rules (functions or a Standard Schema); see `MForm` */
|
|
36
|
+
rules?: ValidationRule | ValidationRule[]
|
|
37
|
+
/** When the rules are checked and shown: on leaving it (default), on change, or only on submit */
|
|
38
|
+
validateOn?: ValidateOn
|
|
39
|
+
/** Wait this long (ms) after the value stops changing before re-checking (one request for an async rule, not one per key). Defaults to its `MForm`'s */
|
|
40
|
+
validateDebounce?: number
|
|
41
|
+
/** The key of this field in its `MForm` */
|
|
42
|
+
name?: string
|
|
26
43
|
}>(),
|
|
27
44
|
{ disabled: false, color: 'primary', icon: true },
|
|
28
45
|
)
|
|
29
46
|
|
|
30
|
-
const emit = defineEmits<{ 'update:modelValue': [boolean] }>()
|
|
47
|
+
const emit = defineEmits<{ 'update:modelValue': [boolean]; blur: [FocusEvent] }>()
|
|
48
|
+
|
|
49
|
+
const inputEl = ref<HTMLInputElement | null>(null)
|
|
50
|
+
|
|
51
|
+
const validation = useFieldValidation({
|
|
52
|
+
value: () => props.modelValue,
|
|
53
|
+
rules: () => props.rules,
|
|
54
|
+
required: () => props.required,
|
|
55
|
+
error: () => props.error,
|
|
56
|
+
errorLabel: () => props.errorLabel,
|
|
57
|
+
name: () => props.name,
|
|
58
|
+
validateOn: () => props.validateOn,
|
|
59
|
+
validateDebounce: () => props.validateDebounce,
|
|
60
|
+
disabled: () => props.disabled,
|
|
61
|
+
focus: () => { inputEl.value?.focus() },
|
|
62
|
+
el: () => inputEl.value,
|
|
63
|
+
setValue: (v) => emit('update:modelValue', v as boolean),
|
|
64
|
+
})
|
|
65
|
+
/** Its own `disabled` or its MForm's */
|
|
66
|
+
const isDisabled = validation.disabled
|
|
67
|
+
const { hasError, message: errorMessage, messageId } = validation
|
|
31
68
|
|
|
32
69
|
// Same 4 named colors as MRadio/MCheckbox's color prop.
|
|
33
70
|
const trackClasses: Record<string, string> = {
|
|
@@ -82,7 +119,7 @@ const stateLayerBg: Record<string, string> = {
|
|
|
82
119
|
// is computed in JS, not a plain class, so CSS pseudo-classes can't reach into it.
|
|
83
120
|
const isPressed = ref(false)
|
|
84
121
|
function onPointerDown() {
|
|
85
|
-
if (!
|
|
122
|
+
if (!isDisabled.value) isPressed.value = true
|
|
86
123
|
}
|
|
87
124
|
function onPointerEnd() {
|
|
88
125
|
isPressed.value = false
|
|
@@ -115,12 +152,19 @@ const stateLayerStyle = computed(() => ({
|
|
|
115
152
|
? 'transform 320ms cubic-bezier(0.34, 1.56, 0.64, 1)'
|
|
116
153
|
: 'transform 240ms cubic-bezier(0.2, 0, 0, 1)',
|
|
117
154
|
}))
|
|
155
|
+
|
|
156
|
+
defineExpose({
|
|
157
|
+
/** Checks its rules and shows the result; resolves to whether they pass */
|
|
158
|
+
validate: validation.validate,
|
|
159
|
+
/** Hides its validation error (until the next check) */
|
|
160
|
+
resetValidation: validation.resetValidation,
|
|
161
|
+
})
|
|
118
162
|
</script>
|
|
119
163
|
|
|
120
164
|
<template>
|
|
121
165
|
<label
|
|
122
|
-
class="group inline-flex
|
|
123
|
-
:class="
|
|
166
|
+
class="group inline-flex gap-3 select-none"
|
|
167
|
+
:class="[isDisabled ? 'cursor-not-allowed opacity-[0.38]' : 'cursor-pointer', errorMessage ? 'items-start' : 'items-center']"
|
|
124
168
|
@pointerdown="onPointerDown"
|
|
125
169
|
@pointerup="onPointerEnd"
|
|
126
170
|
@pointerleave="onPointerEnd"
|
|
@@ -135,19 +179,26 @@ const stateLayerStyle = computed(() => ({
|
|
|
135
179
|
type="checkbox"
|
|
136
180
|
class="peer sr-only"
|
|
137
181
|
:checked="modelValue"
|
|
138
|
-
:disabled="
|
|
182
|
+
:disabled="isDisabled"
|
|
183
|
+
ref="inputEl"
|
|
184
|
+
role="switch"
|
|
185
|
+
:name="name"
|
|
186
|
+
:required="required"
|
|
187
|
+
:aria-invalid="hasError || undefined"
|
|
188
|
+
:aria-describedby="errorMessage ? messageId : undefined"
|
|
139
189
|
@change="emit('update:modelValue', !modelValue)"
|
|
190
|
+
@blur="validation.onBlur(); emit('blur', $event)"
|
|
140
191
|
/>
|
|
141
192
|
|
|
142
193
|
<!-- Hover/press/focus state layer + focus ring, both tracking the thumb's position (see stateLayerStyle doc above) -->
|
|
143
194
|
<span
|
|
144
|
-
v-if="!
|
|
195
|
+
v-if="!isDisabled"
|
|
145
196
|
class="pointer-events-none absolute top-1/2 -left-1 h-10 w-10 -translate-y-1/2 rounded-full opacity-0 transition-opacity duration-150 group-hover:opacity-[0.08] group-active:opacity-[0.12] peer-focus-visible:opacity-[0.08]"
|
|
146
197
|
:class="modelValue ? stateLayerBg[color] : 'bg-on-surface-variant'"
|
|
147
198
|
:style="stateLayerStyle"
|
|
148
199
|
/>
|
|
149
200
|
<span
|
|
150
|
-
v-if="!
|
|
201
|
+
v-if="!isDisabled"
|
|
151
202
|
class="pointer-events-none absolute top-1/2 -left-1 h-10 w-10 -translate-y-1/2 rounded-full ring-0 ring-secondary transition-[box-shadow] duration-150 peer-focus-visible:ring-2"
|
|
152
203
|
:style="stateLayerStyle"
|
|
153
204
|
/>
|
|
@@ -171,6 +222,10 @@ const stateLayerStyle = computed(() => ({
|
|
|
171
222
|
</span>
|
|
172
223
|
</span>
|
|
173
224
|
</span>
|
|
174
|
-
<span v-if="label" class="
|
|
225
|
+
<span v-if="label || errorMessage" class="flex flex-col" :class="errorMessage && 'pt-1'">
|
|
226
|
+
<span v-if="label" class="text-body-large text-on-surface">{{ label }}<span v-if="required" class="text-error"> *</span></span>
|
|
227
|
+
<!-- M3's switch has no error state: only the message says so -->
|
|
228
|
+
<span v-if="errorMessage" :id="messageId" role="alert" class="text-body-small text-error">{{ errorMessage }}</span>
|
|
229
|
+
</span>
|
|
175
230
|
</label>
|
|
176
231
|
</template>
|
|
@@ -6,6 +6,8 @@
|
|
|
6
6
|
* @event debounced Emitted debounce ms after the tag list stops changing (only when debounce > 0)
|
|
7
7
|
*/
|
|
8
8
|
import { computed, ref, useId } from 'vue'
|
|
9
|
+
import { useFieldValidation, useFocusLeave } from '../composables/_useFieldValidation'
|
|
10
|
+
import type { ValidateOn, ValidationRule } from '../composables/validation'
|
|
9
11
|
import MIcon from './MIcon.vue'
|
|
10
12
|
import { useFieldBg } from '../composables/useFieldBg'
|
|
11
13
|
import { useDebounce } from '../composables/useDebounce'
|
|
@@ -25,10 +27,21 @@ const props = withDefaults(
|
|
|
25
27
|
variant?: 'filled' | 'outlined'
|
|
26
28
|
/** Disables the field */
|
|
27
29
|
disabled?: boolean
|
|
28
|
-
/** Error state */
|
|
29
|
-
error?: boolean
|
|
30
|
+
/** Error state. A string is also the message (`:error="errors.x"`) */
|
|
31
|
+
error?: boolean | string
|
|
30
32
|
/** Error message shown when error is true */
|
|
31
33
|
errorLabel?: string
|
|
34
|
+
/**
|
|
35
|
+
* Validation rules: functions `(value, ctx) => true | 'message'` (may be async; see the built-in `required`,
|
|
36
|
+
* `email`, `minLength`…) or a Standard Schema (zod, valibot…). Checked in order; the first failure is shown
|
|
37
|
+
*/
|
|
38
|
+
rules?: ValidationRule | ValidationRule[]
|
|
39
|
+
/** When the rules are checked and shown: on leaving the field (default; live after that), while typing, or only on submit (`MForm`) */
|
|
40
|
+
validateOn?: ValidateOn
|
|
41
|
+
/** Wait this long (ms) after the value stops changing before re-checking (one request for an async rule, not one per key). Defaults to its `MForm`'s */
|
|
42
|
+
validateDebounce?: number
|
|
43
|
+
/** The key of this field in its `MForm`'s values, errors and schema */
|
|
44
|
+
name?: string
|
|
32
45
|
/** Helper text below field */
|
|
33
46
|
hint?: string
|
|
34
47
|
/** Marks as required — adds a red asterisk after the label */
|
|
@@ -59,7 +72,30 @@ const props = withDefaults(
|
|
|
59
72
|
},
|
|
60
73
|
)
|
|
61
74
|
|
|
62
|
-
const emit = defineEmits<{ 'update:modelValue': [string[]]; debounced: [string[]] }>()
|
|
75
|
+
const emit = defineEmits<{ blur: []; 'update:modelValue': [string[]]; debounced: [string[]] }>()
|
|
76
|
+
|
|
77
|
+
const rootEl = ref<HTMLElement | null>(null)
|
|
78
|
+
const validation = useFieldValidation({
|
|
79
|
+
value: () => props.modelValue,
|
|
80
|
+
rules: () => props.rules,
|
|
81
|
+
required: () => props.required,
|
|
82
|
+
error: () => props.error,
|
|
83
|
+
errorLabel: () => props.errorLabel,
|
|
84
|
+
name: () => props.name,
|
|
85
|
+
validateOn: () => props.validateOn,
|
|
86
|
+
validateDebounce: () => props.validateDebounce,
|
|
87
|
+
disabled: () => props.disabled,
|
|
88
|
+
focus: () => { inputEl.value?.focus() },
|
|
89
|
+
el: () => inputEl.value,
|
|
90
|
+
setValue: (v) => emit('update:modelValue', v as string[]),
|
|
91
|
+
})
|
|
92
|
+
/** Its own `disabled` or its MForm's */
|
|
93
|
+
const isDisabled = validation.disabled
|
|
94
|
+
const { hasError, message: errorMessage, messageId } = validation
|
|
95
|
+
const onFocusOut = useFocusLeave(() => rootEl.value, () => {
|
|
96
|
+
validation.onBlur()
|
|
97
|
+
emit('blur')
|
|
98
|
+
})
|
|
63
99
|
|
|
64
100
|
const id = useId()
|
|
65
101
|
const focused = ref(false)
|
|
@@ -135,7 +171,7 @@ function onBlur() {
|
|
|
135
171
|
}
|
|
136
172
|
|
|
137
173
|
function focusInput() {
|
|
138
|
-
if (!
|
|
174
|
+
if (!isDisabled.value) {
|
|
139
175
|
inputEl.value?.focus()
|
|
140
176
|
}
|
|
141
177
|
}
|
|
@@ -147,26 +183,26 @@ const triggerClasses = computed(() => {
|
|
|
147
183
|
const base = [
|
|
148
184
|
'flex min-h-[56px] w-full min-w-0 items-center gap-1.5 flex-wrap',
|
|
149
185
|
'transition-[border-color,border-width] duration-150',
|
|
150
|
-
|
|
186
|
+
isDisabled.value ? 'cursor-not-allowed' : 'cursor-text',
|
|
151
187
|
props.leadingIcon ? 'pl-12' : 'pl-4',
|
|
152
188
|
FIELD_PADDING_RIGHT[rightInset.value],
|
|
153
189
|
]
|
|
154
190
|
|
|
155
191
|
if (props.variant === 'outlined') {
|
|
156
|
-
const border =
|
|
192
|
+
const border = isDisabled.value
|
|
157
193
|
? 'border-on-surface/12'
|
|
158
194
|
: focused.value
|
|
159
|
-
? (
|
|
160
|
-
: (
|
|
195
|
+
? (hasError.value ? 'border-2 border-error' : 'border-2 border-primary')
|
|
196
|
+
: (hasError.value ? 'border-error' : 'border-outline hover:border-on-surface')
|
|
161
197
|
return [...base, 'rounded-xs border bg-transparent py-2', border].join(' ')
|
|
162
198
|
}
|
|
163
199
|
|
|
164
|
-
const border =
|
|
200
|
+
const border = isDisabled.value
|
|
165
201
|
? 'border-on-surface/38'
|
|
166
202
|
: focused.value
|
|
167
|
-
? (
|
|
168
|
-
: (
|
|
169
|
-
const bg =
|
|
203
|
+
? (hasError.value ? 'border-b-2 border-error' : 'border-b-2 border-primary')
|
|
204
|
+
: (hasError.value ? 'border-error' : 'border-on-surface-variant hover:border-on-surface')
|
|
205
|
+
const bg = isDisabled.value
|
|
170
206
|
? 'bg-[color-mix(in_srgb,var(--color-on-surface)_4%,var(--color-surface-container-highest))]'
|
|
171
207
|
: 'bg-surface-container-highest'
|
|
172
208
|
return [...base, 'rounded-t-xs border-b pb-2', hasValue.value || focused.value ? 'pt-7' : 'pt-4', bg, border].join(' ')
|
|
@@ -178,15 +214,19 @@ const labelClasses = computed(() =>
|
|
|
178
214
|
leading: !!props.leadingIcon,
|
|
179
215
|
right: rightInset.value,
|
|
180
216
|
floated: focused.value || hasValue.value,
|
|
181
|
-
color:
|
|
217
|
+
color: isDisabled.value
|
|
182
218
|
? 'text-on-surface/38'
|
|
183
219
|
: focused.value
|
|
184
|
-
? (
|
|
185
|
-
: (
|
|
220
|
+
? (hasError.value ? 'text-error' : 'text-primary')
|
|
221
|
+
: (hasError.value ? 'text-error' : 'text-on-surface-variant'),
|
|
186
222
|
}),
|
|
187
223
|
)
|
|
188
224
|
|
|
189
225
|
defineExpose({
|
|
226
|
+
/** Checks its rules and shows the result; resolves to whether they pass */
|
|
227
|
+
validate: validation.validate,
|
|
228
|
+
/** Hides its validation error (until the next check) */
|
|
229
|
+
resetValidation: validation.resetValidation,
|
|
190
230
|
/** The `<input>` (or `<textarea>`) element */
|
|
191
231
|
inputEl: inputEl,
|
|
192
232
|
/** Focuses the field */
|
|
@@ -201,7 +241,7 @@ defineExpose({
|
|
|
201
241
|
</script>
|
|
202
242
|
|
|
203
243
|
<template>
|
|
204
|
-
<div class="flex flex-col gap-1">
|
|
244
|
+
<div ref="rootEl" class="flex flex-col gap-1" @focusout="onFocusOut">
|
|
205
245
|
<div
|
|
206
246
|
ref="fieldEl"
|
|
207
247
|
class="relative"
|
|
@@ -213,7 +253,7 @@ defineExpose({
|
|
|
213
253
|
class="pointer-events-none absolute left-3.5"
|
|
214
254
|
:class="[
|
|
215
255
|
variant === 'filled' ? 'top-4.5' : 'top-4',
|
|
216
|
-
|
|
256
|
+
isDisabled ? 'text-on-surface/38' : 'text-on-surface-variant',
|
|
217
257
|
]"
|
|
218
258
|
>
|
|
219
259
|
<MIcon :name="leadingIcon" :size="24" />
|
|
@@ -229,12 +269,12 @@ defineExpose({
|
|
|
229
269
|
v-for="(tag, i) in modelValue"
|
|
230
270
|
:key="i"
|
|
231
271
|
class="inline-flex max-w-full min-w-0 items-center gap-1 rounded-full px-2 py-0.5 text-label-small"
|
|
232
|
-
:class="
|
|
272
|
+
:class="isDisabled ? 'bg-on-surface/12 text-on-surface/38' : 'bg-secondary-container text-on-secondary-container'"
|
|
233
273
|
>
|
|
234
274
|
<span v-overflow-title class="min-w-0 truncate">{{ tag }}</span>
|
|
235
275
|
<button
|
|
236
276
|
:aria-label="`${locale.remove} ${tag}`"
|
|
237
|
-
v-if="!
|
|
277
|
+
v-if="!isDisabled"
|
|
238
278
|
type="button"
|
|
239
279
|
class="flex h-4 w-4 shrink-0 items-center justify-center rounded-full hover:bg-on-secondary-container/20"
|
|
240
280
|
@click="removeTag(i, $event)"
|
|
@@ -245,17 +285,19 @@ defineExpose({
|
|
|
245
285
|
|
|
246
286
|
<input
|
|
247
287
|
ref="inputEl"
|
|
288
|
+
:aria-invalid="hasError || undefined"
|
|
289
|
+
:aria-describedby="errorMessage || hint ? messageId : undefined"
|
|
248
290
|
:value="inputValue"
|
|
249
291
|
type="text"
|
|
250
292
|
enterkeyhint="done"
|
|
251
293
|
autocomplete="off"
|
|
252
294
|
:class="[
|
|
253
295
|
'min-w-[60px] flex-1 bg-transparent text-body-large outline-none placeholder:text-on-surface-variant',
|
|
254
|
-
|
|
255
|
-
|
|
296
|
+
hasError ? 'caret-error' : 'caret-primary',
|
|
297
|
+
isDisabled ? 'text-on-surface/38' : 'text-on-surface',
|
|
256
298
|
]"
|
|
257
299
|
:placeholder="!hasValue && (!label || focused) ? placeholder : ''"
|
|
258
|
-
:disabled="
|
|
300
|
+
:disabled="isDisabled"
|
|
259
301
|
:readonly="!canAddMore"
|
|
260
302
|
@input="onInput"
|
|
261
303
|
@keydown="onKeydown"
|
|
@@ -271,7 +313,7 @@ defineExpose({
|
|
|
271
313
|
|
|
272
314
|
<button
|
|
273
315
|
:aria-label="locale.clear"
|
|
274
|
-
v-if="clearable && hasValue && !
|
|
316
|
+
v-if="clearable && hasValue && !isDisabled"
|
|
275
317
|
type="button"
|
|
276
318
|
class="absolute right-2 top-4 flex h-6 w-6 cursor-pointer items-center justify-center rounded-full text-on-surface-variant transition-colors hover:bg-on-surface/8 hover:text-on-surface"
|
|
277
319
|
@click.stop="cancelDebounce(); emit('update:modelValue', []); inputValue = ''"
|
|
@@ -280,7 +322,7 @@ defineExpose({
|
|
|
280
322
|
</button>
|
|
281
323
|
</div>
|
|
282
324
|
|
|
283
|
-
<p v-if="
|
|
284
|
-
<p v-else-if="hint" class="px-4 text-body-small text-on-surface-variant">{{ hint }}</p>
|
|
325
|
+
<p v-if="errorMessage" :id="messageId" role="alert" class="px-4 text-body-small text-error">{{ errorMessage }}</p>
|
|
326
|
+
<p v-else-if="hint" :id="messageId" class="px-4 text-body-small text-on-surface-variant">{{ hint }}</p>
|
|
285
327
|
</div>
|
|
286
328
|
</template>
|
|
@@ -6,6 +6,8 @@
|
|
|
6
6
|
* present
|
|
7
7
|
* @event update:modelValue Emitted on every keystroke — powers v-model
|
|
8
8
|
* @event debounced Emitted debounce ms after the user stops typing (only when debounce > 0)
|
|
9
|
+
* @event blur Emitted when the field loses focus (wire vee-validate's `handleBlur` / Vuelidate's `$touch` here)
|
|
10
|
+
* @event focus Emitted when the field gains focus
|
|
9
11
|
*/
|
|
10
12
|
import { computed, ref, useId, useSlots } from "vue";
|
|
11
13
|
import MIcon from "./MIcon.vue";
|
|
@@ -13,6 +15,8 @@ import { useAutoGrow } from "../composables/useAutoGrow";
|
|
|
13
15
|
import { useFieldBg } from "../composables/useFieldBg";
|
|
14
16
|
import { useDebounce } from "../composables/useDebounce";
|
|
15
17
|
import { useLocale } from '../composables/useLocale'
|
|
18
|
+
import { useFieldValidation } from '../composables/_useFieldValidation'
|
|
19
|
+
import type { ValidateOn, ValidationRule } from '../composables/validation'
|
|
16
20
|
import { FIELD_PADDING_RIGHT, fieldLabelClasses, vOverflowTitle, type FieldRightInset } from '../composables/_fieldLayout'
|
|
17
21
|
|
|
18
22
|
const locale = useLocale()
|
|
@@ -26,15 +30,29 @@ const props = withDefaults(
|
|
|
26
30
|
type?: string;
|
|
27
31
|
/** Visual style */
|
|
28
32
|
variant?: "filled" | "outlined";
|
|
29
|
-
/**
|
|
30
|
-
|
|
33
|
+
/**
|
|
34
|
+
* Puts the field in error state (red border and label). A string is also the message, so a validation
|
|
35
|
+
* library's error plugs straight in: `:error="errors.email"`
|
|
36
|
+
*/
|
|
37
|
+
error?: boolean | string;
|
|
31
38
|
/** Error message shown below the field (only visible when error is true) */
|
|
32
39
|
errorLabel?: string;
|
|
40
|
+
/**
|
|
41
|
+
* Validation rules: functions `(value, ctx) => true | 'message'` (may be async; see the built-in `required`,
|
|
42
|
+
* `email`, `minLength`…) or a Standard Schema (zod, valibot…). Checked in order; the first failure is shown
|
|
43
|
+
*/
|
|
44
|
+
rules?: ValidationRule | ValidationRule[];
|
|
45
|
+
/** When the rules are checked and shown: on leaving the field (default; live after that), while typing, or only on submit (`MForm`) */
|
|
46
|
+
validateOn?: ValidateOn;
|
|
47
|
+
/** Wait this long (ms) after the value stops changing before re-checking (one request for an async rule, not one per key). Defaults to its `MForm`'s */
|
|
48
|
+
validateDebounce?: number;
|
|
49
|
+
/** Native `name`; also the key of this field in its `MForm`'s values, errors and schema */
|
|
50
|
+
name?: string;
|
|
33
51
|
/** Hint text shown below the field */
|
|
34
52
|
hint?: string;
|
|
35
53
|
/** Disables the field */
|
|
36
54
|
disabled?: boolean;
|
|
37
|
-
/** Marks as required — adds a red asterisk after the label */
|
|
55
|
+
/** Marks as required — adds a red asterisk after the label; inside an `MForm` or with `rules`, also validates it */
|
|
38
56
|
required?: boolean;
|
|
39
57
|
/** Renders a textarea instead of an input */
|
|
40
58
|
multiline?: boolean;
|
|
@@ -66,7 +84,7 @@ const props = withDefaults(
|
|
|
66
84
|
},
|
|
67
85
|
);
|
|
68
86
|
|
|
69
|
-
const emit = defineEmits<{ "update:modelValue": [string]; debounced: [string] }>();
|
|
87
|
+
const emit = defineEmits<{ "update:modelValue": [string]; debounced: [string]; blur: [FocusEvent]; focus: [FocusEvent] }>();
|
|
70
88
|
|
|
71
89
|
const id = useId();
|
|
72
90
|
const slots = useSlots();
|
|
@@ -79,13 +97,35 @@ const { debounced: emitDebounced, cancel: cancelDebounce } = useDebounce((v: str
|
|
|
79
97
|
const textareaEl = ref<HTMLTextAreaElement | null>(null);
|
|
80
98
|
const inputOnlyEl = ref<HTMLInputElement | null>(null);
|
|
81
99
|
const fieldEl = computed(() => textareaEl.value ?? inputOnlyEl.value);
|
|
100
|
+
|
|
101
|
+
const validation = useFieldValidation({
|
|
102
|
+
value: () => props.modelValue,
|
|
103
|
+
rules: () => props.rules,
|
|
104
|
+
required: () => props.required,
|
|
105
|
+
error: () => props.error,
|
|
106
|
+
errorLabel: () => props.errorLabel,
|
|
107
|
+
name: () => props.name,
|
|
108
|
+
validateOn: () => props.validateOn,
|
|
109
|
+
validateDebounce: () => props.validateDebounce,
|
|
110
|
+
disabled: () => props.disabled,
|
|
111
|
+
focus: () => fieldEl.value?.focus(),
|
|
112
|
+
el: () => fieldEl.value,
|
|
113
|
+
setValue: (v) => emit("update:modelValue", v as string),
|
|
114
|
+
});
|
|
115
|
+
const { hasError, message: errorMessage, messageId } = validation;
|
|
116
|
+
const isDisabled = validation.disabled;
|
|
117
|
+
|
|
118
|
+
function onBlur(event: FocusEvent) {
|
|
119
|
+
validation.onBlur();
|
|
120
|
+
emit("blur", event);
|
|
121
|
+
}
|
|
82
122
|
useAutoGrow(() => (props.multiline && props.autoGrow ? textareaEl.value : null), {
|
|
83
123
|
minRows: () => props.rows,
|
|
84
124
|
maxRows: () => props.maxRows,
|
|
85
125
|
value: () => props.modelValue,
|
|
86
126
|
});
|
|
87
127
|
|
|
88
|
-
const showClear = computed(() => props.clearable && String(props.modelValue).length > 0 && !
|
|
128
|
+
const showClear = computed(() => props.clearable && String(props.modelValue).length > 0 && !isDisabled.value)
|
|
89
129
|
|
|
90
130
|
// The label and the text both stop before a trailing button (the #trailing slot or the clear button)
|
|
91
131
|
const rightInset = computed<FieldRightInset>(() => (slots.trailing || props.clearable ? "right-12" : "right-4"));
|
|
@@ -98,7 +138,7 @@ const inputClasses = computed(() => {
|
|
|
98
138
|
"peer block w-full text-body-large text-on-surface outline-none placeholder:text-transparent",
|
|
99
139
|
"transition-[border-color,border-width] duration-150",
|
|
100
140
|
"disabled:cursor-not-allowed disabled:text-on-surface/38",
|
|
101
|
-
|
|
141
|
+
hasError.value ? "caret-error" : "caret-primary",
|
|
102
142
|
size,
|
|
103
143
|
pl,
|
|
104
144
|
pr,
|
|
@@ -108,7 +148,7 @@ const inputClasses = computed(() => {
|
|
|
108
148
|
return [
|
|
109
149
|
...base,
|
|
110
150
|
"rounded-xs border bg-transparent py-4",
|
|
111
|
-
|
|
151
|
+
hasError.value
|
|
112
152
|
? "border-error focus:border-2 focus:border-error"
|
|
113
153
|
: "border-outline hover:border-on-surface focus:border-2 focus:border-primary",
|
|
114
154
|
"disabled:border-on-surface/12",
|
|
@@ -122,7 +162,7 @@ const inputClasses = computed(() => {
|
|
|
122
162
|
props.multiline
|
|
123
163
|
? "rounded-t-xs bg-surface-container-highest border-b border-t-24 border-t-transparent pb-2"
|
|
124
164
|
: "rounded-t-xs bg-surface-container-highest border-b pt-6 pb-2",
|
|
125
|
-
|
|
165
|
+
hasError.value
|
|
126
166
|
? "border-b-error focus:border-b-2 focus:border-b-error"
|
|
127
167
|
: "border-b-on-surface-variant hover:border-b-on-surface focus:border-b-2 focus:border-b-primary",
|
|
128
168
|
"disabled:border-b-on-surface/38 disabled:bg-[color-mix(in_srgb,var(--color-on-surface)_4%,var(--color-surface-container-highest))]",
|
|
@@ -136,7 +176,7 @@ const labelClasses = computed(() =>
|
|
|
136
176
|
right: rightInset.value,
|
|
137
177
|
floated: 'peer',
|
|
138
178
|
color: [
|
|
139
|
-
|
|
179
|
+
hasError.value ? 'text-error peer-focus:text-error' : 'text-on-surface-variant peer-focus:text-primary',
|
|
140
180
|
'peer-disabled:text-on-surface/38',
|
|
141
181
|
].join(' '),
|
|
142
182
|
}),
|
|
@@ -157,6 +197,10 @@ defineExpose({
|
|
|
157
197
|
blur: () => fieldEl.value?.blur(),
|
|
158
198
|
/** Selects all its text */
|
|
159
199
|
select: () => fieldEl.value?.select(),
|
|
200
|
+
/** Checks its rules and shows the result; resolves to whether they pass */
|
|
201
|
+
validate: validation.validate,
|
|
202
|
+
/** Hides its validation error (until the next check) */
|
|
203
|
+
resetValidation: validation.resetValidation,
|
|
160
204
|
/** Selects part of its text (e.g. a file name without its extension) */
|
|
161
205
|
setSelectionRange: (start: number, end: number, direction?: 'forward' | 'backward' | 'none') => fieldEl.value?.setSelectionRange(start, end, direction),
|
|
162
206
|
})
|
|
@@ -180,7 +224,7 @@ defineExpose({
|
|
|
180
224
|
class="pointer-events-none absolute left-3.5"
|
|
181
225
|
:class="[
|
|
182
226
|
multiline ? 'top-[55%] -translate-y-1/2' : variant === 'filled' ? 'top-4.5' : 'top-4',
|
|
183
|
-
|
|
227
|
+
isDisabled ? 'text-on-surface/38' : 'text-on-surface-variant',
|
|
184
228
|
]"
|
|
185
229
|
>
|
|
186
230
|
<MIcon :name="leadingIcon" :size="24" />
|
|
@@ -192,11 +236,16 @@ defineExpose({
|
|
|
192
236
|
:id="id"
|
|
193
237
|
:value="String(modelValue)"
|
|
194
238
|
:rows="rows"
|
|
195
|
-
:
|
|
239
|
+
:name="name"
|
|
240
|
+
:disabled="isDisabled"
|
|
196
241
|
:required="required"
|
|
242
|
+
:aria-invalid="hasError || undefined"
|
|
243
|
+
:aria-describedby="errorMessage || hint ? messageId : undefined"
|
|
197
244
|
placeholder=" "
|
|
198
245
|
:class="inputClasses"
|
|
199
246
|
@input="onInput"
|
|
247
|
+
@blur="onBlur"
|
|
248
|
+
@focus="emit('focus', $event)"
|
|
200
249
|
/>
|
|
201
250
|
<input
|
|
202
251
|
v-else
|
|
@@ -204,13 +253,18 @@ defineExpose({
|
|
|
204
253
|
:id="id"
|
|
205
254
|
:type="type"
|
|
206
255
|
:value="modelValue"
|
|
207
|
-
:
|
|
256
|
+
:name="name"
|
|
257
|
+
:disabled="isDisabled"
|
|
208
258
|
:required="required"
|
|
259
|
+
:aria-invalid="hasError || undefined"
|
|
260
|
+
:aria-describedby="errorMessage || hint ? messageId : undefined"
|
|
209
261
|
:autocomplete="autocomplete"
|
|
210
262
|
placeholder=" "
|
|
211
263
|
:class="inputClasses"
|
|
212
264
|
v-overflow-title
|
|
213
265
|
@input="onInput"
|
|
266
|
+
@blur="onBlur"
|
|
267
|
+
@focus="emit('focus', $event)"
|
|
214
268
|
/>
|
|
215
269
|
|
|
216
270
|
<label :for="id" :class="labelClasses">
|
|
@@ -231,7 +285,7 @@ defineExpose({
|
|
|
231
285
|
</button>
|
|
232
286
|
</div>
|
|
233
287
|
|
|
234
|
-
<p v-if="
|
|
235
|
-
<p v-else-if="hint" class="px-4 text-body-small text-on-surface-variant">{{ hint }}</p>
|
|
288
|
+
<p v-if="errorMessage" :id="messageId" role="alert" class="px-4 text-body-small text-error">{{ errorMessage }}</p>
|
|
289
|
+
<p v-else-if="hint" :id="messageId" class="px-4 text-body-small text-on-surface-variant">{{ hint }}</p>
|
|
236
290
|
</div>
|
|
237
291
|
</template>
|
|
@@ -5,6 +5,8 @@
|
|
|
5
5
|
* @event update:modelValue Emitted with the picked time.
|
|
6
6
|
*/
|
|
7
7
|
import { computed, onUnmounted, ref, watch } from 'vue'
|
|
8
|
+
import { useFieldValidation, useFocusLeave } from '../composables/_useFieldValidation'
|
|
9
|
+
import type { ValidateOn, ValidationRule } from '../composables/validation'
|
|
8
10
|
import MIcon from './MIcon.vue'
|
|
9
11
|
import { useFieldBg } from '../composables/useFieldBg'
|
|
10
12
|
import { useLocale } from '../composables/useLocale'
|
|
@@ -21,10 +23,23 @@ const props = withDefaults(defineProps<{
|
|
|
21
23
|
placeholder?: string
|
|
22
24
|
/** Disables the picker */
|
|
23
25
|
disabled?: boolean
|
|
24
|
-
/** Error state */
|
|
25
|
-
error?: boolean
|
|
26
|
+
/** Error state. A string is also the message (`:error="errors.x"`) */
|
|
27
|
+
error?: boolean | string
|
|
26
28
|
/** Error message shown when error is true */
|
|
27
29
|
errorLabel?: string
|
|
30
|
+
/** Marks as required — adds a red asterisk after the label; inside an `MForm` or with `rules`, also validates it */
|
|
31
|
+
required?: boolean
|
|
32
|
+
/**
|
|
33
|
+
* Validation rules: functions `(value, ctx) => true | 'message'` (may be async; see the built-in `required`,
|
|
34
|
+
* `email`, `minLength`…) or a Standard Schema (zod, valibot…). Checked in order; the first failure is shown
|
|
35
|
+
*/
|
|
36
|
+
rules?: ValidationRule | ValidationRule[]
|
|
37
|
+
/** When the rules are checked and shown: on leaving the field (default; live after that), while typing, or only on submit (`MForm`) */
|
|
38
|
+
validateOn?: ValidateOn
|
|
39
|
+
/** Wait this long (ms) after the value stops changing before re-checking (one request for an async rule, not one per key). Defaults to its `MForm`'s */
|
|
40
|
+
validateDebounce?: number
|
|
41
|
+
/** The key of this field in its `MForm`'s values, errors and schema */
|
|
42
|
+
name?: string
|
|
28
43
|
/** Hint text below the field */
|
|
29
44
|
hint?: string
|
|
30
45
|
/** Minute increment step */
|
|
@@ -37,7 +52,26 @@ const props = withDefaults(defineProps<{
|
|
|
37
52
|
|
|
38
53
|
const locale = useLocale()
|
|
39
54
|
|
|
40
|
-
const emit = defineEmits<{ 'update:modelValue': [string | null] }>()
|
|
55
|
+
const emit = defineEmits<{ blur: []; 'update:modelValue': [string | null] }>()
|
|
56
|
+
|
|
57
|
+
const rootEl = ref<HTMLElement | null>(null)
|
|
58
|
+
const validation = useFieldValidation({
|
|
59
|
+
value: () => props.modelValue,
|
|
60
|
+
rules: () => props.rules,
|
|
61
|
+
required: () => props.required,
|
|
62
|
+
error: () => props.error,
|
|
63
|
+
errorLabel: () => props.errorLabel,
|
|
64
|
+
name: () => props.name,
|
|
65
|
+
validateOn: () => props.validateOn,
|
|
66
|
+
validateDebounce: () => props.validateDebounce,
|
|
67
|
+
disabled: () => props.disabled,
|
|
68
|
+
focus: () => { triggerEl.value?.querySelector('button')?.focus() },
|
|
69
|
+
el: () => triggerEl.value,
|
|
70
|
+
setValue: (v) => emit('update:modelValue', v as string | null),
|
|
71
|
+
})
|
|
72
|
+
/** Its own `disabled` or its MForm's */
|
|
73
|
+
const isDisabled = validation.disabled
|
|
74
|
+
const { hasError, message: errorMessage, messageId } = validation
|
|
41
75
|
|
|
42
76
|
const open = ref(false)
|
|
43
77
|
const triggerEl = ref<HTMLElement | null>(null)
|
|
@@ -149,25 +183,40 @@ watch(open, (v) => {
|
|
|
149
183
|
onUnmounted(() => {
|
|
150
184
|
document.removeEventListener('mousedown', onOut)
|
|
151
185
|
})
|
|
186
|
+
|
|
187
|
+
defineExpose({
|
|
188
|
+
/** Checks its rules and shows the result; resolves to whether they pass */
|
|
189
|
+
validate: validation.validate,
|
|
190
|
+
/** Hides its validation error (until the next check) */
|
|
191
|
+
resetValidation: validation.resetValidation,
|
|
192
|
+
})
|
|
193
|
+
|
|
194
|
+
// Last: it watches `open`, declared above
|
|
195
|
+
const onFocusOut = useFocusLeave(() => rootEl.value, () => {
|
|
196
|
+
validation.onBlur()
|
|
197
|
+
emit('blur')
|
|
198
|
+
}, () => open.value)
|
|
152
199
|
</script>
|
|
153
200
|
|
|
154
201
|
<template>
|
|
155
|
-
<div class="flex flex-col gap-1">
|
|
202
|
+
<div ref="rootEl" class="flex flex-col gap-1" @focusout="onFocusOut">
|
|
156
203
|
<div ref="triggerEl" class="relative mt-2" :style="{ '--field-bg': resolvedFieldBg }">
|
|
157
204
|
<button
|
|
205
|
+
:aria-invalid="hasError || undefined"
|
|
206
|
+
:aria-describedby="errorMessage || hint ? messageId : undefined"
|
|
158
207
|
type="button"
|
|
159
208
|
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"
|
|
160
209
|
:class="[
|
|
161
|
-
|
|
162
|
-
!
|
|
163
|
-
?
|
|
164
|
-
:
|
|
210
|
+
isDisabled ? 'pointer-events-none cursor-not-allowed border-on-surface/12' : 'cursor-pointer',
|
|
211
|
+
!isDisabled && (open
|
|
212
|
+
? hasError ? 'border-2 border-error' : 'border-2 border-primary'
|
|
213
|
+
: hasError ? 'border-error' : 'border-outline hover:border-on-surface'),
|
|
165
214
|
]"
|
|
166
|
-
@click="!
|
|
215
|
+
@click="!isDisabled && (open = !open)"
|
|
167
216
|
>
|
|
168
|
-
<MIcon name="schedule" :size="24" class="shrink-0" :class="
|
|
169
|
-
<span v-overflow-title v-if="displayValue" class="min-w-0 truncate flex-1 font-mono" :class="
|
|
170
|
-
<span v-overflow-title v-else class="min-w-0 truncate flex-1" :class="
|
|
217
|
+
<MIcon name="schedule" :size="24" class="shrink-0" :class="isDisabled ? 'text-on-surface/38' : 'text-on-surface-variant'" />
|
|
218
|
+
<span v-overflow-title v-if="displayValue" class="min-w-0 truncate flex-1 font-mono" :class="isDisabled ? 'text-on-surface/38' : 'text-on-surface'">{{ displayValue }}</span>
|
|
219
|
+
<span v-overflow-title v-else class="min-w-0 truncate flex-1" :class="isDisabled ? 'text-on-surface/38' : 'text-on-surface-variant'">{{ label || placeholder || locale.selectTime }}</span>
|
|
171
220
|
<MIcon
|
|
172
221
|
v-if="modelValue"
|
|
173
222
|
name="close"
|
|
@@ -178,14 +227,14 @@ onUnmounted(() => {
|
|
|
178
227
|
</button>
|
|
179
228
|
<label
|
|
180
229
|
v-if="label"
|
|
181
|
-
:class="[OUTLINED_FLOATED_LABEL, 'transition-colors',
|
|
230
|
+
:class="[OUTLINED_FLOATED_LABEL, 'transition-colors', isDisabled ? 'text-on-surface/38' : open ? (hasError ? 'text-error' : 'text-primary') : hasError ? 'text-error' : 'text-on-surface-variant']"
|
|
182
231
|
>
|
|
183
|
-
{{ label }}
|
|
232
|
+
{{ label }}<span v-if="required" class="text-error"> *</span>
|
|
184
233
|
</label>
|
|
185
234
|
</div>
|
|
186
235
|
|
|
187
|
-
<p v-if="
|
|
188
|
-
<p v-else-if="hint" class="px-4 text-body-small text-on-surface-variant">{{ hint }}</p>
|
|
236
|
+
<p v-if="errorMessage" :id="messageId" role="alert" class="px-4 text-body-small text-error">{{ errorMessage }}</p>
|
|
237
|
+
<p v-else-if="hint" :id="messageId" class="px-4 text-body-small text-on-surface-variant">{{ hint }}</p>
|
|
189
238
|
|
|
190
239
|
<Teleport to="body">
|
|
191
240
|
<Transition
|