|
| 1 | +--- |
| 2 | +title: Basic |
| 3 | +--- |
| 4 | + |
| 5 | +import Tabs from '@theme/Tabs'; |
| 6 | +import TabItem from '@theme/TabItem'; |
| 7 | + |
| 8 | +Minimal example, here you can just drag the focal point and the example pictures focal point will be updated on real time. |
| 9 | + |
| 10 | +## How to apply this feature in your code |
| 11 | + |
| 12 | +Import the library styles and the component: |
| 13 | + |
| 14 | +```jsx title="app.tsx" showLineNumbers |
| 15 | +// highlight-start |
| 16 | +import '@lemoncode/react-image-focal-point/style.css'; |
| 17 | +import { ImageFocalPoint } from '@lemoncode/react-image-focal-point'; |
| 18 | +// highlight-end |
| 19 | + |
| 20 | +const App = () => { |
| 21 | + return ( |
| 22 | + |
| 23 | + ); |
| 24 | +} |
| 25 | + |
| 26 | +``` |
| 27 | + |
| 28 | +Then use the component: |
| 29 | + |
| 30 | +```jsx title="app.tsx" showLineNumbers |
| 31 | +import '@lemoncode/react-image-focal-point/style.css'; |
| 32 | +import { ImageFocalPoint } from '@lemoncode/react-image-focal-point'; |
| 33 | + |
| 34 | +const App = () => { |
| 35 | + return ( |
| 36 | + // highlight-start |
| 37 | + <ImageFocalPoint |
| 38 | + src="your-image-src" |
| 39 | + onChange={focalPoint => { |
| 40 | + // Add here your code to do whatever you want to when the user drags on the focal point |
| 41 | + }} |
| 42 | + /> |
| 43 | + // highlight-end |
| 44 | + ); |
| 45 | +}; |
| 46 | +``` |
| 47 | + |
| 48 | +## Live example |
| 49 | + |
| 50 | +<Tabs |
| 51 | + defaultValue="codesandbox" |
| 52 | + values={[ |
| 53 | + { label: 'Codesandbox', value: 'codesandbox' }, |
| 54 | + { label: 'Stackblitz', value: 'stackblitz' }, |
| 55 | + ]} |
| 56 | +> |
| 57 | + <TabItem value="stackblitz"> |
| 58 | + <a |
| 59 | + target="_blank" |
| 60 | + href="https://stackblitz.com/github/Lemoncode/react-image-focal-point/tree/main/examples/basic?embed=1&file=src%2Fapp.tsx" |
| 61 | + > |
| 62 | + <img |
| 63 | + src="https://developer.stackblitz.com/img/open_in_stackblitz.svg" |
| 64 | + alt="Edit on StackBlitz" |
| 65 | + title="Edit on StackBlitz" |
| 66 | + /> |
| 67 | + </a> |
| 68 | + <iframe |
| 69 | + src="https://stackblitz.com/github/Lemoncode/react-image-focal-point/tree/main/examples/basic?embed=1&file=src%2Fapp.tsx" |
| 70 | + style={{ width: '100%', height: '500px', border: 0, borderRadius: '4px', overflow: 'hidden' }} |
| 71 | + ></iframe> |
| 72 | + </TabItem> |
| 73 | + <TabItem value="codesandbox"> |
| 74 | + <a |
| 75 | + target="_blank" |
| 76 | + href="https://codesandbox.io/s/github/Lemoncode/react-image-focal-point/tree/main/examples/basic?file=/src/app.tsx" |
| 77 | + > |
| 78 | + <img |
| 79 | + src="https://codesandbox.io/static/img/play-codesandbox.svg" |
| 80 | + alt="Edit on Codesandbox" |
| 81 | + title="Edit on Codesandbox" |
| 82 | + /> |
| 83 | + </a> |
| 84 | + <iframe |
| 85 | + src="https://codesandbox.io/embed/github/Lemoncode/react-image-focal-point/tree/main/examples/basic?fontsize=14&hidenavigation=1&module=%2Fsrc%2Fapp.tsx&theme=dark&view=editor" |
| 86 | + style={{ width: '100%', height: '500px', border: 0, borderRadius: '4px', overflow: 'hidden' }} |
| 87 | + allow="accelerometer; ambient-light-sensor; camera; encrypted-media; geolocation; gyroscope; hid; microphone; midi; payment; usb; vr; xr-spatial-tracking" |
| 88 | + sandbox="allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts" |
| 89 | + ></iframe> |
| 90 | + </TabItem> |
| 91 | +</Tabs> |
0 commit comments