UNPKG

@base-framework/ui

Version:

This is a UI package that adds components and atoms that use Tailwind CSS and a theme based on Shadcn.

75 lines (74 loc) 2.1 kB
import { I as k, Button as e } from "@base-framework/atoms"; import { Atom as i } from "@base-framework/base"; import { Icons as h } from "./icons.es.js"; const w = { xs: "w-4 h-4", sm: "w-6 h-6", md: "w-8 h-8", lg: "w-10 h-10", xl: "w-12 h-12", "2xl": "w-14 h-14", "3xl": "w-16 h-16" }, o = i((t, n) => { const s = w[t.size || "sm"]; return k({ ...t, class: `stroke-current icon-size ${s} ${t.class || ""}`, html: n[0]?.textContent }); }), a = (t) => i((n, s) => e({ ...t, ...n, class: `bttn ${t.class} ${n.class || ""}` }, s)), u = i( (t, n) => e({ ...t, class: t.class }, [ t.icon && t.position !== "right" ? o({ size: "sm", class: t.animation ?? null }, t.icon) : null, ...n || [], t.icon && t.position === "right" ? o({ size: "sm", class: t.animation ?? null }, t.icon) : null ]) ), l = (t) => i((n, s) => u({ ...t, ...n, class: `bttn ${t.class} ${n.class || ""}` }, s)), y = i((t, n) => { const s = globalThis.history.length, g = () => { if (t.allowHistory === !0 && globalThis.history.length > 1) { const b = globalThis.history.length, c = s - b - 1; if (c < -1) { globalThis.history.go(c); return; } globalThis.history.back(); return; } if (t.backUrl) { app.navigate(t.backUrl); return; } globalThis.history.back(); }, m = { ...t, icon: t.icon || h.chevron.single.left, click: t.click || g }; return u(m, n); }), B = (t) => i((n, s) => y({ ...t, ...n }, s)), r = { primary: a({ class: "primary" }), secondary: a({ class: "secondary" }), destructive: a({ class: "destructive" }), warning: a({ class: "warning" }), outline: a({ class: "outline" }), ghost: a({ class: "ghost" }), link: a({ class: "link" }), icon: l({ class: "icon" }), withIcon: l({ class: "with-icon" }), back: B({ class: "with-icon back-button" }) }, I = i((t, n) => (r[t.variant] || r.primary)(t, n)), f = i((t, n) => I({ ...t, variant: "withIcon", icon: h.loading, animation: "animate-spin" }, n)); export { I as B, o as I, f as L };