From c635b65d7579a232ce5a5b76ca9856de35e7fc94 Mon Sep 17 00:00:00 2001 From: "Manu Mtz.-Almeida" Date: Tue, 24 Jul 2018 01:13:44 +0200 Subject: [PATCH] feat(icon): lazy loading can be disabled --- src/components/components.d.ts | 20 +++++++++++++++++++ src/components/icon/icon.tsx | 18 +++++++++++++++-- .../site/components/usage-page/usage-page.tsx | 4 ++-- 3 files changed, 38 insertions(+), 4 deletions(-) diff --git a/src/components/components.d.ts b/src/components/components.d.ts index 6e7f2cee..c4912754 100644 --- a/src/components/components.d.ts +++ b/src/components/components.d.ts @@ -34,6 +34,9 @@ declare global { * Specifies the label to use for accessibility. Defaults to the icon name. */ 'ariaLabel': string; + /** + * The color to use for the background of the item. + */ 'color': string; /** * A combination of both `name` and `src`. If a `src` url is detected it will set the `src` property. Otherwise it assumes it's a built-in named SVG and set the `name` property. @@ -43,10 +46,17 @@ declare global { * Specifies which icon to use on `ios` mode. */ 'ios': string; + /** + * If enabled, ion-icon will be loaded lazily when it's visible in the viewport. Default, `true`. + */ + 'lazy': boolean; /** * Specifies which icon to use on `md` mode. */ 'md': string; + /** + * The mode determines which platform styles to use. Possible values are: `"ios"` or `"md"`. + */ 'mode': 'ios' | 'md'; /** * Specifies which icon to use from the built-in set of icons. @@ -86,6 +96,9 @@ declare global { * Specifies the label to use for accessibility. Defaults to the icon name. */ 'ariaLabel'?: string; + /** + * The color to use for the background of the item. + */ 'color'?: string; /** * A combination of both `name` and `src`. If a `src` url is detected it will set the `src` property. Otherwise it assumes it's a built-in named SVG and set the `name` property. @@ -95,10 +108,17 @@ declare global { * Specifies which icon to use on `ios` mode. */ 'ios'?: string; + /** + * If enabled, ion-icon will be loaded lazily when it's visible in the viewport. Default, `true`. + */ + 'lazy'?: boolean; /** * Specifies which icon to use on `md` mode. */ 'md'?: string; + /** + * The mode determines which platform styles to use. Possible values are: `"ios"` or `"md"`. + */ 'mode'?: 'ios' | 'md'; /** * Specifies which icon to use from the built-in set of icons. diff --git a/src/components/icon/icon.tsx b/src/components/icon/icon.tsx index 44b522d8..5415e03a 100755 --- a/src/components/icon/icon.tsx +++ b/src/components/icon/icon.tsx @@ -20,9 +20,17 @@ export class Icon { @Prop({ context: 'document' }) doc!: Document; @Prop({ context: 'window' }) win: any; - @Prop() mode?: 'ios' | 'md'; + /** + * The color to use for the background of the item. + */ @Prop() color?: string; + /** + * The mode determines which platform styles to use. + * Possible values are: `"ios"` or `"md"`. + */ + @Prop() mode?: 'ios' | 'md'; + /** * Specifies the label to use for accessibility. Defaults to the icon name. */ @@ -62,6 +70,12 @@ export class Icon { @Prop() size?: string; + /** + * If enabled, ion-icon will be loaded lazily when it's visible in the viewport. + * Default, `true`. + */ + @Prop() lazy = true; + componentWillLoad() { // purposely do not return the promise here because loading // the svg file should not hold up loading the app @@ -81,7 +95,7 @@ export class Icon { waitUntilVisible(el: HTMLElement, rootMargin: string, cb: Function) { - if (this.win && this.win.IntersectionObserver) { + if (this.lazy && this.win && this.win.IntersectionObserver) { const io = this.io = new this.win.IntersectionObserver((data: IntersectionObserverEntry[]) => { if (data[0].isIntersecting) { io.disconnect(); diff --git a/src/docs/site/components/usage-page/usage-page.tsx b/src/docs/site/components/usage-page/usage-page.tsx index d11eb9ad..45a8d9a0 100644 --- a/src/docs/site/components/usage-page/usage-page.tsx +++ b/src/docs/site/components/usage-page/usage-page.tsx @@ -9,12 +9,12 @@ import content from './content'; styleUrl: 'usage-page.scss' }) export class UsagePage { - @Prop({ context: 'queue'}) queue: QueueApi; + @Prop({ context: 'queue'}) queue!: QueueApi; @State() exampleType: string = 'md'; @State() exampleIcon: string = 'heart'; - @Prop() match: MatchResults; + @Prop() match?: MatchResults; @Prop() data: any; componentWillLoad() {