-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Revise README for FocalPointPicker component to use object-position #77722
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: trunk
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,9 @@ | ||
| # FocalPointPicker | ||
|
|
||
| Focal Point Picker is a component which creates a UI for identifying the most important visual point of an image. This component addresses a specific problem: with large background images it is common to see undesirable crops, especially when viewing on smaller viewports such as mobile phones. This component allows the selection of the point with the most important visual information and returns it as a pair of numbers between 0 and 1. This value can be easily converted into the CSS `background-position` attribute, and will ensure that the focal point is never cropped out, regardless of viewport. | ||
| Focal Point Picker is a component which creates a UI for identifying the most important visual point of an image. It addresses two common issues in responsive image rendering. First, large background images are often cropped in undesirable ways, especially on smaller viewports such as mobile devices. Second, the CSS aspect-ratio property can inadvertently crop out the area of highest visual interest. This component allows the selection of the point with the most important visual information and returns it as a pair of numbers between 0 and 1. This value can be easily converted into the CSS `object-position` attribute, and will ensure that the focal point is never cropped out, regardless of viewport. | ||
|
|
||
| - Example focal point picker value: `{ x: 0.5, y: 0.1 }` | ||
| - Corresponding CSS: `background-position: 50% 10%;` | ||
| - Corresponding CSS: `object-position: 50% 10%` | ||
|
Comment on lines
5
to
+6
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's add trailing semi-columns for both bullet points. |
||
|
|
||
| ## Usage | ||
|
|
||
|
|
@@ -14,15 +14,14 @@ import { FocalPointPicker } from '@wordpress/components'; | |
| const Example = () => { | ||
| const [ focalPoint, setFocalPoint ] = useState( { | ||
| x: 0.5, | ||
| y: 0.5, | ||
| y: 0.1, | ||
| } ); | ||
|
|
||
| const url = '/path/to/image'; | ||
|
|
||
| /* Example function to render the CSS styles based on Focal Point Picker value */ | ||
| const style = { | ||
| backgroundImage: `url(${ url })`, | ||
| backgroundPosition: `${ focalPoint.x * 100 }% ${ focalPoint.y * 100 }%`, | ||
| objectPosition: `${ focalPoint.x * 100 }% ${ focalPoint.y * 100 }%`, | ||
| }; | ||
|
|
||
| return ( | ||
|
|
@@ -34,7 +33,7 @@ const Example = () => { | |
| onDrag={ setFocalPoint } | ||
| onChange={ setFocalPoint } | ||
| /> | ||
| <div style={ style } /> | ||
| <img src={ url } style={ style } /> | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think the current example snippet will work as expected, we need to set const style = {
width: '100%',
aspectRatio: '16 / 9',
objectFit: 'cover',
objectPosition: `${ focalPoint.x * 100 }% ${ focalPoint.y * 100 }%`,
};
return (
<>
<FocalPointPicker
url={ url }
value={ focalPoint }
onDragStart={ setFocalPoint }
onDrag={ setFocalPoint }
onChange={ setFocalPoint }
/>
<img src={ url } alt="" style={ style } />
</>
); |
||
| </> | ||
| ); | ||
| }; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whatever changes we end up making to the README, we should always keep them in sync with the JSDoc in
index.tsx