hongluan-ui
Version:
Hongluan Component Library for Vue 3
143 lines (140 loc) • 6.21 kB
JavaScript
import { defineComponent, useSlots, openBlock, createBlock, resolveDynamicComponent, unref, normalizeClass, withCtx, withDirectives, createElementBlock, isRef, withModifiers, vModelCheckbox, createCommentVNode, createVNode, renderSlot, Fragment, createTextVNode, toDisplayString } from 'vue';
import '../../../hooks/index.mjs';
import { HlIcon } from '../../icon/index.mjs';
import '../../system-icon/index.mjs';
import { checkboxProps, checkboxEmits } from './checkbox.mjs';
import './composables/index.mjs';
import { useNamespace } from '../../../hooks/use-namespace/index.mjs';
import { useCheckbox } from './composables/use-checkbox.mjs';
import SystemIndeterminate from '../../system-icon/src/indeterminate.mjs';
import SystemChecked from '../../system-icon/src/checked.mjs';
const __default__ = defineComponent({
name: "Checkbox"
});
const _sfc_main = /* @__PURE__ */ defineComponent({
...__default__,
props: checkboxProps,
emits: checkboxEmits,
setup(__props) {
const props = __props;
const slots = useSlots();
const { namespace } = useNamespace("checkbox");
const {
inputId,
isLabeledByFormItem,
isChecked,
isDisabled,
isFocused,
isCustom,
isRound,
isFill,
checkboxType,
checkboxSize,
hasOwnLabel,
model,
actualValue,
handleChange,
onClickRoot
} = useCheckbox(props, slots);
return (_ctx, _cache) => {
return openBlock(), createBlock(resolveDynamicComponent(!unref(hasOwnLabel) && unref(isLabeledByFormItem) ? "span" : "label"), {
class: normalizeClass([
unref(namespace),
unref(checkboxType) || "",
unref(checkboxSize) || "",
{ "round": unref(isRound) },
{ "fill": unref(isFill) },
{ "is-disabled": unref(isDisabled) },
{ "is-checked": unref(isChecked) },
{ "is-indeterminate": _ctx.indeterminate },
{ "is-focus": unref(isFocused) },
{ "custom": unref(isCustom) },
{ "show-label": _ctx.showLabel }
]),
"aria-controls": _ctx.indeterminate ? _ctx.controls || _ctx.ariaControls : null,
tabindex: _ctx.indeterminate ? 0 : void 0,
role: _ctx.indeterminate ? "checkbox" : void 0,
"aria-checked": _ctx.indeterminate ? "mixed" : void 0,
onClick: unref(onClickRoot)
}, {
default: withCtx(() => {
var _a, _b;
return [
_ctx.trueValue || _ctx.falseValue || _ctx.trueLabel || _ctx.falseLabel ? withDirectives((openBlock(), createElementBlock("input", {
key: 0,
id: unref(inputId),
"onUpdate:modelValue": ($event) => isRef(model) ? model.value = $event : null,
class: "checkbox-input",
type: "checkbox",
indeterminate: _ctx.indeterminate,
name: _ctx.name,
tabindex: _ctx.tabindex,
disabled: unref(isDisabled),
"true-value": (_a = _ctx.trueValue) != null ? _a : _ctx.trueLabel,
"false-value": (_b = _ctx.falseValue) != null ? _b : _ctx.falseLabel,
onChange: unref(handleChange),
onFocus: ($event) => isFocused.value = true,
onBlur: ($event) => isFocused.value = false,
onClick: withModifiers(() => {
}, ["stop"])
}, null, 40, ["id", "onUpdate:modelValue", "indeterminate", "name", "tabindex", "disabled", "true-value", "false-value", "onChange", "onFocus", "onBlur", "onClick"])), [
[vModelCheckbox, unref(model)]
]) : withDirectives((openBlock(), createElementBlock("input", {
key: 1,
id: unref(inputId),
"onUpdate:modelValue": ($event) => isRef(model) ? model.value = $event : null,
class: "checkbox-input",
type: "checkbox",
indeterminate: _ctx.indeterminate,
disabled: unref(isDisabled),
value: unref(actualValue),
name: _ctx.name,
tabindex: _ctx.tabindex,
onChange: unref(handleChange),
onFocus: ($event) => isFocused.value = true,
onBlur: ($event) => isFocused.value = false,
onClick: withModifiers(() => {
}, ["stop"])
}, null, 40, ["id", "onUpdate:modelValue", "indeterminate", "disabled", "value", "name", "tabindex", "onChange", "onFocus", "onBlur", "onClick"])), [
[vModelCheckbox, unref(model)]
]),
!unref(isCustom) ? (openBlock(), createElementBlock("em", {
key: 2,
class: "checkbox-inner"
}, [
_ctx.indeterminate ? (openBlock(), createBlock(unref(HlIcon), {
key: 0,
class: "icon-indeterminate"
}, {
default: withCtx(() => [
_ctx.indeterminate ? (openBlock(), createBlock(unref(SystemIndeterminate), { key: 0 })) : createCommentVNode("v-if", true)
]),
_: 1
})) : (openBlock(), createBlock(unref(HlIcon), {
key: 1,
class: "icon-checked"
}, {
default: withCtx(() => [
createVNode(unref(SystemChecked))
]),
_: 1
}))
])) : createCommentVNode("v-if", true),
unref(isCustom) ? renderSlot(_ctx.$slots, "default", { key: 3 }) : unref(hasOwnLabel) && _ctx.showLabel ? (openBlock(), createElementBlock("span", {
key: 4,
class: "checkbox-label"
}, [
renderSlot(_ctx.$slots, "default"),
!_ctx.$slots.default ? (openBlock(), createElementBlock(Fragment, { key: 0 }, [
createTextVNode(toDisplayString(_ctx.label), 1)
], 2112)) : createCommentVNode("v-if", true)
])) : createCommentVNode("v-if", true)
];
}),
_: 3
}, 8, ["class", "aria-controls", "tabindex", "role", "aria-checked", "onClick"]);
};
}
});
export { _sfc_main as default };
//# sourceMappingURL=checkbox2.mjs.map