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
[example] More expansive device detection and not load hidden imaged #38
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 |
---|---|---|
|
@@ -34,8 +34,37 @@ const LargeStyle: CSSProperties = { | |
backgroundColor: "red", | ||
} | ||
|
||
// From https://www.smashingmagazine.com/2013/07/simple-responsive-images-with-css-background-images/ | ||
const Img: React.SFC< | ||
{ src: string; aspectRatio: number } & React.HTMLProps<HTMLSpanElement> | ||
> = ({ src, aspectRatio, style, ...props }) => ( | ||
<span | ||
{...props} | ||
style={{ | ||
width: "100%", | ||
display: "inline-block", | ||
fontSize: "0", | ||
lineHeight: "0", | ||
verticalAlign: "middle", | ||
backgroundSize: "100%", | ||
backgroundPosition: "50% 50%", | ||
backgroundRepeat: "no-repeat", | ||
backgroundImage: `url(${src})`, | ||
...style, | ||
}} | ||
> | ||
<span | ||
style={{ | ||
display: "block", | ||
height: "0", | ||
paddingTop: `${(aspectRatio * 100).toFixed(2)}%`, | ||
}} | ||
/> | ||
</span> | ||
) | ||
|
||
export const App: React.SFC = () => ( | ||
<div style={{ width: "400px" }}> | ||
<div> | ||
<div> | ||
<h1> | ||
Default <code><div></code> container | ||
|
@@ -135,5 +164,29 @@ export const App: React.SFC = () => ( | |
</div> | ||
</Media> | ||
</div> | ||
<div> | ||
<h1>Example of not loading hidden images</h1> | ||
<Media lessThan="md"> | ||
<Img | ||
aspectRatio={1.261044176706827} | ||
src="https://d32dm0rphc51dk.cloudfront.net/JAo7pAN1p63YwolybeZgOg/small.jpg" | ||
style={{ width: "100px" }} | ||
/> | ||
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. How does this translate to Reaction and other consumers? What will be required on the app side of things? 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. This is the most extreme version imaginable, I don’t believe we have any place on Artsy where the size of the image isn’t constrained along at least one axis. The important part is using 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 guess what I'm wondering is is there's anything we have to change in our codebase -- modify all images to use a background image rather than 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. Gotcha. Yeah I think we’d have an |
||
</Media> | ||
<Media at="md"> | ||
<Img | ||
aspectRatio={1.261044176706827} | ||
src="https://d32dm0rphc51dk.cloudfront.net/JAo7pAN1p63YwolybeZgOg/medium.jpg" | ||
style={{ width: "400px" }} | ||
/> | ||
</Media> | ||
<Media at="lg"> | ||
<Img | ||
aspectRatio={1.261044176706827} | ||
src="https://d32dm0rphc51dk.cloudfront.net/JAo7pAN1p63YwolybeZgOg/large.jpg" | ||
style={{ width: "800px" }} | ||
/> | ||
</Media> | ||
</div> | ||
</div> | ||
) |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"extends": "../tsconfig.json", | ||
"compilerOptions": { | ||
"rootDirs": ["../example", "../src"], | ||
"resolveJsonModule": true | ||
} | ||
} |
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.
All of this is to automatically size the container according to the actual aspect ratio. In cases the width and height are fixed this shouldn’t be necessary.