script[setup]: input-hash (#18416)

* script[setup]: input-hash

* Use defineComponent in options script

* Require value
This commit is contained in:
Rijk van Zanten
2023-05-02 17:56:17 -04:00
committed by GitHub
parent 1d3899555a
commit 9d76b4a2e4

View File

@@ -15,58 +15,49 @@
</template>
<script lang="ts">
import { useI18n } from 'vue-i18n';
import { defineComponent, computed, ref, watch } from 'vue';
import { defineComponent } from 'vue';
export default defineComponent({
inheritAttrs: false,
props: {
value: {
type: String,
default: null,
},
disabled: {
type: Boolean,
default: false,
},
placeholder: {
type: String,
default: null,
},
masked: {
type: Boolean,
default: false,
},
},
emits: ['input'],
setup(props, { emit }) {
const { t } = useI18n();
const isHashed = ref(false);
const localValue = ref<string | null>(null);
const internalPlaceholder = computed(() => {
return isHashed.value ? t('value_hashed') : props.placeholder;
});
watch(
() => props.value,
() => {
isHashed.value = !!(props.value && props.value.length > 0);
},
{ immediate: true }
);
return { internalPlaceholder, isHashed, localValue, emitValue };
function emitValue(newValue: string) {
emit('input', newValue);
localValue.value = newValue;
}
},
});
</script>
<script setup lang="ts">
import { computed, ref, watch } from 'vue';
import { useI18n } from 'vue-i18n';
const props = defineProps<{
value: string | null;
disabled?: boolean;
placeholder?: string;
masked?: boolean;
}>();
const emit = defineEmits(['input']);
const { t } = useI18n();
const isHashed = ref(false);
const localValue = ref<string | null>(null);
const internalPlaceholder = computed(() => {
return isHashed.value ? t('value_hashed') : props.placeholder;
});
watch(
() => props.value,
() => {
isHashed.value = !!(props.value && props.value.length > 0);
},
{ immediate: true }
);
function emitValue(newValue: string) {
emit('input', newValue);
localValue.value = newValue;
}
</script>
<style lang="scss" scoped>
.v-input {
--v-input-font-family: var(--family-monospace);