最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Ant?Design?組件庫之步驟條實現(xiàn)

 更新時間:2022年08月19日 15:03:41   作者:極智視界  
這篇文章主要為大家介紹了Ant?Design組件庫之步驟條實現(xiàn),有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪

引言

antd 組件庫是基于 Ant Design 設(shè)計體系的 React UI 組件庫,antd 為 Web 應(yīng)用提供了豐富的基礎(chǔ) UI 組件,可以用于研發(fā)企業(yè)級中后臺產(chǎn)品。這篇咱們介紹 antd 組件庫之 步驟條

1 antd 之 Steps API

步驟條 Steps 的用處是在 當任務(wù)復雜或者存在先后關(guān)系時,將其分解成一系列的步驟,從而達到簡化任務(wù)的目的。其 DOM 節(jié)點為 :

<Steps>
  <Step>...</Step>
  <Step>...</Step>
  <Step>...</Step>
</Steps>

antd 中的步驟條樣式豐富,可以通過設(shè)置 Steps 和 Step 的屬性來產(chǎn)生不同的 步驟條 樣式,詳細的這里我進行一個整理:

下面做一些實踐。

2 antd 之 Steps 示例

先來看最簡單的靜態(tài)的步驟條,看代碼:

import { Steps } from 'antd';
import React from 'react';
const { Step } = Steps;
const App = () => (
  <Steps current={1}>
    <Step title="Finished" description="This is a description." />
    <Step title="In Progress" subTitle="Left 00:00:08" description="This is a description." />
    <Step title="Waiting" description="This is a description." />
  </Steps>
);
export default App;

可以看到現(xiàn)在 current 默認選擇了 1,來看效果:

如果 current 我們選擇了 2, 那會是什么樣子的呢:

再來看一個 帶圖標的步驟條,這里用了 antd 的 icon,上代碼:

import { LoadingOutlined, SmileOutlined, SolutionOutlined, UserOutlined } from '@ant-design/icons';
import { Steps } from 'antd';
import React from 'react';
const { Step } = Steps;
const App = () => (
  <Steps>
    <Step status="finish" title="Login" icon={<UserOutlined />} />
    <Step status="finish" title="Verification" icon={<SolutionOutlined />} />
    <Step status="process" title="Pay" icon={<LoadingOutlined />} />
    <Step status="wait" title="Done" icon={<SmileOutlined />} />
  </Steps>
);
export default App;

來看效果:

來有意思一些的,看看動態(tài)的吧:配合按鈕進行步進或后退,來表示一個流程的處理進度,上代碼:

import { Button, message, Steps } from 'antd';
import React, { useState } from 'react';
const { Step } = Steps;
const steps = [
  {
    title: 'First',
    content: 'First-content',
  },
  {
    title: 'Second',
    content: 'Second-content',
  },
  {
    title: 'Last',
    content: 'Last-content',
  },
];
const App = () => {
  const [current, setCurrent] = useState(0);
  const next = () => {
    setCurrent(current + 1);
  };
  const prev = () => {
    setCurrent(current - 1);
  };
  return (
    <>
      <Steps current={current}>
        {steps.map((item) => (
          <Step key={item.title} title={item.title} />
        ))}
      </Steps>
      <div className="steps-content">{steps[current].content}</div>
      <div className="steps-action">
        {current < steps.length - 1 && (
          <Button type="primary" onClick={() => next()}>
            Next
          </Button>
        )}
        {current === steps.length - 1 && (
          <Button type="primary" onClick={() => message.success('Processing complete!')}>
            Done
          </Button>
        )}
        {current > 0 && (
          <Button
            style={{
              margin: '0 8px',
            }}
            onClick={() => prev()}
          >
            Previous
          </Button>
        )}
      </div>
    </>
  );
};
export default App;

還有 CSS 代碼,同級目錄下寫個 index.less

.steps-content {
    min-height: 200px;
    margin-top: 16px;
    padding-top: 80px;
    text-align: center;
    background-color: #fafafa;
    border: 1px dashed #e9e9e9;
    border-radius: 2px;
  }
  .steps-action {
    margin-top: 24px;
  }

來看效果:

步驟條還可以通過 Steps 的 status 屬性來指定當前步驟的狀態(tài),來看示例:

import { Steps } from 'antd';
import React from 'react';
const { Step } = Steps;
const App = () => (
  <Steps current={1} status="error">
    <Step title="Finished" description="This is a description" />
    <Step title="In Process" description="This is a description" />
    <Step title="Waiting" description="This is a description" />
  </Steps>
);
export default App;

來看效果,這里是第 1 步出現(xiàn) err 了:

咱們也可以給步驟條的每個步驟添加自定義的展示,上代碼:

import { Popover, Steps } from 'antd';
import React from 'react';
const { Step } = Steps;
const customDot = (dot, { status, index }) => (
  <Popover
    content={
      <span>
        step {index} status: {status}
      </span>
    }
  >
    {dot}
  </Popover>
);
const App = () => (
  <Steps current={1} progressDot={customDot}>
    <Step title="Finished" description="You can hover on the dot." />
    <Step title="In Progress" description="You can hover on the dot." />
    <Step title="Waiting" description="You can hover on the dot." />
    <Step title="Waiting" description="You can hover on the dot." />
  </Steps>
);
export default App;

來看效果:

最后來看一個 Steps 中的 Step 可點擊的步驟條,上代碼:

import { Divider, Steps } from 'antd';
import React, { useState } from 'react';
const { Step } = Steps;
const App = () => {
  const [current, setCurrent] = useState(0);
  const onChange = (value) => {
    console.log('onChange:', current);
    setCurrent(value);
  };
  return (
    <>
      <Steps current={current} onChange={onChange}>
        <Step title="Step 1" description="This is a description." />
        <Step title="Step 2" description="This is a description." />
        <Step title="Step 3" description="This is a description." />
      </Steps>
      <Divider />
      <Steps current={current} onChange={onChange} direction="vertical">
        <Step title="Step 1" description="This is a description." />
        <Step title="Step 2" description="This is a description." />
        <Step title="Step 3" description="This is a description." />
      </Steps>
    </>
  );
};
export default App;

從上面的代碼可以看到,當你點擊 change Steps 的時候,會觸發(fā) onChange 回調(diào)函數(shù),咱們這里的 onChange 只做了兩件事情:

(1) 控制臺打印 current,current 大家應(yīng)該熟悉,就是第幾個 Step;

(2) 設(shè)置 setCurrent。這個地方不限于此,盡可以發(fā)揮想象。

來看效果:

好了,以上分享了 Ant Design 組件庫之步驟條。

更多關(guān)于Ant Design 組件庫步驟條的資料請關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

  • React中classnames庫使用示例

    React中classnames庫使用示例

    這篇文章主要為大家介紹了React中classnames庫使用示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2022-10-10
  • React Native之TextInput組件解析示例

    React Native之TextInput組件解析示例

    本篇文章主要介紹了React Native之TextInput組件解析示例,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-08-08
  • react-router中<Link/>的屬性詳解

    react-router中<Link/>的屬性詳解

    這篇文章主要給大家介紹了關(guān)于react-router中<Link/>屬性的相關(guān)資料,文中介紹的非常詳細,對大家具有一定的參考學習價值,需要的朋友們下面來一起看看吧。
    2017-06-06
  • React?組件傳?children?的各種案例方案詳解

    React?組件傳?children?的各種案例方案詳解

    自定義組件的時候往往需要傳?children,由于寫法比較多樣,我就總結(jié)了一下,要自定義的組件其中包含一個?title?和一個?children,本文通過實例代碼給大家介紹的非常詳細,需要的朋友參考下吧
    2023-10-10
  • React中獲取數(shù)據(jù)的3種方法及優(yōu)缺點

    React中獲取數(shù)據(jù)的3種方法及優(yōu)缺點

    這篇文章主要介紹了React中獲取數(shù)據(jù)的3種方法及優(yōu)缺點,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2020-02-02
  • React實現(xiàn)createElement 和 cloneElement的區(qū)別

    React實現(xiàn)createElement 和 cloneElement的區(qū)別

    本文詳細介紹了React中React.createElement和React.cloneElement兩種方法的定義、用法、區(qū)別及適用場景,具有一定的參考價值,感興趣的可以了解一下
    2024-09-09
  • 詳解react關(guān)于事件綁定this的四種方式

    詳解react關(guān)于事件綁定this的四種方式

    這篇文章主要介紹了詳解react關(guān)于事件綁定this的四種方式,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-03-03
  • 詳解React中如何拆分組件

    詳解React中如何拆分組件

    這篇文章主要為大家詳細介紹了React中拆分組件的相關(guān)知識,文中的示例代碼講解詳細,對我們掌握React有一定的幫助,需要的小伙伴可以參考一下
    2023-12-12
  • react同構(gòu)實踐之實現(xiàn)自己的同構(gòu)模板

    react同構(gòu)實踐之實現(xiàn)自己的同構(gòu)模板

    這篇文章主要介紹了react同構(gòu)實踐之實現(xiàn)自己的同構(gòu)模板,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2019-03-03
  • 淺談React的React.FC與React.Component的使用

    淺談React的React.FC與React.Component的使用

    本文主要介紹了React的React.FC與React.Component的使用,文中通過示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2021-09-09

最新評論

乐安县| 五大连池市| 胶南市| 江山市| 甘肃省| 延安市| 文水县| 延安市| 栾川县| 栾川县| 辛集市| 德令哈市| 滁州市| 施秉县| 信丰县| 丰台区| 兴安县| 资中县| 岳普湖县| 疏附县| 南丰县| 英德市| 八宿县| 巴林右旗| 海门市| 房产| 罗田县| 化州市| 甘德县| 曲松县| 鄄城县| 林口县| 阿鲁科尔沁旗| 大荔县| 铜鼓县| 红安县| 高阳县| 兴仁县| 沧州市| 东乌珠穆沁旗| 阿拉善左旗|