@aplus-frontend/ui
Version:
103 lines (102 loc) • 3.21 kB
JavaScript
import { defineComponent as W, useSlots as z, ref as L, computed as t, createBlock as w, openBlock as M, unref as a, mergeProps as P, createSlots as T, renderList as _, withCtx as S, renderSlot as $, normalizeProps as x, guardReactiveProps as N } from "vue";
import { Button as A } from "@aplus-frontend/antdv";
import { wait as D } from "@aplus-frontend/utils";
import "../config-provider/index.mjs";
import { omit as F } from "lodash-unified";
import { transferOpacityColor as O, isAsynchronous as j } from "./utils/index.mjs";
import { useNamespace as G } from "../config-provider/hooks/use-namespace.mjs";
import { useGlobalConfig as I } from "../config-provider/hooks/use-global-config.mjs";
const R = 72, q = 300, Y = /* @__PURE__ */ W({
__name: "ap-button",
props: {
prefixCls: {},
htmlType: {},
shape: {},
size: {},
loading: { type: [Boolean, Object], default: void 0 },
disabled: { type: Boolean },
ghost: { type: Boolean },
block: { type: Boolean },
danger: { type: Boolean },
icon: {},
href: {},
target: {},
title: {},
onMousedown: {},
autoInsertSpace: { type: Boolean },
iconPosition: {},
color: {},
variant: {},
type: { default: "default" },
borderLinkColor: {},
minWidth: { type: [Boolean, Number, String], default: !1 },
lazy: { type: [Boolean, Number], default: !0 },
onClick: {}
},
setup(m) {
const y = z(), e = m, l = {
aplus: "#0070FF",
admin: "#34b77c"
}, { b: i } = G("ap-action-button"), b = I("uiMode"), n = L(!1), v = t(
() => e.borderLinkColor || l[b.value] || l.aplus
), s = t(
() => e.type === "borderLink" && !e.disabled ? v.value : void 0
), u = t(
() => O(s.value)
), h = t(() => e.minWidth === !0 ? `${R}px` : typeof e.minWidth == "number" ? `${e.minWidth}px` : typeof e.minWidth == "string" ? e.minWidth : void 0), g = t(
() => (e.type === "borderLink" ? "default" : e.type) || "default"
), c = t(() => e.loading ?? n.value ?? !1), d = t(() => e.lazy === !0 ? q : typeof e.lazy == "number" && e.lazy >= 0 ? e.lazy : 0);
function k() {
const o = F(e, [
"type",
"borderLinkColor",
"minWidth",
"onClick",
"loading"
]);
return o ? {
...o,
type: g.value,
onclick: C
} : {};
}
async function C() {
if (c.value) return;
const o = j(e.onClick), p = Date.now();
try {
o && (n.value = !0, await o);
} finally {
if (o) {
const r = Date.now() - p;
r < d.value && await D(d.value - r), n.value = !1;
}
}
}
return (o, p) => (M(), w(a(A), P({
class: {
[a(i)()]: !0,
[`${a(i)()}-border-link`]: u.value
}
}, {
...o.$attrs,
...k()
}, {
style: {
color: s.value,
minWidth: h.value,
"--button-border-color": u.value
},
loading: c.value
}), T({ _: 2 }, [
_(y, (r, f) => ({
name: f,
fn: S((B) => [
$(o.$slots, f, x(N(B || {})))
])
}))
]), 1040, ["class", "style", "loading"]));
}
});
export {
Y as default
};