Skip to content

Commit

Permalink
Refactor GanttChartRow component to improve readability and add paddi…
Browse files Browse the repository at this point in the history
…ng to child rows
  • Loading branch information
simlarsen committed Apr 18, 2024
1 parent 01477fd commit c8db6f2
Showing 1 changed file with 26 additions and 21 deletions.
47 changes: 26 additions & 21 deletions CommonUI/src/Components/GanttChart/Row/Row.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,37 +35,42 @@ const Row: FunctionComponent<ComponentProps> = (
level = 0;
}

const hasChildRows = row.childRows.length > 0;
const hasChildRows: boolean = row.childRows.length > 0;

const shouldShowChildRows = level < 2;
const shouldShowChildRows: boolean = level < 2;

const [showChildRows, setShowChildRows] = useState(shouldShowChildRows);

const paddingCount: number = level * 4;

return (
// rectangle div with curved corners and text inside in tailwindcss
<div>
<div
className={`flex w-full border-b-2 border-gray-200 border-l-2 border-l-gray-400 border-r-2 border-r-gray-400`}
>
<div className={`p-2 flex w-1/4 border-r-2 border-gray-300`}>
<div className="w-5 h-5">
{hasChildRows && (
<Icon
icon={
showChildRows
? IconProp.ChevronDown
: IconProp.ChevronRight
}
onClick={() => {
return setShowChildRows(!showChildRows);
}}
/>
)}
<div className="flex w-1/4 border-r-2 border-gray-300">
<div className={`pl-${paddingCount} pt-2 pb-2 pr-2 flex`}>
<div className="w-5 h-5 ml-3 mt-1">
{hasChildRows && (
<Icon
icon={
showChildRows
? IconProp.ChevronDown
: IconProp.ChevronRight
}
className="cursor-pointer h-4 w-4 text-gray-500 hover:text-gray-800 font-semibold"
onClick={() => {
return setShowChildRows(!showChildRows);
}}
/>
)}
</div>
<RowLabel
title={row.rowInfo.title}
description={row.rowInfo.description}
/>
</div>
<RowLabel
title={row.rowInfo.title}
description={row.rowInfo.description}
/>
</div>
<div className="flex w-3/4">
{row.bars.map((bar: GanttChartBar, i: number) => {
Expand Down Expand Up @@ -110,7 +115,7 @@ const Row: FunctionComponent<ComponentProps> = (
</div>
</div>
{showChildRows && (
<div className={`ml-4`}>
<div>
{row.childRows.map((childRow: GanttChartRow, i: number) => {
return (
<div key={i}>
Expand Down

0 comments on commit c8db6f2

Please sign in to comment.