@vuesax-alpha/nightly
Version:
A Component Library for Vue 3
122 lines (119 loc) • 4.78 kB
JavaScript
import { defineComponent, useSlots, computed, openBlock, createElementBlock, normalizeClass, normalizeStyle, createElementVNode, unref, withDirectives, mergeProps, isRef, vModelCheckbox, createBlock, renderSlot, createCommentVNode, Fragment, createTextVNode, toDisplayString } from 'vue';
import '../../../hooks/index.mjs';
import '../../../utils/index.mjs';
import { IconCheck, IconLoading } from '../../icon/index.mjs';
import { checkboxProps, checkboxEmits } from './checkbox.mjs';
import './composables/index.mjs';
import _export_sfc from '../../../_virtual/plugin-vue_export-helper.mjs';
import { useNamespace } from '../../../hooks/use-namespace/index.mjs';
import { useId } from '../../../hooks/use-id/index.mjs';
import { useCheckbox } from './composables/use-checkbox.mjs';
import { useVuesaxBaseComponent } from '../../../hooks/use-base-component/index.mjs';
import { useColor } from '../../../hooks/use-common-props/index.mjs';
import { getVsColor } from '../../../utils/color.mjs';
const _hoisted_1 = ["id", "value", "name", "disabled"];
const _hoisted_2 = ["for"];
const __default__ = defineComponent({
inheritAttrs: false,
name: "VsCheckbox"
});
const _sfc_main = defineComponent({
...__default__,
props: checkboxProps,
emits: checkboxEmits,
setup(__props, { emit }) {
var _a;
const props = __props;
const slots = useSlots();
const ns = useNamespace("checkbox");
const checkboxId = (_a = props.id) != null ? _a : useId();
const { isChecked, isDisabled, model, hasOwnLabel, handleChange } = useCheckbox(
props,
emit,
slots
);
const vsBaseClasses = useVuesaxBaseComponent(useColor());
const checkboxKls = computed(() => [
ns.b(),
vsBaseClasses,
ns.is("disabled", isDisabled.value),
ns.is("checked", isChecked.value),
ns.is("label-before", props.labelBefore),
ns.is("loading", props.loading)
]);
const checkboxStyles = computed(() => [
ns.cssVar({
color: getVsColor(props.color)
})
]);
return (_ctx, _cache) => {
return openBlock(), createElementBlock(
"div",
{
class: normalizeClass(checkboxKls.value),
style: normalizeStyle(checkboxStyles.value)
},
[
createElementVNode(
"div",
{
class: normalizeClass(unref(ns).e("input"))
},
[
withDirectives(createElementVNode("input", mergeProps(_ctx.$attrs, {
id: unref(checkboxId),
"onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => isRef(model) ? model.value = $event : null),
value: _ctx.value,
name: _ctx.name,
disabled: unref(isDisabled),
class: unref(ns).e("original"),
type: "checkbox",
onChange: _cache[1] || (_cache[1] = (...args) => unref(handleChange) && unref(handleChange)(...args))
}), null, 16, _hoisted_1), [
[vModelCheckbox, unref(model)]
]),
createElementVNode(
"div",
{
class: normalizeClass(unref(ns).em("input", "mask"))
},
[
!_ctx.$slots.icon ? (openBlock(), createBlock(unref(IconCheck), {
key: 0,
active: unref(isChecked),
indeterminate: _ctx.indeterminate
}, null, 8, ["active", "indeterminate"])) : renderSlot(_ctx.$slots, "icon", { key: 1 })
],
2
),
_ctx.loading ? (openBlock(), createBlock(unref(IconLoading), { key: 0 })) : createCommentVNode("v-if", true)
],
2
),
unref(hasOwnLabel) ? (openBlock(), createElementBlock("label", {
key: 0,
for: unref(checkboxId),
class: normalizeClass([unref(ns).e("label"), unref(ns).is("line-through", _ctx.lineThrough)])
}, [
renderSlot(_ctx.$slots, "default"),
!_ctx.$slots.default ? (openBlock(), createElementBlock(
Fragment,
{ key: 0 },
[
createTextVNode(
toDisplayString(_ctx.label),
1
)
],
64
)) : createCommentVNode("v-if", true)
], 10, _hoisted_2)) : createCommentVNode("v-if", true)
],
6
);
};
}
});
var Checkbox = /* @__PURE__ */ _export_sfc(_sfc_main, [["__file", "/home/runner/work/vuesax-alpha/vuesax-alpha/packages/components/checkbox/src/checkbox.vue"]]);
export { Checkbox as default };
//# sourceMappingURL=checkbox2.mjs.map