feat: moved to shared-components and implemented focal point picker in RTE
This commit is contained in:
53
shared-components/FocalPointPicker/index.tsx
Normal file
53
shared-components/FocalPointPicker/index.tsx
Normal file
@@ -0,0 +1,53 @@
|
||||
import React from "react"
|
||||
|
||||
import useFocalPoint from "./useFocalPoint"
|
||||
import type { FocalPoint } from "~/types/imagevault"
|
||||
|
||||
import "./focalPointPicker.css"
|
||||
|
||||
export interface FocalPointPickerProps {
|
||||
focalPoint?: FocalPoint
|
||||
imageSrc: string
|
||||
onChange: (focalPoint: FocalPoint) => void
|
||||
}
|
||||
|
||||
export default function FocalPointPicker({
|
||||
focalPoint,
|
||||
imageSrc,
|
||||
onChange,
|
||||
}: FocalPointPickerProps) {
|
||||
const { ref, x, y, onMove, canMove, setCanMove } = useFocalPoint({
|
||||
focalPoint,
|
||||
onChange,
|
||||
})
|
||||
|
||||
const imagesArray = Array.from({ length: 4 })
|
||||
|
||||
return (
|
||||
<div className="container">
|
||||
<div className="focalPointWrapper" ref={ref} onMouseMove={onMove}>
|
||||
<button
|
||||
className="focalPointButton"
|
||||
style={{
|
||||
left: `${x}%`,
|
||||
top: `${y}%`,
|
||||
cursor: canMove ? "grabbing" : "grab",
|
||||
}}
|
||||
onMouseDown={() => setCanMove(true)}
|
||||
onMouseUp={() => setCanMove(false)}
|
||||
></button>
|
||||
<img className="focalPointImage" src={imageSrc} alt="" />
|
||||
</div>
|
||||
<div className="examples">
|
||||
{imagesArray.map((_, idx) => (
|
||||
<img
|
||||
key={idx}
|
||||
src={imageSrc}
|
||||
alt=""
|
||||
style={{ objectPosition: `${x}% ${y}%` }}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user