-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: improve
tera-toggleable-input
(#4464)
- Loading branch information
Showing
6 changed files
with
173 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 0 additions & 49 deletions
49
packages/client/hmi-client/src/components/widgets/tera-toggleable-edit.vue
This file was deleted.
Oops, something went wrong.
77 changes: 77 additions & 0 deletions
77
packages/client/hmi-client/src/components/widgets/tera-toggleable-input.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<template> | ||
<div v-if="isEditing" v-bind="$attrs" class="flex align-items-center gap-1"> | ||
<tera-input-text | ||
ref="inputRef" | ||
:model-value="modelValue" | ||
@update:model-value="emit('update:model-value', $event)" | ||
@keydown="handleKeyDown" | ||
/> | ||
<Button text icon="pi pi-times" @click="onCancel" /> | ||
<Button text icon="pi pi-check" @click="onConfirm" /> | ||
</div> | ||
<Button v-else :class="$attrs.class" class="text-to-edit" text @click="onEdit"> | ||
<component class="btn-content" :is="tag">{{ modelValue }}</component> | ||
<i class="pi pi-pencil" /> | ||
</Button> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { ref, nextTick, ComponentPublicInstance } from 'vue'; | ||
import Button from 'primevue/button'; | ||
import TeraInputText from '@/components/widgets/tera-input-text.vue'; | ||
const props = withDefaults( | ||
defineProps<{ | ||
modelValue: string; | ||
tag: 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6' | 'p' | 'span'; | ||
}>(), | ||
{ | ||
tag: 'span' | ||
} | ||
); | ||
const emit = defineEmits(['update:model-value']); | ||
let initialValue = ''; | ||
const inputRef = ref<ComponentPublicInstance<typeof TeraInputText> | null>(null); | ||
const isEditing = ref(false); | ||
const onEdit = async () => { | ||
initialValue = props.modelValue; | ||
isEditing.value = true; | ||
await nextTick(); | ||
inputRef.value?.$el.querySelector('input')?.focus(); | ||
}; | ||
const onConfirm = () => { | ||
isEditing.value = false; | ||
}; | ||
const onCancel = () => { | ||
emit('update:model-value', initialValue); // Revert changes | ||
isEditing.value = false; | ||
}; | ||
const handleKeyDown = (event: KeyboardEvent) => { | ||
if (event.key === 'Enter') onConfirm(); | ||
else if (event.key === 'Escape') onCancel(); | ||
}; | ||
</script> | ||
|
||
<style scoped> | ||
button.text-to-edit { | ||
display: flex; | ||
gap: var(--gap-3); | ||
width: fit-content; | ||
padding: var(--gap-2); | ||
& > .btn-content { | ||
color: var(--text-color); | ||
} | ||
& > .pi { | ||
color: var(--text-color-subdued); | ||
} | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.