From a90ea10cccdb83cc22b9456ea866d5ec36d5d15a Mon Sep 17 00:00:00 2001 From: prabu-ssb <62878049+prabu-ssb@users.noreply.github.com> Date: Fri, 26 Jun 2020 13:14:21 +0200 Subject: [PATCH] MIMIR-491 PictureCard interface (#216) * PictureCard contrast background * Change prop from 'image' (object) to 'imageSrc' (url); add prop 'altText' * update test, snapshot --- src/components/PictureCard/README.md | 7 ++++--- .../PictureCard/__snapshots__/pictureCard.test.jsx.snap | 3 ++- src/components/PictureCard/index.jsx | 7 ++++--- src/components/PictureCard/pictureCard.story.jsx | 4 ++-- src/components/PictureCard/pictureCard.test.jsx | 8 +++++--- 5 files changed, 17 insertions(+), 12 deletions(-) diff --git a/src/components/PictureCard/README.md b/src/components/PictureCard/README.md index 8e08e9bb..a5f6aeda 100644 --- a/src/components/PictureCard/README.md +++ b/src/components/PictureCard/README.md @@ -17,17 +17,18 @@ PictureCard #### React ```jsx harmony -} onClick={function} type="Type" title="Tittel" /> + ``` ```jsx harmony -} link="./" type="Type" title="Tittel" /> + ``` Available props: | Name | Type | Description | | ---------- | ------------- | ----- | | className | string | Optional container class| -| image | required element | An image to be put as background | +| imageSrc | required (url) | URL of the image to be used | +| altText | required string | alt text for screen readers | | link | string | Link to be navigated to | | onClick | func | Function callback to be used instead of link | | title | string | Title text | diff --git a/src/components/PictureCard/__snapshots__/pictureCard.test.jsx.snap b/src/components/PictureCard/__snapshots__/pictureCard.test.jsx.snap index 36b2d919..82835bd1 100644 --- a/src/components/PictureCard/__snapshots__/pictureCard.test.jsx.snap +++ b/src/components/PictureCard/__snapshots__/pictureCard.test.jsx.snap @@ -9,7 +9,8 @@ exports[`ImageLink component Matches the snapshot 1`] = ` className="image-background" >
{ +const PictureCard = ({ className, imageSrc, altText, link, onClick, orientation, title, type }) => { const [hoverRef, hovered] = useHover(); return (
- + {altText}
{type} @@ -60,7 +60,8 @@ PictureCard.defaultProps = { PictureCard.propTypes = { className: PropTypes.string, - imageSrc: PropTypes.element.isRequired, + imageSrc: PropTypes.string.isRequired, + altText: PropTypes.string.isRequired, link: PropTypes.string, onClick: PropTypes.func, orientation: PropTypes.oneOf(['horizontal', 'vertical']), diff --git a/src/components/PictureCard/pictureCard.story.jsx b/src/components/PictureCard/pictureCard.story.jsx index f0758bbc..e209960a 100644 --- a/src/components/PictureCard/pictureCard.story.jsx +++ b/src/components/PictureCard/pictureCard.story.jsx @@ -10,8 +10,8 @@ const sup = (() => { storiesOf('Picture Card', module).addDecorator(centered) .add('Default', () => ( - + )) .add('Horizontal', () => ( - + )); diff --git a/src/components/PictureCard/pictureCard.test.jsx b/src/components/PictureCard/pictureCard.test.jsx index d4e615f2..bc812dae 100644 --- a/src/components/PictureCard/pictureCard.test.jsx +++ b/src/components/PictureCard/pictureCard.test.jsx @@ -5,15 +5,17 @@ import cardImage from './cards_bilde.jpg'; describe('ImageLink component', () => { test('Matches the snapshot', () => { - const wrapper = shallow(} onClick={() => {}} type="Type" title="Tittel" />); + const wrapper = shallow( + {}} type="Type" altText="img alt" title="Tittel" /> + ); expect(wrapper).toMatchSnapshot(); }); test('Sets default orientation className', () => { - const wrapper = shallow(} onClick={() => {}} type="Type" title="Tittel" />); + const wrapper = shallow( {}} type="Type" title="Tittel" />); expect(wrapper.hasClass('vertical')).toEqual(true); }); test('Switches className on orientation change', () => { - const wrapper = shallow(} onClick={() => {}} type="Type" title="Tittel" />); + const wrapper = shallow( {}} type="Type" title="Tittel" />); expect(wrapper.hasClass('horizontal')).toEqual(true); }); });