Skip to content

Commit

Permalink
feat(component): loading支持包装器加载模式
Browse files Browse the repository at this point in the history
  • Loading branch information
ShanaMaid committed Sep 14, 2018
1 parent c04b409 commit 842ef45
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 9 deletions.
44 changes: 35 additions & 9 deletions components/Loading/Loading.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ export interface ILoadingProps extends IBaseComponent {
* 加载文本
*/
text?: string | boolean;
/**
* 自定义icon
*/
icon?: React.ReactNode;
/**
* 加载
*/
loading?: boolean;
}

export interface ILoadingState {
Expand All @@ -32,30 +40,48 @@ export class Loading extends Component<ILoadingProps, ILoadingState> {
type: 'a',
size: 'default',
text: false,
loading: true,
};

render() {
const {className, style, children, type, size, text, ...otherProps} = this.props;
const {
className, style, children, type,
size, text, icon, loading, ...otherProps
} = this.props;
const preCls = 'yoshino-loading';
const iconType = `load-${type}`;
const loadSize = `${preCls}-${size}`;
const hasChildren = !!children;
const clsName = classNames(
preCls, loadSize, className,
{
[`${preCls}-children-box`]: hasChildren,
}
);
return (
<div
className={clsName}
style={style}
{...otherProps}
>
<span className={`${preCls}-icon`}>
{children ? children : <Icon type={iconType}/>}
</span>
{
text ? (
<p className={`${preCls}-text`}>{typeof text === 'string' ? text : '加载中'}</p>
) : null
}
{hasChildren ? <div className={`${preCls}-children`}>{children}</div> : null}
{
loading ? (
<>
<div className={classNames({[`${preCls}-container`]: hasChildren})}>
<span className={`${preCls}-icon`}>
{icon ? icon : <Icon type={iconType}/>}
</span>
{
text ? (
<p className={`${preCls}-text`}>{typeof text === 'string' ? text : '加载中'}</p>
) : null
}
</div>
{hasChildren ? <div className={`${preCls}-mask`}/> : null}
</>
) : null
}
</div>
);
}
Expand Down
23 changes: 23 additions & 0 deletions components/Loading/style/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
.@{loading-prefix-cls} {
color: @primary-color;
text-align: center;
display: inline-block;
position: relative;

&-icon {
display: inline-block;
Expand All @@ -26,4 +28,25 @@
&-text {
font-size: 12px;
}

&-container {
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
}

&-mask {
position: absolute;
left: 0;
top: 0;
right: 0;
bottom: 0;
opacity: @loading-mask-opacity;
background: @loading-mask-background;
}

&-children-box {
display: block;
}
}
3 changes: 3 additions & 0 deletions components/Loading/style/var.less
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@
@loading-size-small: 14px;
@loading-size-default: 20px;
@loading-size-large: 32px;

@loading-mask-opacity: 0.5;
@loading-mask-background: white;
12 changes: 12 additions & 0 deletions docs/pages/components/Loading/api.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,18 @@ export default [
type: 'string | boolean',
defaultValue: '-',
},
{
props: 'icon',
intro: '自定义icon',
type: 'ReactNode',
defaultValue: '-',
},
{
props: 'loading',
intro: '加载状态',
type: 'boolean',
defaultValue: 'true',
},
]
}
];
1 change: 1 addition & 0 deletions docs/pages/components/Loading/demo/loadingContainer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#### 包裹需要加载的页面
21 changes: 21 additions & 0 deletions docs/pages/components/Loading/demo/loadingContainer.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import * as React from 'react';
import { Loading, Switch, Alert } from '@yoshino/components/';

export default class App extends React.Component {
state = {
value: false,
};

render() {
return (
<div>
<Loading text='自定义加载文本' size='large' type='b' loading={this.state.value}>
<Alert type='info' showIcon title='消息提示文案'/>
</Loading>
<div>
<Switch checked={this.state.value} onChange={(v) => this.setState({value: v})} />
</div>
</div>
);
}
}
6 changes: 6 additions & 0 deletions docs/pages/components/Loading/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ import LoadingCustom from './demo/loadingCustom';
import * as loadingCustomMd from './demo/loadingCustom.md';
const loadingCustomCode = require('!raw-loader!./demo/loadingCustom');

import LoadingContainer from './demo/loadingContainer';
import * as loadingContainerMd from './demo/loadingContainer.md';
const loadingContainerCode = require('!raw-loader!./demo/loadingContainer');

export default class LoadingPage extends Component {
render() {
return (
Expand All @@ -22,6 +26,8 @@ export default class LoadingPage extends Component {
<CodeBox text={loadingDemoMd} demo={<LoadingDemo/>} code={loadingDemoCode}/>

<CodeBox text={loadingCustomMd} demo={<LoadingCustom/>} code={loadingCustomCode}/>

<CodeBox text={loadingContainerMd} demo={<LoadingContainer/>} code={loadingContainerCode}/>
<ApiBox api={Api}/>
</div>
);
Expand Down

0 comments on commit 842ef45

Please sign in to comment.