Ant-Design自定义样式

简介: Ant-Design自定义样式
(一) 使用Ant-design
1.什么是Ant Design?

antd 是蚂蚁金服开源的 React UI 组件库,主要用于研发企业级中后台产品,相当于Vue 版本的 Element UI

2.Ant Design特点

🌈 提炼自企业级中后台产品的交互语言和视觉风格。

📦 开箱即用的高质量 React 组件。

🛡 使用 TypeScript 开发,提供完整的类型定义文件。

⚙ 全链路开发和设计工具体系(业务战略-用户场景-设计目标-交互体验-用户流程-预期效率等全方面考虑和分析)。

🌍 数十个国际化语言支持。

🎨 深入每个细节的主题定制能力。

3.Ant Design兼容性

antd@2.0 之后不再支持 IE8。

antd@4.0 之后不再支持 React 15 和 IE9/10。

4.Ant Design使用

npm install antd --save

然后打开官方文档抄

官方文档地址: Ant-Design

import React from 'react';
import { DownloadOutlined } from '@ant-design/icons';
import { Button, Radio, Space, Divider } from 'antd';
function App() {
  return (
    <>
      <Radio.Group value="large">
        <Radio.Button value="large">Large</Radio.Button>
        <Radio.Button value="default">Default</Radio.Button>
        <Radio.Button value="small">Small</Radio.Button>
      </Radio.Group>
      <Divider orientation="left" plain>
        Preview
      </Divider>
      <Space direction="vertical">
        <Space wrap>
          <Button type="primary">
            Primary
          </Button>
          <Button>Default</Button>
          <Button type="dashed">
            Dashed
          </Button>
        </Space>
        <Button type="link">
          Link
        </Button>
        <Space wrap>
          <Button type="primary" icon={<DownloadOutlined />}/>
          <Button type="primary" shape="circle" icon={<DownloadOutlined />} />
          <Button type="primary" shape="round" icon={<DownloadOutlined />}/>
          <Button type="primary" shape="round" icon={<DownloadOutlined />}>
            Download
          </Button>
          <Button type="primary" icon={<DownloadOutlined />}>
            Download
          </Button>
        </Space>
      </Space>
    </>
  );
};
export default App;

70.png

根据官网抄的.png

如何使用定制的主题呢

https://ant.design/docs/react/customize-theme-cn

import React from 'react';
import { DownloadOutlined } from '@ant-design/icons';
import { Button, Radio, Space, Divider, ConfigProvider } from 'antd';
function App() {
  return (
    <>
    <ConfigProvider
    theme={{
      token: {
        colorPrimary: '#00b96b',
      },
    }}
  >
      <Radio.Group value="large">
        <Radio.Button value="large">Large</Radio.Button>
        <Radio.Button value="default">Default</Radio.Button>
        <Radio.Button value="small">Small</Radio.Button>
      </Radio.Group>
      <Divider orientation="left" plain>
        Preview
      </Divider>
      <Space direction="vertical">
        <Space wrap>
          <Button type="primary">
            Primary
          </Button>
          <Button>Default</Button>
          <Button type="dashed">
            Dashed
          </Button>
        </Space>
        <Button type="link">
          Link
        </Button>
        <Space wrap>
          <Button type="primary" icon={<DownloadOutlined />}/>
          <Button type="primary" shape="circle" icon={<DownloadOutlined />} />
          <Button type="primary" shape="round" icon={<DownloadOutlined />}/>
          <Button type="primary" shape="round" icon={<DownloadOutlined />}>
            Download
          </Button>
          <Button type="primary" icon={<DownloadOutlined />}>
            Download
          </Button>
        </Space>
      </Space>
      </ConfigProvider>
    </>
  );
};
export default App;

69.png

将primary的样色修改为绿色.png

修改组件变量 (Component Token)不影响其他组件的primary的颜色为官方给的颜色

import React from 'react';
import { Button, Radio, Space, ConfigProvider } from 'antd';
function App() {
  return (
    <>
     <ConfigProvider
    theme={{
      components: {
        Radio: {
          colorPrimary: '#00b96b',
        },
      },
    }}
  >
      <Radio.Group value="large">
        <Radio.Button value="large">Large</Radio.Button>
        <Radio.Button value="default">Default</Radio.Button>
        <Radio.Button value="small">Small</Radio.Button>
      </Radio.Group>
      <Space direction="vertical">
        <Space wrap>
          <Button type="primary">
            Primary
          </Button>
          <Button>Default</Button>
          <Button type="dashed">
            Dashed
          </Button>
        </Space>
        <Button type="link">
          Link
        </Button>
      </Space>
      </ConfigProvider>
    </>
  );
};
export default App;

68.png


image.png


其实还可以通过webpack修改,但是我是一个webpack深度恐惧者,从来没有配置成功过,哈哈,我只知道通过npx create的react-app默认是不显示webpack配置的,可以通过npm run eject可以将webpack配置显示

//终端运行命令
npm run eject

bye~


目录
相关文章
|
8月前
|
人工智能 数据可视化 搜索推荐
什么是低代码开发?3步让你看懂“低代码开发”与“传统开发”的区别
低代码开发自2014年由Forrester提出后逐渐升温,尤其近两年因高效、易用等特点成为热门领域。本文解析低代码与传统开发的区别,前者通过可视化界面和拖放组件简化开发流程,适用于业务管理层应用;后者以手写代码为主,灵活性高但成本大。低代码的核心价值包括自动数据收集、规范业务流程、促进数据共享、减少开发人员需求、个性化搭建、降低成本及提升市场响应速度等,助力企业数字化转型。未来,结合AI技术的低代码将成企业转型的重要基础设施。
|
JavaScript 前端开发 搜索推荐
快收藏!超实用标签title属性重写,让同事对你刮目相看
【10月更文挑战第1天】快收藏!超实用标签title属性重写,让同事对你刮目相看
358 10
快收藏!超实用标签title属性重写,让同事对你刮目相看
|
druid Java 数据库
德鲁伊druid数据库明文密码加密
德鲁伊druid数据库明文密码加密
1152 0
德鲁伊druid数据库明文密码加密
|
前端开发 JavaScript
掌握 Promise.all:优雅处理多个异步操作
掌握 Promise.all:优雅处理多个异步操作
|
存储 算法 安全
|
人工智能 安全 数据可视化
2024黑帽大会最热门的九大AI网络安全工具
在2024年的黑帽大会(Black Hat 2024)上,AI驱动的网络安全工具和技术成为焦点,引领了网络安全行业新趋势。众多安全厂商和初创公司展示了他们的最新成果,利用生成式AI来管理风险、检测并对抗网络犯罪,保障企业安全。以下是大会上一些备受瞩目的AI驱动网络安全产品和服务:
|
JavaScript 容器
技术经验解读:【详解】提示框(tooltip)的使用
技术经验解读:【详解】提示框(tooltip)的使用
|
移动开发 前端开发 JavaScript
使用JavaScript实现一个复杂功能:自定义拖拽排序列表
使用JavaScript实现一个复杂功能:自定义拖拽排序列表
|
前端开发 JavaScript API
深入探讨 React 中 useDispatch 和 useSelector 的使用
深入探讨 React 中 useDispatch 和 useSelector 的使用
769 0