-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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
Conversation
d74e361
to
35824c8
Compare
There was a problem hiding this 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; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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 } |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, thanks @stacey-gammon!
There was a problem hiding this comment.
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)}> |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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;
There was a problem hiding this 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.
* port k7 popover component over * Fix line height * Clean up css
Design in K6:
Design in k7: