1 import { clx } from "@medusajs/ui"
2 import { ConditionalTooltip } from "../../../../common/conditional-tooltip"
3 import { PlaceholderCell } from "../placeholder-cell"
4
5 type CellProps = {
6 text?: string | number
7 align?: "left" | "center" | "right"
8 maxWidth?: number
9 }
10
11 type HeaderProps = {
12 text: string
13 align?: "left" | "center" | "right"
14 }
15
16 export const TextCell = ({
17 text,
18 align = "left",
19 maxWidth = 220,
20 }: CellProps) => {
21 if (!text) {
22 return <PlaceholderCell />
23 }
24
25 const stringLength = text.toString().length
26
27 return (
28 <ConditionalTooltip content={text} showTooltip={stringLength > 20}>
29 <div
30 className={clx(
31 "flex h-full w-full items-center gap-x-3 overflow-hidden",
32 {
33 "justify-start text-start": align === "left",
34 "justify-center text-center": align === "center",
35 "justify-end text-end": align === "right",
36 }
37 )}
38 style={{
39 maxWidth: maxWidth,
40 }}
41 >
42 <span className="truncate">{text}</span>
43 </div>
44 </ConditionalTooltip>
45 )
46 }
47
48 export const TextHeader = ({ text, align = "left" }: HeaderProps) => {
49 return (
50 <div
51 className={clx("flex h-full w-full items-center", {
52 "justify-start text-start": align === "left",
53 "justify-center text-center": align === "center",
54 "justify-end text-end": align === "right",
55 })}
56 >
57 <span className="truncate">{text}</span>
58 </div>
59 )
60 }