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~


目录
相关文章
|
缓存 JavaScript 安全
2022年最新最详细的安装Node.js以及cnpm(详细图解过程、绝对成功)
这篇文章提供了2022年最新最详细的Node.js和cnpm安装教程,包括步骤图解、全局配置路径、cnpm安装命令、nrm的安装与使用,以及如何管理npm源和测试速度。
2022年最新最详细的安装Node.js以及cnpm(详细图解过程、绝对成功)
|
自然语言处理 JavaScript 前端开发
vue2 div滚动条下拉到底部时触发事件(懒加载) 超级简易版本的懒加载
【6月更文挑战第4天】导文 vue2 div滚动条下拉到底部时触发事件(懒加载) 超级简易版本的懒加载 文章重点 内容效果展示: 当div拉到底部的时候: 在这里插入图片描述 编辑器返回: 在这里插入图片描述 代码展示 在Vue 2中,可以通过监听div的scroll事件来判断滚动条是否到达了底部。以下是一个简单的示例:
477 2
|
10月前
|
移动开发 前端开发 JavaScript
React 视频播放器组件:Video Player
本文介绍了如何使用 React 和 HTML5 `&lt;video&gt;` 标签构建自定义视频播放器组件。首先,通过创建基础的 React 项目和 VideoPlayer 组件,实现了基本的播放、暂停功能。接着,探讨了常见问题如视频加载失败、控制条样式不一致、性能优化不足及状态管理混乱,并提供了相应的解决方案。最后,总结了构建高效视频播放器的关键要点,帮助开发者应对实际开发中的挑战。
973 27
|
自然语言处理 前端开发 JavaScript
推荐 10 个前端开发会用到的工具网站
本文介绍了多个前端开发工具,包括 Web Design Museum、Landing Page、Google Fonts、Lorem Ipsum、Animista、Blobmaker、Spline、CodeToGo、UnusedCSS 和 Responsively,帮助开发者提高效率和项目质量。这些工具涵盖了设计、动画、代码片段管理、响应式测试等多个方面。
579 0
推荐 10 个前端开发会用到的工具网站
|
JavaScript 前端开发 搜索推荐
快收藏!超实用标签title属性重写,让同事对你刮目相看
【10月更文挑战第1天】快收藏!超实用标签title属性重写,让同事对你刮目相看
294 10
快收藏!超实用标签title属性重写,让同事对你刮目相看
|
druid Java 数据库
德鲁伊druid数据库明文密码加密
德鲁伊druid数据库明文密码加密
1021 0
德鲁伊druid数据库明文密码加密
|
存储 算法 安全
|
前端开发 JavaScript
掌握 Promise.all:优雅处理多个异步操作
掌握 Promise.all:优雅处理多个异步操作
|
移动开发 前端开发 JavaScript
使用JavaScript实现一个复杂功能:自定义拖拽排序列表
使用JavaScript实现一个复杂功能:自定义拖拽排序列表
|
JavaScript
vue中高精度小数问题(加减乘除方法封装)处理
vue中高精度小数问题(加减乘除方法封装)处理
505 0

热门文章

最新文章