Skip to content

Decouple flowtip-react-dom rendering logic#62

Merged
10xjs merged 2 commits intomasterfrom
decoupled-render
Mar 21, 2018
Merged

Decouple flowtip-react-dom rendering logic#62
10xjs merged 2 commits intomasterfrom
decoupled-render

Conversation

@10xjs
Copy link
Contributor

@10xjs 10xjs commented Mar 21, 2018

Remove the component rendering and style generation logic from within the FlowTip react component and allow it to be pluggable through a render interface.

The previous behavior is preserved through the default configuration. Different renderer types (other than a Content and Tail component interface) can be easily replace the default renderer.

Consumer-facing Changes:

Previously, the appearance could only be customized through the tail and content components. This interface remains supported and unchanged.

import FlowTip from 'flowtip-react-dom';

  <FlowTip target={this.state.target} content={Content} tail={Tail}>
    FlowTip Content
  </FlowTip>

Using the render prop, the consumer has lower-level access to the rendering behavior. This pattern has far fewer assumptions about the style or shape of the rendered DOM nodes.

import FlowTip from 'flowtip-react-dom';

  <FlowTip
    target={this.state.target}
    render={({onContentSize, onTailSize, state, props}) => {
      // entirely custom render logic
    }}
  >
    FlowTip Content
  </FlowTip>

@10xjs 10xjs force-pushed the decoupled-render branch 3 times, most recently from 62330af to ddfd1bd Compare March 21, 2018 01:12
Copy link
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.

The ideas behind this seem pretty great to me. Left a few thoughts. The only thing that might be an area to dry up is there seems to be some repeat logic around document.documentElement. Nothing critical though.

}

/**
* Determne if a rect-like object has valid positive area.
Copy link
Contributor

Choose a reason for hiding this comment

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

Spelling 😄

);
}

return null;
Copy link
Contributor

Choose a reason for hiding this comment

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

Should there be a warning in this case? Or use of invariant instead?

* @param {number} size - Height of the triangle in px.
* @returns {Object} Border triangle style.
*/
export const cssTriangle = (region: Region, color: string, size: number) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

What is this used for? There's no reference to it anywhere. Is this intended to be part of a separate thing to help consumers quickly generate carets for use in a tail component?

}

/**
* Get current minimum linear overlap value.
Copy link
Contributor

Choose a reason for hiding this comment

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

I know you've used this term before but is there a definition of what "linear" overlap is vs some other kind of overlap? This comment has little to do with the PR itself, just if it's going to be part of the nomenclature for this library a working definition would be handy. A cursory google reveals no common definition or use of this term.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

overlap is one of the named config options of flowtip-core

Copy link
Contributor

Choose a reason for hiding this comment

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

No concern with overlap – as above more curious what the linear qualifier means.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

"Linear" here refers to parallel with the edge of the target facing the content, as opposed to perpendicular.

The overlap related computations are effectively 2D with respect to one of the four regions.

/**
* Determne if a rect-like object has valid positive area.
*
* @param {object} [rect] A rect-like object.
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason this object is lowercase and all the other ones are not?

@10xjs 10xjs force-pushed the decoupled-render branch from ddfd1bd to 703c6d2 Compare March 21, 2018 20:49
10xjs added 2 commits March 21, 2018 14:06
Remove the component rendering and style generation logic from within the `FlowTip` react component and allow it to be pluggable through a `render` interface.

The previous behavior is preserved through the default configuration. Different renderer types (other than a `Content` and `Tail` component interface) can be easily replace the default renderer.
@10xjs 10xjs force-pushed the decoupled-render branch from 703c6d2 to 5e3c09c Compare March 21, 2018 21:13
@10xjs 10xjs merged commit 60e6763 into master Mar 21, 2018
@10xjs 10xjs deleted the decoupled-render branch March 21, 2018 22:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants