reset zoom buttons
This commit is contained in:
parent
8071d33c96
commit
b5dea67d6c
5 changed files with 245 additions and 141 deletions
|
@ -0,0 +1,28 @@
|
|||
import React, { useState, useMemo } from 'react'
|
||||
|
||||
export const PanZoomContext = React.createContext({})
|
||||
|
||||
export const PanZoomContextProvider = ({ children }) => {
|
||||
const [zoomed, setZoomed] = useState(false)
|
||||
const [_zoomFunctions, setZoomFunctions] = useState(false)
|
||||
|
||||
const value = useMemo(() => {
|
||||
const onTransformed = (_ref, state) => {
|
||||
setZoomed(state.scale !== 1)
|
||||
}
|
||||
|
||||
const reset = () => {
|
||||
setZoomed(false)
|
||||
_zoomFunctions.resetTransform()
|
||||
}
|
||||
|
||||
return {
|
||||
zoomed,
|
||||
zoomFunctions: _zoomFunctions ? { ..._zoomFunctions, reset } : false,
|
||||
setZoomFunctions,
|
||||
onTransformed,
|
||||
}
|
||||
}, [zoomed, setZoomed, _zoomFunctions, setZoomFunctions])
|
||||
|
||||
return <PanZoomContext.Provider value={value}>{children}</PanZoomContext.Provider>
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue