-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: proper handling of user-specified aspect-ratio (#11)
- Introduce `<ImageWrapper />` to wrap `<Image />` when a custom aspect ratio is specified by the user (via the `style` prop). This prevents conflicts with our internally calculated aspect ratio, resolving previous sizing issues. - bump package version: `1.0.3`
- Loading branch information
1 parent
81d77de
commit 86a490a
Showing
6 changed files
with
45 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import type { CSSProperties, ReactNode } from "react"; | ||
|
||
interface ImageWrapperProps { | ||
aspectRatio: CSSProperties["aspectRatio"]; | ||
children: ReactNode; | ||
} | ||
|
||
const imageWrapperStyles: CSSProperties = { | ||
overflow: "hidden", | ||
}; | ||
|
||
/** | ||
* Wrapper component that applies a user-specified aspect ratio. | ||
* - Wraps the usual `<Image />` component when the user specifies `aspect-ratio` via the `style` prop. | ||
* - Position the inner image and blur by using `top`/`left` or `transform: translateX/translateY` on the `<Image />` component. | ||
* - Storybook example: https://visionary-ux.github.io/visionary-image/?path=/story/visionary-image--custom-aspect-ratio | ||
*/ | ||
export const ImageWrapper = ({ aspectRatio, children }: ImageWrapperProps) => ( | ||
<div style={{ aspectRatio, ...imageWrapperStyles }}>{children}</div> | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters