Skip to content

Commit ce61fc3

Browse files
committed
feat: Add weekendColor prop to highlight weekend columns
- Add weekendColor prop to StylingOption interface - Add weekendColor support in GridBodyProps and GridBody component - Implement weekend detection logic using getDay() (0=Sunday, 6=Saturday) - Add weekend column highlighting with configurable color - Update Gantt component to accept and pass weekendColor prop - Add weekendColor usage examples in example app (#97979714) - Update README.md with weekendColor documentation - Change todayColor default from rgba(252, 248, 227, 0.5) to rgba(252, 248, 227, 1) Based on PR MaTeMaTuK#122 from MaTeMaTuK/gantt-task-react by AquilesOliveiraDev
1 parent f7becb1 commit ce61fc3

File tree

5 files changed

+24
-1
lines changed

5 files changed

+24
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ npm start
113113
| arrowColor | string | Specifies the relationship arrow fill color. |
114114
| arrowIndent | number | Specifies the relationship arrow right indent. Sets in px |
115115
| todayColor | string | Specifies the current period column fill color. |
116+
| weekendColor | string | Specifies the weekend columns fill color. |
116117
| TooltipContent | | Specifies the Tooltip view for selected taskbar. |
117118
| TaskListHeader | | Specifies the task list Header view |
118119
| TaskListTable | | Specifies the task list Table view |

example/src/App.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ const App = () => {
8787
onExpanderClick={handleExpanderClick}
8888
listCellWidth={isChecked ? "155px" : ""}
8989
columnWidth={columnWidth}
90+
weekendColor={"#97979714"}
9091
/>
9192
<h3>Gantt With Limited Height</h3>
9293
<Gantt
@@ -102,6 +103,7 @@ const App = () => {
102103
listCellWidth={isChecked ? "155px" : ""}
103104
ganttHeight={300}
104105
columnWidth={columnWidth}
106+
weekendColor={"#97979714"}
105107
/>
106108
</div>
107109
);

src/components/gantt/gantt.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ export const Gantt: React.FunctionComponent<GanttProps> = ({
5353
fontFamily = "Arial, Roboto, Oxygen, Ubuntu, Cantarell, Fira Sans, Droid Sans, Helvetica Neue",
5454
fontSize = "14px",
5555
arrowIndent = 20,
56-
todayColor = "rgba(252, 248, 227, 0.5)",
56+
todayColor = "rgba(252, 248, 227, 1)",
57+
weekendColor = "transparent",
5758
viewDate,
5859
TooltipContent = StandardTooltipContent,
5960
TaskListHeader = TaskListHeaderDefault,
@@ -394,6 +395,7 @@ export const Gantt: React.FunctionComponent<GanttProps> = ({
394395
rowHeight,
395396
dates: dateSetup.dates,
396397
todayColor,
398+
weekendColor,
397399
rtl,
398400
};
399401
const calendarProps: CalendarProps = {

src/components/grid/grid-body.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export type GridBodyProps = {
1010
rowHeight: number;
1111
columnWidth: number;
1212
todayColor: string;
13+
weekendColor: string;
1314
rtl: boolean;
1415
};
1516
export const GridBody: React.FC<GridBodyProps> = ({
@@ -19,6 +20,7 @@ export const GridBody: React.FC<GridBodyProps> = ({
1920
svgWidth,
2021
columnWidth,
2122
todayColor,
23+
weekendColor,
2224
rtl,
2325
}) => {
2426
let y = 0;
@@ -60,6 +62,7 @@ export const GridBody: React.FC<GridBodyProps> = ({
6062
const now = new Date();
6163
let tickX = 0;
6264
const ticks: ReactElement[] = [];
65+
const weekends: ReactElement[] = [];
6366
let today: ReactElement = <rect />;
6467
for (let i = 0; i < dates.length; i++) {
6568
const date = dates[i];
@@ -73,6 +76,19 @@ export const GridBody: React.FC<GridBodyProps> = ({
7376
className={styles.gridTick}
7477
/>
7578
);
79+
80+
if (weekendColor !== "transparent" && dates[i + 1] && [0, 6].includes(dates[i + 1].getDay())) {
81+
weekends.push(
82+
<rect
83+
key={"WeekendColumn" + i}
84+
x={tickX + columnWidth}
85+
y={0}
86+
width={columnWidth}
87+
height={y}
88+
fill={weekendColor}
89+
/>
90+
);
91+
}
7692
if (
7793
(i + 1 !== dates.length &&
7894
date.getTime() < now.getTime() &&
@@ -121,6 +137,7 @@ export const GridBody: React.FC<GridBodyProps> = ({
121137
<g className="rows">{gridRows}</g>
122138
<g className="rowLines">{rowLines}</g>
123139
<g className="ticks">{ticks}</g>
140+
<g className="weekends">{weekends}</g>
124141
<g className="today">{today}</g>
125142
</g>
126143
);

src/types/public-types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ export interface StylingOption {
113113
arrowColor?: string;
114114
arrowIndent?: number;
115115
todayColor?: string;
116+
weekendColor?: string;
116117
TooltipContent?: React.FC<{
117118
task: Task;
118119
fontSize: string;

0 commit comments

Comments
 (0)