mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-11-10 00:27:41 +08:00
fix(): update to Stencil One 🎉🎊
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
import { Component, ComponentInterface, Element, Event, EventEmitter, Listen, Method, Prop } from '@stencil/core';
|
||||
import { Component, ComponentInterface, Element, Event, EventEmitter, Listen, Method, Prop, h } from '@stencil/core';
|
||||
|
||||
import { Animation, AnimationBuilder, Config, Mode, OverlayEventDetail, OverlayInterface, SpinnerTypes } from '../../interface';
|
||||
import { getIonMode } from '../../global/ionic-global';
|
||||
import { Animation, AnimationBuilder, Config, OverlayEventDetail, OverlayInterface, SpinnerTypes } from '../../interface';
|
||||
import { BACKDROP, dismiss, eventMethod, present } from '../../utils/overlays';
|
||||
import { sanitizeDOMString } from '../../utils/sanitization';
|
||||
import { getClassMap } from '../../utils/theme';
|
||||
@ -10,6 +11,9 @@ import { iosLeaveAnimation } from './animations/ios.leave';
|
||||
import { mdEnterAnimation } from './animations/md.enter';
|
||||
import { mdLeaveAnimation } from './animations/md.leave';
|
||||
|
||||
/**
|
||||
* @virtualProp {"ios" | "md"} mode - The mode determines which platform styles to use.
|
||||
*/
|
||||
@Component({
|
||||
tag: 'ion-loading',
|
||||
styleUrls: {
|
||||
@ -23,6 +27,7 @@ export class Loading implements ComponentInterface, OverlayInterface {
|
||||
|
||||
presented = false;
|
||||
animation?: Animation;
|
||||
mode = getIonMode(this);
|
||||
|
||||
@Element() el!: HTMLElement;
|
||||
|
||||
@ -31,11 +36,6 @@ export class Loading implements ComponentInterface, OverlayInterface {
|
||||
/** @internal */
|
||||
@Prop() overlayIndex!: number;
|
||||
|
||||
/**
|
||||
* The mode determines which platform styles to use.
|
||||
*/
|
||||
@Prop() mode!: Mode;
|
||||
|
||||
/**
|
||||
* If `true`, the keyboard will be automatically dismissed when the overlay is presented.
|
||||
*/
|
||||
@ -114,9 +114,10 @@ export class Loading implements ComponentInterface, OverlayInterface {
|
||||
|
||||
componentWillLoad() {
|
||||
if (this.spinner === undefined) {
|
||||
const mode = getIonMode(this);
|
||||
this.spinner = this.config.get(
|
||||
'loadingSpinner',
|
||||
this.config.get('spinner', this.mode === 'ios' ? 'lines' : 'crescent')
|
||||
this.config.get('spinner', mode === 'ios' ? 'lines' : 'crescent')
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -175,13 +176,14 @@ export class Loading implements ComponentInterface, OverlayInterface {
|
||||
}
|
||||
|
||||
hostData() {
|
||||
const mode = getIonMode(this);
|
||||
return {
|
||||
style: {
|
||||
zIndex: 40000 + this.overlayIndex
|
||||
},
|
||||
class: {
|
||||
...getClassMap(this.cssClass),
|
||||
[`${this.mode}`]: true,
|
||||
[`${mode}`]: true,
|
||||
'loading-translucent': this.translucent
|
||||
}
|
||||
};
|
||||
|
||||
@ -96,48 +96,28 @@ async function presentLoadingWithOptions() {
|
||||
### React
|
||||
|
||||
```tsx
|
||||
import React, { Component } from 'react'
|
||||
import { IonLoading } from '@ionic/react';
|
||||
import React, { useState } from 'react';
|
||||
import { IonLoading, IonButton, IonContent } from '@ionic/react';
|
||||
|
||||
type Props = {}
|
||||
type State = {
|
||||
showLoading1: boolean
|
||||
showLoading2: boolean
|
||||
}
|
||||
|
||||
export class LoadingExample extends Component<Props, State> {
|
||||
export const LoadingExample: React.FunctionComponent = () => {
|
||||
const [showLoading, setShowLoading] = useState(true);
|
||||
|
||||
constructor(props: Props) {
|
||||
super(props);
|
||||
this.state = {
|
||||
showLoading1: false
|
||||
showLoading2: false
|
||||
};
|
||||
}
|
||||
setTimeout(() => {
|
||||
setShowLoading(false);
|
||||
}, 2000);
|
||||
|
||||
render() {
|
||||
return (
|
||||
return (
|
||||
<IonContent>
|
||||
<IonButton onClick={() => setShowLoading(true)}>Show Loading</IonButton>
|
||||
<IonLoading
|
||||
isOpen={this.state.showLoading1}
|
||||
onDidDismiss={() => this.setState(() => ({ showLoading1: false }))}
|
||||
message={'Hellooo'}
|
||||
duration={200}
|
||||
>
|
||||
</IonLoading>
|
||||
|
||||
<IonLoading
|
||||
isOpen={this.state.showLoading2}
|
||||
onDidDismiss={() => this.setState(() => ({ showLoading2: false }))}
|
||||
spinner={null}
|
||||
isOpen={showLoading}
|
||||
onDidDismiss={() => setShowLoading(false)}
|
||||
message={'Loading...'}
|
||||
duration={5000}
|
||||
message='Please wait...'}
|
||||
translucent={true}
|
||||
cssClass='custom-class custom-loading'
|
||||
>
|
||||
</IonLoading>
|
||||
);
|
||||
}
|
||||
}
|
||||
/>
|
||||
</IonContent>
|
||||
);
|
||||
};
|
||||
```
|
||||
|
||||
|
||||
@ -214,12 +194,12 @@ export default {
|
||||
|
||||
## Events
|
||||
|
||||
| Event | Description | Type |
|
||||
| ----------------------- | ----------------------------------------- | --------------------------------- |
|
||||
| `ionLoadingDidDismiss` | Emitted after the loading has dismissed. | `CustomEvent<OverlayEventDetail>` |
|
||||
| `ionLoadingDidPresent` | Emitted after the loading has presented. | `CustomEvent<void>` |
|
||||
| `ionLoadingWillDismiss` | Emitted before the loading has dismissed. | `CustomEvent<OverlayEventDetail>` |
|
||||
| `ionLoadingWillPresent` | Emitted before the loading has presented. | `CustomEvent<void>` |
|
||||
| Event | Description | Type |
|
||||
| ----------------------- | ----------------------------------------- | -------------------------------------- |
|
||||
| `ionLoadingDidDismiss` | Emitted after the loading has dismissed. | `CustomEvent<OverlayEventDetail<any>>` |
|
||||
| `ionLoadingDidPresent` | Emitted after the loading has presented. | `CustomEvent<void>` |
|
||||
| `ionLoadingWillDismiss` | Emitted before the loading has dismissed. | `CustomEvent<OverlayEventDetail<any>>` |
|
||||
| `ionLoadingWillPresent` | Emitted before the loading has presented. | `CustomEvent<void>` |
|
||||
|
||||
|
||||
## Methods
|
||||
@ -228,13 +208,6 @@ export default {
|
||||
|
||||
Dismiss the loading overlay after it has been presented.
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Type | Description |
|
||||
| ------ | --------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| `data` | `any` | Any data to emit in the dismiss events. |
|
||||
| `role` | `string \| undefined` | The role of the element that is dismissing the loading. This can be useful in a button handler for determining which button was clicked to dismiss the loading. Some examples include: ``"cancel"`, `"destructive"`, "selected"`, and `"backdrop"`. |
|
||||
|
||||
#### Returns
|
||||
|
||||
Type: `Promise<boolean>`
|
||||
@ -286,6 +259,21 @@ Type: `Promise<void>`
|
||||
| `--width` | Width of the loading dialog |
|
||||
|
||||
|
||||
## Dependencies
|
||||
|
||||
### Depends on
|
||||
|
||||
- [ion-backdrop](../backdrop)
|
||||
- [ion-spinner](../spinner)
|
||||
|
||||
### Graph
|
||||
```mermaid
|
||||
graph TD;
|
||||
ion-loading --> ion-backdrop
|
||||
ion-loading --> ion-spinner
|
||||
style ion-loading fill:#f9f,stroke:#333,stroke-width:4px
|
||||
```
|
||||
|
||||
----------------------------------------------
|
||||
|
||||
*Built with [StencilJS](https://stenciljs.com/)*
|
||||
|
||||
@ -8,8 +8,8 @@
|
||||
<link href="../../../../../css/ionic.bundle.css" rel="stylesheet">
|
||||
<link href="../../../../../scripts/testing/styles.css" rel="stylesheet">
|
||||
<script src="../../../../../scripts/testing/scripts.js"></script>
|
||||
<script src="../../../../../dist/ionic.js"></script>
|
||||
</head>
|
||||
<script nomodule src="../../../../../dist/ionic/ionic.js"></script>
|
||||
<script type="module" src="../../../../../dist/ionic/ionic.esm.js"></script></head>
|
||||
|
||||
<body>
|
||||
<ion-app>
|
||||
|
||||
@ -8,8 +8,8 @@
|
||||
<link href="../../../../../css/ionic.bundle.css" rel="stylesheet">
|
||||
<link href="../../../../../scripts/testing/styles.css" rel="stylesheet">
|
||||
<script src="../../../../../scripts/testing/scripts.js"></script>
|
||||
<script src="../../../../../dist/ionic.js"></script>
|
||||
</head>
|
||||
<script nomodule src="../../../../../dist/ionic/ionic.js"></script>
|
||||
<script type="module" src="../../../../../dist/ionic/ionic.esm.js"></script></head>
|
||||
|
||||
<body>
|
||||
<ion-app>
|
||||
|
||||
@ -8,8 +8,8 @@
|
||||
<link href="../../../../../css/core.css" rel="stylesheet">
|
||||
<link href="../../../../../scripts/testing/styles.css" rel="stylesheet">
|
||||
<script src="../../../../../scripts/testing/scripts.js"></script>
|
||||
<script src="../../../../../dist/ionic.js"></script>
|
||||
</head>
|
||||
<script nomodule src="../../../../../dist/ionic/ionic.js"></script>
|
||||
<script type="module" src="../../../../../dist/ionic/ionic.esm.js"></script></head>
|
||||
|
||||
<body>
|
||||
<button id="basic-loading" onclick="presentLoading()">Show Loading</button>
|
||||
|
||||
@ -1,44 +1,24 @@
|
||||
```tsx
|
||||
import React, { Component } from 'react'
|
||||
import { IonLoading } from '@ionic/react';
|
||||
import React, { useState } from 'react';
|
||||
import { IonLoading, IonButton, IonContent } from '@ionic/react';
|
||||
|
||||
type Props = {}
|
||||
type State = {
|
||||
showLoading1: boolean
|
||||
showLoading2: boolean
|
||||
}
|
||||
export const LoadingExample: React.FunctionComponent = () => {
|
||||
const [showLoading, setShowLoading] = useState(true);
|
||||
|
||||
export class LoadingExample extends Component<Props, State> {
|
||||
|
||||
constructor(props: Props) {
|
||||
super(props);
|
||||
this.state = {
|
||||
showLoading1: false
|
||||
showLoading2: false
|
||||
};
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<IonLoading
|
||||
isOpen={this.state.showLoading1}
|
||||
onDidDismiss={() => this.setState(() => ({ showLoading1: false }))}
|
||||
message={'Hellooo'}
|
||||
duration={200}
|
||||
>
|
||||
</IonLoading>
|
||||
setTimeout(() => {
|
||||
setShowLoading(false);
|
||||
}, 2000);
|
||||
|
||||
return (
|
||||
<IonContent>
|
||||
<IonButton onClick={() => setShowLoading(true)}>Show Loading</IonButton>
|
||||
<IonLoading
|
||||
isOpen={this.state.showLoading2}
|
||||
onDidDismiss={() => this.setState(() => ({ showLoading2: false }))}
|
||||
spinner={null}
|
||||
isOpen={showLoading}
|
||||
onDidDismiss={() => setShowLoading(false)}
|
||||
message={'Loading...'}
|
||||
duration={5000}
|
||||
message='Please wait...'}
|
||||
translucent={true}
|
||||
cssClass='custom-class custom-loading'
|
||||
>
|
||||
</IonLoading>
|
||||
);
|
||||
}
|
||||
}
|
||||
/>
|
||||
</IonContent>
|
||||
);
|
||||
};
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user