Toolbar
The widget provides two possible ways to configure the Toolbar:
- using the internal Toolbar component of Gantt (import from @svar-ui/react-gantt) and the getToolbarButtons helper
- using the external Toolbar component with configurable data (import from @svar-ui/react-toolbar)
Adding the default toolbar
To add a toolbar, import the Toolbar component of Gantt, and add the Toolbar element. You should also obtain the Gantt API reference (via a ref) and pass it to the Toolbar using the api prop.
import { useState } from "react";
import { getData } from "./common/data";
import { Gantt, Toolbar } from "@svar-ui/react-gantt";
const data = getData();
export default function Example() {
const [api, setApi] = useState(null);
return (
<>
<Toolbar api={api} />
<Gantt ref={setApi} tasks={data.tasks} />
</>
);
}
If multiple tasks are selected, clicking the built-in Add task button adds a single new task next to the last selected task, not to each selected task.
In the auto scheduling mode, the default toolbar also has the Conflicts button | PRO feature. It opens and closes the ConflictReport list, shows a dot when there are scheduling conflicts, and stays pressed while the list is open. For details, see Constraints.
Configuring the set of buttons in the toolbar
To configure the toolbar (the set of buttons in the toolbar and their appearance), import the Toolbar component of Gantt and make necessary changes to the items array. Do not forget to add the items attribute to the Toolbar element.
import { useState } from "react";
import { getData } from "../data";
import { Gantt, Toolbar } from "@svar-ui/react-gantt";
const data = getData();
export default function Example() {
const [api, setApi] = useState(null);
const items = [
{
id: "add-task",
comp: "button",
icon: "wxi-plus",
text: "Add task",
type: "primary",
},
{
id: "edit-task",
comp: "button",
icon: "wxi-edit",
text: "Edit",
type: "link",
},
];
return (
<>
<Toolbar api={api} items={items} />
<Gantt ref={setApi} tasks={data.tasks} />
</>
);
}
You can also customize the Toolbar using the getToolbarButtons helper to get the default array.
import { useState } from "react";
import { getData } from "../data";
import { Gantt, Toolbar, getToolbarButtons } from "@svar-ui/react-gantt";
const data = getData();
export default function Example() {
const [api, setApi] = useState(null);
// remove indentation buttons
const items = getToolbarButtons().filter((b) => {
return !b.id?.includes("indent");
});
return (
<>
<Toolbar api={api} items={items} />
<Gantt ref={setApi} tasks={data.tasks} />
</>
);
}