Skip to content

Rewrite FlowTip component and layout algorithm#37

Merged
10xjs merged 1 commit intomasterfrom
5.x.x
Aug 31, 2017
Merged

Rewrite FlowTip component and layout algorithm#37
10xjs merged 1 commit intomasterfrom
5.x.x

Conversation

@10xjs
Copy link
Copy Markdown
Contributor

@10xjs 10xjs commented Aug 29, 2017

This is a major overhaul of both the internal mechanics and public interface of the FlowTip library.

The most important changes are a total separation of the layout algorithm from the React component and an a much simpler React component implementation.

With the React component and layout algorithm decoupled, the stage is set for additional FlowTip implementations on other platforms.

flowtip-core

The new layout algorithm (now published as flowtip-core) is now an entirely pure function with no coupling to React or to the DOM environment. It now has very clearly defined behavior around even the most unusual layout edge cases.

The algorithm is designed to serve the FlowTip React component, but exists as a separate module for both test isolation and to be available for additional uses.

The algorithm also now features full test coverage using a novel ascii renderer combined with Jest snapshots.

flowtip-react-dom

The previous flowtip component module is succeeded by flowtip-react-dom. It provides a friendly React interface to the underlying flowtip-core algorithm with specific bindings to DOM events and the React component lifecycle.

The main architectural motivations for the design of the new of the React component are simplicity and declarative composability with a simple interface inspired by modules like react-motion, react-router, and redux-form.

The component behaves as an inline "decorator" which enhances a provided Content component with tooltip layout behavior. Because it avoids owning any unnecessary state, it requires a parent component (or global state e.g. Redux) to manage the target rect and "active" state.

It also forgoes implementing what could be seen as valuable core features for the sake of simplicity. Additional libraries like react-resize-observer, react-motion, tj/react-click-outside, and focus-trap-react are recommended to compose a full user experience. Since flowtip-react-dom renders no markup of it's own and defers all rendering responsibility to consumer defined components, composition with the mentioned libraries should be without conflict.

This minimal approach offers the best balance of core features and compatibility with various consumer use cases.

TODO:

/cc @qiushihe @izaakschroeder

Copy link
Copy Markdown
Collaborator

@qiushihe qiushihe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

However I noticed a few small things... first there seems to be many commented out console.log statements and I think they should just be removed; second, neither package.json from the two packages have homepage set which would help with discovery once they are published so I think those should be added.

@10xjs
Copy link
Copy Markdown
Contributor Author

10xjs commented Aug 29, 2017

@qiushihe Updated - thanks!

Comment thread package.json Outdated
"babel-preset-react": "^6.24.1",
"babel-preset-stage-2": "^6.24.1",
"eslint": "^4.5.0",
"eslint-config-metalab": "^7.0.0",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You probably want 7.0.1.

@10xjs 10xjs force-pushed the 5.x.x branch 5 times, most recently from be65794 to 3e8e537 Compare August 31, 2017 00:39
Copy link
Copy Markdown
Contributor

@izaakschroeder izaakschroeder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM pending CI 🎉 Nice work!

This is a major overhaul of both the internal mechanics and public interface of the FlowTip library.

The most important changes are a total separation of the layout algorithm from the React component and an a much simpler React component implementation.

With the React component and layout algorithm decoupled, the stage is set for additional FlowTip implementations on other platforms.

**`flowtip-core`**

The new layout algorithm (now published as `flowtip-core`) is now an entirely pure function with no coupling to React or to the DOM environment. It now has very clearly defined behavior around even the most unusual layout edge cases.

The algorithm is designed to serve the FlowTip React component, but exists as a separate module for both test isolation and to be available for additional uses.

The algorithm also now features full test coverage using a novel ascii renderer combined with Jest snapshots.

**`flowtip-react-dom`**

The previous `flowtip` component module is succeeded by `flowtip-react-dom`. It provides a friendly React interface to the underlying `flowtip-core` algorithm with specific bindings to DOM events and the React component lifecycle.

The main architectural motivations for the design of the new of the React component are simplicity and declarative composability with a simple interface inspired by modules like `react-motion`, `react-router`, and `redux-form`.

The component behaves as an inline "decorator" which enhances a provided `Content` component with tooltip layout behavior. Because it avoids owning any unnecessary state, it requires a parent component (or global state e.g. Redux) to manage the target rect and "active" state.

It also forgoes implementing what could be seen as valuable core features for the sake of simplicity. Additional libraries like `react-resize-observer`, `react-motion`, `tj/react-click-outside`, and `focus-trap-react` are recommended to compose a full user experience. Since `flowtip-react-dom` renders no markup of it's own and defers all rendering responsibility to consumer defined components, composition with the mentioned libraries should be without conflict.

This minimal approach offers the best balance of core features and compatibility with various consumer use cases.
@10xjs 10xjs merged commit 5f5e8c8 into master Aug 31, 2017
@10xjs 10xjs deleted the 5.x.x branch August 31, 2017 01:10
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

Successfully merging this pull request may close these issues.

3 participants