import { use, suffixPx } from '../utils'; import { inherit } from '../utils/functional'; // Types import { CreateElement, RenderContext } from 'vue/types'; import { DefaultSlots } from '../utils/use/sfc'; export type LoadingType = 'circular' | 'spinner'; export type LoadingProps = { type: LoadingType; size?: string | number; color: string; vertical?: boolean; textSize?: string | number; }; const [sfc, bem] = use('loading'); const DEFAULT_COLOR = '#c9c9c9'; function Loading( h: CreateElement, props: LoadingProps, slots: DefaultSlots, ctx: RenderContext ) { const { color, size, type } = props; const style: { [key: string]: string } = { color }; if (size) { const iconSize = suffixPx(size); style.width = iconSize; style.height = iconSize; } const Spin = []; if (type === 'spinner') { for (let i = 0; i < 12; i++) { Spin.push(); } } const Circular = type === 'circular' && ( ); function Text() { if (slots.default) { const style = props.textSize && { fontSize: suffixPx(props.textSize) }; return ( {slots.default()} ); } } return (
{Spin} {Circular} {Text()}
); } Loading.props = { size: [String, Number], textSize: [String, Number], vertical: Boolean, type: { type: String, default: 'circular' }, color: { type: String, default: DEFAULT_COLOR } }; export default sfc(Loading);