Add dbclick to full size
parent
295d196e01
commit
64898d14e3
|
@ -11,7 +11,8 @@ interface Props {
|
||||||
draggable: boolean
|
draggable: boolean
|
||||||
orientation: string
|
orientation: string
|
||||||
render: () => ReactElement<any>
|
render: () => ReactElement<any>
|
||||||
onHandleStartDrag: (id: string, e: MouseEvent<HTMLElement>) => any
|
onHandleStartDrag: (id: string, e: MouseEvent<HTMLElement>) => void
|
||||||
|
onDoubleClick: (id: string) => void
|
||||||
}
|
}
|
||||||
|
|
||||||
class Division extends PureComponent<Props> {
|
class Division extends PureComponent<Props> {
|
||||||
|
@ -24,7 +25,11 @@ class Division extends PureComponent<Props> {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div className="threesizer--division" style={this.style}>
|
<div className="threesizer--division" style={this.style}>
|
||||||
<div className="threesizer--handle" onMouseDown={this.dragCallback}>
|
<div
|
||||||
|
className={`threesizer--handle ${this.disabled}`}
|
||||||
|
onMouseDown={this.dragCallback}
|
||||||
|
onDoubleClick={this.handleDoubleClick}
|
||||||
|
>
|
||||||
{name}
|
{name}
|
||||||
</div>
|
</div>
|
||||||
{render()}
|
{render()}
|
||||||
|
@ -33,12 +38,26 @@ class Division extends PureComponent<Props> {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private get disabled(): string {
|
||||||
|
const {draggable} = this.props
|
||||||
|
if (draggable) {
|
||||||
|
return ''
|
||||||
|
}
|
||||||
|
|
||||||
|
return 'disabled'
|
||||||
|
}
|
||||||
|
|
||||||
private get style() {
|
private get style() {
|
||||||
return {
|
return {
|
||||||
height: `calc((100% - 90px) * ${this.props.size} + 30px)`,
|
height: `calc((100% - 90px) * ${this.props.size} + 30px)`,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private handleDoubleClick = () => {
|
||||||
|
const {id, onDoubleClick} = this.props
|
||||||
|
return onDoubleClick(id)
|
||||||
|
}
|
||||||
|
|
||||||
private dragCallback = e => {
|
private dragCallback = e => {
|
||||||
const {draggable, id} = this.props
|
const {draggable, id} = this.props
|
||||||
if (!draggable) {
|
if (!draggable) {
|
||||||
|
|
|
@ -123,6 +123,7 @@ class Threesizer extends Component<Props, State> {
|
||||||
minPixels={d.minPixels}
|
minPixels={d.minPixels}
|
||||||
orientation={orientation}
|
orientation={orientation}
|
||||||
activeHandleID={activeHandleID}
|
activeHandleID={activeHandleID}
|
||||||
|
onDoubleClick={this.handleDoubleClick}
|
||||||
onHandleStartDrag={this.handleStartDrag}
|
onHandleStartDrag={this.handleStartDrag}
|
||||||
render={this.props.divisions[i].render}
|
render={this.props.divisions[i].render}
|
||||||
/>
|
/>
|
||||||
|
@ -155,13 +156,24 @@ class Threesizer extends Component<Props, State> {
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private handleDoubleClick = (id: string): void => {
|
||||||
|
const divisions = this.state.divisions.map(d => {
|
||||||
|
if (d.id !== id) {
|
||||||
|
return {...d, size: 0}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {...d, size: 1}
|
||||||
|
})
|
||||||
|
|
||||||
|
this.setState({divisions})
|
||||||
|
}
|
||||||
|
|
||||||
private handleStartDrag = (activeHandleID, e: MouseEvent<HTMLElement>) => {
|
private handleStartDrag = (activeHandleID, e: MouseEvent<HTMLElement>) => {
|
||||||
const dragEvent = this.mousePosWithinContainer(e)
|
const dragEvent = this.mousePosWithinContainer(e)
|
||||||
this.setState({activeHandleID, dragEvent})
|
this.setState({activeHandleID, dragEvent})
|
||||||
}
|
}
|
||||||
|
|
||||||
private handleStopDrag = () => {
|
private handleStopDrag = () => {
|
||||||
console.log('handleStopDrag')
|
|
||||||
this.setState({activeHandleID: '', dragEvent: initialDragEvent})
|
this.setState({activeHandleID: '', dragEvent: initialDragEvent})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -209,42 +221,6 @@ class Threesizer extends Component<Props, State> {
|
||||||
return Math.abs(delta / height)
|
return Math.abs(delta / height)
|
||||||
}
|
}
|
||||||
|
|
||||||
private minPercentX = (xMinPixels: number): number => {
|
|
||||||
if (!this.containerRef) {
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
const {width} = this.containerRef.getBoundingClientRect()
|
|
||||||
|
|
||||||
return xMinPixels / width
|
|
||||||
}
|
|
||||||
|
|
||||||
private minPercentY = (yMinPixels: number): number => {
|
|
||||||
if (!this.containerRef) {
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
const {height} = this.containerRef.getBoundingClientRect()
|
|
||||||
return yMinPixels / height
|
|
||||||
}
|
|
||||||
|
|
||||||
private get maximumHeightPercent(): number {
|
|
||||||
if (!this.containerRef) {
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
|
|
||||||
const {divisions} = this.state
|
|
||||||
const {height} = this.containerRef.getBoundingClientRect()
|
|
||||||
|
|
||||||
const totalMinPixels = divisions.reduce(
|
|
||||||
(acc, div) => acc + div.minPixels,
|
|
||||||
0
|
|
||||||
)
|
|
||||||
|
|
||||||
const maximumPixels = height - totalMinPixels
|
|
||||||
|
|
||||||
return this.minPercentY(maximumPixels)
|
|
||||||
}
|
|
||||||
|
|
||||||
private handleDrag = (e: MouseEvent<HTMLElement>) => {
|
private handleDrag = (e: MouseEvent<HTMLElement>) => {
|
||||||
const {activeHandleID} = this.state
|
const {activeHandleID} = this.state
|
||||||
if (!activeHandleID) {
|
if (!activeHandleID) {
|
||||||
|
@ -255,16 +231,6 @@ class Threesizer extends Component<Props, State> {
|
||||||
this.setState({dragEvent})
|
this.setState({dragEvent})
|
||||||
}
|
}
|
||||||
|
|
||||||
private taller = (size: number): number => {
|
|
||||||
const newSize = size + this.percentChangeY
|
|
||||||
return newSize > 1 ? 1 : newSize
|
|
||||||
}
|
|
||||||
|
|
||||||
private shorter = (size: number): number => {
|
|
||||||
const newSize = size - this.percentChangeY
|
|
||||||
return newSize < 0 ? 0 : newSize
|
|
||||||
}
|
|
||||||
|
|
||||||
private get move() {
|
private get move() {
|
||||||
const {activeHandleID} = this.state
|
const {activeHandleID} = this.state
|
||||||
|
|
||||||
|
@ -376,6 +342,16 @@ class Threesizer extends Component<Props, State> {
|
||||||
|
|
||||||
this.setState({divisions})
|
this.setState({divisions})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private taller = (size: number): number => {
|
||||||
|
const newSize = size + this.percentChangeY
|
||||||
|
return newSize > 1 ? 1 : newSize
|
||||||
|
}
|
||||||
|
|
||||||
|
private shorter = (size: number): number => {
|
||||||
|
const newSize = size - this.percentChangeY
|
||||||
|
return newSize < 0 ? 0 : newSize
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default Threesizer
|
export default Threesizer
|
||||||
|
|
Loading…
Reference in New Issue