2022-09-06 12:03:37 +00:00
|
|
|
<template>
|
2023-03-17 08:47:12 +00:00
|
|
|
<div v-focustrap :class="containerClass" aria-live="polite">
|
2022-12-08 11:04:25 +00:00
|
|
|
<div v-if="!d_active" ref="display" :class="displayClass" :tabindex="$attrs.tabindex || '0'" role="button" @click="open" @keydown.enter="open" v-bind="displayProps">
|
2022-09-06 12:03:37 +00:00
|
|
|
<slot name="display"></slot>
|
|
|
|
</div>
|
2022-09-14 11:26:01 +00:00
|
|
|
<div v-else class="p-inplace-content">
|
2022-09-06 12:03:37 +00:00
|
|
|
<slot name="content"></slot>
|
2023-04-13 10:32:32 +00:00
|
|
|
<IPButton v-if="closable" :aria-label="closeAriaLabel" @click="close" v-bind="closeButtonProps">
|
|
|
|
<template #icon>
|
|
|
|
<slot name="closeicon">
|
|
|
|
<component :is="closeIcon ? 'span' : 'TimesIcon'" :class="closeIcon"></component>
|
|
|
|
</slot>
|
|
|
|
</template>
|
|
|
|
</IPButton>
|
2022-09-06 12:03:37 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
import Button from 'primevue/button';
|
2023-03-17 08:47:12 +00:00
|
|
|
import FocusTrap from 'primevue/focustrap';
|
2023-04-13 10:32:32 +00:00
|
|
|
import TimesIcon from 'primevue/icon/times';
|
2022-09-06 12:03:37 +00:00
|
|
|
export default {
|
|
|
|
name: 'Inplace',
|
|
|
|
emits: ['open', 'close', 'update:active'],
|
|
|
|
props: {
|
|
|
|
closable: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false
|
|
|
|
},
|
|
|
|
active: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false
|
|
|
|
},
|
|
|
|
disabled: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false
|
2022-12-08 11:04:25 +00:00
|
|
|
},
|
|
|
|
closeIcon: {
|
|
|
|
type: String,
|
2023-04-13 10:32:32 +00:00
|
|
|
default: undefined
|
2022-12-08 11:04:25 +00:00
|
|
|
},
|
|
|
|
displayProps: {
|
|
|
|
type: null,
|
|
|
|
default: null
|
|
|
|
},
|
|
|
|
closeButtonProps: {
|
|
|
|
type: null,
|
|
|
|
default: null
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
d_active: this.active
|
2022-09-14 11:26:01 +00:00
|
|
|
};
|
|
|
|
},
|
|
|
|
watch: {
|
|
|
|
active(newValue) {
|
|
|
|
this.d_active = newValue;
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
open(event) {
|
|
|
|
if (this.disabled) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.$emit('open', event);
|
|
|
|
this.d_active = true;
|
|
|
|
this.$emit('update:active', true);
|
|
|
|
},
|
|
|
|
close(event) {
|
|
|
|
this.$emit('close', event);
|
|
|
|
this.d_active = false;
|
|
|
|
this.$emit('update:active', false);
|
2022-12-08 11:04:25 +00:00
|
|
|
setTimeout(() => {
|
|
|
|
this.$refs.display.focus();
|
|
|
|
}, 0);
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
containerClass() {
|
2022-09-14 11:26:01 +00:00
|
|
|
return ['p-inplace p-component', { 'p-inplace-closable': this.closable }];
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
|
|
|
displayClass() {
|
2022-09-14 11:26:01 +00:00
|
|
|
return ['p-inplace-display', { 'p-disabled': this.disabled }];
|
2022-12-08 11:04:25 +00:00
|
|
|
},
|
|
|
|
closeAriaLabel() {
|
|
|
|
return this.$primevue.config.locale.aria ? this.$primevue.config.locale.aria.close : undefined;
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
components: {
|
2023-04-13 10:32:32 +00:00
|
|
|
IPButton: Button,
|
|
|
|
TimesIcon
|
2023-03-17 08:47:12 +00:00
|
|
|
},
|
|
|
|
directives: {
|
|
|
|
focustrap: FocusTrap
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
2022-09-14 11:26:01 +00:00
|
|
|
};
|
2022-09-06 12:03:37 +00:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<style>
|
|
|
|
.p-inplace .p-inplace-display {
|
|
|
|
display: inline;
|
|
|
|
cursor: pointer;
|
|
|
|
}
|
|
|
|
|
|
|
|
.p-inplace .p-inplace-content {
|
|
|
|
display: inline;
|
|
|
|
}
|
|
|
|
|
|
|
|
.p-fluid .p-inplace.p-inplace-closable .p-inplace-content {
|
|
|
|
display: flex;
|
|
|
|
}
|
|
|
|
|
|
|
|
.p-fluid .p-inplace.p-inplace-closable .p-inplace-content > .p-inputtext {
|
|
|
|
flex: 1 1 auto;
|
|
|
|
width: 1%;
|
|
|
|
}
|
|
|
|
</style>
|