feat: Add inline editing support for CRM attributes (#2241)

This commit is contained in:
Nithin David Thomas 2021-05-10 20:01:45 +05:30 committed by GitHub
parent a216297ce1
commit 627a89faf0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 41 additions and 5 deletions

View file

@ -8,7 +8,26 @@
{{ label }} {{ label }}
</h4> </h4>
</div> </div>
<div class="value-wrap"> <div v-show="isEditing">
<div class="input-group small">
<input
ref="inputfield"
v-model="editedValue"
type="text"
class="input-group-field"
autofocus="true"
@keyup.enter="onUpdate"
/>
<div class="input-group-button">
<woot-button size="small" icon="ion-checkmark" @click="onUpdate" />
</div>
</div>
</div>
<div
v-show="!isEditing"
class="value--view"
:class="{ 'is-editable': showEdit }"
>
<p v-if="value" class="value"> <p v-if="value" class="value">
{{ value }} {{ value }}
</p> </p>
@ -39,9 +58,25 @@ export default {
value: { type: [String, Number], default: '' }, value: { type: [String, Number], default: '' },
showEdit: { type: Boolean, default: false }, showEdit: { type: Boolean, default: false },
}, },
data() {
return {
isEditing: false,
editedValue: this.value,
};
},
methods: { methods: {
focusInput() {
this.$refs.inputfield.focus();
},
onEdit() { onEdit() {
this.$emit('edit'); this.isEditing = true;
this.$nextTick(() => {
this.focusInput();
});
},
onUpdate() {
this.isEditing = false;
this.$emit('update', this.editedValue);
}, },
}, },
}; };
@ -54,6 +89,7 @@ export default {
.title-wrap { .title-wrap {
display: flex; display: flex;
align-items: center; align-items: center;
margin-bottom: var(--space-mini);
} }
.title { .title {
display: flex; display: flex;
@ -66,10 +102,10 @@ export default {
.edit-button { .edit-button {
display: none; display: none;
} }
.value-wrap { .value--view {
display: flex; display: flex;
&:hover { &.is-editable:hover {
.value { .value {
background: var(--color-background); background: var(--color-background);
} }

View file

@ -34,7 +34,7 @@ export default {
const Template = (args, { argTypes }) => ({ const Template = (args, { argTypes }) => ({
props: Object.keys(argTypes), props: Object.keys(argTypes),
components: { ContactAttribute }, components: { ContactAttribute },
template: '<contact-attribute v-bind="$props" @edit="onEdit" />', template: '<contact-attribute v-bind="$props" @update="onEdit" />',
}); });
export const DefaultAttribute = Template.bind({}); export const DefaultAttribute = Template.bind({});