2.0.1 • Published 9 months ago

antd-spin v2.0.1

Weekly downloads
5
License
MIT
Repository
github
Last release
9 months ago

antd-spin

NPM version Downloads License GitHub stars

Enhancing Ant Design's Spin as a Service. Inspired by Element Plus's Loading component.

Motivation

Enhance the Spin component of antd to support service calls, and the global state is a singleton mode.

Usage

Install

$ npm install antd-spin

Service

Import Spin service:

import { antdSpin } from "antd-spin";

Invoke it:

antdSpin.service(options);

The parameter options is the configuration of Spin, and its details can be found in the following table. SpinService returns a Spin instance, and you can close it by invoking its close method:

const spinInstance = antdSpin.service(options);
spinInstance.close();

Note that in this case the full screen Spin is singleton. If a new full screen Spin is invoked before an existing one is closed, the existing full screen Spin instance will be returned instead of actually creating another Spin instance:

const spinInstance1 = antdSpin.service();
const spinInstance2 = antdSpin.service();

// true
console.log(spinInstance1 === spinInstance2);

setTimeout(() => {
	// Calling the `close` method on any one of them can close this full screen Spin.
	spinInstance2.close();
}, 5000);

show time

singleton-mode

Directive

import { AntdSpin } from "antd-spin";

const DemoSpin = () => {
	return (
		<AntdSpin fullscreen={true} />
	);
}
  • fullscreen is true, return a fullscreen Spin.
  • fullscreen is false, return a Spin.

Options

NameDescriptionTypeDefault
targetThe DOM node Spin needs to cover. Accepts a DOM object or a string. If it's a string, it will be passed to document.querySelector to get the corresponding DOM nodestring / HTMLElementdocument.body
fullscreenShow a full screen Spinbooleantrue
lockDisable background scrollingbooleanfalse
backgroundBackground color of the maskstring
customClassCustom class name for Spinstring
spinPropsThe properties of antd's Spin componentSpinProps{}

SpinProps

NameTypeDescription
prefixClsstringPrefix class name (optional)
classNamestringClass name (optional)
rootClassNamestringRoot element class name (optional)
spinningbooleanWhether to display the loading state
styleReact.CSSPropertiesCustom style object (optional)
sizeSpinSizeSize (optional)
tipReact.ReactNodeTip content (optional)
delaynumberTime in milliseconds to delay showing the loading state (optional)
wrapperClassNamestringWrapper element class name (optional)
indicatorSpinIndicatorCustom loading indicator (optional)
childrenReact.ReactNodeChild elements (optional)
2.0.0-beta.0

9 months ago

2.0.1

9 months ago

2.0.0

9 months ago

1.0.2

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago