Skip to content

Commit

Permalink
feat: Add types for frappe-gantt (DefinitelyTyped#41561)
Browse files Browse the repository at this point in the history
* Add frappe-gantt types

* Add refresh method

* Update index.d.ts
  • Loading branch information
samalexander committed Feb 3, 2020
1 parent 33fa63b commit c56c683
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 0 deletions.
36 changes: 36 additions & 0 deletions types/frappe-gantt/frappe-gantt-tests.ts
@@ -0,0 +1,36 @@
import Gantt from 'frappe-gantt';

const tasks = [
{
id: 'Task 1',
name: 'Redesign website',
start: '2016-12-28',
end: '2016-12-31',
progress: 20,
dependencies: 'Task 2, Task 3'
}
];
const gantt1 = new Gantt('#gantt', tasks);

gantt1.change_view_mode('Week');
gantt1.refresh(tasks);

new Gantt('#gantt', tasks, {
on_click: (task) => { },
on_date_change: (task, start, end) => { },
on_progress_change: (task, progress) => { },
on_view_change: (mode) => { }
});

new Gantt('#gantt', tasks, {
custom_popup_html: (task) => {
const end_date = task._end.format('MMM D');
return `
<div class="details-container">
<h5>${task.name}</h5>
<p>Expected to finish by ${end_date}</p>
<p>${task.progress}% completed!</p>
</div>
`;
}
});
45 changes: 45 additions & 0 deletions types/frappe-gantt/index.d.ts
@@ -0,0 +1,45 @@
// Type definitions for frappe-gantt 0.3
// Project: https://github.com/frappe/gantt
// Definitions by: Sam Alexander <https://github.com/samalexander>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped

export = Gantt;

declare class Gantt {
constructor(wrapper: string, tasks: Gantt.Task[], options?: Gantt.Options);

change_view_mode(mode: Gantt.viewMode): void;
refresh(tasks: Gantt.Task[]): void;
}

declare namespace Gantt {
interface Task {
id: string;
name: string;
start: string;
end: string;
progress: number;
dependencies: string;
custom_class?: string;
}

interface Options {
header_height?: number;
column_width?: number;
step?: number;
view_modes?: viewMode[];
bar_height?: number;
bar_corner_radius?: number;
arrow_curve?: number;
padding?: number;
view_mode?: viewMode;
date_format?: string;
custom_popup_html?: string | ((task: any) => string);
on_click?: (task: any) => void;
on_date_change?: (task: any, start: string, end: string) => void;
on_progress_change?: (task: any, progress: number) => void;
on_view_change?: (mode: viewMode) => void;
}

type viewMode = 'Quarter Day' | 'Half Day' | 'Day' | 'Week' | 'Month';
}
24 changes: 24 additions & 0 deletions types/frappe-gantt/tsconfig.json
@@ -0,0 +1,24 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictFunctionTypes": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true,
"esModuleInterop": true
},
"files": [
"index.d.ts",
"frappe-gantt-tests.ts"
]
}
1 change: 1 addition & 0 deletions types/frappe-gantt/tslint.json
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }

0 comments on commit c56c683

Please sign in to comment.