欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

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

引言

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

1 antd 之 Steps API

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

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

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

下面做一些實(shí)踐。

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 默認(rèn)選擇了 1,來看效果:

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

再來看一個 帶圖標(biāo)的步驟條,這里用了 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)的吧:配合按鈕進(jìn)行步進(jìn)或后退,來表示一個流程的處理進(jìn)度,上代碼:

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 屬性來指定當(dāng)前步驟的狀態(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 可點(diǎn)擊的步驟條,上代碼:

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;

從上面的代碼可以看到,當(dāng)你點(diǎn)擊 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父子組件間的傳值的方法

    React父子組件間的傳值的方法

    在單頁面里面,父子組件傳值是比較常見的,這篇文章主要介紹了React父子組件間的傳值的方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-11-11
  • React國際化react-i18next詳解

    React國際化react-i18next詳解

    react-i18next 是基于 i18next 的一款強(qiáng)大的國際化框架,可以用于 react 和 react-native 應(yīng)用,是目前非常主流的國際化解決方案。這篇文章主要介紹了React國際化react-i18next的相關(guān)知識,需要的朋友可以參考下
    2021-10-10
  • 基于React.js實(shí)現(xiàn)簡單的文字跑馬燈效果

    基于React.js實(shí)現(xiàn)簡單的文字跑馬燈效果

    剛好手上有一個要實(shí)現(xiàn)文字跑馬燈的react項(xiàng)目,然后ant-design上面沒有這個組件,于是只能自己手?jǐn)]一個,文中的實(shí)現(xiàn)方法講解詳細(xì),希望對大家有所幫助
    2023-01-01
  • React Native 中添加自定義字體的方法

    React Native 中添加自定義字體的方法

    這篇文章主要介紹了如何在 React Native 中添加自定義字體,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2022-08-08
  • react16.8.0以上MobX在hook中的使用方法詳解

    react16.8.0以上MobX在hook中的使用方法詳解

    這篇文章主要為大家介紹了react16.8.0以上MobX在hook中的使用方法詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-07-07
  • React組件間通信的三種方法(簡單易用)

    React組件間通信的三種方法(簡單易用)

    React知識中一個主要內(nèi)容便是組件之間的通信,以下列舉幾種常用的組件通信方式,本文就詳細(xì)的介紹一下,感興趣的可以了解一下
    2021-10-10
  • 淺析React 對state的理解

    淺析React 對state的理解

    state狀態(tài)是組件實(shí)例對象身上的狀態(tài),不是組件類本身身上的,是由這個類締造的實(shí)例身上的。這篇文章主要介紹了React 對state的理解,需要的朋友可以參考下
    2021-09-09
  • 減少react組件不必要的重新渲染實(shí)現(xiàn)方法

    減少react組件不必要的重新渲染實(shí)現(xiàn)方法

    這篇文章主要為大家介紹了減少react組件不必要的重新渲染實(shí)現(xiàn)方法詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-01-01
  • react項(xiàng)目中@路徑簡單配置指南

    react項(xiàng)目中@路徑簡單配置指南

    這篇文章主要給大家介紹了關(guān)于react項(xiàng)目中@路徑簡單配置的相關(guān)資料,文中還介紹了React配置@路徑別名的方法,文中通過實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2022-09-09
  • React 服務(wù)器組件的使用方法詳解

    React 服務(wù)器組件的使用方法詳解

    最近,React 服務(wù)器組件受到了廣泛的關(guān)注和熱捧,這是因?yàn)?nbsp;React 服務(wù)器組件允許開發(fā)人員將與組件相關(guān)的任務(wù)外包給服務(wù)器,在本文中,我們將討論什么是 React 服務(wù)器組件,以及如何將它們集成到構(gòu)建應(yīng)用程序中,需要的朋友可以參考下
    2023-10-10

最新評論