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

Forward ref to Event #32

Open
denvash opened this issue Oct 28, 2019 · 2 comments
Open

Forward ref to Event #32

denvash opened this issue Oct 28, 2019 · 2 comments
Labels
enhancement New feature or request

Comments

@denvash
Copy link

denvash commented Oct 28, 2019

When developing a library it's a good practice to expose a reference of a component.
It can be achieved with forwardRef.

Working with this library I couldn't obtain Event reference in order to animate it.

A straight forward implementation can be something like this:

const Event = forwardRef(({ date, marker, children, className, card }, ref) => {
...
return <Container ref={ref}>...</Container>
});

The user then can use the reference for his care, like reveal animation:

const Timeline = () => {
  const revealEvents = useRef([]);

  useEffect(() => {
    revealEvents.current.forEach((ref, i) => sr.reveal(ref, srConfig(i * 100)));
  }, []);

  const events = useTimeline();

  return (
    <ThemedTimeline>
      <Events>
        {events.map(({ ... }, i) => {
          const MyCustomCard = () => (... );
          const date = () => (... );

          return <Event key={i} date={date} card={MyCustomCard} ref={el => (revealEvents.current[i] = el)}/>;
        })}
      </Events>
    </ThemedTimeline>
  );
};

I hope I'll able to add a merge request in a few days.

@steven-mercatante
Copy link
Owner

Thanks for filing this issue. I've been thinking about how best to support animating events - I'd love to see your final implementation. It would be a great addition to the docs.

@steven-mercatante steven-mercatante added the enhancement New feature or request label Oct 28, 2019
@denvash
Copy link
Author

denvash commented Oct 28, 2019

You can check the result on my personal site (work still in progress, fully customized timeline with reveal animation).

Try switching the theme on pressing the logo at the navbar.

And the code of the Timeline component here.

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

No branches or pull requests

2 participants