UNPKG

@aplus-frontend/ui

Version:

101 lines (100 loc) 3.15 kB
import { defineComponent as B, useSlots as W, ref as z, computed as o, createBlock as L, openBlock as w, unref as n, mergeProps as P, createSlots as S, renderList as T, withCtx as _, renderSlot as $, normalizeProps as x, guardReactiveProps as M } from "vue"; import { Button as N } from "@aplus-frontend/antdv"; import { wait as A } from "@aplus-frontend/utils"; import "../config-provider/index.mjs"; import { omit as D } from "lodash-unified"; import { transferOpacityColor as I, isAsynchronous as O } from "./utils/index.mjs"; import j from "./style/index.mjs"; import { useNamespace as R } from "../config-provider/hooks/use-namespace.mjs"; const q = 72, E = 300, X = /* @__PURE__ */ B({ __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(f) { const m = W(), e = f, { b: l } = R("ap-action-button"), y = j("ap-action-button"), r = z(!1), b = o( () => e.borderLinkColor || "var(--ap-button-border-link-color)" ), i = o( () => e.type === "borderLink" && !e.disabled ? b.value : void 0 ), s = o( () => I(i.value) ), h = o(() => e.minWidth === !0 ? `${q}px` : typeof e.minWidth == "number" ? `${e.minWidth}px` : typeof e.minWidth == "string" ? e.minWidth : void 0), v = o( () => (e.type === "borderLink" ? "default" : e.type) || "default" ), u = o(() => e.loading ?? r.value ?? !1), c = o(() => e.lazy === !0 ? E : typeof e.lazy == "number" && e.lazy >= 0 ? e.lazy : 0); function k() { const t = D(e, [ "type", "borderLinkColor", "minWidth", "onClick", "loading" ]); return t ? { ...t, type: v.value, onclick: g } : {}; } async function g() { if (u.value) return; const t = O(e.onClick), d = Date.now(); try { t && (r.value = !0, await t); } finally { if (t) { const a = Date.now() - d; a < c.value && await A(c.value - a), r.value = !1; } } } return (t, d) => (w(), L(n(N), P({ class: { [n(l)()]: !0, [`${n(l)()}-border-link`]: s.value, [`${n(y)}`]: !0 } }, { ...t.$attrs, ...k() }, { style: { color: i.value, minWidth: h.value, "--button-border-color": s.value }, loading: u.value }), S({ _: 2 }, [ T(m, (a, p) => ({ name: p, fn: _((C) => [ $(t.$slots, p, x(M(C || {}))) ]) })) ]), 1040, ["class", "style", "loading"])); } }); export { X as default };