2022-09-06 12:03:37 +00:00
|
|
|
<template>
|
2023-06-08 11:26:48 +00:00
|
|
|
<div :class="cx('headerCheckboxWrapper')" @click="onClick" @keydown.space.prevent="onClick" v-bind="getColumnPT('headerCheckboxWrapper')">
|
2023-07-03 22:20:35 +00:00
|
|
|
<div class="p-hidden-accessible" v-bind="getColumnPT('hiddenHeaderInputWrapper')" :data-p-hidden-accessible="true">
|
2023-05-09 14:57:31 +00:00
|
|
|
<input
|
|
|
|
ref="input"
|
|
|
|
type="checkbox"
|
|
|
|
:checked="checked"
|
|
|
|
:disabled="disabled"
|
|
|
|
:tabindex="disabled ? null : '0'"
|
|
|
|
:aria-label="headerCheckboxAriaLabel"
|
|
|
|
@focus="onFocus($event)"
|
|
|
|
@blur="onBlur($event)"
|
2023-06-05 13:45:43 +00:00
|
|
|
v-bind="getColumnPT('hiddenHeaderInput')"
|
2023-05-09 14:57:31 +00:00
|
|
|
/>
|
2022-12-08 11:04:25 +00:00
|
|
|
</div>
|
2023-06-08 11:26:48 +00:00
|
|
|
<div ref="box" :class="cx('headerCheckbox')" v-bind="getColumnPT('headerCheckbox')">
|
|
|
|
<component v-if="headerCheckboxIconTemplate" :is="headerCheckboxIconTemplate" :checked="checked" :class="cx('headerCheckboxIcon')" />
|
|
|
|
<CheckIcon v-else-if="!headerCheckboxIconTemplate && !!checked" :class="cx('headerCheckboxIcon')" v-bind="getColumnPT('headerCheckboxIcon')" />
|
2022-09-06 12:03:37 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2023-05-08 14:08:06 +00:00
|
|
|
import BaseComponent from 'primevue/basecomponent';
|
2023-04-18 12:53:43 +00:00
|
|
|
import CheckIcon from 'primevue/icons/check';
|
2022-12-08 11:04:25 +00:00
|
|
|
import { DomHandler } from 'primevue/utils';
|
2023-07-19 12:05:06 +00:00
|
|
|
import { mergeProps } from 'vue';
|
2022-12-08 11:04:25 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
export default {
|
|
|
|
name: 'HeaderCheckbox',
|
2023-06-08 11:26:48 +00:00
|
|
|
hostName: 'DataTable',
|
2023-05-08 14:08:06 +00:00
|
|
|
extends: BaseComponent,
|
2022-09-06 12:03:37 +00:00
|
|
|
emits: ['change'],
|
|
|
|
props: {
|
2022-12-08 11:04:25 +00:00
|
|
|
checked: null,
|
2023-04-13 14:42:33 +00:00
|
|
|
disabled: null,
|
2023-05-09 14:57:31 +00:00
|
|
|
column: null,
|
2023-04-13 14:42:33 +00:00
|
|
|
headerCheckboxIconTemplate: {
|
2023-04-13 18:05:42 +00:00
|
|
|
type: Function,
|
2023-04-13 14:42:33 +00:00
|
|
|
default: null
|
|
|
|
}
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
focused: false
|
|
|
|
};
|
|
|
|
},
|
|
|
|
methods: {
|
2023-06-05 13:45:43 +00:00
|
|
|
getColumnPT(key) {
|
2023-07-19 12:05:06 +00:00
|
|
|
const columnMetaData = {
|
2023-05-09 14:57:31 +00:00
|
|
|
props: this.column.props,
|
|
|
|
parent: {
|
2023-12-05 11:06:32 +00:00
|
|
|
instance: this,
|
2023-05-09 14:57:31 +00:00
|
|
|
props: this.$props,
|
|
|
|
state: this.$data
|
|
|
|
},
|
2023-05-08 14:08:06 +00:00
|
|
|
context: {
|
|
|
|
checked: this.checked,
|
|
|
|
focused: this.focused,
|
|
|
|
disabled: this.disabled
|
|
|
|
}
|
2023-07-19 12:05:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
return mergeProps(this.ptm(`column.${key}`, { column: columnMetaData }), this.ptm(`column.${key}`, columnMetaData), this.ptmo(this.getColumnProp(), key, columnMetaData));
|
2023-05-08 14:08:06 +00:00
|
|
|
},
|
2023-05-09 14:57:31 +00:00
|
|
|
getColumnProp() {
|
|
|
|
return this.column.props && this.column.props.pt ? this.column.props.pt : undefined; //@todo:
|
|
|
|
},
|
2022-09-06 12:03:37 +00:00
|
|
|
onClick(event) {
|
2022-12-08 11:04:25 +00:00
|
|
|
if (!this.disabled) {
|
2022-09-06 12:03:37 +00:00
|
|
|
this.$emit('change', {
|
|
|
|
originalEvent: event,
|
|
|
|
checked: !this.checked
|
|
|
|
});
|
2022-12-08 11:04:25 +00:00
|
|
|
|
|
|
|
DomHandler.focus(this.$refs.input);
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
onFocus() {
|
|
|
|
this.focused = true;
|
|
|
|
},
|
|
|
|
onBlur() {
|
|
|
|
this.focused = false;
|
|
|
|
}
|
2022-12-08 11:04:25 +00:00
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
headerCheckboxAriaLabel() {
|
|
|
|
return this.$primevue.config.locale.aria ? (this.checked ? this.$primevue.config.locale.aria.selectAll : this.$primevue.config.locale.aria.unselectAll) : undefined;
|
|
|
|
}
|
2023-04-13 14:42:33 +00:00
|
|
|
},
|
|
|
|
components: {
|
|
|
|
CheckIcon: CheckIcon
|
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>
|