diff --git a/package.json b/package.json index 5ad3fc6e..d4a12866 100644 --- a/package.json +++ b/package.json @@ -53,6 +53,7 @@ "glob": "^7.1.4", "jest": "^24.9.0", "jest-vue-preprocessor": "^1.5.0", + "lodash.merge": "^4.6.2", "storybook-addon-vue-info": "1.4.2", "storybook-vue-router": "^1.0.7", "stylelint": "^11.0.0", diff --git a/src/atoms/image/Image.html b/src/atoms/image/Image.html new file mode 100644 index 00000000..dacc7c40 --- /dev/null +++ b/src/atoms/image/Image.html @@ -0,0 +1,13 @@ + + + + + + diff --git a/src/atoms/image/Image.js b/src/atoms/image/Image.js new file mode 100644 index 00000000..90c9f0de --- /dev/null +++ b/src/atoms/image/Image.js @@ -0,0 +1,33 @@ +import getClass from '../../../utils/helpers/get-class.js' + +export default { + mixins: [getClass], + inheritAttrs: false, + props: { + /** + * To use another tag instead of `img`, e.g. `picture` + */ + tag: { + type: String, + default: 'img', + validator: tag => tag === 'img' || tag === 'picture' + } + }, + data () { + return { + config: { + base: { + image: [ + 'block', + 'max-w-full' + ] + } + } + } + }, + computed: { + usePicture () { + return this.tag === 'picture' + } + } +} diff --git a/src/atoms/image/Image.spec.js b/src/atoms/image/Image.spec.js new file mode 100644 index 00000000..1845f4cf --- /dev/null +++ b/src/atoms/image/Image.spec.js @@ -0,0 +1,25 @@ +import { mount } from '@vue/test-utils' +import AImage from './Image.vue' + +describe('Image', () => { + it('has default structure', () => { + const wrapper = mount(AImage, { + propsData: { + src: '/images/image/banner.jpg' + } + }) + + expect(wrapper.element.tagName).toBe('IMG') + }) + + it('should be generated with the `alt` passed as attributes', () => { + const wrapper = mount(AImage, { + attrs: { + alt: 'Sample Image' + } + }) + + expect(wrapper.attributes().alt).toBeDefined() + expect(wrapper.attributes().alt).toEqual('Sample Image') + }) +}) diff --git a/src/atoms/image/Image.stories.js b/src/atoms/image/Image.stories.js new file mode 100644 index 00000000..648ffd87 --- /dev/null +++ b/src/atoms/image/Image.stories.js @@ -0,0 +1,160 @@ +import AImage from './Image.vue' +import ALazyImage from './LazyImage.vue' + +export default { + title: 'Atoms/Image', + components: { + AImage, + ALazyImage + }, + argTypes: { + src: { + control: { + type: 'text' + } + }, + tag: { + control: { + type: 'text' + } + }, + alt: { + control: { + type: 'text' + } + }, + placeholderSrc: { + control: { + type: 'text' + } + } + } +} + +const sources = [ + { + src: 'images/image/banner-480_480.png', + width: '480px' + }, + { + src: 'images/image/banner-768_402.png', + width: '768px' + }, + { + src: 'images/image/banner-992_254.png', + width: '992px' + } +] + +const TemplateImage = (args, { argTypes }) => ({ + components: { AImage }, + props: Object.keys(argTypes), + template: ` + + ` +}) + +const TemplatePicture = (args, { argTypes }) => ({ + components: { AImage }, + props: Object.keys(argTypes), + template: ` + + + + + + ` +}) + +export const Image = TemplateImage.bind({}) +Image.args = { + tag: 'img', + src: 'images/image/banner.jpg', + alt: 'alt text goes here' +} + +export const Picture = TemplatePicture.bind({}) +Picture.args = { + tag: 'picture', + src: 'images/image/banner.jpg', + alt: 'alt text goes here' +} + +const TemplateLazyImage = (args, { argTypes }) => ({ + components: { ALazyImage }, + props: Object.keys(argTypes), + template: ` + + ` +}) + +export const LazyImage = TemplateLazyImage.bind({}) +LazyImage.args = { + tag: 'img', + src: 'images/image/banner.jpg', + alt: 'alt text goes here' +} + +export const LazyImageWithPlaceholder = TemplateLazyImage.bind({}) +LazyImageWithPlaceholder.args = { + tag: 'img', + src: 'images/image/banner.jpg', + alt: 'alt text goes here', + placeholderSrc: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAIAAAACCAYAAABytg0kAAAAG0lEQVQYV2M8c+bMfwZGRgbGs2fO/v/P8J8BAFA1CMsVPhxYAAAAAElFTkSuQmCC' +} + +const TemplateLazyPicture = (args, { argTypes }) => ({ + components: { ALazyImage }, + props: Object.keys(argTypes), + template: ` + + + + + + + ` +}) +export const LazyPicture = TemplateLazyPicture.bind({}) +LazyPicture.args = { + tag: 'picture', + src: 'images/image/banner.jpg', + alt: 'alt text goes here' +} +export const LazyPictureWithPlaceholder = TemplateLazyPicture.bind({}) +LazyPictureWithPlaceholder.args = { + tag: 'picture', + src: 'images/image/banner.jpg', + alt: 'alt text goes here', + placeholderSrc: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAIAAAACCAYAAABytg0kAAAAG0lEQVQYV2M8c+bMfwZGRgbGs2fO/v/P8J8BAFA1CMsVPhxYAAAAAElFTkSuQmCC' +} diff --git a/src/atoms/image/Image.vue b/src/atoms/image/Image.vue new file mode 100644 index 00000000..ad1067cf --- /dev/null +++ b/src/atoms/image/Image.vue @@ -0,0 +1,10 @@ +