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

155 lines (147 loc) 4.7 kB
import { ObjectUtils } from 'primevue/utils'; import { openBlock, createElementBlock, normalizeClass, createElementVNode, mergeProps, normalizeStyle } from 'vue'; var script = { name: 'Checkbox', emits: ['click', 'update:modelValue', 'change', 'input', 'focus', 'blur'], props: { value: null, modelValue: null, binary: Boolean, name: { type: String, default: null }, trueValue: { type: null, default: true }, falseValue: { type: null, default: false }, disabled: { type: Boolean, default: false }, readonly: { type: Boolean, default: false }, required: { type: Boolean, default: false }, tabindex: { type: Number, default: null }, inputId: { type: String, default: null }, inputClass: { type: [String, Object], default: null }, inputStyle: { type: Object, default: null }, inputProps: { type: null, default: null }, 'aria-labelledby': { type: String, default: null }, 'aria-label': { type: String, default: null } }, data() { return { focused: false }; }, methods: { onClick(event) { if (!this.disabled && !this.readonly) { let newModelValue; if (this.binary) { newModelValue = this.checked ? this.falseValue : this.trueValue; } else { if (this.checked) newModelValue = this.modelValue.filter((val) => !ObjectUtils.equals(val, this.value)); else newModelValue = this.modelValue ? [...this.modelValue, this.value] : [this.value]; } this.$emit('click', event); this.$emit('update:modelValue', newModelValue); this.$emit('change', event); this.$emit('input', newModelValue); this.$refs.input.focus(); } }, onFocus(event) { this.focused = true; this.$emit('focus', event); }, onBlur(event) { this.focused = false; this.$emit('blur', event); } }, computed: { checked() { return this.binary ? this.modelValue === this.trueValue : ObjectUtils.contains(this.value, this.modelValue); }, containerClass() { return [ 'p-checkbox p-component', { 'p-checkbox-checked': this.checked, 'p-checkbox-disabled': this.disabled, 'p-checkbox-focused': this.focused } ]; } } }; const _hoisted_1 = { class: "p-hidden-accessible" }; const _hoisted_2 = ["id", "value", "name", "checked", "tabindex", "disabled", "readonly", "required", "aria-labelledby", "aria-label"]; function render(_ctx, _cache, $props, $setup, $data, $options) { return (openBlock(), createElementBlock("div", { class: normalizeClass($options.containerClass), onClick: _cache[2] || (_cache[2] = $event => ($options.onClick($event))) }, [ createElementVNode("div", _hoisted_1, [ createElementVNode("input", mergeProps({ ref: "input", id: $props.inputId, type: "checkbox", value: $props.value, name: $props.name, checked: $options.checked, tabindex: $props.tabindex, disabled: $props.disabled, readonly: $props.readonly, required: $props.required, "aria-labelledby": _ctx.ariaLabelledby, "aria-label": _ctx.ariaLabel, onFocus: _cache[0] || (_cache[0] = $event => ($options.onFocus($event))), onBlur: _cache[1] || (_cache[1] = $event => ($options.onBlur($event))) }, $props.inputProps), null, 16, _hoisted_2) ]), createElementVNode("div", { ref: "box", class: normalizeClass(['p-checkbox-box', $props.inputClass, { 'p-highlight': $options.checked, 'p-disabled': $props.disabled, 'p-focus': $data.focused }]), style: normalizeStyle($props.inputStyle) }, [ createElementVNode("span", { class: normalizeClass(['p-checkbox-icon', { 'pi pi-check': $options.checked }]) }, null, 2) ], 6) ], 2)) } script.render = render; export { script as default };