@kopexa/preview-card
Version:
Part of the Kopexa Sight Design System.
95 lines (92 loc) • 2.63 kB
JavaScript
"use client";
// src/preview-card.tsx
import { IconButton } from "@kopexa/button";
import { CloseIcon } from "@kopexa/icons";
import { createContext } from "@kopexa/react-utils";
import { previewCard } from "@kopexa/theme";
import { Slot } from "@radix-ui/react-slot";
import { jsx } from "react/jsx-runtime";
var [Provider, useProvider] = createContext();
var PreviewCardRoot = (props) => {
const {
className,
children,
asChild,
size,
border,
hoverBorder,
hoverBg,
hoverTitle,
showAction,
...rest
} = props;
const Component = asChild ? Slot : "div";
const styles = previewCard({
size,
border,
hoverBorder,
hoverBg,
hoverTitle,
showAction
});
return /* @__PURE__ */ jsx(Provider, { value: { styles }, children: /* @__PURE__ */ jsx(Component, { className: styles.root({ className }), ...rest, children }) });
};
function PreviewCardIcon(props) {
const { className, children, ...rest } = props;
const { styles } = useProvider();
return /* @__PURE__ */ jsx("div", { className: styles.icon({ className }), ...rest, children });
}
function PreviewCardContent(props) {
const { className, children, ...rest } = props;
const { styles } = useProvider();
return /* @__PURE__ */ jsx("div", { className: styles.content({ className }), ...rest, children });
}
function PreviewCardTitle({ className, ...props }) {
const { styles } = useProvider();
return /* @__PURE__ */ jsx("p", { className: styles.title({ className }), ...props });
}
function PreviewCardDescription({
className,
...props
}) {
const { styles } = useProvider();
return /* @__PURE__ */ jsx("p", { className: styles.description({ className }), ...props });
}
var PreviewCardAction = ({
className,
onClick,
...props
}) => {
const { styles } = useProvider();
return /* @__PURE__ */ jsx(
IconButton,
{
variant: "ghost",
size: "sm",
className: styles.action({ className }),
onClick: (e) => {
e.stopPropagation();
e.preventDefault();
onClick == null ? void 0 : onClick(e);
},
...props,
children: /* @__PURE__ */ jsx(CloseIcon, {})
}
);
};
function PreviewCardTags({ className, ...props }) {
const { styles } = useProvider();
return /* @__PURE__ */ jsx("div", { className: styles.tags({ className }), ...props });
}
var PreviewCard = Object.assign(PreviewCardRoot, {
Icon: PreviewCardIcon,
Content: PreviewCardContent,
Title: PreviewCardTitle,
Description: PreviewCardDescription,
Action: PreviewCardAction,
Tags: PreviewCardTags
});
export {
PreviewCardAction,
PreviewCard
};