fix(): mode support

This commit is contained in:
Manu Mtz.-Almeida
2019-06-07 14:54:54 +02:00
parent 9f77b8c7a2
commit 55fcc4b9f2
10 changed files with 137 additions and 137 deletions
+18 -22
View File
@@ -39,9 +39,9 @@ export namespace Components {
*/
'md'?: string;
/**
* The mode determines which platform styles to use. Possible values are: `"ios"` or `"md"`.
* The mode determines which platform styles to use.
*/
'mode'?: 'ios' | 'md';
'mode'?: "ios" | "md";
/**
* Specifies which icon to use from the built-in set of icons.
*/
@@ -57,8 +57,21 @@ export namespace Components {
}
}
declare global {
interface HTMLIonIconElement extends Components.IonIcon, HTMLStencilElement {}
var HTMLIonIconElement: {
prototype: HTMLIonIconElement;
new (): HTMLIonIconElement;
};
interface HTMLElementTagNameMap {
'ion-icon': HTMLIonIconElement;
}
}
declare namespace LocalJSX {
interface IonIcon extends JSXBase.HTMLAttributes {
interface IonIcon extends JSXBase.HTMLAttributes<HTMLIonIconElement> {
/**
* Specifies the label to use for accessibility. Defaults to the icon name.
*/
@@ -88,9 +101,9 @@ declare namespace LocalJSX {
*/
'md'?: string;
/**
* The mode determines which platform styles to use. Possible values are: `"ios"` or `"md"`.
* The mode determines which platform styles to use.
*/
'mode'?: 'ios' | 'md';
'mode'?: "ios" | "md";
/**
* Specifies which icon to use from the built-in set of icons.
*/
@@ -120,20 +133,3 @@ declare module "@stencil/core" {
}
declare global {
interface HTMLIonIconElement extends Components.IonIcon, HTMLStencilElement {}
var HTMLIonIconElement: {
prototype: HTMLIonIconElement;
new (): HTMLIonIconElement;
};
interface HTMLElementTagNameMap {
'ion-icon': HTMLIonIconElement;
}
interface ElementTagNameMap extends HTMLElementTagNameMap {}
}
+3
View File
@@ -0,0 +1,3 @@
import { setMode } from '@stencil/core';
setMode((el: any) => el.tagName === 'ION-ICON' ? el.mode || el.getAttribute('mode') : null);
+17 -16
View File
@@ -1,6 +1,9 @@
import { Build, Component, Element, Host, Prop, State, Watch, getAssetPath, h } from '@stencil/core';
import { Build, Component, Element, Host, Prop, State, Watch, getAssetPath, getMode, h } from '@stencil/core';
import { getIconMap, getName, getSrc, isSrc, isValid } from './utils';
/**
* @virtualProp {"ios" | "md"} mode - The mode determines which platform styles to use.
*/
@Component({
tag: 'ion-icon',
assetsDir: 'svg',
@@ -9,6 +12,7 @@ import { getIconMap, getName, getSrc, isSrc, isValid } from './utils';
})
export class Icon {
private io?: IntersectionObserver;
private mode = getIonMode(this);
@Element() el!: HTMLElement;
@@ -20,12 +24,6 @@ export class Icon {
*/
@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.
*/
@@ -75,7 +73,7 @@ export class Icon {
*/
@Prop() lazy = false;
componentWillLoad() {
connectedCallback() {
// purposely do not return the promise here because loading
// the svg file should not hold up loading the app
// only load the svg if it's visible
@@ -85,7 +83,7 @@ export class Icon {
});
}
componentDidUnload() {
disconnectedCallback() {
if (this.io) {
this.io.disconnect();
this.io = undefined;
@@ -93,7 +91,7 @@ export class Icon {
}
private waitUntilVisible(el: HTMLElement, rootMargin: string, cb: () => void) {
if (this.lazy && typeof window !== 'undefined' && (window as any).IntersectionObserver) {
if (Build.isBrowser && this.lazy && typeof window !== 'undefined' && (window as any).IntersectionObserver) {
const io = this.io = new (window as any).IntersectionObserver((data: IntersectionObserverEntry[]) => {
if (data[0].isIntersecting) {
io.disconnect();
@@ -139,7 +137,7 @@ export class Icon {
}
}
getName() {
private getName() {
if (this.name !== undefined) {
return this.name;
}
@@ -149,7 +147,7 @@ export class Icon {
return undefined;
}
getUrl() {
private getUrl() {
let url = getSrc(this.src);
if (url) {
return url;
@@ -168,7 +166,6 @@ export class Icon {
return null;
}
render() {
const mode = this.mode || 'md';
const flipRtl = this.flipRtl || (this.ariaLabel && this.ariaLabel.indexOf('arrow') > -1 && this.flipRtl !== false);
@@ -180,15 +177,19 @@ export class Icon {
[`icon-${this.size}`]: !!this.size,
'flip-rtl': !!flipRtl && (this.el.ownerDocument as Document).dir === 'rtl'
}}>{(
(Build.isBrowser && this.svgContent) ?
<div class="icon-inner" innerHTML={this.svgContent}></div> :
<div class="icon-inner"></div>
(Build.isBrowser && this.svgContent)
? <div class="icon-inner" innerHTML={this.svgContent}></div>
: <div class="icon-inner"></div>
)}
</Host>
);
}
}
const getIonMode = (ref: any) => {
return getMode(ref) || document.documentElement.getAttribute('mode') || 'md';
};
const getNamedUrl = (name: string) => {
const url = getIconMap().get(name);
if (url) {
+13 -13
View File
@@ -7,19 +7,19 @@
## Properties
| Property | Attribute | Description | Type | Default |
| ----------- | ------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ---------------------------- | ----------- |
| `ariaLabel` | `aria-label` | Specifies the label to use for accessibility. Defaults to the icon name. | `string \| undefined` | `undefined` |
| `color` | `color` | The color to use for the background of the item. | `string \| undefined` | `undefined` |
| `flipRtl` | `flip-rtl` | Specifies whether the icon should horizontally flip when `dir` is `"rtl"`. | `boolean \| undefined` | `undefined` |
| `icon` | `icon` | 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. | `string \| undefined` | `undefined` |
| `ios` | `ios` | Specifies which icon to use on `ios` mode. | `string \| undefined` | `undefined` |
| `lazy` | `lazy` | If enabled, ion-icon will be loaded lazily when it's visible in the viewport. Default, `false`. | `boolean` | `false` |
| `md` | `md` | Specifies which icon to use on `md` mode. | `string \| undefined` | `undefined` |
| `mode` | `mode` | The mode determines which platform styles to use. Possible values are: `"ios"` or `"md"`. | `"ios" \| "md" \| undefined` | `undefined` |
| `name` | `name` | Specifies which icon to use from the built-in set of icons. | `string \| undefined` | `undefined` |
| `size` | `size` | The size of the icon. Available options are: `"small"` and `"large"`. | `string \| undefined` | `undefined` |
| `src` | `src` | Specifies the exact `src` of an SVG file to use. | `string \| undefined` | `undefined` |
| Property | Attribute | Description | Type | Default |
| ----------- | ------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ---------------------- | ----------- |
| `ariaLabel` | `aria-label` | Specifies the label to use for accessibility. Defaults to the icon name. | `string \| undefined` | `undefined` |
| `color` | `color` | The color to use for the background of the item. | `string \| undefined` | `undefined` |
| `flipRtl` | `flip-rtl` | Specifies whether the icon should horizontally flip when `dir` is `"rtl"`. | `boolean \| undefined` | `undefined` |
| `icon` | `icon` | 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. | `string \| undefined` | `undefined` |
| `ios` | `ios` | Specifies which icon to use on `ios` mode. | `string \| undefined` | `undefined` |
| `lazy` | `lazy` | If enabled, ion-icon will be loaded lazily when it's visible in the viewport. Default, `false`. | `boolean` | `false` |
| `md` | `md` | Specifies which icon to use on `md` mode. | `string \| undefined` | `undefined` |
| `mode` | `mode` | The mode determines which platform styles to use. | `"ios" \| "md"` | `undefined` |
| `name` | `name` | Specifies which icon to use from the built-in set of icons. | `string \| undefined` | `undefined` |
| `size` | `size` | The size of the icon. Available options are: `"small"` and `"large"`. | `string \| undefined` | `undefined` |
| `src` | `src` | Specifies the exact `src` of an SVG file to use. | `string \| undefined` | `undefined` |
----------------------------------------------
+62 -67
View File
@@ -10,7 +10,6 @@ import {
MatchResults,
} from '@stencil/router';
export namespace Components {
interface FooterBar {}
interface HeaderBar {
@@ -47,72 +46,9 @@ export namespace Components {
}
}
declare namespace LocalJSX {
interface FooterBar extends JSXBase.HTMLAttributes {}
interface HeaderBar extends JSXBase.HTMLAttributes {
'isSearchVisible'?: boolean;
'onToggleHeaderSearch'?: (event: CustomEvent<any>) => void;
'query'?: string;
'version'?: string;
}
interface IconList extends JSXBase.HTMLAttributes {
'data'?: any;
'query'?: string;
}
interface IconSearch extends JSXBase.HTMLAttributes {
'autofocus'?: string;
'onHasSearched'?: (event: CustomEvent<any>) => void;
'query'?: string;
'size'?: string;
}
interface IoniconsSite extends JSXBase.HTMLAttributes {}
interface LandingPage extends JSXBase.HTMLAttributes {
'data'?: any;
'query'?: string;
}
interface NotfoundPage extends JSXBase.HTMLAttributes {}
interface ToastBar extends JSXBase.HTMLAttributes {
'onClearToast'?: (event: CustomEvent<any>) => void;
'onToggleHeaderSearch'?: (event: CustomEvent<any>) => void;
'selectedIcon'?: {
name: string,
icons: string[],
tags: string[]
};
'selectedIconType'?: string;
}
interface UsagePage extends JSXBase.HTMLAttributes {
'data'?: any;
'match'?: MatchResults;
}
interface IntrinsicElements {
'footer-bar': FooterBar;
'header-bar': HeaderBar;
'icon-list': IconList;
'icon-search': IconSearch;
'ionicons-site': IoniconsSite;
'landing-page': LandingPage;
'notfound-page': NotfoundPage;
'toast-bar': ToastBar;
'usage-page': UsagePage;
}
}
export { LocalJSX as JSX };
declare module "@stencil/core" {
export namespace JSX {
interface IntrinsicElements extends LocalJSX.IntrinsicElements {}
}
}
declare global {
interface HTMLFooterBarElement extends Components.FooterBar, HTMLStencilElement {}
var HTMLFooterBarElement: {
prototype: HTMLFooterBarElement;
@@ -166,7 +102,6 @@ declare global {
prototype: HTMLUsagePageElement;
new (): HTMLUsagePageElement;
};
interface HTMLElementTagNameMap {
'footer-bar': HTMLFooterBarElement;
'header-bar': HTMLHeaderBarElement;
@@ -178,7 +113,67 @@ declare global {
'toast-bar': HTMLToastBarElement;
'usage-page': HTMLUsagePageElement;
}
interface ElementTagNameMap extends HTMLElementTagNameMap {}
}
declare namespace LocalJSX {
interface FooterBar extends JSXBase.HTMLAttributes<HTMLFooterBarElement> {}
interface HeaderBar extends JSXBase.HTMLAttributes<HTMLHeaderBarElement> {
'isSearchVisible'?: boolean;
'onToggleHeaderSearch'?: (event: CustomEvent<any>) => void;
'query'?: string;
'version'?: string;
}
interface IconList extends JSXBase.HTMLAttributes<HTMLIconListElement> {
'data'?: any;
'query'?: string;
}
interface IconSearch extends JSXBase.HTMLAttributes<HTMLIconSearchElement> {
'autofocus'?: string;
'onHasSearched'?: (event: CustomEvent<any>) => void;
'query'?: string;
'size'?: string;
}
interface IoniconsSite extends JSXBase.HTMLAttributes<HTMLIoniconsSiteElement> {}
interface LandingPage extends JSXBase.HTMLAttributes<HTMLLandingPageElement> {
'data'?: any;
'query'?: string;
}
interface NotfoundPage extends JSXBase.HTMLAttributes<HTMLNotfoundPageElement> {}
interface ToastBar extends JSXBase.HTMLAttributes<HTMLToastBarElement> {
'onClearToast'?: (event: CustomEvent<any>) => void;
'onToggleHeaderSearch'?: (event: CustomEvent<any>) => void;
'selectedIcon'?: {
name: string,
icons: string[],
tags: string[]
};
'selectedIconType'?: string;
}
interface UsagePage extends JSXBase.HTMLAttributes<HTMLUsagePageElement> {
'data'?: any;
'match'?: MatchResults;
}
interface IntrinsicElements {
'footer-bar': FooterBar;
'header-bar': HeaderBar;
'icon-list': IconList;
'icon-search': IconSearch;
'ionicons-site': IoniconsSite;
'landing-page': LandingPage;
'notfound-page': NotfoundPage;
'toast-bar': ToastBar;
'usage-page': UsagePage;
}
}
export { LocalJSX as JSX };
declare module "@stencil/core" {
export namespace JSX {
interface IntrinsicElements extends LocalJSX.IntrinsicElements {}
}
}
+4 -2
View File
@@ -36,11 +36,13 @@
<meta name="msapplication-TileImage" content="/assets/img/meta/ms-icon-144x144.png">
<meta name="theme-color" content="#16161d">
<script type="module" src="/build/docssite.esm.js"></script>
<script nomodule src="/build/docssite.js"></script>
<link href="https://fonts.googleapis.com/css?family=Roboto+Mono:500" rel="stylesheet">
<link rel="stylesheet" href="/css/ionicons.min.css">
<link rel="stylesheet" href="/build/docssite.css">
<script type="module" src="/build/docssite.esm.js"></script>
<script nomodule src="/build/docssite.js"></script>
</head>
<body>