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

Is it possible to turn your lib into react component? #22

Open
kubarskii opened this issue Feb 18, 2019 · 2 comments
Open

Is it possible to turn your lib into react component? #22

kubarskii opened this issue Feb 18, 2019 · 2 comments

Comments

@kubarskii
Copy link

It would be perfect if you could turn your lib into react component.

@elvezpablo
Copy link

I agree and put in a second vote. In the meantime I hacked this together to get it to work for my purposes.

`import React, { Component } from "react";
import * as gantt from "gantt";

const data = [
{
id: 1,
type: "group",
text: "1 Waterfall model",
start: new Date("2018-10-10T09:24:24.319Z"),
end: new Date("2018-12-12T09:32:51.245Z"),
percent: 0.1,
links: [],
},
{
id: 11,
parent: 1,
type: "group",
text: "1.1 Requirements",
start: new Date("2018-10-21T09:24:24.319Z"),
end: new Date("2018-11-22T01:01:08.938Z"),
percent: 0.29,
links: [
{
target: 12,
type: "FS",
},
],
},
{
id: 12,
parent: 1,
text: "1.2 Design",
start: new Date("2018-11-05T09:24:24.319Z"),
end: new Date("2019-01-12T09:32:51.245Z"),
percent: 0.78,
},
];

class Gantt extends Component {
myRef: any;
constructor(props: any) {
super(props);
this.myRef = React.createRef();
}
componentDidMount() {
const strGantt = new gantt.SVGGantt("#gantt", data, {
viewMode: "week",
});
strGantt.render();
}
render() {
return <div id="gantt" style={{ overflowY: "hidden" }} ref={this.myRef} />;
}
}

export default Gantt;
`

@calebfaruki
Copy link

calebfaruki commented Sep 21, 2021

Here was my approach. Functional component implementation.

import React, { createRef, useEffect, useMemo } from "react";
import { StrGantt } from 'gantt';

export default function Gantt ({ data }) {
  const ganttRef = createRef();

  const gantt = useMemo(() => {
    return new StrGantt(data, {
      viewMode: 'week'
    });
  }, [data]);

  useEffect(() => {
    ganttRef.current.innerHTML = gantt.render();
  });

  useEffect(() => {
    gantt.setData(data)
  }, [data, gantt]);

  return <div style={{ overflowX: "scroll" }} ref={ganttRef} />;
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants