# Loading

用于页面和区块的加载中状态。

## Usage

### Basic

```tsx
import React, { useState } from 'react'
import { Loading, Button } from 'react-icecream'

export default () => {
  const [loading, setLoading] = useState(true)
  return (
    <>
      <div style={{ height: '100px' }}>
        <div style={{ marginBottom: '10px' }}>
          <Loading loading={loading}>
            Hello world.
          </Loading>
        </div>
        <div style={{ marginBottom: '10px' }}>
          <Loading loading={loading} childrenVisibility="hidden">
            Hello world.
          </Loading>
        </div>
        <div>
          {loading ? <Loading /> : <div>Hello world.</div>}
        </div>
      </div>
      <Button size="small" onClick={() => setLoading(!loading)}>toggle loading</Button>
    </>
  )
}
```

### 行内需求

```tsx
import React, { useState } from 'react'
import { Loading, LoadingProps, Button } from 'react-icecream'

function InlineLoading(props: LoadingProps) {
  return (
    <div style={{ display: 'inline-block' }}>
      <Loading {...props} />
    </div>
  )
}

export default () => {
  const [loading, setLoading] = useState(true)
  return (
    <>
      <div style={{ marginBottom: '20px' }}>
        Hello <InlineLoading loading={loading}>Icecream</InlineLoading> world.
        My name is <InlineLoading loading={loading} childrenVisibility="hidden">Loading</InlineLoading>.
        Now is {loading ? <InlineLoading /> : new Date().toLocaleTimeString()}.
        <InlineLoading loading={loading}> My description is {'very '.repeat(100)}long.</InlineLoading>
      </div>
      <Button size="small" onClick={() => setLoading(!loading)}>toggle loading</Button>
    </>
  )
}
```

### 撑满父容器并居中

```tsx
import React, { useState } from 'react'
import { Loading, Button } from 'react-icecream'

function CoverLoading(props: LoadingProps) {
  return (
    <Loading {...props} style={{ height: '100%', ...props.style }} />
  )
}

export default () => {
  const [loading, setLoading] = useState(true)
  return (
    <>
      <div style={{ display: 'flex', marginBottom: '20px' }}>
        <div style={{ width: '100px', height: '100px', background: '#bfbfbf', marginRight: '10px' }}>
          <CoverLoading loading={loading}>
            <div style={{ background: '#DDD' }}>Hello world.</div>
          </CoverLoading>
        </div>
        <div style={{ display: 'flex', flexDirection: 'column', width: '100px', height: '100px', background: '#bfbfbf', marginRight: '10px' }}>
          <Loading style={{ flex: 1 }} childrenVisibility="hidden" loading={loading}>
            <div style={{ background: '#DDD' }}>World in flex.</div>
          </Loading>
        </div>
        <div style={{ width: '100px', height: '100px', background: '#bfbfbf', marginRight: '10px' }}>
          <CoverLoading loading={loading}>
            <div style={{ width: '100%', height: '100%', display: 'flex', justifyContent: 'center', alignItems: 'center' }}>
              <div style={{ background: '#DDD' }}>Hello world.</div>
            </div>
          </CoverLoading>
        </div>
        <div style={{ width: '100px', height: '100px', background: '#bfbfbf' }}>
          {loading ? <CoverLoading /> : <div style={{ background: '#DDD' }}>Hello world.</div>}
        </div>
      </div>
      <Button size="small" onClick={() => setLoading(!loading)}>toggle loading</Button>
    </>
  )
}
```

### Loading 动画最大高度只有 200px

```tsx
import React from 'react'
import { Loading, Button } from 'react-icecream'

export default () => {
  const renderContent = (height: number) => (
    <div style={{ display: 'flex', alignItems: 'center', justifyContent: 'center', height: `${height}px` }}>
      <div style={{ marginTop: '-3em' }}>有遮罩 鼠标不能点击 <Button onClick={() => alert('漏了')}>按钮</Button></div>
    </div>
  )
  return (
    <>
      <h4 style={{ marginTop: 0 }}>无 children 示例：</h4>
      <div style={{ height: '600px' }}>
        <Loading style={{ height: '100%', background: '#bfbfbf' }} />
      </div>
      <h4>有 children 示例：</h4>
      <Loading>
        <div style={{ height: '100%', position: 'relative' }}>
          {renderContent(400)}
          {renderContent(200)}
        </div>
      </Loading>
    </>
  )
}
```

### Loading 嵌套 Loading

```tsx
import React, { useState } from 'react'
import { Loading, Button } from 'react-icecream'

export default () => {
  const [outerLoading, setOuterLoading] = useState(false)
  const [innerLoading, setInnerLoading] = useState(true)
  return (
    <>
      <Loading loading={outerLoading}>
        Hello
        <div style={{ display: 'inline-block' }}>
          <Loading loading={!outerLoading && innerLoading} style={{ padding: '0 20px' }}>
            inner
          </Loading>
        </div>
        world.
      </Loading>
      <div style={{ marginTop: '20px' }}>
        <Button size="small" onClick={() => setOuterLoading(!outerLoading)}>toggle outer loading</Button>
        <Button size="small" onClick={() => setInnerLoading(!innerLoading)}>toggle inner loading</Button>
      </div>
    </>
  )
}
```

<API></API>
