-
Notifications
You must be signed in to change notification settings - Fork 2
PW-15: Image Lazy Loading #306
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
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
406421b
Update Element UI version.
e351e5c
Added Skeleton component.
c25ecf9
Updated UI Lib version, Added SImage component, added and updated sto…
b402846
Merge branch 'develop' into feature/pw-15-image-lazy-loading
5faf0d9
Refactoring and SImage props fixing.
98cdd16
Refactored stories.
55063a3
Fixed Dropdown divider colors.
a4a71af
Refactored due to PR comments.
82a6de8
Refactored due to PR comments, added scrollContainer prop to SImage.
0d61a14
Merge branch 'develop' into feature/pw-15-image-lazy-loading
21a8ec6
Updated skeleton background colors.
2bc6c41
Refactored due to PR comments.
7bde15b
SImage: Added required flag to Src property.
8d50f3a
Refactored due to PR comments.
3bd5c1d
Refactored due to PR comments.
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| <template> | ||
| <el-image | ||
| ref="image" | ||
| class="s-image" | ||
| :src="src" | ||
| :fit="fit" | ||
| :alt="alt" | ||
| :lazy="lazy" | ||
| :scroll-container="scrollContainer" | ||
| :z-ndex="zIndex" | ||
| > | ||
| <s-skeleton v-if="hasSkeleton" slot="placeholder" :animated="animated"> | ||
| <template #template> | ||
| <s-skeleton-item :element="SkeletonItemElement.IMAGE" /> | ||
| </template> | ||
| </s-skeleton> | ||
| </el-image> | ||
| </template> | ||
|
|
||
| <script lang="ts"> | ||
| import { Vue, Component, Prop, Ref } from 'vue-property-decorator' | ||
| import ElImage from 'element-ui/lib/image' | ||
|
|
||
| import { SSkeleton, SSkeletonItem, SkeletonItemElement } from '../../Skeleton' | ||
| import { ImageFit } from '../consts' | ||
|
|
||
| @Component({ | ||
| components: { | ||
| ElImage, | ||
| SSkeleton, | ||
| SSkeletonItem | ||
| } | ||
| }) | ||
| export default class SImage extends Vue { | ||
| /** | ||
| * Image source, same as native, this is required property | ||
| */ | ||
| @Prop({ type: String, required: true }) readonly src!: string | ||
| /** | ||
| * Indicate how the image should be resized to fit its container, same as object-fit. | ||
| * Possible values are: `fill` / `contain` / `cover` / `none` / `scale-down`. | ||
| * Default value is ImageFit.NONE. | ||
| */ | ||
| @Prop({ default: ImageFit.NONE, type: String }) readonly fit!: string | ||
| /** | ||
| * Native alt | ||
| */ | ||
| @Prop({ default: '', type: String }) readonly alt!: string | ||
| /** | ||
| * Whether to use lazy load | ||
| */ | ||
| @Prop({ default: false, type: Boolean }) readonly lazy!: boolean | ||
| /** | ||
| * The container to add scroll listener when using lazy load. | ||
| * Posssible value is the nearest parent container whose overflow property is auto or scroll | ||
| */ | ||
| @Prop({ type: [String, HTMLElement] }) readonly scrollContainer!: string | HTMLElement | ||
| /** | ||
| * Set image preview z-index | ||
| */ | ||
| @Prop({ default: 0, type: Number }) readonly zIndex!: number | ||
| /** | ||
| * Whether image has skeleton | ||
| */ | ||
| @Prop({ default: true, type: Boolean }) readonly hasSkeleton!: boolean | ||
| /** | ||
| * Whether skeleton has animation | ||
| */ | ||
| @Prop({ default: true, type: Boolean }) readonly animated!: boolean | ||
|
|
||
| readonly SkeletonItemElement = SkeletonItemElement | ||
|
|
||
| @Ref('image') elImage!: any | ||
| } | ||
| </script> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| import { Components, SFCWithInstall } from '../../../types/components' | ||
| import install from '../../../utils/install' | ||
|
|
||
| import _SImage from './SImage.vue' | ||
|
|
||
| const SImage = _SImage as SFCWithInstall<typeof _SImage> | ||
|
|
||
| SImage.install = install(Components.SImage, SImage) | ||
|
|
||
| export { SImage } | ||
| export default SImage |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| export enum ImageFit { | ||
| FILL = 'fill', | ||
| CONTAIN = 'contain', | ||
| COVER = 'cover', | ||
| NONE = 'none', | ||
| SCALE_DOWN = 'scale-down' | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| export { SImage } from './SImage' | ||
| export { ImageFit } from './consts' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| <template> | ||
| <el-skeleton | ||
| class="s-skeleton" | ||
| :animated="animated" | ||
| :count="count" | ||
| :loading="loading" | ||
| :rows="rows" | ||
| :throttle="throttle" | ||
| > | ||
| <slot slot="template" name="template" /> | ||
| <slot /> | ||
| </el-skeleton> | ||
| </template> | ||
|
|
||
| <script lang="ts"> | ||
| import { Vue, Component, Prop } from 'vue-property-decorator' | ||
| import ElSkeleton from 'element-ui/lib/skeleton' | ||
| import ElSkeletonItem from 'element-ui/lib/skeleton-item' | ||
|
|
||
| @Component({ | ||
| components: { ElSkeleton, ElSkeletonItem } | ||
| }) | ||
| export default class SSkeleton extends Vue { | ||
| /** | ||
| * Whether showing the animation, default value is false. | ||
| */ | ||
| @Prop({ default: false, type: Boolean }) readonly animated!: boolean | ||
| /** | ||
| * How many fake items to render in the DOM, should have integer value. | ||
| * Default value is 1. | ||
| */ | ||
| @Prop({ default: 1, type: Number }) readonly count!: number | ||
| /** | ||
| * Whether showing the skeleton | ||
| */ | ||
| @Prop({ default: true, type: Boolean }) readonly loading!: boolean | ||
| /** | ||
| * Numbers of the row, only useful when no template slot were given, should have integer value. | ||
| * Default value is 1. | ||
| */ | ||
| @Prop({ default: 4, type: Number }) readonly rows!: number | ||
| /** | ||
| * Rendering delay in millseconds, should have integer value. Default value is zero. | ||
| */ | ||
| @Prop({ default: 0, type: Number }) readonly throttle!: number | ||
| } | ||
| </script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| import { Components, SFCWithInstall } from '../../../types/components' | ||
| import install from '../../../utils/install' | ||
|
|
||
| import _SSkeleton from './SSkeleton.vue' | ||
|
|
||
| const SSkeleton = _SSkeleton as SFCWithInstall<typeof _SSkeleton> | ||
|
|
||
| SSkeleton.install = install(Components.SSkeleton, SSkeleton) | ||
|
|
||
| export { SSkeleton } | ||
| export default SSkeleton |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| <template> | ||
| <el-skeleton-item :variant="element" /> | ||
| </template> | ||
|
|
||
| <script lang="ts"> | ||
| import { Vue, Component, Prop } from 'vue-property-decorator' | ||
| import ElSkeletonItem from 'element-ui/lib/skeleton-item' | ||
|
|
||
| import { SkeletonItemElement } from '../consts' | ||
|
|
||
| @Component({ | ||
| components: { ElSkeletonItem } | ||
| }) | ||
| export default class SSkeletonItem extends Vue { | ||
| /** | ||
| * The current rendering skeleton type. | ||
| * Possible values are: `p` / `text` / `h1` / `h2` / `h3` / `text` / `caption` / `button` / `image` / `circle` / `rect`. | ||
| * Default value is SkeletonItemElement.TEXT. | ||
| */ | ||
| @Prop({ default: SkeletonItemElement.TEXT, type: String }) readonly element!: string | ||
| } | ||
| </script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| import { Components, SFCWithInstall } from '../../../types/components' | ||
| import install from '../../../utils/install' | ||
|
|
||
| import _SSkeletonItem from './SSkeletonItem.vue' | ||
|
|
||
| const SSkeletonItem = _SSkeletonItem as SFCWithInstall<typeof _SSkeletonItem> | ||
|
|
||
| SSkeletonItem.install = install(Components.SSkeleton, SSkeletonItem) | ||
|
|
||
| export { SSkeletonItem } | ||
| export default SSkeletonItem |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| export enum SkeletonItemElement { | ||
| P = 'p', | ||
| TEXT = 'text', | ||
| H1 = 'h1', | ||
| H2 = 'h2', | ||
| H3 = 'h3', | ||
| CAPTION = 'caption', | ||
| BUTTON = 'button', | ||
| IMAGE = 'image', | ||
| CIRCLE = 'circle', | ||
| RECT = 'rect' | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| export { SSkeleton } from './SSkeleton' | ||
| export { SSkeletonItem } from './SSkeletonItem' | ||
| export { SkeletonItemElement } from './consts' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| import { text, boolean, number, select, withKnobs } from '@storybook/addon-knobs' | ||
|
|
||
| import { SImage, ImageFit } from '../components/Image' | ||
|
|
||
| export default { | ||
| component: SImage, | ||
| title: 'Design System/Components/Image', | ||
| decorators: [withKnobs] | ||
| } | ||
|
|
||
| export const configurable = () => ({ | ||
| components: { SImage }, | ||
| template: `<s-image | ||
| :src="src" | ||
| :fit="fit" | ||
| :alt="alt" | ||
| :lazy="lazy" | ||
| :z-index="zIndex" | ||
| :has-skeleton="hasSkeleton" | ||
| :animated="animated" | ||
| style="height: 300px;" | ||
| />`, | ||
| props: { | ||
| src: { | ||
| default: text('Src', 'https://picsum.photos/1024') | ||
| }, | ||
| fit: { | ||
| default: select('Fit', Object.values(ImageFit), ImageFit.NONE) | ||
| }, | ||
| lazy: { | ||
| default: boolean('Lazy', true) | ||
| }, | ||
| alt: { | ||
| default: text('Alt', '') | ||
| }, | ||
| zIndex: { | ||
| default: number('Z-index', 0) | ||
| }, | ||
| hasSkeleton: { | ||
| default: boolean('Has Skeleton', true) | ||
| }, | ||
| animated: { | ||
| default: boolean('Skeleton has Animation', true) | ||
| } | ||
| } | ||
| }) | ||
|
|
||
| export const LazyImages = () => ({ | ||
| components: { SImage }, | ||
| template: `<div style="width: 100%; overflow-y: auto; height: 300px;"> | ||
| <s-image :src="imageSrc + '?random=1'" lazy style="height: inherit;" /> | ||
| <s-image :src="imageSrc + '?random=2'" lazy style="height: inherit;" /> | ||
| <s-image :src="imageSrc + '?random=3'" lazy style="height: inherit;" /> | ||
| <s-image :src="imageSrc + '?random=4'" lazy style="height: inherit;" /> | ||
| <s-image :src="imageSrc + '?random=5'" lazy style="height: inherit;" /> | ||
| <s-image :src="imageSrc + '?random=6'" lazy style="height: inherit;" /> | ||
| <s-image :src="imageSrc + '?random=7'" lazy style="height: inherit;" /> | ||
| <s-image :src="imageSrc + '?random=8'" lazy style="height: inherit;" /> | ||
| <s-image :src="imageSrc + '?random=9'" lazy style="height: inherit;" /> | ||
| <s-image :src="imageSrc + '?random=10'" lazy style="height: inherit;" /> | ||
| <s-image :src="imageSrc + '?random=11'" lazy style="height: inherit;" /> | ||
| <s-image :src="imageSrc + '?random=12'" lazy style="height: inherit;" /> | ||
| <s-image :src="imageSrc + '?random=13'" lazy style="height: inherit;" /> | ||
| <s-image :src="imageSrc + '?random=14'" lazy style="height: inherit;" /> | ||
| <s-image :src="imageSrc + '?random=15'" lazy style="height: inherit;" /> | ||
| </div>`, | ||
| data: () => ({ | ||
| imageSrc: 'https://picsum.photos/1024/300' | ||
| }) | ||
| }) | ||
|
|
||
| export const FailedImage = () => ({ | ||
| components: { SImage }, | ||
| template: '<s-image src="\'\'" lazy style="height: 300px;" />' | ||
| }) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.