/** * Common part of Checkbox & Radio */ import Icon from '../icon'; import { ChildrenMixin } from './relation'; import { addUnit } from '../utils'; export const CheckboxMixin = ({ parent, bem, role }) => ({ mixins: [ChildrenMixin(parent)], props: { name: null, value: null, disabled: Boolean, iconSize: [Number, String], checkedColor: String, labelPosition: String, labelDisabled: Boolean, shape: { type: String, default: 'round' }, bindGroup: { type: Boolean, default: true } }, computed: { disableBindRelation() { return !this.bindGroup; }, isDisabled() { return (this.parent && this.parent.disabled) || this.disabled; }, iconStyle() { const checkedColor = this.checkedColor || (this.parent && this.parent.checkedColor); if (checkedColor && this.checked && !this.isDisabled) { return { borderColor: checkedColor, backgroundColor: checkedColor }; } }, tabindex() { if (this.isDisabled || (role === 'radio' && !this.checked)) { return -1; } return 0; } }, methods: { onClick(event) { const { label } = this.$refs; const { target } = event; const labelClicked = label && (label === target || label.contains(target)); if (!this.isDisabled && !(labelClicked && this.labelDisabled)) { this.toggle(); } this.$emit('click', event); } }, render() { const { slots, checked } = this; const CheckIcon = slots('icon', { checked }) || ( ); const Label = slots() && ( {slots()} ); const iconSize = this.iconSize || (this.parent && this.parent.iconSize); const Children = [
{CheckIcon}
]; if (this.labelPosition === 'left') { Children.unshift(Label); } else { Children.push(Label); } return (
{Children}
); } });