0.8.7 • Published 2 years ago

dynamic-antd-theme v0.8.7

Weekly downloads
185
License
MIT
Repository
github
Last release
2 years ago

npm.io

build-passing release

A simple plugin to dynamic change ant-design theme whether less or css.

English | 简体中文

After gzip: 42.7kB

This project was initially targeted at 'ant-design', that means it's used in the React project. However, the core style was also applicable to 'ant-design-vue' || 'ant-design-angular'. In addition, for the convenience of one-key and auto use, the color-picker was also packaged into the project, resulting in too large a volume of the project. Aiming at this problem, I develope a new minor version —— mini-dynamic-antd-theme.

🏠 HomePage

Dynamic-Antd-Theme-Demo

🌍 Browser Support

ChromeEdgeFirefoxIESafari
Chrome 39.0+ ✔Edge 12.0+ ✔Firefox 30.0+ ✔IE 11+ ✔Safari 9.1+ ✔

📦 Install

npm install dynamic-antd-theme or yarn add dynamic-antd-theme

🔨 Usage

The best usage of the dynamic-antd-theme is in the common compnent (Layout/Header etc...) of your application.

// Layout.js
...
import DynamicAntdTheme from 'dynamic-antd-theme';
...

<div className='theme-container'>
  <span>Change antd theme: </span>
  <DynamicAntdTheme />
</div>

✨ Props

PropsTypeDefaultDescription
primaryColorString#1890d5your antd initial @primary-color
storageNameStringcustom-antd-primary-colorthe name that is saved in the localStorage
styleObjectnullyou can custom the component style simply
placementStringbottomRightchange the color-picker position, bottom, bottomRight, right, topRight, top, topLeft, left, bottomLeft
themeChangeCallbackFuncnullyou can do something use themeColor when themeColor changed.
customCssString''you can define custom css effect any element.

How to use the primaryColors in customCss?

You can do this using the following four variables(just like scss):

  • $primary-color
  • $primary-hover-color
  • $primary-active-color
  • $primary-shadow-color
const customCss = `
  .ant-btn {
    font-family: fantasy;
  }
  .custom-title {
    color: $primary-color;
  }
  .custom-title:hover {
    color: $primary-hover-color;
    cursor: pointer;
  }
  #custom-id {
    color: $primary-shadow-color;
  }
`;

🌞 Export

exportDescription
defaultThe component
changeAntdThemeparam: (color, options), change the antd theme. The options specific attributes are as follows: - storageName: This can be configured to set storageName when not using picker . - customCss: custom Css

🌰 More Example

Basic Use

<DynamicAntdTheme primaryColor='#77dd66' />

<DynamicAntdTheme storageName='my-custom-define-color' />

<DynamicAntdTheme style={{ display: 'margin: 10px' }} />

function themeChangeCallback (color) {
  document.getElementById('my-header-bar').style.backgroundColor = color;
}

<DynamicAntdTheme themeChangeCallback={this.themeChangeCallback} />

Define Custom CSS

// define custom css
const customCss = `
  .ant-btn {
    font-family: fantasy;
  }
  .custom-title {
    color: $primary-color;
  }
  .custom-title:hover {
    color: $primary-hover-color;
    cursor: pointer;
  }
  #custom-id {
    color: $primary-shadow-color;
  }
`;

<DynamicAntdTheme
  customCss={customCss}
/>

The effects as flow:

npm.io

No Color-Picker

If u don't need the color-pickermini-dynamic-antd-theme is more suitable for you.

import { generateThemeColor, changeAntdTheme } from 'dynamic-antd-theme';
...

<Button
  onClick={
    () => {
      const color = 'blue';
      changeAntdTheme(color);
    }
  }
>Change Theme</Button>

⚠️ Attention

This solution is easy to use, so it is prone to problems. We hope you can give us timely feedback. For example, if there is a problem with any component, we will fix the updated version as soon as possible.

  • The current version requires your antd version to be lower than v3.19.0

The antd version is higher than v3.19.0 you can also use it, if have some problems remember give me an issue.

  • ...Plugin versions are updated from time to time based on antd (new antd components are updated)

🔗 Changelogs

CHANGELOG

🍎 Follow-Up Plan

  • More custom type: border-color, border-radius, etc.

If you're interested in this repository, Fork/PR/Issue all are welcome.

0.8.7

2 years ago

0.8.6

2 years ago

0.8.5

3 years ago

0.8.4

3 years ago

0.8.3

3 years ago

0.8.2

3 years ago

0.8.1

3 years ago

0.8.0

3 years ago

0.7.1

3 years ago

0.7.0

3 years ago

0.6.7

3 years ago

0.6.6

3 years ago

0.6.5

3 years ago

0.6.3

3 years ago

0.6.4

3 years ago

0.6.2

4 years ago

0.6.1

4 years ago

0.6.0

4 years ago

0.5.3

4 years ago

0.5.2

4 years ago

0.5.1

4 years ago

0.4.1

4 years ago

0.4.0

4 years ago

0.3.9

4 years ago

0.3.8

4 years ago

0.3.7

4 years ago

0.3.6

5 years ago

0.3.5

5 years ago

0.3.4

5 years ago

0.3.3

5 years ago

0.3.2

5 years ago

0.3.1

5 years ago

0.3.0

5 years ago

0.2.7

5 years ago

0.2.6

5 years ago

0.2.5

5 years ago

0.2.4

5 years ago

0.2.3

5 years ago

0.2.2

5 years ago

0.2.1

5 years ago

0.2.0

5 years ago

0.1.7

5 years ago

0.1.6

5 years ago

0.1.5

5 years ago

0.1.4

5 years ago

0.1.3

5 years ago

0.1.2

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago