2022-09-06 12:03:37 +00:00
|
|
|
<template>
|
2024-01-12 07:07:55 +00:00
|
|
|
<div :class="cx('root')" v-bind="getPTOptions('root')" data-pc-name="tristatecheckbox" :data-p-highlight="active" :data-p-disabled="disabled">
|
|
|
|
<input
|
|
|
|
:id="inputId"
|
|
|
|
type="checkbox"
|
|
|
|
:class="[cx('input'), inputClass]"
|
|
|
|
:style="inputStyle"
|
|
|
|
:value="modelValue"
|
|
|
|
:checked="checked"
|
|
|
|
:tabindex="tabindex"
|
|
|
|
:disabled="disabled"
|
|
|
|
:readonly="readonly"
|
|
|
|
:aria-labelledby="ariaLabelledby"
|
|
|
|
:aria-label="ariaLabel"
|
|
|
|
@focus="onFocus"
|
|
|
|
@blur="onBlur"
|
|
|
|
@change="onChange"
|
|
|
|
v-bind="getPTOptions('input')"
|
|
|
|
/>
|
|
|
|
<span role="status" class="p-hidden-accessible" aria-live="polite" v-bind="getPTOptions('hiddenValueLabel')" :data-p-hidden-accessible="true">{{ ariaValueLabel }}</span>
|
|
|
|
<div :class="cx('box')" v-bind="getPTOptions('box')">
|
2023-05-24 14:39:47 +00:00
|
|
|
<slot v-if="modelValue === true" name="checkicon" :class="cx('checkIcon')">
|
2024-01-12 07:07:55 +00:00
|
|
|
<CheckIcon :class="cx('checkIcon')" v-bind="getPTOptions('checkIcon')" />
|
2023-04-04 12:42:13 +00:00
|
|
|
</slot>
|
2023-05-24 14:39:47 +00:00
|
|
|
<slot v-else-if="modelValue === false" name="uncheckicon" :class="cx('uncheckIcon')">
|
2024-01-12 07:07:55 +00:00
|
|
|
<TimesIcon :class="cx('uncheckIcon')" v-bind="getPTOptions('uncheckIcon')" />
|
2023-04-14 12:28:17 +00:00
|
|
|
</slot>
|
2024-01-12 07:07:55 +00:00
|
|
|
<slot v-else name="nullableicon" :class="cx('nullableIcon')" />
|
2022-09-06 12:03:37 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2023-04-18 12:53:43 +00:00
|
|
|
import CheckIcon from 'primevue/icons/check';
|
|
|
|
import TimesIcon from 'primevue/icons/times';
|
2023-05-24 14:39:47 +00:00
|
|
|
import BaseTriStateCheckbox from './BaseTriStateCheckbox.vue';
|
2023-04-04 12:42:13 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
export default {
|
|
|
|
name: 'TriStateCheckbox',
|
2023-05-24 14:39:47 +00:00
|
|
|
extends: BaseTriStateCheckbox,
|
2024-01-12 07:07:55 +00:00
|
|
|
emits: ['update:modelValue', 'change', 'focus', 'blur'],
|
2022-09-06 12:03:37 +00:00
|
|
|
methods: {
|
2023-05-09 09:17:12 +00:00
|
|
|
getPTOptions(key) {
|
|
|
|
return this.ptm(key, {
|
|
|
|
context: {
|
2024-01-12 07:07:55 +00:00
|
|
|
active: this.active,
|
2023-05-09 09:17:12 +00:00
|
|
|
disabled: this.disabled
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
2022-09-06 12:03:37 +00:00
|
|
|
updateModel() {
|
2024-01-12 07:07:55 +00:00
|
|
|
let newValue;
|
2022-09-06 12:03:37 +00:00
|
|
|
|
2024-01-12 07:07:55 +00:00
|
|
|
switch (this.modelValue) {
|
|
|
|
case true:
|
|
|
|
newValue = false;
|
|
|
|
break;
|
2022-09-06 12:03:37 +00:00
|
|
|
|
2024-01-12 07:07:55 +00:00
|
|
|
case false:
|
|
|
|
newValue = null;
|
|
|
|
break;
|
2022-09-06 12:03:37 +00:00
|
|
|
|
2024-01-12 07:07:55 +00:00
|
|
|
default:
|
|
|
|
newValue = true;
|
|
|
|
break;
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
2024-01-12 07:07:55 +00:00
|
|
|
|
|
|
|
this.$emit('update:modelValue', newValue);
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
2024-01-12 07:07:55 +00:00
|
|
|
onChange(event) {
|
|
|
|
if (!this.disabled && !this.readonly) {
|
2022-09-06 12:03:37 +00:00
|
|
|
this.updateModel();
|
2024-01-12 07:07:55 +00:00
|
|
|
this.$emit('change', event);
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
onFocus(event) {
|
|
|
|
this.$emit('focus', event);
|
|
|
|
},
|
|
|
|
onBlur(event) {
|
|
|
|
this.$emit('blur', event);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
computed: {
|
2024-01-12 07:07:55 +00:00
|
|
|
active() {
|
|
|
|
return this.modelValue != null;
|
|
|
|
},
|
|
|
|
checked() {
|
|
|
|
return this.modelValue === true;
|
|
|
|
},
|
2022-09-06 12:03:37 +00:00
|
|
|
ariaValueLabel() {
|
2022-09-14 11:26:01 +00:00
|
|
|
return this.modelValue ? this.$primevue.config.locale.aria.trueLabel : this.modelValue === false ? this.$primevue.config.locale.aria.falseLabel : this.$primevue.config.locale.aria.nullLabel;
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
2023-04-04 12:42:13 +00:00
|
|
|
},
|
|
|
|
components: {
|
2024-01-12 07:07:55 +00:00
|
|
|
CheckIcon,
|
|
|
|
TimesIcon
|
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>
|