mirror of
https://github.com/EnixCoda/Gitako.git
synced 2026-03-11 08:54:44 +00:00
feat: basic auto sizer
This commit is contained in:
parent
26b841921f
commit
82e7f94156
1 changed files with 38 additions and 0 deletions
38
src/components/AutoSizer.js
Normal file
38
src/components/AutoSizer.js
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
import React from 'react'
|
||||
import PropTypes from 'prop-types'
|
||||
|
||||
export default class AutoSizer extends React.Component {
|
||||
static propTypes = {}
|
||||
|
||||
static defaultProps = {}
|
||||
|
||||
state = {
|
||||
size: {
|
||||
width: 0,
|
||||
height: 0,
|
||||
},
|
||||
}
|
||||
|
||||
ref = React.createRef()
|
||||
|
||||
componentDidMount() {
|
||||
const container = this.ref.current
|
||||
if (container) {
|
||||
this.setState({
|
||||
size: {
|
||||
width: container.offsetWidth,
|
||||
height: container.offsetHeight,
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
render() {
|
||||
const { size } = this.state
|
||||
return (
|
||||
<div {...this.props} ref={this.ref}>
|
||||
{this.props.children(size)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue