npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-antd-cssvars

v0.7.3

Published

A minimal cssvars antd module

Downloads

117

Readme

react-antd-cssvars

npm CircleCI

Usage

Provide a way to dynamically change the color of ant design components.

  1. import the less file of this library to replace all ant design colors by the associated the custom property
  2. create a Theme to modify the values with javacript

Note: Support hex8.

Done

  • Alert: add secondary color
  • Autocomplete
  • BackTop
  • Badge
  • Button: add secondary, success, warning type
  • Calendar
  • Card
  • Caroussel
  • Cascader
  • CheckBox
  • Collapse
  • Comment
  • Datepicker
  • Divider
  • Descriptions
  • Dropdown
  • Form
  • Input
  • InputNumber
  • List
  • Mentions
  • Menu
  • Message
  • Notification
  • Modal
  • PageHeader
  • PopConfirm
  • Popover
  • Progress
  • Radio
  • Rate: default color set to primary
  • Result
  • Select
  • Slider
  • Spin
  • Statistic
  • Steps
  • Switch
  • Table
  • Tabs
  • Tag: add primary, secondary and danger color
  • Timeline: add primary, secondary, success and danger color (Item need to import the one from the package)
  • Timepicker
  • Tooltip
  • Transfert
  • Tree
  • TreeSelect

Not Done Yet

  • Skeleton

Demo page

A. Styles

I. Less

@import "~antd/dist/antd.less";
@import "~react-antd-cssvars/dist/style.less";

II. Default list here

You can redifine the default color value


// in your less file
@import "~antd/dist/antd.less";
@import "~react-antd-cssvars/dist/style.less";

@default-antd-primary-color: #fff;
@default-antd-primary-color-hover: #333333;

III. Custom properties list here

@default-debug-background: #333333;
root {
	--debug-background : @default-debug-background;
}
// to use as a variable in your less files
@debug-background: var(--debug-background);

B. Theme See example source

I. Create

// in your typescript file
import { Theme, TThemeColorTypes } from "react-antd-cssvars"

const theme = new Theme<TThemeColorTypes>()

II. Init theme

You can initialize the theme with the first parameter of the contructor.
note: it will trigger the compute function

import { Theme, TThemeColorTypes, TTheme } from "react-antd-cssvars"

const initTheme: TTheme<TThemeColorTypes> = {
	"menu-background": "#000000",
	"submenu-background": "#333333",
	"menu-text-color": "#fff",
}

const theme = new Theme<TThemeColorTypes>(initTheme)

III. Compute color

You can compute color from others color change by using the second parameter.

import { Theme, TThemeColorTypes, TTheme } from "react-antd-cssvars"

const computed = (key: TThemeColorTypes, value: string, luminance: number) => {
	if (key === "primary-color") {
		theme.set("table-head-text-color", value)
		const background = Theme.tint(value, 90)
		theme.set("table-head-background", background)
		theme.set("background-selected", background)
		theme.set("table-head-background-hover", Theme.tint(value, 75))
		theme.set("table-head-background-selected", Theme.tint(value, 15))
		theme.set("table-head-background-selected-hover", value)
		theme.set("box-shadow-color", value, false, 20)
	}
	if (theme.has(`${key}-hover` as TThemeColorTypes)) {
		theme.set(`${key}-hover` as TThemeColorTypes, Theme.tint(value, 17.5), false)
	}
	if (theme.has(`${key}-background` as TThemeColorTypes)) {
		theme.set(`${key}-background` as TThemeColorTypes, Theme.tint(value, 75), false)
	}
	if (key === "menu-background") {
		if (luminance < 0.015) {
			theme.set("submenu-background", Theme.tint(value, 20), false)
		} else {
			theme.set("submenu-background", Theme.shade(value, 20), false)
		}
		if (Theme.isdark(value)) {
			theme.set("menu-text-color", theme.get("text-color-inv"), false, 0.65)
		} else {
			theme.set("menu-text-color", theme.get("text-color"), false, 0.65)
		}
	}
}

const theme = new Theme<TThemeColorTypes>(null, computed)

IV. Customize cssvars

If you want to manage more cssvars. (Do not forget to define and initialize it in your less/css file)

import { Theme, TThemeColorTypes, TTheme, DThemeColorTypes, ThemeColorKeys } from "react-antd-cssvars"
type CustomTThemeColorTypes = TThemeColorTypes | "debug"
const customDThemeColorTypes: CustomTThemeColorTypes[] = [...ThemeColorKeys]
customDThemeColorTypes.push("debug")

// optional if you have define it in your less/css file
const initTheme: TTheme<CustomTThemeColorTypes> = {
	"debug": "#333333",
}

const theme = new Theme<CustomTThemeColorTypes>(initTheme, null, customDThemeColorTypes)

V. Functions See documentation

C. Custom Component

I. Button:

  1. add secondary, success, warning type
  2. add uppercase props

II. Tag:

  1. add primary, secondary and danger color

III. Timeline:

  1. add primary, secondary, success and danger color (Item need to import the one from the package)

IV. ColorPicker:

  • add new component ColorPicker

V. Status:

  • add new component Status Derived from Badge

D. Requirements

  • "@types/react": ">=16.0.0"
  • "antd": "^4.13.0"
  • "react": ">=16.0.0"
  • "react-dom": ">=16.0.0