GithubHelp home page GithubHelp logo

songjuxin / antd-theme-generator Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mzohaibqc/antd-theme-generator

0.0 1.0 0.0 5.05 MB

This script is to generate color.less file to update color related css in browser.

Home Page: https://mzohaibqc.github.io/antd-theme-generator/

JavaScript 100.00%

antd-theme-generator's Introduction

antd-theme-generator

This script generates color specific styles/less file which you can use to change theme dynamically in browser

Example:

const { generateTheme } = require('antd-theme-generator');

const options = {
  antDir: path.join(__dirname, './node_modules/antd'),
  stylesDir: path.join(__dirname, './src'), // all files with .less extension will be processed
  varFile: path.join(__dirname, './src/styles/variables.less'), // default path is Ant Design default.less file
  themeVariables: ['@primary-color'],
  outputFilePath: path.join(__dirname, './public/color.less') // if provided, file will be created with generated less/styles
  customColorRegexArray: [/^fade\(.*\)$/], // An array of regex codes to match your custom color variable values so that code can identify that it's a valid color. Make sure your regex does not adds false positives.
}

generateTheme(options).then(less => {
  console.log('Theme generated successfully');
})
.catch(error => {
  console.log('Error', error);
})
Property Type Default Descript
antdDir string - This is path to antd directory in your node_modules
stylesDir string, [string] - Path/Paths to your custom styles directory containing .less files
stylesPath string, [string] - The path to the custom style directory of the "less" file.stylesPath will overwrite stylesDir.
varFile string - Path to your theme related variables file
themeVariables array ['@primary-color'] List of variables that you want to dynamically change
outputFilePath string - Generated less content will be written to file path specified otherwise it will not be written. However, you can use returned output and write in any file as you want
customColorRegexArray array ['color', 'lighten', 'darken', 'saturate', 'desaturate', 'fadein', 'fadeout', 'fade', 'spin', 'mix', 'hsv', 'tint', 'shade', 'greyscale', 'multiply', 'contrast', 'screen', 'overlay'].map(name => new RegExp(${name}\(.*\)))] This array is to provide regex which will match your color value, most of the time you don't need this

Add following lines in your main html file

<link rel="stylesheet/less" type="text/css" href="/color.less" />
<script>
  window.less = {
    async: true,
    env: 'production'
  };
</script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/less.js/2.7.2/less.min.js"></script>

Now you can update colors by updating less variables like this

window.less.modifyVars({
  '@primary-color': '#0035ff'
})

antd-theme-generator's People

Contributors

405go avatar afc163 avatar brsjsk avatar chenshuai2144 avatar dependabot[bot] avatar freemenl avatar gordanat96 avatar landerson352 avatar mzohaibqc avatar zohaibijaznbs avatar zombiej avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.