240 lines
9.1 KiB
JavaScript
240 lines
9.1 KiB
JavaScript
import { cn } from '@primeuix/utils';
|
|
import { contains, equals } from '@primeuix/utils/object';
|
|
import CheckIcon from '@primevue/icons/check';
|
|
import MinusIcon from '@primevue/icons/minus';
|
|
import BaseInput from '@primevue/core/baseinput';
|
|
import CheckboxStyle from 'primevue/checkbox/style';
|
|
import { resolveComponent, createElementBlock, openBlock, mergeProps, createElementVNode, renderSlot, normalizeClass, createBlock, createCommentVNode } from 'vue';
|
|
|
|
var script$1 = {
|
|
name: 'BaseCheckbox',
|
|
"extends": BaseInput,
|
|
props: {
|
|
value: null,
|
|
binary: Boolean,
|
|
indeterminate: {
|
|
type: Boolean,
|
|
"default": false
|
|
},
|
|
trueValue: {
|
|
type: null,
|
|
"default": true
|
|
},
|
|
falseValue: {
|
|
type: null,
|
|
"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
|
|
},
|
|
ariaLabelledby: {
|
|
type: String,
|
|
"default": null
|
|
},
|
|
ariaLabel: {
|
|
type: String,
|
|
"default": null
|
|
}
|
|
},
|
|
style: CheckboxStyle,
|
|
provide: function provide() {
|
|
return {
|
|
$pcCheckbox: this,
|
|
$parentInstance: this
|
|
};
|
|
}
|
|
};
|
|
|
|
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: true, configurable: true, writable: true }) : e[r] = t, e; }
|
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
|
|
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
|
|
function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
|
|
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
var script = {
|
|
name: 'Checkbox',
|
|
"extends": script$1,
|
|
inheritAttrs: false,
|
|
emits: ['change', 'focus', 'blur', 'update:indeterminate'],
|
|
inject: {
|
|
$pcCheckboxGroup: {
|
|
"default": undefined
|
|
}
|
|
},
|
|
data: function data() {
|
|
return {
|
|
d_indeterminate: this.indeterminate
|
|
};
|
|
},
|
|
watch: {
|
|
indeterminate: function indeterminate(newValue) {
|
|
this.d_indeterminate = newValue;
|
|
this.updateIndeterminate();
|
|
}
|
|
},
|
|
mounted: function mounted() {
|
|
this.updateIndeterminate();
|
|
},
|
|
updated: function updated() {
|
|
this.updateIndeterminate();
|
|
},
|
|
methods: {
|
|
getPTOptions: function getPTOptions(key) {
|
|
var _ptm = key === 'root' ? this.ptmi : this.ptm;
|
|
return _ptm(key, {
|
|
context: {
|
|
checked: this.checked,
|
|
indeterminate: this.d_indeterminate,
|
|
disabled: this.disabled
|
|
}
|
|
});
|
|
},
|
|
onChange: function onChange(event) {
|
|
var _this = this;
|
|
if (!this.disabled && !this.readonly) {
|
|
var value = this.$pcCheckboxGroup ? this.$pcCheckboxGroup.d_value : this.d_value;
|
|
var newModelValue;
|
|
if (this.binary) {
|
|
newModelValue = this.d_indeterminate ? this.trueValue : this.checked ? this.falseValue : this.trueValue;
|
|
} else {
|
|
if (this.checked || this.d_indeterminate) newModelValue = value.filter(function (val) {
|
|
return !equals(val, _this.value);
|
|
});else newModelValue = value ? [].concat(_toConsumableArray(value), [this.value]) : [this.value];
|
|
}
|
|
if (this.d_indeterminate) {
|
|
this.d_indeterminate = false;
|
|
this.$emit('update:indeterminate', this.d_indeterminate);
|
|
}
|
|
this.$pcCheckboxGroup ? this.$pcCheckboxGroup.writeValue(newModelValue, event) : this.writeValue(newModelValue, event);
|
|
this.$emit('change', event);
|
|
}
|
|
},
|
|
onFocus: function onFocus(event) {
|
|
this.$emit('focus', event);
|
|
},
|
|
onBlur: function onBlur(event) {
|
|
var _this$formField$onBlu, _this$formField;
|
|
this.$emit('blur', event);
|
|
(_this$formField$onBlu = (_this$formField = this.formField).onBlur) === null || _this$formField$onBlu === void 0 || _this$formField$onBlu.call(_this$formField, event);
|
|
},
|
|
updateIndeterminate: function updateIndeterminate() {
|
|
if (this.$refs.input) {
|
|
this.$refs.input.indeterminate = this.d_indeterminate;
|
|
}
|
|
}
|
|
},
|
|
computed: {
|
|
groupName: function groupName() {
|
|
return this.$pcCheckboxGroup ? this.$pcCheckboxGroup.groupName : this.$formName;
|
|
},
|
|
checked: function checked() {
|
|
var value = this.$pcCheckboxGroup ? this.$pcCheckboxGroup.d_value : this.d_value;
|
|
return this.d_indeterminate ? false : this.binary ? value === this.trueValue : contains(this.value, value);
|
|
},
|
|
dataP: function dataP() {
|
|
return cn(_defineProperty({
|
|
invalid: this.$invalid,
|
|
checked: this.checked,
|
|
disabled: this.disabled,
|
|
filled: this.$variant === 'filled'
|
|
}, this.size, this.size));
|
|
}
|
|
},
|
|
components: {
|
|
CheckIcon: CheckIcon,
|
|
MinusIcon: MinusIcon
|
|
}
|
|
};
|
|
|
|
var _hoisted_1 = ["data-p-checked", "data-p-indeterminate", "data-p-disabled", "data-p"];
|
|
var _hoisted_2 = ["id", "value", "name", "checked", "tabindex", "disabled", "readonly", "required", "aria-labelledby", "aria-label", "aria-invalid"];
|
|
var _hoisted_3 = ["data-p"];
|
|
function render(_ctx, _cache, $props, $setup, $data, $options) {
|
|
var _component_CheckIcon = resolveComponent("CheckIcon");
|
|
var _component_MinusIcon = resolveComponent("MinusIcon");
|
|
return openBlock(), createElementBlock("div", mergeProps({
|
|
"class": _ctx.cx('root')
|
|
}, $options.getPTOptions('root'), {
|
|
"data-p-checked": $options.checked,
|
|
"data-p-indeterminate": $data.d_indeterminate || undefined,
|
|
"data-p-disabled": _ctx.disabled,
|
|
"data-p": $options.dataP
|
|
}), [createElementVNode("input", mergeProps({
|
|
ref: "input",
|
|
id: _ctx.inputId,
|
|
type: "checkbox",
|
|
"class": [_ctx.cx('input'), _ctx.inputClass],
|
|
style: _ctx.inputStyle,
|
|
value: _ctx.value,
|
|
name: $options.groupName,
|
|
checked: $options.checked,
|
|
tabindex: _ctx.tabindex,
|
|
disabled: _ctx.disabled,
|
|
readonly: _ctx.readonly,
|
|
required: _ctx.required,
|
|
"aria-labelledby": _ctx.ariaLabelledby,
|
|
"aria-label": _ctx.ariaLabel,
|
|
"aria-invalid": _ctx.invalid || undefined,
|
|
onFocus: _cache[0] || (_cache[0] = function () {
|
|
return $options.onFocus && $options.onFocus.apply($options, arguments);
|
|
}),
|
|
onBlur: _cache[1] || (_cache[1] = function () {
|
|
return $options.onBlur && $options.onBlur.apply($options, arguments);
|
|
}),
|
|
onChange: _cache[2] || (_cache[2] = function () {
|
|
return $options.onChange && $options.onChange.apply($options, arguments);
|
|
})
|
|
}, $options.getPTOptions('input')), null, 16, _hoisted_2), createElementVNode("div", mergeProps({
|
|
"class": _ctx.cx('box')
|
|
}, $options.getPTOptions('box'), {
|
|
"data-p": $options.dataP
|
|
}), [renderSlot(_ctx.$slots, "icon", {
|
|
checked: $options.checked,
|
|
indeterminate: $data.d_indeterminate,
|
|
"class": normalizeClass(_ctx.cx('icon')),
|
|
dataP: $options.dataP
|
|
}, function () {
|
|
return [$options.checked ? (openBlock(), createBlock(_component_CheckIcon, mergeProps({
|
|
key: 0,
|
|
"class": _ctx.cx('icon')
|
|
}, $options.getPTOptions('icon'), {
|
|
"data-p": $options.dataP
|
|
}), null, 16, ["class", "data-p"])) : $data.d_indeterminate ? (openBlock(), createBlock(_component_MinusIcon, mergeProps({
|
|
key: 1,
|
|
"class": _ctx.cx('icon')
|
|
}, $options.getPTOptions('icon'), {
|
|
"data-p": $options.dataP
|
|
}), null, 16, ["class", "data-p"])) : createCommentVNode("", true)];
|
|
})], 16, _hoisted_3)], 16, _hoisted_1);
|
|
}
|
|
|
|
script.render = render;
|
|
|
|
export { script as default };
|
|
//# sourceMappingURL=index.mjs.map
|