Refactor #3965 - For InputMask

pull/3997/head
Tuğçe Küçükoğlu 2023-05-24 13:28:20 +03:00
parent 98599434e8
commit c51d223526
3 changed files with 65 additions and 34 deletions

View File

@ -0,0 +1,57 @@
<script>
import BaseComponent from 'primevue/basecomponent';
import { useStyle } from 'primevue/usestyle';
const styles = `
`;
const classes = {
root: ({ instance }) => [
'p-inputmask p-inputtext p-component',
{
'p-filled': instance.filled
}
]
};
const { load: loadStyle, unload: unloadStyle } = useStyle(styles, { id: 'primevue_inputmask_style', manual: true });
export default {
name: 'BaseInputMask',
extends: BaseComponent,
props: {
modelValue: null,
slotChar: {
type: String,
default: '_'
},
mask: {
type: String,
default: null
},
autoClear: {
type: Boolean,
default: true
},
unmask: {
type: Boolean,
default: false
},
readonly: {
type: Boolean,
default: false
}
},
css: {
classes
},
watch: {
isUnstyled: {
immediate: true,
handler(newValue) {
!newValue && loadStyle();
}
}
}
};
</script>

View File

@ -66,6 +66,11 @@ export interface InputMaskProps {
* @type {InputMaskPassThroughOptions} * @type {InputMaskPassThroughOptions}
*/ */
pt?: InputMaskPassThroughOptions; pt?: InputMaskPassThroughOptions;
/**
* When enabled, it removes component related styles in the core.
* @defaultValue false
*/
unstyled?: boolean;
} }
export interface InputMaskSlots {} export interface InputMaskSlots {}

View File

@ -1,38 +1,15 @@
<template> <template>
<input :class="inputClass" :readonly="readonly" @input="onInput" @focus="onFocus" @blur="onBlur" @keydown="onKeyDown" @keypress="onKeyPress" @paste="onPaste" v-bind="ptm('root')" /> <input :class="cx('root')" :readonly="readonly" @input="onInput" @focus="onFocus" @blur="onBlur" @keydown="onKeyDown" @keypress="onKeyPress" @paste="onPaste" v-bind="ptm('root')" />
</template> </template>
<script> <script>
import BaseComponent from 'primevue/basecomponent';
import { DomHandler } from 'primevue/utils'; import { DomHandler } from 'primevue/utils';
import BaseInputMask from './BaseInputMask.vue';
export default { export default {
name: 'InputMask', name: 'InputMask',
extends: BaseComponent, extends: BaseInputMask,
emits: ['update:modelValue', 'focus', 'blur', 'keydown', 'complete', 'keypress', 'paste'], emits: ['update:modelValue', 'focus', 'blur', 'keydown', 'complete', 'keypress', 'paste'],
props: {
modelValue: null,
slotChar: {
type: String,
default: '_'
},
mask: {
type: String,
default: null
},
autoClear: {
type: Boolean,
default: true
},
unmask: {
type: Boolean,
default: false
},
readonly: {
type: Boolean,
default: false
}
},
watch: { watch: {
mask(newMask, oldMask) { mask(newMask, oldMask) {
if (oldMask !== newMask) { if (oldMask !== newMask) {
@ -519,14 +496,6 @@ export default {
computed: { computed: {
filled() { filled() {
return this.modelValue != null && this.modelValue.toString().length > 0; return this.modelValue != null && this.modelValue.toString().length > 0;
},
inputClass() {
return [
'p-inputmask p-inputtext p-component',
{
'p-filled': this.filled
}
];
} }
} }
}; };