UNPKG

@premieroctet/next-admin

Version:

Next-Admin provides a customizable and turnkey admin dashboard for applications built with Next.js and powered by the Prisma ORM. It aims to simplify the development process by providing a turnkey admin system that can be easily integrated into your proje

101 lines (100 loc) 5.52 kB
import { jsx, jsxs } from "react/jsx-runtime"; import external_react_default from "react"; import external_clsx_default from "clsx"; import Link_mjs_default from "./common/Link.mjs"; import { useConfig } from "../context/ConfigContext.mjs"; import { getDisplayedValue } from "../utils/tools.mjs"; import Clipboard_mjs_default from "./common/Clipboard.mjs"; function Cell({ cell, formatter, copyable, getRawData }) { const { basePath, nextAdminContext } = useConfig(); let cellValue = cell?.__nextadmin_formatted; const renderCustomElement = (val)=>/*#__PURE__*/ jsxs("div", { className: "flex gap-1", children: [ val, copyable && /*#__PURE__*/ jsx(Clipboard_mjs_default, { value: getDisplayedValue(val) }) ] }); const isReactNode = (cell)=>/*#__PURE__*/ external_react_default.isValidElement(cell); if (cell && null !== cell) { if (/*#__PURE__*/ external_react_default.isValidElement(cellValue)) return renderCustomElement(cellValue); if ("object" == typeof cell && !isReactNode(cellValue)) { if (formatter) { cellValue = formatter(getRawData?.(), nextAdminContext); if (/*#__PURE__*/ external_react_default.isValidElement(cellValue)) return renderCustomElement(cellValue); } if ("link" === cell.type) { const url = cell.isOverridden ? cell.value.url : `${basePath}/${cell.value.url}`; return /*#__PURE__*/ jsxs(Link_mjs_default, { onClick: (e)=>e.stopPropagation(), href: url, className: "text-nextadmin-brand-emphasis dark:text-dark-nextadmin-brand-subtle hover:text-nextadmin-brand-emphasis dark:hover:text-dark-nextadmin-brand-emphasis flex cursor-pointer items-center gap-1 font-semibold hover:underline", children: [ cellValue, copyable && /*#__PURE__*/ jsx(Clipboard_mjs_default, { value: url }) ] }); } if ("count" === cell.type) return /*#__PURE__*/ jsx("div", { className: "bg-nextadmin-background-subtle dark:bg-dark-nextadmin-background-subtle text-nextadmin-content-subtle dark:text-dark-nextadmin-content-subtle ring-nextadmin-border-default dark:ring-dark-nextadmin-border-strong inline-flex items-center rounded-md px-2 py-1 text-xs font-medium ring-1 ring-inset", children: /*#__PURE__*/ jsx("p", { children: cellValue }) }); if ("date" === cell.type) return /*#__PURE__*/ jsxs("div", { className: "text-nextadmin-content-subtle dark:text-dark-nextadmin-content-subtle flex max-w-[20ch] items-center gap-1 overflow-hidden text-ellipsis whitespace-nowrap", children: [ /*#__PURE__*/ jsx("p", { children: cellValue }), copyable && /*#__PURE__*/ jsx(Clipboard_mjs_default, { value: cellValue?.toString() ?? "" }) ] }); else if ("scalar" === cell.type && "string" == typeof cell.value) return /*#__PURE__*/ jsxs("div", { className: "text-nextadmin-content-subtle dark:text-dark-nextadmin-content-subtle flex items-center gap-1 overflow-hidden text-ellipsis whitespace-nowrap", children: [ /*#__PURE__*/ jsx("p", { children: cellValue }), copyable && /*#__PURE__*/ jsx(Clipboard_mjs_default, { value: cellValue?.toString() ?? "" }) ] }); else if ("scalar" === cell.type && "number" == typeof cell.value) return /*#__PURE__*/ jsxs("div", { className: "text-nextadmin-content-subtle dark:text-dark-nextadmin-content-subtle flex max-w-[20ch] items-center gap-1 overflow-hidden text-ellipsis whitespace-nowrap", children: [ /*#__PURE__*/ jsx("p", { children: cellValue }), copyable && /*#__PURE__*/ jsx(Clipboard_mjs_default, { value: cellValue?.toString() ?? "" }) ] }); else if ("scalar" === cell.type && "boolean" == typeof cell.value) return /*#__PURE__*/ jsx("div", { className: external_clsx_default("inline-flex items-center rounded-md px-2 py-1 text-xs font-medium", "bg-nextadmin-background-subtle dark:bg-dark-nextadmin-background-subtle text-nextadmin-brand-subtle dark:text-dark-nextadmin-content-subtle"), children: /*#__PURE__*/ jsx("p", { children: cellValue?.toString() }) }); } return /*#__PURE__*/ jsxs("div", { className: "text-nextadmin-brand-subtle dark:text-dark-nextadmin-content-subtle flex items-center gap-1", children: [ JSON.stringify(cellValue), copyable && /*#__PURE__*/ jsx(Clipboard_mjs_default, { value: JSON.stringify(cellValue) }) ] }); } return null; } export { Cell as default };