|
| 1 | +import React from 'react'; |
| 2 | +import { FocalPoint } from '@lemoncode/react-image-focal-point'; |
| 3 | +import classes from './playground.module.css'; |
| 4 | + |
| 5 | +interface Props { |
| 6 | + src: string; |
| 7 | + focalPoint?: FocalPoint; |
| 8 | + children: React.ReactNode; |
| 9 | +} |
| 10 | + |
| 11 | +export const Playground: React.FC<Props> = props => { |
| 12 | + const { src, children } = props; |
| 13 | + const [focalPoint, setFocalPoint] = React.useState<FocalPoint>(); |
| 14 | + |
| 15 | + const handleSubmit = (event: React.FormEvent<HTMLFormElement>) => { |
| 16 | + event.preventDefault(); |
| 17 | + if (props.focalPoint) { |
| 18 | + setFocalPoint(props.focalPoint); |
| 19 | + } |
| 20 | + }; |
| 21 | + |
| 22 | + return ( |
| 23 | + <div className={classes.root}> |
| 24 | + <h1 className={classes.title}>Basic example, apply button</h1> |
| 25 | + <p className={classes.description}> |
| 26 | + In this example you can play changing the focal point by dragging it, and once you are done you can click on the |
| 27 | + apply button and it will reflected on the example pictures |
| 28 | + </p> |
| 29 | + <h2 className={classes.focalPointSubtitle}>Image focal point</h2> |
| 30 | + <form className={classes.focalPoint} onSubmit={handleSubmit}> |
| 31 | + {children} |
| 32 | + <button className={classes.submitButton} type="submit"> |
| 33 | + Apply |
| 34 | + </button> |
| 35 | + </form> |
| 36 | + |
| 37 | + <h2 className={classes.resultSubtitle}>Example results</h2> |
| 38 | + <div className={classes.result}> |
| 39 | + <img |
| 40 | + src={src} |
| 41 | + className={classes.portraitImage} |
| 42 | + style={{ objectPosition: `${focalPoint?.x}% ${focalPoint?.y}%` }} |
| 43 | + /> |
| 44 | + <img |
| 45 | + src={src} |
| 46 | + className={classes.landscapeImage} |
| 47 | + style={{ objectPosition: `${focalPoint?.x}% ${focalPoint?.y}%` }} |
| 48 | + /> |
| 49 | + <img |
| 50 | + src={src} |
| 51 | + className={classes.squareImage} |
| 52 | + style={{ objectPosition: `${focalPoint?.x}% ${focalPoint?.y}%` }} |
| 53 | + /> |
| 54 | + </div> |
| 55 | + </div> |
| 56 | + ); |
| 57 | +}; |
0 commit comments