-
Notifications
You must be signed in to change notification settings - Fork 230
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
Amp Img #1101
Amp Img #1101
Changes from 2 commits
206e4b8
2df0125
aafe6c3
4e18239
8b5da7b
5c6a973
ed6791f
da39b3d
3dc4bbf
5121fbc
fec261b
a79ff57
766a0e5
921929a
58c0ec8
39db323
bc0d448
aba7527
a849328
0b2f529
13e46dc
d981939
ff2bd2a
3ef1341
baa6570
a166b7c
db7df3b
a7303a6
89002af
7e291e3
8399629
974b8ec
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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Image component | ||
|
||
## Usage | ||
|
||
Importing the standard Image component, which renders an `<img />` tag. | ||
|
||
```jsx | ||
import { Img } from '../components/Image'; | ||
|
||
const WrappingContainer = ({ alt, height, src, width }) => ( | ||
<Img alt={alt} src={src} height={height} width={width} /> | ||
); | ||
``` | ||
|
||
Importing an Amp Image component, which renders an `<amp-img />` tag. | ||
|
||
```jsx | ||
import { AmpImg } from '../components/Image'; | ||
|
||
const WrappingContainer = ({ alt, height, src, width }) => ( | ||
<AmpImg alt={alt} src={src} height={height} width={width} /> | ||
sareh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
); | ||
``` | ||
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. Needs the rest of the README structure (guess I could have raised an issue for that!), e.g. https://github.com/BBC-News/psammead/tree/latest/packages/components/psammead-paragraph 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. The CoC and other links will need to change when we move it to Psammead. I've added a note to the description in this Issue: BBC-archive/psammead#203 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Image - AmpImg should render image with custom dimensions correctly 1`] = ` | ||
.c0 { | ||
display: block; | ||
width: 100%; | ||
} | ||
|
||
<img | ||
className="c0" | ||
/> | ||
`; | ||
|
||
exports[`Image - AmpImg should render landscape image correctly 1`] = ` | ||
.c0 { | ||
display: block; | ||
width: 100%; | ||
} | ||
|
||
<img | ||
className="c0" | ||
/> | ||
`; | ||
|
||
exports[`Image - AmpImg should render portrait image correctly 1`] = ` | ||
.c0 { | ||
display: block; | ||
width: 100%; | ||
} | ||
|
||
<img | ||
className="c0" | ||
/> | ||
`; | ||
|
||
exports[`Image - AmpImg should render square image correctly 1`] = ` | ||
.c0 { | ||
display: block; | ||
width: 100%; | ||
} | ||
|
||
<img | ||
className="c0" | ||
/> | ||
`; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
export const imageAltLandscape = 'Birthday illustration with llama and dogs'; | ||
export const imageSrcLandscape = | ||
'https://ichef.bbci.co.uk/news/1024/cpsprodpb/537D/production/_104837312_crazyrichbirthday_illustration_dogs-nc976.jpg'; | ||
|
||
export const imageAltPortrait = | ||
'Map of the UK displaying Syrian refugees and asylum seekers per 10000 population. Ranges from 0 to 17.'; | ||
export const imageSrcPortrait = | ||
'https://ichef.bbci.co.uk/news/640/cpsprodpb/439A/production/_100960371_syrians_and_asylum_v2-nc.png'; | ||
|
||
export const imageAltSquare = 'Tracks through the snow'; | ||
export const imageSrcSquare = | ||
'https://ichef.bbci.co.uk/news/660/cpsprodpb/114FE/production/_104801907_79010.jpg'; | ||
|
||
export const imageAltCustom = 'By Elisa Decker, from her series "Sidewalk"'; | ||
export const imageSrcCustom = | ||
sareh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
'https://ichef.bbci.co.uk/news/445/cpsprodpb/164BB/production/_104032319_03270dcc-9dda-4bd4-96a0-db89f6b915ae.jpg'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import React from 'react'; | ||
import { Img } from '.'; | ||
|
||
const AmpImg = () => <Img as="amp-img" layout="responsive" />; | ||
sareh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
export default AmpImg; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import React from 'react'; | ||
import { storiesOf } from '@storybook/react'; // eslint-disable-line import/no-extraneous-dependencies | ||
import AmpImg from './index.amp'; | ||
import { | ||
imageAltLandscape, | ||
imageSrcLandscape, | ||
imageAltPortrait, | ||
imageSrcPortrait, | ||
imageAltSquare, | ||
imageSrcSquare, | ||
imageAltCustom, | ||
imageSrcCustom, | ||
} from './fixtureData'; | ||
|
||
storiesOf('Image - AmpImg', module) | ||
sareh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
.add('16:9 landscape image', () => ( | ||
<AmpImg alt={imageAltLandscape} src={imageSrcLandscape} /> | ||
)) | ||
.add('16:9 portrait image', () => ( | ||
sareh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
<AmpImg alt={imageAltPortrait} src={imageSrcPortrait} /> | ||
)) | ||
.add('1:1 square image', () => ( | ||
<AmpImg alt={imageAltSquare} src={imageSrcSquare} /> | ||
)) | ||
.add('custom ratio image', () => ( | ||
<AmpImg alt={imageAltCustom} src={imageSrcCustom} /> | ||
)); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import React from 'react'; | ||
import { shouldMatchSnapshot } from '../../../helpers/tests/testHelpers'; | ||
import AmpImg from './index.amp'; | ||
import { | ||
imageAltLandscape, | ||
imageSrcLandscape, | ||
imageAltPortrait, | ||
imageSrcPortrait, | ||
imageAltSquare, | ||
imageSrcSquare, | ||
imageAltCustom, | ||
imageSrcCustom, | ||
} from './fixtureData'; | ||
|
||
describe('Image - AmpImg', () => { | ||
sareh marked this conversation as resolved.
Show resolved
Hide resolved
sareh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
shouldMatchSnapshot( | ||
'should render portrait image correctly', | ||
<AmpImg | ||
alt={imageAltPortrait} | ||
src={imageSrcPortrait} | ||
height={723} | ||
sareh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
width={578} | ||
/>, | ||
); | ||
shouldMatchSnapshot( | ||
'should render landscape image correctly', | ||
<AmpImg | ||
alt={imageAltLandscape} | ||
src={imageSrcLandscape} | ||
height={1024} | ||
width={578} | ||
/>, | ||
); | ||
shouldMatchSnapshot( | ||
'should render square image correctly', | ||
<AmpImg | ||
alt={imageAltSquare} | ||
src={imageSrcSquare} | ||
height={660} | ||
width={660} | ||
/>, | ||
); | ||
shouldMatchSnapshot( | ||
'should render image with custom dimensions correctly', | ||
<AmpImg | ||
alt={imageAltCustom} | ||
src={imageSrcCustom} | ||
height={660} | ||
width={660} | ||
sareh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/>, | ||
); | ||
}); |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,8 +1,21 @@ | ||||||
import React from 'react'; | ||||||
import styled from 'styled-components'; | ||||||
import { number, string } from 'prop-types'; | ||||||
|
||||||
const Image = styled.img` | ||||||
const ImgWithStyles = styled.img` | ||||||
display: block; | ||||||
width: 100%; | ||||||
`; | ||||||
|
||||||
export default Image; | ||||||
export const Img = ({ alt, height, src, width }) => ( | ||||||
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. Should this file not also be exporting AmpImg? 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. Yes I think that's what we agreed 👍 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. Yes, this is fixed now. 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.
Suggested change
(ordering consistency) |
||||||
<ImgWithStyles alt={alt} src={src} height={height} width={width} /> | ||||||
); | ||||||
|
||||||
Img.propTypes = { | ||||||
alt: string.isRequired, | ||||||
height: number.isRequired, | ||||||
src: string.isRequired, | ||||||
ChrisBAshton marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
width: number.isRequired, | ||||||
}; | ||||||
|
||||||
export default Img; |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,12 +1,27 @@ | ||||||
import React from 'react'; | ||||||
import { storiesOf } from '@storybook/react'; // eslint-disable-line import/no-extraneous-dependencies | ||||||
import Image from './index'; | ||||||
import { Img } from './index'; | ||||||
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.
Suggested change
|
||||||
import { | ||||||
imageAltLandscape, | ||||||
imageSrcLandscape, | ||||||
imageAltPortrait, | ||||||
imageSrcPortrait, | ||||||
imageAltSquare, | ||||||
imageSrcSquare, | ||||||
imageAltCustom, | ||||||
imageSrcCustom, | ||||||
} from './fixtureData'; | ||||||
|
||||||
const imageAlt = | ||||||
'Map of the UK displaying Syrian refugees and asylum seekers per 10000 population. Ranges from 0 to 17.'; | ||||||
const imageSrc = | ||||||
'https://ichef.bbci.co.uk/news/640/cpsprodpb/439A/production/_100960371_syrians_and_asylum_v2-nc.png'; | ||||||
|
||||||
storiesOf('Image', module).add('default', () => ( | ||||||
<Image alt={imageAlt} src={imageSrc} /> | ||||||
)); | ||||||
storiesOf('Image - Img', module) | ||||||
sareh marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
.add('16:9 landscape image', () => ( | ||||||
<Img alt={imageAltLandscape} src={imageSrcLandscape} /> | ||||||
)) | ||||||
.add('16:9 portrait image', () => ( | ||||||
<Img alt={imageAltPortrait} src={imageSrcPortrait} /> | ||||||
)) | ||||||
.add('1:1 square image', () => ( | ||||||
<Img alt={imageAltSquare} src={imageSrcSquare} /> | ||||||
)) | ||||||
.add('custom ratio image', () => ( | ||||||
<Img alt={imageAltCustom} src={imageSrcCustom} /> | ||||||
)); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,42 @@ | ||
import React from 'react'; | ||
import { shouldMatchSnapshot } from '../../../helpers/tests/testHelpers'; | ||
import Image from './index'; | ||
import { Img } from './index'; | ||
import { | ||
imageAltLandscape, | ||
imageSrcLandscape, | ||
imageAltPortrait, | ||
imageSrcPortrait, | ||
imageAltSquare, | ||
imageSrcSquare, | ||
imageAltCustom, | ||
imageSrcCustom, | ||
} from './fixtureData'; | ||
|
||
const imageAlt = | ||
'Map of the UK displaying Syrian refugees and asylum seekers per 10000 population. Ranges from 0 to 17.'; | ||
const imageSrc = | ||
'https://ichef.bbci.co.uk/news/640/cpsprodpb/439A/production/_100960371_syrians_and_asylum_v2-nc.png'; | ||
|
||
describe('Image', () => { | ||
describe('Image - Img', () => { | ||
sareh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
shouldMatchSnapshot( | ||
'should render portrait image correctly', | ||
<Img | ||
alt={imageAltPortrait} | ||
src={imageSrcPortrait} | ||
height={723} | ||
width={578} | ||
/>, | ||
); | ||
shouldMatchSnapshot( | ||
'should render landscape image correctly', | ||
<Img | ||
alt={imageAltLandscape} | ||
src={imageSrcLandscape} | ||
height={1024} | ||
width={578} | ||
/>, | ||
); | ||
shouldMatchSnapshot( | ||
'should render square image correctly', | ||
<Img alt={imageAltSquare} src={imageSrcSquare} height={660} width={660} />, | ||
); | ||
shouldMatchSnapshot( | ||
'should render correctly', | ||
<Image alt={imageAlt} src={imageSrc} />, | ||
'should render image with custom dimensions correctly', | ||
<Img alt={imageAltCustom} src={imageSrcCustom} height={660} width={660} />, | ||
); | ||
}); |
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.
(makes it consistent with the other below)