-
Notifications
You must be signed in to change notification settings - Fork 332
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new Toolbar.Popover component to display anything in a Toolbar (#…
…5692) * Introduce popover component for Toolbar * Add some very basic styling for the Toolbar Popover
- Loading branch information
Showing
16 changed files
with
300 additions
and
210 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
src/Sulu/Bundle/AdminBundle/Resources/js/components/Toolbar/Popover.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
// @flow | ||
import React from 'react'; | ||
import type {ElementRef} from 'react'; | ||
import {action, observable} from 'mobx'; | ||
import {observer} from 'mobx-react'; | ||
import classNames from 'classnames'; | ||
import PopoverComponent from '../Popover'; | ||
import type {Popover as PopoverProps} from './types'; | ||
import Button from './Button'; | ||
import popoverStyles from './popover.scss'; | ||
|
||
@observer | ||
class Popover extends React.Component<PopoverProps> { | ||
@observable open: boolean = false; | ||
|
||
static defaultProps = { | ||
showText: true, | ||
}; | ||
|
||
@observable buttonRef: ?ElementRef<'button'>; | ||
|
||
@action setButtonRef = (ref: ?ElementRef<'button'>) => { | ||
if (ref) { | ||
this.buttonRef = ref; | ||
} | ||
}; | ||
|
||
@action close = () => { | ||
this.open = false; | ||
}; | ||
|
||
@action toggle = () => { | ||
this.open = !this.open; | ||
}; | ||
|
||
componentDidUpdate() { | ||
const {disabled} = this.props; | ||
|
||
if (disabled) { | ||
this.close(); | ||
} | ||
} | ||
|
||
handleButtonClick = () => { | ||
this.toggle(); | ||
}; | ||
|
||
handlePopoverClose = () => { | ||
this.close(); | ||
}; | ||
|
||
render() { | ||
const { | ||
children, | ||
className, | ||
icon, | ||
size, | ||
skin, | ||
label, | ||
disabled, | ||
loading, | ||
showText, | ||
} = this.props; | ||
const popoverClass = classNames( | ||
className, | ||
popoverStyles.popover, | ||
{ | ||
[popoverStyles[size]]: size, | ||
} | ||
); | ||
|
||
return ( | ||
<div className={popoverClass}> | ||
<Button | ||
active={this.open} | ||
buttonRef={this.setButtonRef} | ||
disabled={disabled} | ||
hasOptions={true} | ||
icon={icon} | ||
label={showText ? label : undefined} | ||
loading={loading} | ||
onClick={this.handleButtonClick} | ||
size={size} | ||
skin={skin} | ||
/> | ||
<PopoverComponent | ||
anchorElement={this.buttonRef} | ||
onClose={this.handlePopoverClose} | ||
open={this.open} | ||
> | ||
{ | ||
(setPopoverElementRef, popoverStyle) => ( | ||
<div className={popoverStyles[skin]} ref={setPopoverElementRef} style={popoverStyle}> | ||
{children(this.close)} | ||
</div> | ||
) | ||
} | ||
</PopoverComponent> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
export default Popover; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.