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

port k7 popover component over #13322

Merged
merged 5 commits into from
Aug 9, 2017

Conversation

stacey-gammon
Copy link
Contributor

Design in K6:

screen shot 2017-08-03 at 2 11 00 pm

Design in k7:

screen shot 2017-08-03 at 1 42 02 pm

@stacey-gammon stacey-gammon added Team:Platform-Design Team Label for Kibana Design Team. Support the Analyze group of plugins. :Sharing review v6.1.0 labels Aug 3, 2017
@stacey-gammon stacey-gammon requested a review from cjcenizal August 3, 2017 18:13
Copy link
Contributor

@cjcenizal cjcenizal left a comment

Choose a reason for hiding this comment

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

Nice job porting this over! Looks great overall, just had a couple suggestions.

$popOverBackgroundColor: #FFF;
$popOverBorder: 1 solid #D9D9D9;
$tabHoverBackgroundColor: #F2F2F2;
$popOverSizeS: 8px;
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we remove this? It doesn't look like it's being used.

@@ -0,0 +1,6 @@
$popOverBackgroundColor: #FFF;
$popOverBorder: 1 solid #D9D9D9;
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we remove this? Looks like it's not in use.

@@ -0,0 +1,6 @@
$popOverBackgroundColor: #FFF;
$popOverBorder: 1 solid #D9D9D9;
$tabHoverBackgroundColor: #F2F2F2;
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this one is leftover from a copy-paste.


return (
<div
onClick={ this.onClickRootElement }
Copy link
Contributor

Choose a reason for hiding this comment

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

Since this pattern is now being used for both Popover and the ColorPicker, I wonder if we should extract this out into a reusable component. @zinckiwi didn't you have this idea originally, something like <KuiClickOutsideToClose>?

I didn't test this, but I think we could generally use it like this:

<KuiClickOutsideToClose
  onClickOutside={this.props.closePopover}
>
  <div
    className={ classes }
    { ...rest }
  >
    {button}
    {body}
  </div>
</KuiClickOutsideToClose>

And I think the component would look like this:

export class KuiClickOutsideToClose extends Component {
  constructor(props) {
    super(props);

    // Use this variable to differentiate between clicks on the element that should not cause the pop up
    // to close, and external clicks that should cause the pop up to close.
    this.didClickMyself = false;
  }

  onClickOutside = () => {
    if (this.didClickMyself) {
      this.didClickMyself = false;
      return;
    }
 
    this.props.onClickOutside();
  };

  onClickRootElement = () => {
    // This prevents clicking on the element from closing it, due to the event handler on the
    // document object.
    this.didClickMyself = true;
  };

  componentDidMount() {
    // When the user clicks somewhere outside of the color picker, we will dismiss it.
    document.addEventListener('click', this.onClickOutside);
  }

  componentWillUnmount() {
    document.removeEventListener('click', this.onClickOutside);
  }

  render() {
    const props = Object.assign({}, this.props.children.props, {
      onClick: this.onClickRootElement,
    });

    return cloneElement(this.props.children, props);
  }
}

Thoughts?

Copy link

@zinckiwi zinckiwi Aug 7, 2017

Choose a reason for hiding this comment

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

Yeah, that's the gist. It can also be extended in the future to handle tabbing-out of its content if applicable/desirable.

Unless there's a recent change I'm not up to date on, I believe the preferred pattern for the child mutation is:

render() {
  return React.Children.only(child =>
    React.cloneElement(child, {
      onClick: this.onClickRootElement
    })
}

It's a stylistic preference as to whether to enforce a single child (with React.Children.only) or to support arbitrary content (in which case you'll need to render a containing div or equivalent, and attach the onClick handler to that). I have a slight preference for the latter so you don't have to remember that child React components need to handle the onClick, but it does create an extra element.

Copy link
Contributor

Choose a reason for hiding this comment

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

so you don't have to remember that child React components need to handle the onClick

Could you explain what you mean by this? KuiClickOutsideToClose is adding the onClick handler to the child, so I'm not sure I see why you'd have to remember that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm in favor, but mind if I create an issue for this to track/tackle it separately and not be a requirement of this PR?

Copy link
Contributor

Choose a reason for hiding this comment

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

Sure, thanks @stacey-gammon!

Copy link

Choose a reason for hiding this comment

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

It adds it to the child which is fine for html elements (div etc.) since they implicitly bind any html handler. But React components don't have to. I could have a <SomeChild /> component as the child of KuiClickOutsideToClose and if it didn't {...props} or onclick={ this.props.onClick } nothing would happen.


render() {
const button = (
<KuiButton onClick={this.onButtonClick.bind(this)}>
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we add buttonType="basic" to the Button instances in these examples, just so they don't look funny?


// Animation happens on the body.
.kuiPopover__body {
line-height: 20px;
Copy link
Contributor

Choose a reason for hiding this comment

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

We can match the typography of other components by changing this to:

    line-height: $globalLineHeight;
    font-size: $globalFontSize;

Copy link
Contributor

@cjcenizal cjcenizal left a comment

Choose a reason for hiding this comment

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

🚀 Awesome! I'm so glad we're able to port components over like this.

@stacey-gammon stacey-gammon merged commit 7199476 into elastic:master Aug 9, 2017
stacey-gammon added a commit to stacey-gammon/kibana that referenced this pull request Aug 9, 2017
* port k7 popover component over

* Fix line height

* Clean up css
stacey-gammon added a commit that referenced this pull request Aug 9, 2017
* port k7 popover component over

* Fix line height

* Clean up css
@stacey-gammon stacey-gammon deleted the design/panel-menu branch October 24, 2017 13:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
review Team:Platform-Design Team Label for Kibana Design Team. Support the Analyze group of plugins. v6.1.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants