Skip to content

Commit

Permalink
pass alignmen to generic cell
Browse files Browse the repository at this point in the history
  • Loading branch information
thormengkheang committed Apr 1, 2024
1 parent 9e5437c commit 32fda95
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/components/table-cell/GenericCell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ import { useMemo } from "react";
import styles from "./styles.module.css";
import { isLinkString } from "@/lib/validation";
import DisplayLinkCell from "./display-link-cell";
import { cn } from "@/lib/utils";

interface TableCellProps<T = unknown> {
align?: "left" | "right";
value: T;
focus?: boolean;
isChanged?: boolean;
Expand All @@ -16,6 +18,7 @@ export default function GenericCell({
onFocus,
isChanged,
focus,
align,
onDoubleClick,
}: TableCellProps<unknown>) {
const className = [
Expand All @@ -27,13 +30,17 @@ export default function GenericCell({
.filter(Boolean)
.join(" ");

const isAlignRight = align === "right";

const textBaseStyle = cn("text-gray-500", isAlignRight ? "float-right" : "");

const content = useMemo(() => {
if (value === null) {
return <span className="text-gray-500 float-right">NULL</span>;
return <span className={textBaseStyle}>NULL</span>;
}

if (value === undefined) {
return <span className="text-gray-500 float-right">DEFAULT</span>;
return <span className={textBaseStyle}>DEFAULT</span>;
}

if (typeof value === "string") {
Expand Down Expand Up @@ -88,7 +95,7 @@ export default function GenericCell({
}

return <span>{value.toString()}</span>;
}, [value, isChanged]);
}, [value, textBaseStyle, isChanged]);

return (
<div
Expand Down
1 change: 1 addition & 0 deletions src/components/table-cell/createEditableCell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ export default function createEditableCell<T = unknown>({
value={toValue(editValue)}
focus={focus}
isChanged={isChanged}
align={align}
onDoubleClick={() => {
if (!readOnly) {
setEditMode(true);
Expand Down

0 comments on commit 32fda95

Please sign in to comment.