1
Fork 0
mirror of https://github.com/Steffo99/bluelib.git synced 2024-12-22 11:34:21 +00:00

Add builtinColor prop, allowing to choose a builtin color without using bluelibClassNames

`customColor` has priority over it
This commit is contained in:
Steffo 2021-10-10 18:23:16 +02:00
parent bc64c160e6
commit 6ede5afd9e
Signed by: steffo
GPG key ID: 6965406171929D01
3 changed files with 21 additions and 2 deletions

View file

@ -9,6 +9,13 @@ export const parameters = {
description: "Additional Bluelib classNames to be appended to the element's classNames",
table: {category: "Global props"}
},
builtinColor: {
type: "string",
options: ["", "red", "orange", "yellow", "lime", "cyan", "blue", "magenta", "gray"],
control: {type: "select"},
description: "Apply a Bluelib builtin color to the element",
table: {category: "Global props"}
},
customColor: {
type: "string",
control: {type: "color"},

View file

@ -1,5 +1,6 @@
import * as React from "react"
import * as ReactDOM from "react-dom"
import {BuiltinColor} from "../types"
import * as Types from "../types"
import * as Colors from "../utils/Colors"
import * as BluelibMapper from "../utils/BluelibMapper"
@ -11,18 +12,23 @@ export interface BaseElementProps extends React.HTMLProps<any> {
kind: string,
bluelibClassNames?: Types.ClassNames,
disabled?: boolean,
builtinColor?: BuiltinColor,
customColor?: typeof Color,
}
export function BaseElement({kind = "div", bluelibClassNames, disabled = false, customColor, ...props}: BaseElementProps): JSX.Element {
export function BaseElement({kind = "div", bluelibClassNames, disabled = false, builtinColor, customColor, ...props}: BaseElementProps): JSX.Element {
// Set the Bluelib color
if(customColor) {
props.style = {...props.style, ...Colors.colorToBluelibStyle("color", customColor)}
}
// Possibly disable the element
bluelibClassNames = mergeClassNames(bluelibClassNames, disabled ? "status-disabled" : "")
bluelibClassNames = mergeClassNames(
bluelibClassNames,
disabled ? "status-disabled" : "",
builtinColor?.length ? `color-${builtinColor}` : ""
)
// @ts-ignore
props.disabled = disabled

View file

@ -37,3 +37,9 @@ export type Validator<T> = (value: T, abort: AbortSignal) => Promise<Validity> |
* - `null` means that the value is in progress of being checked.
*/
export type Validity = boolean | null | undefined
/**
* Bluelib's builtin colors, as strings.
*/
export type BuiltinColor = "red" | "orange" | "yellow" | "lime" | "cyan" | "blue" | "magenta" | "gray"