@payfit/unity-components
Version:
71 lines (70 loc) • 2.68 kB
JavaScript
import { CardContext as e } from "./Card.context.js";
import { forwardRef as t, useLayoutEffect as n, useRef as r, useState as i } from "react";
import { uyTv as a } from "@payfit/unity-themes";
import { jsx as o } from "react/jsx-runtime";
import { useId as s } from "react-aria/useId";
//#region src/core/components/card/Card.tsx
var c = a({
slots: { base: ["uy:flex uy:flex-col uy:gap-200 uy:rounded-lg"] },
variants: {
density: {
default: { base: "uy:p-200 uy:sm:p-300" },
compact: { base: "uy:p-200" }
},
shadow: {
none: { base: "uy:shadow-none" },
raising: { base: "uy:shadow-100" },
flying: { base: "uy:shadow-300" },
100: { base: "uy:shadow-100" },
300: { base: "uy:shadow-300" }
},
bgColor: {
"surface.neutral": { base: "uy:bg-surface-neutral uy:border uy:border-solid uy:border-border-neutral" },
"surface.neutral.low": { base: "uy:bg-surface-neutral-low" },
"surface.neutral.lowest": { base: "uy:bg-surface-neutral-lowest" },
"surface.decorative-teal.lowest": { base: "uy:bg-surface-decorative-teal-lowest" },
"surface.decorative-purple.lowest": { base: "uy:bg-surface-decorative-purple-lowest" },
"surface.decorative-plum.lowest": { base: "uy:bg-surface-decorative-plum-lowest" },
"surface.decorative-orange.lowest": { base: "uy:bg-surface-decorative-orange-lowest" }
}
},
defaultVariants: {
density: "default",
shadow: "none",
bgColor: "surface.neutral"
}
}), l = t(({ density: t, shadow: a, bgColor: l, children: u, className: d, asElement: f, ...p }, m) => {
let h = s(), g = r(null), [_, v] = i(!1), y = p.id ?? `unity-card-${h}`, b = `unity-card-${h}__title`, x = p["aria-label"];
n(() => {
let e = g.current;
if (!e) return;
let t = e.querySelector("[data-unity-slot=\"card.title\"]");
v(!!t), process.env.NODE_ENV === "development" && !t && !x && console.warn("Card: A Card must have either a CardTitle child or an aria-label prop for accessibility.");
}, [u, x]);
let S = (l ?? "surface.neutral") === "surface.neutral" && (a ?? "none") !== "none", { base: C } = c({
className: d,
density: t,
shadow: S ? a : "none",
bgColor: l
}), w = { titleId: b }, T = f ?? "section";
return /* @__PURE__ */ o(e.Provider, {
value: w,
children: /* @__PURE__ */ o(T, {
"data-dd-privacy": "show",
...p,
id: y,
ref: (e) => {
g.current = e, typeof m == "function" ? m(e) : m && (m.current = e);
},
className: C(),
"aria-labelledby": _ ? b : void 0,
"aria-label": _ ? void 0 : x,
"data-unity-component": "card",
"data-unity-variant": S ? "shadow" : void 0,
children: u
})
});
});
l.displayName = "Card";
//#endregion
export { l as Card, c as card };