feat(spinner): add circular spinner for MD default (#19052)

This commit is contained in:
Adam Bradley
2019-08-08 16:08:13 -05:00
committed by GitHub
parent e8cdda0fae
commit e33cf854a9
12 changed files with 200 additions and 118 deletions

View File

@ -417,7 +417,7 @@ ion-infinite-scroll,method,complete,complete() => Promise<void>
ion-infinite-scroll,event,ionInfinite,void,true
ion-infinite-scroll-content,none
ion-infinite-scroll-content,prop,loadingSpinner,"bubbles" | "circles" | "crescent" | "dots" | "lines" | "lines-small" | null | undefined,undefined,false,false
ion-infinite-scroll-content,prop,loadingSpinner,"bubbles" | "circles" | "circular" | "crescent" | "dots" | "lines" | "lines-small" | null | undefined,undefined,false,false
ion-infinite-scroll-content,prop,loadingText,string | undefined,undefined,false,false
ion-input,scoped
@ -585,7 +585,7 @@ ion-loading,prop,leaveAnimation,((Animation: Animation, baseEl: any, opts?: any)
ion-loading,prop,message,string | undefined,undefined,false,false
ion-loading,prop,mode,"ios" | "md",undefined,false,false
ion-loading,prop,showBackdrop,boolean,true,false,false
ion-loading,prop,spinner,"bubbles" | "circles" | "crescent" | "dots" | "lines" | "lines-small" | null | undefined,undefined,false,false
ion-loading,prop,spinner,"bubbles" | "circles" | "circular" | "crescent" | "dots" | "lines" | "lines-small" | null | undefined,undefined,false,false
ion-loading,prop,translucent,boolean,false,false,false
ion-loading,method,dismiss,dismiss(data?: any, role?: string | undefined) => Promise<boolean>
ion-loading,method,onDidDismiss,onDidDismiss() => Promise<OverlayEventDetail<any>>
@ -892,7 +892,7 @@ ion-refresher,event,ionStart,void,true
ion-refresher-content,none
ion-refresher-content,prop,pullingIcon,null | string | undefined,undefined,false,false
ion-refresher-content,prop,pullingText,string | undefined,undefined,false,false
ion-refresher-content,prop,refreshingSpinner,"bubbles" | "circles" | "crescent" | "dots" | "lines" | "lines-small" | null | undefined,undefined,false,false
ion-refresher-content,prop,refreshingSpinner,"bubbles" | "circles" | "circular" | "crescent" | "dots" | "lines" | "lines-small" | null | undefined,undefined,false,false
ion-refresher-content,prop,refreshingText,string | undefined,undefined,false,false
ion-reorder,shadow
@ -1098,7 +1098,7 @@ ion-slides,css-prop,--bullet-background-active
ion-spinner,shadow
ion-spinner,prop,color,string | undefined,undefined,false,false
ion-spinner,prop,duration,number | undefined,undefined,false,false
ion-spinner,prop,name,"bubbles" | "circles" | "crescent" | "dots" | "lines" | "lines-small" | undefined,undefined,false,false
ion-spinner,prop,name,"bubbles" | "circles" | "circular" | "crescent" | "dots" | "lines" | "lines-small" | undefined,undefined,false,false
ion-spinner,prop,paused,boolean,false,false,false
ion-spinner,css-prop,--color

View File

@ -59,8 +59,8 @@ The `ion-infinite-scroll-content` component is not supported in React.
## Properties
| Property | Attribute | Description | Type | Default |
| ---------------- | ----------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------- | ----------- |
| `loadingSpinner` | `loading-spinner` | An animated SVG spinner that shows while loading. | `"bubbles" \| "circles" \| "crescent" \| "dots" \| "lines" \| "lines-small" \| null \| undefined` | `undefined` |
| ---------------- | ----------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------- | ----------- |
| `loadingSpinner` | `loading-spinner` | An animated SVG spinner that shows while loading. | `"bubbles" \| "circles" \| "circular" \| "crescent" \| "dots" \| "lines" \| "lines-small" \| null \| undefined` | `undefined` |
| `loadingText` | `loading-text` | Optional text to display while loading. `loadingText` can accept either plaintext or HTML as a string. To display characters normally reserved for HTML, they must be escaped. For example `<Ionic>` would become `&lt;Ionic&gt;` For more information: [Security Documentation](https://ionicframework.com/docs/faq/security) | `string \| undefined` | `undefined` |

View File

@ -175,7 +175,7 @@ export default {
## Properties
| Property | Attribute | Description | Type | Default |
| ----------------- | ------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------- | ----------- |
| ----------------- | ------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------- | ----------- |
| `animated` | `animated` | If `true`, the loading indicator will animate. | `boolean` | `true` |
| `backdropDismiss` | `backdrop-dismiss` | If `true`, the loading indicator will be dismissed when the backdrop is clicked. | `boolean` | `false` |
| `cssClass` | `css-class` | Additional classes to apply for custom CSS. If multiple classes are provided they should be separated by spaces. | `string \| string[] \| undefined` | `undefined` |
@ -186,7 +186,7 @@ export default {
| `message` | `message` | Optional text content to display in the loading indicator. | `string \| undefined` | `undefined` |
| `mode` | `mode` | The mode determines which platform styles to use. | `"ios" \| "md"` | `undefined` |
| `showBackdrop` | `show-backdrop` | If `true`, a backdrop will be displayed behind the loading indicator. | `boolean` | `true` |
| `spinner` | `spinner` | The name of the spinner to display. | `"bubbles" \| "circles" \| "crescent" \| "dots" \| "lines" \| "lines-small" \| null \| undefined` | `undefined` |
| `spinner` | `spinner` | The name of the spinner to display. | `"bubbles" \| "circles" \| "circular" \| "crescent" \| "dots" \| "lines" \| "lines-small" \| null \| undefined` | `undefined` |
| `translucent` | `translucent` | If `true`, the loading indicator will be translucent. Only applies when the mode is `"ios"` and the device supports [`backdrop-filter`](https://developer.mozilla.org/en-US/docs/Web/CSS/backdrop-filter#Browser_compatibility). | `boolean` | `false` |

View File

@ -10,10 +10,10 @@ The refresher content contains the text, icon and spinner to display during a pu
## Properties
| Property | Attribute | Description | Type | Default |
| ------------------- | -------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------- | ----------- |
| ------------------- | -------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------- | ----------- |
| `pullingIcon` | `pulling-icon` | A static icon to display when you begin to pull down | `null \| string \| undefined` | `undefined` |
| `pullingText` | `pulling-text` | The text you want to display when you begin to pull down. `pullingText` can accept either plaintext or HTML as a string. To display characters normally reserved for HTML, they must be escaped. For example `<Ionic>` would become `&lt;Ionic&gt;` For more information: [Security Documentation](https://ionicframework.com/docs/faq/security) | `string \| undefined` | `undefined` |
| `refreshingSpinner` | `refreshing-spinner` | An animated SVG spinner that shows when refreshing begins | `"bubbles" \| "circles" \| "crescent" \| "dots" \| "lines" \| "lines-small" \| null \| undefined` | `undefined` |
| `refreshingSpinner` | `refreshing-spinner` | An animated SVG spinner that shows when refreshing begins | `"bubbles" \| "circles" \| "circular" \| "crescent" \| "dots" \| "lines" \| "lines-small" \| null \| undefined` | `undefined` |
| `refreshingText` | `refreshing-text` | The text you want to display when performing a refresh. `refreshingText` can accept either plaintext or HTML as a string. To display characters normally reserved for HTML, they must be escaped. For example `<Ionic>` would become `&lt;Ionic&gt;` For more information: [Security Documentation](https://ionicframework.com/docs/faq/security) | `string \| undefined` | `undefined` |

View File

@ -111,10 +111,10 @@ export const SpinnerExample: React.FunctionComponent = () => (
## Properties
| Property | Attribute | Description | Type | Default |
| ---------- | ---------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------- | ----------- |
| ---------- | ---------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------- | ----------- |
| `color` | `color` | The color to use from your application's color palette. Default options are: `"primary"`, `"secondary"`, `"tertiary"`, `"success"`, `"warning"`, `"danger"`, `"light"`, `"medium"`, and `"dark"`. For more information on colors, see [theming](/docs/theming/basics). | `string \| undefined` | `undefined` |
| `duration` | `duration` | Duration of the spinner animation in milliseconds. The default varies based on the spinner. | `number \| undefined` | `undefined` |
| `name` | `name` | The name of the SVG spinner to use. If a name is not provided, the platform's default spinner will be used. | `"bubbles" \| "circles" \| "crescent" \| "dots" \| "lines" \| "lines-small" \| undefined` | `undefined` |
| `name` | `name` | The name of the SVG spinner to use. If a name is not provided, the platform's default spinner will be used. | `"bubbles" \| "circles" \| "circular" \| "crescent" \| "dots" \| "lines" \| "lines-small" \| undefined` | `undefined` |
| `paused` | `paused` | If `true`, the spinner's animation will be paused. | `boolean` | `false` |

View File

@ -2,41 +2,6 @@ import { SpinnerConfigs } from './spinner-interface';
const spinners = {
'lines': {
dur: 1000,
lines: 12,
fn: (dur: number, index: number, total: number) => {
const transform = `rotate(${ 30 * index + (index < 6 ? 180 : -180) }deg)`;
const animationDelay = `${ (dur * index / total) - dur }ms`;
return {
y1: 17,
y2: 29,
style: {
'transform': transform,
'animation-delay': animationDelay,
}
};
}
},
'lines-small': {
dur: 1000,
lines: 12,
fn: (dur: number, index: number, total: number) => {
const transform = `rotate(${30 * index + (index < 6 ? 180 : -180)}deg)`;
const animationDelay = `${ (dur * index / total) - dur }ms`;
return {
y1: 12,
y2: 20,
style: {
'transform': transform,
'animation-delay': animationDelay,
}
};
}
},
'bubbles': {
dur: 1000,
circles: 9,
@ -72,6 +37,23 @@ const spinners = {
}
},
'circular': {
dur: 1400,
elmDuration: true,
circles: 1,
fn: () => {
return {
r: 20,
cx: 44,
cy: 44,
fill: 'none',
viewBox: '22 22 44 44',
transform: 'translate(0,0)',
style: {}
};
}
},
'crescent': {
dur: 750,
circles: 1,
@ -96,8 +78,44 @@ const spinners = {
}
};
}
},
'lines': {
dur: 1000,
lines: 12,
fn: (dur: number, index: number, total: number) => {
const transform = `rotate(${ 30 * index + (index < 6 ? 180 : -180) }deg)`;
const animationDelay = `${ (dur * index / total) - dur }ms`;
return {
y1: 17,
y2: 29,
style: {
'transform': transform,
'animation-delay': animationDelay,
}
};
}
},
'lines-small': {
dur: 1000,
lines: 12,
fn: (dur: number, index: number, total: number) => {
const transform = `rotate(${30 * index + (index < 6 ? 180 : -180)}deg)`;
const animationDelay = `${ (dur * index / total) - dur }ms`;
return {
y1: 12,
y2: 20,
style: {
'transform': transform,
'animation-delay': animationDelay,
}
};
}
}
};
export const SPINNERS: SpinnerConfigs = spinners;
export type SpinnerTypes = keyof typeof spinners;

View File

@ -9,6 +9,7 @@ export interface SpinnerConfig {
dur: number;
circles?: number;
lines?: number;
elmDuration?: boolean;
fn: (dur: number, index: number, total: number) => SpinnerData;
}
@ -16,5 +17,9 @@ export interface SpinnerData {
r?: number;
y1?: number;
y2?: number;
cx?: number;
cy?: number;
style: any;
viewBox?: string;
transform?: string;
}

View File

@ -99,10 +99,29 @@ svg {
}
// Spinner: circular
// --------------------------------------------------
:host(.spinner-circular) {
animation: spinner-circular linear infinite;
}
:host(.spinner-circular) circle {
animation: spinner-circular-inner ease-in-out infinite;
stroke: currentColor;
stroke-dasharray: 80px, 200px;
stroke-dashoffset: 0px;
stroke-width: 3.6;
fill: none;
}
// Spinner: paused
// --------------------------------------------------
:host(.spinner-paused) svg {
:host(.spinner-paused),
:host(.spinner-paused) svg,
:host(.spinner-paused) circle {
animation-play-state: paused;
}
@ -162,3 +181,24 @@ svg {
opacity: .9;
}
}
@keyframes spinner-circular {
100% {
transform: rotate(360deg);
}
}
@keyframes spinner-circular-inner {
0% {
stroke-dasharray: 1px, 200px;
stroke-dashoffset: 0px;
}
50% {
stroke-dasharray: 100px, 200px;
stroke-dashoffset: -15px;
}
100% {
stroke-dasharray: 100px, 200px;
stroke-dashoffset: -125px;
}
}

View File

@ -38,19 +38,20 @@ export class Spinner implements ComponentInterface {
@Prop() paused = false;
private getName(): SpinnerTypes {
const name = this.name || config.get('spinner');
const spinnerName = this.name || config.get('spinner');
const mode = getIonMode(this);
if (name) {
return name;
if (spinnerName) {
return spinnerName;
}
return (mode === 'ios') ? 'lines' : 'crescent';
return (mode === 'ios') ? 'lines' : 'circular';
}
render() {
const mode = getIonMode(this);
const name = this.getName();
const spinner = SPINNERS[name] || SPINNERS['lines'];
const duration = (typeof this.duration === 'number' && this.duration > 10 ? this.duration : spinner.dur);
const self = this;
const mode = getIonMode(self);
const spinnerName = self.getName();
const spinner = SPINNERS[spinnerName] || SPINNERS['lines'];
const duration = (typeof self.duration === 'number' && self.duration > 10 ? self.duration : spinner.dur);
const svgs: any[] = [];
if (spinner.circles !== undefined) {
@ -67,11 +68,13 @@ export class Spinner implements ComponentInterface {
return (
<Host
class={{
...createColorClasses(this.color),
...createColorClasses(self.color),
[mode]: true,
[`spinner-${name}`]: true,
'spinner-paused': !!this.paused || config.getBoolean('_testing')
[`spinner-${spinnerName}`]: true,
'spinner-paused': !!self.paused || config.getBoolean('_testing')
}}
role="progressbar"
style={spinner.elmDuration ? { animationDuration: duration + 'ms' } : {}}
>
{svgs}
</Host>
@ -81,21 +84,27 @@ export class Spinner implements ComponentInterface {
const buildCircle = (spinner: SpinnerConfig, duration: number, index: number, total: number) => {
const data = spinner.fn(duration, index, total);
data.style['animation-duration'] = `${duration}ms`;
data.style['animation-duration'] = duration + 'ms';
return (
<svg viewBox="0 0 64 64" style={data.style}>
<circle transform="translate(32,32)" r={data.r}></circle>
<svg viewBox={data.viewBox || '0 0 64 64'} style={data.style}>
<circle
transform={data.transform || 'translate(32,32)'}
cx={data.cx}
cy={data.cy}
r={data.r}
style={spinner.elmDuration ? { animationDuration: duration + 'ms' } : {}}
/>
</svg>
);
};
const buildLine = (spinner: SpinnerConfig, duration: number, index: number, total: number) => {
const data = spinner.fn(duration, index, total);
data.style['animation-duration'] = `${duration}ms`;
data.style['animation-duration'] = duration + 'ms';
return (
<svg viewBox="0 0 64 64" style={data.style}>
<svg viewBox={data.viewBox || '0 0 64 64'} style={data.style}>
<line transform="translate(32,32)" y1={data.y1} y2={data.y2}></line>
</svg>
);

View File

@ -27,62 +27,70 @@
</ion-list-header>
<ion-item>
<ion-spinner slot="start"></ion-spinner>
Default Spinner
Platform Default Spinner
</ion-item>
<ion-item>
<ion-spinner slot="start" name="lines"></ion-spinner>
Lines
<code>lines</code>
</ion-item>
<ion-item>
<ion-spinner slot="start" name="lines-small"></ion-spinner>
Lines Small
<code>lines-small</code>
</ion-item>
<ion-item>
<ion-spinner slot="start" name="circular"></ion-spinner>
<code>circular</code>
</ion-item>
<ion-item>
<ion-spinner slot="start" name="dots"></ion-spinner>
Dots
<code>dots</code>
</ion-item>
<ion-item>
<ion-spinner slot="start" name="bubbles"></ion-spinner>
Bubbles
<code>bubbles</code>
</ion-item>
<ion-item>
<ion-spinner slot="start" name="circles"></ion-spinner>
Circles
<code>circles</code>
</ion-item>
<ion-item>
<ion-spinner slot="start" name="crescent"></ion-spinner>
Crescent
<code>crescent</code>
</ion-item>
</ion-list>
<ion-list>
<ion-item>
<ion-spinner slot="start" paused></ion-spinner>
Paused Default Spinner
Paused Platform Default Spinner
</ion-item>
<ion-item>
<ion-spinner slot="start" name="lines" paused></ion-spinner>
Paused Lines
<code>lines</code>
</ion-item>
<ion-item>
<ion-spinner slot="start" name="lines-small" paused></ion-spinner>
Paused Lines Small
<code>lines-small</code>
</ion-item>
<ion-item>
<ion-spinner slot="start" name="circular" paused></ion-spinner>
<code>circular</code>
</ion-item>
<ion-item>
<ion-spinner slot="start" name="dots" paused></ion-spinner>
Paused Dots
<code>dots</code>
</ion-item>
<ion-item>
<ion-spinner slot="start" name="bubbles" paused></ion-spinner>
Paused Bubbles
<code>bubbles</code>
</ion-item>
<ion-item>
<ion-spinner slot="start" name="circles" paused></ion-spinner>
Paused Circles
<code>circles</code>
</ion-item>
<ion-item>
<ion-spinner slot="start" name="crescent" paused></ion-spinner>
Paused Crescent
<code>crescent</code>
</ion-item>
</ion-list>
</ion-content>

View File

@ -22,40 +22,41 @@
<ion-content id="content">
<ion-list>
<ion-list-header>
Spinner Loading Indicators
</ion-list-header>
<ion-item>
<ion-spinner slot="start"></ion-spinner>
Show Default Spinner
Platform Default Spinner
</ion-item>
<ion-item>
<ion-spinner color="primary" slot="start" name="lines"></ion-spinner>
Show Lines (Primary)
<code>lines</code> (primary)
</ion-item>
<ion-item>
<ion-spinner color="secondary" slot="start" name="ios-small"></ion-spinner>
Show Lines Small (Secondary)
<ion-spinner color="secondary" slot="start" name="lines-small"></ion-spinner>
<code>lines-small</code> (secondary)
</ion-item>
<ion-item>
<ion-spinner color="danger" slot="start" name="dots"></ion-spinner>
Show Dots (Danger)
<ion-spinner color="tertiary" slot="start" name="circular"></ion-spinner>
<code>circular</code> (tertiary)
</ion-item>
<ion-item>
<ion-spinner color="light" slot="start" name="bubbles"></ion-spinner>
Show Bubbles (Light)
<ion-spinner color="success" slot="start" name="dots"></ion-spinner>
<code>dots</code> (success)
</ion-item>
<ion-item>
<ion-spinner color="dark" slot="start" name="circles"></ion-spinner>
Show Circles (Dark)
<ion-spinner color="warning" slot="start" name="bubbles"></ion-spinner>
<code>bubbles</code> (warning)
</ion-item>
<ion-item>
<ion-spinner color="primary" slot="start" name="crescent"></ion-spinner>
Show Crescent (Primary)
<ion-spinner color="danger" slot="start" name="circles"></ion-spinner>
<code>circles</code> (danger)
</ion-item>
<ion-item>
<ion-spinner color="secondary" slot="start" paused></ion-spinner>
Show Paused Default Spinner (Secondary)
<ion-spinner color="dark" slot="start" name="crescent"></ion-spinner>
<code>crescent</code> (dark)
</ion-item>
<ion-item>
<ion-spinner color="medium" slot="start" name="lines" paused></ion-spinner>
<code>lines</code> (paused, medium)
</ion-item>
</ion-list>
</ion-content>

View File

@ -14,7 +14,8 @@
<body>
<ion-spinner></ion-spinner>
<ion-spinner name="lines"></ion-spinner>
<ion-spinner name="ios-small"></ion-spinner>
<ion-spinner name="lines-small"></ion-spinner>
<ion-spinner name="circular"></ion-spinner>
<ion-spinner name="dots"></ion-spinner>
<ion-spinner name="bubbles"></ion-spinner>
<ion-spinner name="circles"></ion-spinner>