11<script setup lang="ts">
2- import { DatePicker } from ' v-calendar '
2+ import { type MaskaDetail } from ' maska '
33import { type Component , computed } from ' vue'
44import { type Validatable } from ' ../composables/Validation'
55import { type Day , day } from ' ../support/Day'
6- import SInputBase , { type Color , type Size } from ' ./SInputBase .vue'
6+ import SInputText , { type Color , type Size } from ' ./SInputText .vue'
77
88export type { Color , Size }
99
@@ -30,26 +30,24 @@ const emit = defineEmits<{
3030}>()
3131
3232const classes = computed (() => [
33- props .size ?? ' small '
33+ props .block && ' block '
3434])
3535
3636const value = computed (() => {
3737 return props .modelValue ? day (props .modelValue ).format (' YYYY-MM-DD' ) : null
3838})
3939
40- function emitInput(date ? : string ) {
41- emit (' update:model-value' , date ? day (date ) : null )
42- }
43-
44- function onBlur() {
45- setTimeout (() => {
46- props .validation && props .validation .$touch ()
47- }, 100 )
40+ function onChange(detail : MaskaDetail ): void {
41+ if (! detail .unmasked ) {
42+ emit (' update:model-value' , null )
43+ } else if (detail .completed ) {
44+ emit (' update:model-value' , day (detail .masked ))
45+ }
4846}
4947 </script >
5048
5149<template >
52- <SInputBase
50+ <SInputText
5351 class =" SInputDate"
5452 :class =" classes"
5553 :size
@@ -58,136 +56,38 @@ function onBlur() {
5856 :note
5957 :info
6058 :help
59+ placeholder =" YYYY-MM-DD"
6160 :check-icon
6261 :check-text
6362 :check-color
64- :hide-error
63+ :disabled
64+ :tabindex
65+ :model-value =" value"
6566 :validation
67+ :hide-error
68+ :maska =" { mask: '####-##-##', eager: true }"
69+ @maska =" onChange"
6670 >
67- <div class =" container" >
68- <DatePicker
69- v-slot =" { inputValue, inputEvents }"
70- color =" blue"
71- is-dark
72- :masks =" { input: 'YYYY-MM-DD' }"
73- :model-config =" { type: 'string', mask: 'YYYY-MM-DD' }"
74- :popover =" { placement: 'bottom', visibility: 'click' }"
75- :model-value =" value"
76- @update:model-value =" emitInput"
77- >
78- <input
79- :id =" name"
80- class =" input"
81- :class =" { block, disabled }"
82- type =" text"
83- placeholder =" YYYY-MM-DD"
84- autocomplete =" off"
85- :value =" inputValue"
86- :disabled
87- :tabindex
88- v-on =" disabled ? {} : inputEvents"
89- @blur =" onBlur"
90- >
91- </DatePicker >
92- </div >
9371 <template v-if =" $slots .info " #info ><slot name =" info" /></template >
94- </SInputBase >
72+ </SInputText >
9573</template >
9674
9775<style lang="postcss" scoped>
98- .SInputDate.sm ,
99- .SInputDate.mini {
100- .input {
101- padding : 3 px 8 px ;
102- max-width : 114 px ;
103- height : 32 px ;
104- line-height : 24 px ;
105- font-size : var (--input-font-size, var (--input-mini-font-size ));
106- }
107-
108- .input.block {
109- max-width : 100 % ;
110- }
76+ .SInputDate.sm :deep (.box),
77+ .SInputDate.mini :deep (.box) {
78+ max-width : 114 px ;
11179}
11280
113- .SInputDate.md {
114- .input {
115- padding : 6 px 10 px ;
116- max-width : 120 px ;
117- height : 36 px ;
118- line-height : 24 px ;
119- font-size : var (--input-font-size, var (--input-small-font-size ));
120- }
121-
122- .input.block {
123- max-width : 100 % ;
124- }
81+ .SInputDate.md :deep (.box) {
82+ max-width : 120 px ;
12583}
12684
127- .SInputDate.small {
128- .input {
129- padding : 5 px 12 px ;
130- max-width : 136 px ;
131- height : 40 px ;
132- line-height : 24 px ;
133- font-size : var (--input-font-size, 14 px );
134- }
135-
136- .input.block {
137- max-width : 100 % ;
138- }
85+ .SInputDate.small :deep (.box),
86+ .SInputDate.medium :deep (.box) {
87+ max-width : 136 px ;
13988}
14089
141- .SInputDate.medium {
142- .input {
143- padding : 11 px 12 px ;
144- max-width : 136 px ;
145- height : 48 px ;
146- line-height : 24 px ;
147- font-size : var (--input-font-size, var (--input-medium-font-size ));
148- }
149-
150- .input.block {
151- max-width : 100 % ;
152- }
153- }
154-
155- .SInputDate.has-error {
156- .input {
157- border-color : var (--input-error-border-color );
158-
159- &:focus {
160- border-color : var (--input-error-border-color );
161- }
162- }
163- }
164-
165- .input {
166- display : block;
167- border : 1 px solid var (--input-border-color );
168- border-radius : 6 px ;
169- width : 100 % ;
170- font-weight : 400 ;
171- font-feature-settings : 'tnum' ;
172- background-color : var (--input-bg-color );
173- transition : border-color 0.25 s , background-color 0.25 s ;
174-
175- &::placeholder {
176- color : var (--input-placeholder-color );
177- }
178-
179- &:hover {
180- border-color : var (--input-hover-border-color );
181- }
182-
183- &:focus {
184- border-color : var (--input-focus-border-color );
185- }
186-
187- & .disabled {
188- border-color : var (--input-disabled-border-color );
189- background-color : var (--input-disabled-bg-color );
190- cursor : not-allowed;
191- }
90+ .SInputDate.block :deep (.box) {
91+ max-width : 100 % ;
19292}
19393 </style >
0 commit comments