mirror of
https://github.com/directus/directus.git
synced 2026-04-03 03:00:39 -04:00
script[setup]: input-hash (#18416)
* script[setup]: input-hash * Use defineComponent in options script * Require value
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user