-
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.
- Loading branch information
Showing
14 changed files
with
136 additions
and
77 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
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,47 @@ | ||
import { FunctionComponent, PropsWithChildren } from "react"; | ||
import * as Styled from "./styles"; | ||
|
||
export interface FrameProps { | ||
aspectRatio: string; | ||
zoom?: number; | ||
position?: string; | ||
className?: string; | ||
} | ||
|
||
const defaultRatio = "16:9"; | ||
const defaultPosition = "50% 50%"; | ||
const defaultZoom = 1; | ||
|
||
const Frame: FunctionComponent<PropsWithChildren<FrameProps>> = ({ | ||
aspectRatio = defaultRatio, | ||
position = defaultPosition, | ||
zoom = defaultZoom, | ||
className, | ||
children, | ||
}) => { | ||
let ratio = aspectRatio.split(":"); | ||
|
||
if (ratio.length < 2) { | ||
ratio = defaultRatio.split(":"); | ||
} | ||
|
||
const [n, d] = ratio; | ||
|
||
return ( | ||
<Styled.Frame | ||
style={{ | ||
"--n": n, | ||
"--d": d, | ||
"--position-img": position, | ||
"--zoom-img": zoom, | ||
}} | ||
className={className} | ||
> | ||
{children} | ||
</Styled.Frame> | ||
); | ||
}; | ||
|
||
Frame.displayName = "Atomic.Frame"; | ||
|
||
export default Frame; |
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,18 @@ | ||
import styled from "styled-components"; | ||
|
||
export const Frame = styled.div` | ||
aspect-ratio: var(--n) / var(--d); | ||
overflow: hidden; | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
& > img, | ||
& > video { | ||
inline-size: 100%; | ||
block-size: 100%; | ||
object-fit: cover; | ||
object-position: var(--position-img); | ||
transform: scale(var(--zoom-img)); | ||
} | ||
`; |
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
30 changes: 0 additions & 30 deletions
30
packages/epo-react-lib/src/atomic/ResponsiveImage/ResponsiveImage.tsx
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
21 changes: 0 additions & 21 deletions
21
packages/epo-react-lib/src/atomic/ResponsiveImage/styles.ts
This file was deleted.
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
36 changes: 36 additions & 0 deletions
36
packages/epo-react-lib/src/molecules/ResponsiveImage/index.tsx
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,36 @@ | ||
import { FunctionComponent } from "react"; | ||
import { ImageProps } from "@/atomic/Image"; | ||
import Frame from "@/atomic/Frame"; | ||
import Image from "@/atomic/Image"; | ||
|
||
interface ResponsiveImageProps extends ImageProps { | ||
/** @deprecated use `aspectRatio` instead */ | ||
ratio?: string; | ||
aspectRatio: string; | ||
position?: string; | ||
zoom?: number; | ||
} | ||
|
||
const defaultRatio = "8:5"; | ||
|
||
const ResponsiveImage: FunctionComponent<ResponsiveImageProps> = ({ | ||
ratio = defaultRatio, | ||
aspectRatio = defaultRatio, | ||
zoom, | ||
position, | ||
className, | ||
...props | ||
}) => { | ||
return ( | ||
<Frame | ||
{...{ className, position, zoom }} | ||
aspectRatio={aspectRatio || ratio} | ||
> | ||
<Image {...props} /> | ||
</Frame> | ||
); | ||
}; | ||
|
||
ResponsiveImage.displayName = "Atomic.ResponsiveImage"; | ||
|
||
export default ResponsiveImage; |
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