2023-06-01 20:18:37 +02:00
|
|
|
// Dependencies
|
2023-06-22 10:52:02 -05:00
|
|
|
import { forwardRef, useContext } from 'react'
|
2023-06-01 20:18:37 +02:00
|
|
|
// Hooks
|
|
|
|
import { useTranslation } from 'next-i18next'
|
|
|
|
// Context
|
2023-06-22 14:57:47 -05:00
|
|
|
import { PanZoomContext } from 'shared/components/workbench/pattern/pan-zoom-context.mjs'
|
2023-06-01 20:18:37 +02:00
|
|
|
// Components
|
|
|
|
import { TransformWrapper, TransformComponent } from 'react-zoom-pan-pinch'
|
|
|
|
import { Pattern } from 'pkgs/react-components/src/index.mjs'
|
|
|
|
|
|
|
|
export const ns = ['workbench']
|
|
|
|
|
2023-06-23 20:17:59 -05:00
|
|
|
/*
|
|
|
|
* A pattern you can pan and zoom
|
2023-06-01 20:18:37 +02:00
|
|
|
*/
|
|
|
|
export const PanZoomPattern = forwardRef((props, ref) => {
|
|
|
|
const { t } = useTranslation(ns)
|
|
|
|
|
2023-06-07 14:12:51 -05:00
|
|
|
const { renderProps = false, components = {} } = props
|
2023-06-22 10:52:02 -05:00
|
|
|
const { onTransformed, setZoomFunctions } = useContext(PanZoomContext)
|
2023-06-01 20:18:37 +02:00
|
|
|
|
|
|
|
return (
|
2023-06-23 20:17:59 -05:00
|
|
|
<TransformWrapper
|
|
|
|
minScale={0.1}
|
|
|
|
centerZoomedOut={true}
|
|
|
|
wheel={{ activationKeys: ['Control'] }}
|
|
|
|
doubleClick={{ mode: 'reset' }}
|
|
|
|
onTransformed={onTransformed}
|
|
|
|
onInit={setZoomFunctions}
|
|
|
|
>
|
|
|
|
<TransformComponent
|
|
|
|
wrapperStyle={{ width: '100%', height: '100%' }}
|
|
|
|
contentStyle={{ width: '100%', height: '100%' }}
|
|
|
|
wrapperClass={'pan-zoom-pattern'}
|
|
|
|
id="pan-zoom-pattern"
|
|
|
|
>
|
2023-06-26 11:41:56 -05:00
|
|
|
{props.children || <Pattern {...{ t, components, renderProps }} ref={ref} />}
|
2023-06-23 20:17:59 -05:00
|
|
|
</TransformComponent>
|
|
|
|
</TransformWrapper>
|
2023-06-01 20:18:37 +02:00
|
|
|
)
|
|
|
|
})
|
2023-06-07 14:12:51 -05:00
|
|
|
|
|
|
|
PanZoomPattern.displayName = 'PanZoomPattern'
|