@opensig/opendesign
Version:
<p align="center"><img src="../docs/public/opendesign-logo-light.png"/></p> <h1 align="center">opendesign</h1> <p align="center">一个 Vue 3 组件库</p> <p align="center"><b>皮肤可定制,使用 TypeScript</b></p>
103 lines (102 loc) • 3.42 kB
JavaScript
import { defineComponent, createElementBlock, openBlock, Fragment, createElementVNode, normalizeClass, renderSlot, createVNode, unref, createCommentVNode } from "vue";
import { IconChevronUp, IconChevronDown, IconAdd, IconMinus } from "../_utils/icons.mjs";
const _hoisted_1 = { class: "o-input-number-btn-wrap" };
const _sfc_main = /* @__PURE__ */ defineComponent({
__name: "NumberControl",
props: {
type: {},
addable: { type: Boolean },
reducible: { type: Boolean }
},
emits: ["plus", "minus"],
setup(__props, { emit: __emit }) {
const props = __props;
const emits = __emit;
const onControlClick = (type, e) => {
if (type === "plus" && props.addable) {
emits("plus", e);
} else if (type === "minus" && props.reducible) {
emits("minus", e);
}
};
const isDisabledWhenNotBoth = () => {
if (props.type === "plus") {
return !props.addable;
} else if (props.type === "minus") {
return !props.reducible;
}
};
return (_ctx, _cache) => {
return openBlock(), createElementBlock("div", _hoisted_1, [
props.type === "both" ? (openBlock(), createElementBlock(
Fragment,
{ key: 0 },
[
createElementVNode(
"div",
{
class: normalizeClass(["o-input-number-btn", [
{
"is-disabled": !props.addable
},
`type-${props.type}`
]]),
tabindex: "-1",
onClick: _cache[0] || (_cache[0] = (e) => onControlClick("plus", e))
},
[
renderSlot(_ctx.$slots, "plus", {}, () => [
createVNode(unref(IconChevronUp), { class: "o-input-number-icon-plus" })
])
],
2
/* CLASS */
),
createElementVNode(
"div",
{
class: normalizeClass(["o-input-number-btn minus", {
"is-disabled": !props.reducible
}]),
tabindex: "-1",
onClick: _cache[1] || (_cache[1] = (e) => onControlClick("minus", e))
},
[
renderSlot(_ctx.$slots, "minus", {}, () => [
createVNode(unref(IconChevronDown), { class: "o-input-number-icon-minus" })
])
],
2
/* CLASS */
)
],
64
/* STABLE_FRAGMENT */
)) : (openBlock(), createElementBlock(
"div",
{
key: 1,
class: normalizeClass(["o-input-number-btn", {
"is-disabled": isDisabledWhenNotBoth()
}]),
tabindex: "-1",
onClick: _cache[2] || (_cache[2] = (e) => onControlClick(props.type, e))
},
[
props.type === "plus" ? renderSlot(_ctx.$slots, "plus", { key: 0 }, () => [
createVNode(unref(IconAdd))
]) : createCommentVNode("v-if", true),
props.type === "minus" ? renderSlot(_ctx.$slots, "minus", { key: 1 }, () => [
createVNode(unref(IconMinus))
]) : createCommentVNode("v-if", true)
],
2
/* CLASS */
))
]);
};
}
});
export {
_sfc_main as default
};