Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new props days, duration, progress to tooltip and applied locale … #130

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ npm start
| preStepsCount | number | Specifies empty space before the fist task |
| locale | string | Specifies the month name language. Able formats: ISO 639-2, Java Locale. |
| rtl | boolean | Sets rtl mode. |
| days | string | Specifies the translation of the day |
| duration | string | Specifies the translation of the duration |
| progress | string | Specifies the progress translation |

### StylingOption

Expand Down
7 changes: 7 additions & 0 deletions src/components/gantt/gantt.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ export const Gantt: React.FunctionComponent<GanttProps> = ({
viewMode = ViewMode.Day,
preStepsCount = 1,
locale = "en-GB",
days = "Days",
duration = "Duration",
progress = "Progress",
barFill = 60,
barCornerRadius = 3,
barProgressColor = "#a3a3ff",
Expand Down Expand Up @@ -474,6 +477,10 @@ export const Gantt: React.FunctionComponent<GanttProps> = ({
svgContainerWidth={svgContainerWidth}
fontFamily={fontFamily}
fontSize={fontSize}
locale={locale}
days={days}
duration={duration}
progress={progress}
scrollX={scrollX}
scrollY={scrollY}
task={ganttEvent.changedTask}
Expand Down
65 changes: 51 additions & 14 deletions src/components/other/tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,18 @@ export type TooltipProps = {
rowHeight: number;
fontSize: string;
fontFamily: string;
locale: string;
days: string;
duration: string;
progress: string;
TooltipContent: React.FC<{
task: Task;
fontSize: string;
fontFamily: string;
locale: string;
days: string;
duration: string;
progress: string;
}>;
};
export const Tooltip: React.FC<TooltipProps> = ({
Expand All @@ -34,6 +42,10 @@ export const Tooltip: React.FC<TooltipProps> = ({
arrowIndent,
fontSize,
fontFamily,
locale,
days,
duration,
progress,
headerHeight,
taskListWidth,
TooltipContent,
Expand Down Expand Up @@ -107,39 +119,64 @@ export const Tooltip: React.FC<TooltipProps> = ({
}
style={{ left: relatedX, top: relatedY }}
>
<TooltipContent task={task} fontSize={fontSize} fontFamily={fontFamily} />
<TooltipContent
task={task}
fontSize={fontSize}
fontFamily={fontFamily}
locale={locale}
days={days}
duration={duration}
progress={progress} />
</div>
);
};

export const StandardTooltipContent: React.FC<{
export interface TooltipContentProps {
task: Task;
fontSize: string;
fontFamily: string;
}> = ({ task, fontSize, fontFamily }) => {
locale: string;
days: string;
duration: string;
progress: string;
};

export const StandardTooltipContent: React.FC<TooltipContentProps> = ({
task,
fontSize,
fontFamily,
locale,
days,
duration,
progress
}) => {
const style = {
fontSize,
fontFamily,
};

const dateTimeOptions: Intl.DateTimeFormatOptions = {
weekday: "short",
year: "numeric",
month: "2-digit",
day: "numeric",
};

const formaDate = (date: Date) => date.toLocaleDateString(locale, dateTimeOptions);

return (
<div className={styles.tooltipDefaultContainer} style={style}>
<b style={{ fontSize: fontSize + 6 }}>{`${
task.name
}: ${task.start.getDate()}-${
task.start.getMonth() + 1
}-${task.start.getFullYear()} - ${task.end.getDate()}-${
task.end.getMonth() + 1
}-${task.end.getFullYear()}`}</b>
<b style={{ fontSize: fontSize + 6 }}>{task.name}: {formaDate(task.start)} - {formaDate(task.end)}</b>
{task.end.getTime() - task.start.getTime() !== 0 && (
<p className={styles.tooltipDefaultContainerParagraph}>{`Duration: ${~~(
<p className={styles.tooltipDefaultContainerParagraph}>{`${duration}: ${(
(task.end.getTime() - task.start.getTime()) /
(1000 * 60 * 60 * 24)
)} day(s)`}</p>
)} ${days}(s)`}</p>
)}

<p className={styles.tooltipDefaultContainerParagraph}>
{!!task.progress && `Progress: ${task.progress} %`}
{!!task.progress && `${progress}: ${task.progress} %`}
</p>
</div>
);
};
};
7 changes: 7 additions & 0 deletions src/types/public-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ export interface DisplayOption {
*/
locale?: string;
rtl?: boolean;
days?: string;
duration?: string;
progress?: string;
}

export interface StylingOption {
Expand Down Expand Up @@ -116,6 +119,10 @@ export interface StylingOption {
task: Task;
fontSize: string;
fontFamily: string;
locale: string;
days: string;
duration: string;
progress: string;
}>;
TaskListHeader?: React.FC<{
headerHeight: number;
Expand Down