1
0
Fork 0
freesewing/sites/shared/components/workbench/pan-zoom-pattern.mjs

51 lines
1.5 KiB
JavaScript
Raw Normal View History

2023-09-29 16:01:27 +02:00
// __SDEFILE__ - This file is a dependency for the stand-alone environment
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"
>
{props.children || (
<Pattern
{...{ t, components, renderProps }}
ref={ref}
className="freesewing pattern w-full"
/>
)}
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'