UNPKG

primevue

Version:

[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![npm version](https://badge.fury.io/js/primevue.svg)](https://badge.fury.io/js/primevue) [![Discord Chat](https://img.shields.io/discord/55794023

163 lines (150 loc) 5.95 kB
this.primevue = this.primevue || {}; this.primevue.tristatecheckbox = (function (CheckIcon, TimesIcon, vue) { 'use strict'; function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } var CheckIcon__default = /*#__PURE__*/_interopDefaultLegacy(CheckIcon); var TimesIcon__default = /*#__PURE__*/_interopDefaultLegacy(TimesIcon); var script = { name: 'TriStateCheckbox', emits: ['click', 'update:modelValue', 'change', 'keydown', 'focus', 'blur'], props: { modelValue: null, inputId: { type: String, default: null }, inputProps: { type: null, default: null }, disabled: { type: Boolean, default: false }, tabindex: { type: Number, default: 0 }, 'aria-labelledby': { type: String, default: null }, 'aria-label': { type: String, default: null } }, data() { return { focused: false }; }, methods: { updateModel() { if (!this.disabled) { let newValue; switch (this.modelValue) { case true: newValue = false; break; case false: newValue = null; break; default: newValue = true; break; } this.$emit('update:modelValue', newValue); } }, onClick(event) { this.updateModel(); this.$emit('click', event); this.$emit('change', event); this.$refs.input.focus(); }, onKeyDown(event) { if (event.code === 'Enter') { this.updateModel(); this.$emit('keydown', event); event.preventDefault(); } }, onFocus(event) { this.focused = true; this.$emit('focus', event); }, onBlur(event) { this.focused = false; this.$emit('blur', event); } }, computed: { containerClass() { return [ 'p-checkbox p-component', { 'p-checkbox-checked': this.modelValue === true, 'p-checkbox-disabled': this.disabled, 'p-checkbox-focused': this.focused } ]; }, ariaValueLabel() { return this.modelValue ? this.$primevue.config.locale.aria.trueLabel : this.modelValue === false ? this.$primevue.config.locale.aria.falseLabel : this.$primevue.config.locale.aria.nullLabel; } }, components: { CheckIcon: CheckIcon__default["default"], TimesIcon: TimesIcon__default["default"] } }; const _hoisted_1 = { class: "p-hidden-accessible" }; const _hoisted_2 = ["id", "checked", "tabindex", "disabled", "aria-labelledby", "aria-label"]; const _hoisted_3 = { class: "p-sr-only", "aria-live": "polite" }; const _hoisted_4 = /*#__PURE__*/vue.createElementVNode("span", { class: "p-checkbox-icon" }, null, -1); function render(_ctx, _cache, $props, $setup, $data, $options) { return (vue.openBlock(), vue.createElementBlock("div", { class: vue.normalizeClass($options.containerClass), onClick: _cache[3] || (_cache[3] = $event => ($options.onClick($event))) }, [ vue.createElementVNode("div", _hoisted_1, [ vue.createElementVNode("input", vue.mergeProps({ ref: "input", id: $props.inputId, type: "checkbox", checked: $props.modelValue === true, tabindex: $props.tabindex, disabled: $props.disabled, "aria-labelledby": _ctx.ariaLabelledby, "aria-label": _ctx.ariaLabel, onKeydown: _cache[0] || (_cache[0] = $event => ($options.onKeyDown($event))), onFocus: _cache[1] || (_cache[1] = $event => ($options.onFocus($event))), onBlur: _cache[2] || (_cache[2] = $event => ($options.onBlur($event))) }, $props.inputProps), null, 16, _hoisted_2) ]), vue.createElementVNode("span", _hoisted_3, vue.toDisplayString($options.ariaValueLabel), 1), vue.createElementVNode("div", { ref: "box", class: vue.normalizeClass(['p-checkbox-box', { 'p-highlight': $props.modelValue != null, 'p-disabled': $props.disabled, 'p-focus': $data.focused }]) }, [ ($props.modelValue === true) ? vue.renderSlot(_ctx.$slots, "checkicon", { key: 0 }, () => [ (vue.openBlock(), vue.createBlock(vue.resolveDynamicComponent('CheckIcon'), { class: "p-checkbox-icon" })) ]) : ($props.modelValue === false) ? vue.renderSlot(_ctx.$slots, "uncheckicon", { key: 1 }, () => [ (vue.openBlock(), vue.createBlock(vue.resolveDynamicComponent('TimesIcon'), { class: "p-checkbox-icon" })) ]) : vue.renderSlot(_ctx.$slots, "nullableicon", { key: 2 }, () => [ _hoisted_4 ]) ], 2) ], 2)) } script.render = render; return script; })(primevue.icons.check, primevue.icons.times, Vue);