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

Ant?Design?組件庫按鈕實現(xiàn)示例詳解

 更新時間:2022年08月19日 15:21:23   作者:極智視界  
這篇文章主要介紹了Ant?Design?組件庫按鈕實現(xiàn)示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪</P><P><BR>

1 antd 之 Button API

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

按鈕 Button 是一個比較基礎(chǔ)的 UI 組件,一般在有交互的應(yīng)用中都會用到。

其 DOM 節(jié)點為 <Button>...</Button>,antd 中的按鈕樣式豐富,可以通過設(shè)置 Button 的屬性來產(chǎn)生不同的 按鈕樣式。

這些可配置的屬性主要包括:type、shape、size、loading 等,詳細的這里我進行一個整理:

下面做一些實踐。

2 antd 之 Button 示例

先來看 type 屬性的六個簡單的按鈕,上代碼 (JavaScript的):

import { Button } from 'antd';
import React from 'react';
const App = () => (
  <>
    <Button type="primary">Primary Button</Button>
    <Button>Default Button</Button>
    <Button type="dashed">Dashed Button</Button>
    <br />
    <Button type="text">Text Button</Button>
    <Button type="link">Link Button</Button>
  	<Button type="ghost">Ghost Button</Button>
  </>
);
export default App;

來看效果:

接下來看一波帶 icon 圖標(biāo)的按鈕,上代碼:

import { SearchOutlined, PlayCircleOutlined,
  ZoomInOutlined, RedoOutlined, AndroidOutlined,
  AppleOutlined, WechatOutlined, EyeOutlined, 
  ShareAltOutlined, MessageOutlined} from '@ant-design/icons';
import { Button, Tooltip } from 'antd';
import React from 'react';
const App = () => (
  <>
    <Tooltip title="search">
      <Button type="primary" shape="circle" icon={<PlayCircleOutlined />} />
    </Tooltip>
    <Button type="primary" shape="circle">
      A
    </Button>
    <Button type="primary" icon={<ZoomInOutlined />}>
      Search
    </Button>
    <Tooltip title="search">
      <Button shape="circle" icon={<RedoOutlined />} />
    </Tooltip>
    <Button icon={<AndroidOutlined />}>Search</Button>
    <br />
    <Tooltip title="search">
      <Button shape="circle" icon={<SearchOutlined />} />
    </Tooltip>
    <Button icon={<SearchOutlined />}>Search</Button>
    <Tooltip title="search">
      <Button type="dashed" shape="circle" icon={<SearchOutlined />} />
    </Tooltip>
    <Button type="dashed" icon={<SearchOutlined />}>
      Search
    </Button>
    <Button icon={<SearchOutlined />}  rel="external nofollow"  rel="external nofollow"  />
    <br />
    <br />
    <Tooltip title="search">
      <Button type="primary" shape="circle" icon={<AppleOutlined />} size="large" />
    </Tooltip>
    <Button type="primary" shape="circle" size="large">
      A
    </Button>
    <Button type="primary" icon={<WechatOutlined />} size="large">
      Search
    </Button>
    <Tooltip title="search">
      <Button shape="circle" icon={<SearchOutlined />} size="large" />
    </Tooltip>
    <Button icon={<EyeOutlined />} size="large">
      Search
    </Button>
    <br />
    <Tooltip title="search">
      <Button shape="circle" icon={<SearchOutlined />} size="large" />
    </Tooltip>
    <Button icon={<ShareAltOutlined />} size="large">
      Search
    </Button>
    <Tooltip title="search">
      <Button type="dashed" shape="circle" icon={<SearchOutlined />} size="large" />
    </Tooltip>
    <Button type="dashed" icon={<SearchOutlined />} size="large">
      Search
    </Button>
    <Button icon={<MessageOutlined />} size="large"  rel="external nofollow"  rel="external nofollow"  />
  </>
);
export default App;

來看效果:

你應(yīng)該可以發(fā)現(xiàn),我這里用了很多不同的 icon 圖標(biāo),可以這么說:用 antd 的 Button 搭配 antd 的 Icon 圖標(biāo),幾乎能實現(xiàn)你想要的所有按鈕樣式。除了按鈕的圖標(biāo),上面的示例也演示了 按鈕 Size 的調(diào)整,通過 size 可以配置 largesmall, 分別對應(yīng)將按鈕設(shè)置為 大尺寸和 小尺寸,若不設(shè)置 size, 則默認為中尺寸。

接著,我們來看按鈕的 disabled 屬性,意思即為按鈕處于不可用的狀態(tài),上代碼:

import { Button } from 'antd';
import React from 'react';
const App = () => (
  <>
    <Button type="primary">Primary</Button>
    <Button type="primary" disabled>
      Primary(disabled)
    </Button>
    <br />
    <Button>Default</Button>
    <Button disabled>Default(disabled)</Button>
    <br />
    <Button type="dashed">Dashed</Button>
    <Button type="dashed" disabled>
      Dashed(disabled)
    </Button>
    <br />
    <Button type="text">Text</Button>
    <Button type="text" disabled>
      Text(disabled)
    </Button>
    <br />
    <Button type="link">Link</Button>
    <Button type="link" disabled>
      Link(disabled)
    </Button>
    <br />
    <Button danger>Danger Default</Button>
    <Button danger disabled>
      Danger Default(disabled)
    </Button>
    <br />
    <Button danger type="text">
      Danger Text
    </Button>
    <Button danger type="text" disabled>
      Danger Text(disabled)
    </Button>
    <br />
    <Button type="link" danger>
      Danger Link
    </Button>
    <Button type="link" danger disabled>
      Danger Link(disabled)
    </Button>
    <div className="site-button-ghost-wrapper">
      <Button ghost>Ghost</Button>
      <Button ghost disabled>
        Ghost(disabled)
      </Button>
    </div>
  </>
);
export default App;

來看效果:

還有一種按鈕是,點擊后服務(wù)器需要響應(yīng)一會兒,即加載狀態(tài),這個 Loding... 的狀態(tài)用 antd 的按鈕也可以展現(xiàn),上代碼:

import { PoweroffOutlined } from '@ant-design/icons';
import { Button, Space } from 'antd';
import React, { useState } from 'react';
const App = () => {
  const [loadings, setLoadings] = useState([]);
  const enterLoading = (index) => {
    setLoadings((prevLoadings) => {
      const newLoadings = [...prevLoadings];
      newLoadings[index] = true;
      return newLoadings;
    });
    setTimeout(() => {
      setLoadings((prevLoadings) => {
        const newLoadings = [...prevLoadings];
        newLoadings[index] = false;
        return newLoadings;
      });
    }, 6000);
  };
  return (
    <>
      <Space
        style={{
          width: '100%',
        }}
      >
        <Button type="primary" loading>
          Loading
        </Button>
        <Button type="primary" size="small" loading>
          Loading
        </Button>
        <Button type="primary" icon={<PoweroffOutlined />} loading />
      </Space>
      <Space
        style={{
          width: '100%',
        }}
      >
        <Button type="primary" loading={loadings[0]} onClick={() => enterLoading(0)}>
          Click me!
        </Button>
        <Button
          type="primary"
          icon={<PoweroffOutlined />}
          loading={loadings[1]}
          onClick={() => enterLoading(1)}
        >
          Click me!
        </Button>
        <Button
          type="primary"
          icon={<PoweroffOutlined />}
          loading={loadings[2]}
          onClick={() => enterLoading(2)}
        />
      </Space>
    </>
  );
};
export default App;

來看效果:

好了,以上分享了 Ant Design 組件庫之按鈕。希望我的分享能對你的學(xué)習(xí)有一點幫助。

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

相關(guān)文章

  • React實現(xiàn)表格選取

    React實現(xiàn)表格選取

    這篇文章主要為大家詳細介紹了React實現(xiàn)表格選取,類似于Excel選中一片區(qū)域并獲得選中區(qū)域的所有數(shù)據(jù),文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-08-08
  • 詳解React之key的使用和實踐

    詳解React之key的使用和實踐

    這篇文章主要介紹了詳解React之key的使用和實踐,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-09-09
  • React合成事件原理解析

    React合成事件原理解析

    事件是在編程時系統(tǒng)內(nèi)發(fā)生的動作或者發(fā)生的事情,而開發(fā)者可以某種方式對事件做出回應(yīng),而這里有幾個先決條件,這篇文章主要介紹了React合成事件原理解析,需要的朋友可以參考下
    2022-07-07
  • ReactJS?應(yīng)用兼容ios9對標(biāo)ie11解決方案

    ReactJS?應(yīng)用兼容ios9對標(biāo)ie11解決方案

    這篇文章主要為大家介紹了ReactJS?應(yīng)用兼容ios9對標(biāo)ie11解決方案詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2023-01-01
  • react hooks實現(xiàn)原理解析

    react hooks實現(xiàn)原理解析

    這篇文章主要介紹了react hooks實現(xiàn)原理,文中給大家介紹了useState dispatch 函數(shù)如何與其使用的 Function Component 進行綁定,節(jié)后實例代碼給大家介紹的非常詳細,需要的朋友可以參考下
    2022-10-10
  • React函數(shù)組件hook原理及構(gòu)建hook鏈表算法詳情

    React函數(shù)組件hook原理及構(gòu)建hook鏈表算法詳情

    這篇文章主要介紹了React函數(shù)組件hook原理及構(gòu)建hook鏈表算法詳情,每一個?hook?函數(shù)都有對應(yīng)的?hook?對象保存狀態(tài)信息,更多詳細分析,需要的朋友可以參考一下
    2022-07-07
  • React優(yōu)化子組件render的使用

    React優(yōu)化子組件render的使用

    這篇文章主要介紹了React優(yōu)化子組件render的使用,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2019-05-05
  • ahooks解決React閉包問題方法示例

    ahooks解決React閉包問題方法示例

    這篇文章主要為大家介紹了ahooks解決React閉包問題方法示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2022-07-07
  • react中涉及的增加,刪除list方式

    react中涉及的增加,刪除list方式

    這篇文章主要介紹了react中涉及的增加,刪除list方式,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2024-01-01
  • React星星評分組件的實現(xiàn)

    React星星評分組件的實現(xiàn)

    評分插件在購物的應(yīng)用中經(jīng)??梢钥吹玫剑怯弥鴦e人的總是沒有自己寫的順手,本文就使用React實現(xiàn)星星評分組件,感興趣的可以了解一下
    2021-06-06

最新評論