-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Performance issue with Loans list (#983)
* implement dropdown with Popper component * lint changes
- Loading branch information
Showing
3 changed files
with
150 additions
and
43 deletions.
There are no files selected for viewing
8 changes: 8 additions & 0 deletions
8
src/components/Loans/OpenLoans/components/ActionsDropdown/ActionsDropdown.css
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,8 @@ | ||
.actionDropDown { | ||
padding: 7px 3px; | ||
background-color: #fff; | ||
border-radius: 6px; | ||
border: 1px solid #ccc; | ||
box-shadow: 0 4px 32px rgba(0, 0, 0, 0.175); | ||
pointer-events: all; | ||
} |
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
82 changes: 82 additions & 0 deletions
82
src/components/Loans/OpenLoans/components/ActionsDropdown/Popdown.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,82 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { | ||
Button, | ||
} from '@folio/stripes/components'; | ||
/* eslint-disable */ | ||
import Popper from '@folio/stripes-components/lib/Popper/Popper'; | ||
import RootCloseWrapper from 'react-overlays/lib/RootCloseWrapper'; | ||
/* eslint-enable */ | ||
|
||
class Popdown extends React.Component { | ||
static propTypes = { | ||
children: PropTypes.node, | ||
buttonProps: PropTypes.object, | ||
label: PropTypes.node, | ||
renderTrigger: PropTypes.func, | ||
portal: PropTypes.bool, | ||
} | ||
|
||
constructor(props) { | ||
super(props); | ||
this.state = { | ||
open: false | ||
}; | ||
|
||
this.triggerRef = React.createRef(); | ||
} | ||
|
||
toggleMenu = (e) => { | ||
e.stopPropagation(); | ||
this.setState((curState) => { | ||
return { | ||
open: !curState.open | ||
}; | ||
}); | ||
}; | ||
|
||
renderTrigger = () => { | ||
const { renderTrigger: renderTriggerProp, buttonProps, label } = this.props; | ||
const ariaProps = { | ||
'aria-expanded': this.state.open, | ||
'aria-haspopup': true | ||
}; | ||
|
||
if (renderTriggerProp) { | ||
return renderTriggerProp(this.triggerRef, this.toggleMenu, ariaProps); | ||
} | ||
|
||
return ( | ||
<Button | ||
buttonRef={this.triggerRef} | ||
buttonStyle="none" | ||
onClick={this.toggleMenu} | ||
{...buttonProps} | ||
{...ariaProps} | ||
> | ||
{label} | ||
</Button> | ||
); | ||
} | ||
|
||
render() { | ||
const { children, portal } = this.props; | ||
const portalEl = document.getElementById('OverlayContainer'); | ||
return ( | ||
<React.Fragment> | ||
{this.renderTrigger()} | ||
<Popper | ||
isOpen={this.state.open} | ||
anchorRef={this.triggerRef} | ||
portal={portal ? portalEl : null} | ||
> | ||
<RootCloseWrapper onRootClose={this.toggleMenu}> | ||
{children} | ||
</RootCloseWrapper> | ||
</Popper> | ||
</React.Fragment> | ||
); | ||
} | ||
} | ||
|
||
export default Popdown; |