Skip to content

Commit

Permalink
feat(image): Add responsive image css class
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Raider committed Feb 27, 2019
1 parent 4c2683a commit 9255112
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 21 deletions.
48 changes: 48 additions & 0 deletions packages/ray/lib/_image.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
@mixin ImgContainer {
display: block;
width: 100%;
height: auto;
position: relative;
overflow: hidden;
background-color: $gray30;

img {
position: absolute;
width: 100%;
top: 0;
left: 0;
right: 0;
bottom: 0;
margin: auto;
}
}

.ImgContainer--16by9 {
@include ImgContainer;
padding-bottom: calc(100% / (16 / 9));
}

.ImgContainer--3by4 {
@include ImgContainer;
padding-bottom: calc(100% / (3 / 4));
}

@mixin Background {
display: block;
width: 100%;
height: auto;
background-color: $gray30;
background-size: cover;
background-position: center;
background-repeat: no-repeat;
}

.Background--16by9 {
@include Background;
padding-bottom: calc(100% / (16 / 9));
}

.Background--3by4 {
@include Background;
padding-bottom: calc(100% / (3 / 4));
}
2 changes: 1 addition & 1 deletion packages/ray/lib/application.scss
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
@import 'typography';
@import 'forms';
@import 'card';

@import 'image';
@import 'buttons';
42 changes: 22 additions & 20 deletions packages/ray/stories/card.stories.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
import React from 'react';
import { storiesOf } from '@storybook/react';

storiesOf('Card', module).addWithJSX('All', () => (
<div
style={{
padding: '1rem',
maxWidth: '400px'
}}
>
<div className="card">
<img
className="responsive-image"
src="https://source.unsplash.com/random/800x450"
/>
import withPadding from './util/withPadding';

<div className="card__content">
<h2 className="h5">Spacetravel guidelines</h2>
<p className="copy5">
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Dolorem
atque minima itaque sint! Doloremque odio quia saepe.
</p>
storiesOf('Card', module).addWithJSX('All', () =>
withPadding(
<div
style={{
maxWidth: '400px'
}}
>
<div className="card">
<div className="ImgContainer--16by9">
<img src="https://source.unsplash.com/random/800x450" />
</div>

<div className="card__content">
<h2 className="h5">Spacetravel guidelines</h2>
<p className="copy5">
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Dolorem
atque minima itaque sint! Doloremque odio quia saepe.
</p>
</div>
</div>
</div>
</div>
));
)
);
38 changes: 38 additions & 0 deletions packages/ray/stories/image.stories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import React from 'react';
import { storiesOf } from '@storybook/react';

storiesOf('Image', module)
.addWithJSX('16/9 img', () => (
<div style={{ maxWidth: '500px' }}>
<div className="ImgContainer--16by9">
<img src="https://source.unsplash.com/random/800x800" />
</div>
</div>
))
.addWithJSX('3/4 img', () => (
<div style={{ maxWidth: '400px' }}>
<div className="ImgContainer--3by4">
<img src="https://source.unsplash.com/random/800x1200" />
</div>
</div>
))
.addWithJSX('16/9 background', () => (
<div style={{ maxWidth: '500px' }}>
<div
className="Background--16by9"
style={{
backgroundImage: `url(https://source.unsplash.com/random/800x800)`
}}
/>
</div>
))
.addWithJSX('3/4 background', () => (
<div style={{ maxWidth: '400px' }}>
<div
className="Background--3by4"
style={{
backgroundImage: `url(https://source.unsplash.com/random/800x1200)`
}}
/>
</div>
));

0 comments on commit 9255112

Please sign in to comment.