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:
parent
bc64c160e6
commit
6ede5afd9e
3 changed files with 21 additions and 2 deletions
|
@ -9,6 +9,13 @@ export const parameters = {
|
||||||
description: "Additional Bluelib classNames to be appended to the element's classNames",
|
description: "Additional Bluelib classNames to be appended to the element's classNames",
|
||||||
table: {category: "Global props"}
|
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: {
|
customColor: {
|
||||||
type: "string",
|
type: "string",
|
||||||
control: {type: "color"},
|
control: {type: "color"},
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import * as React from "react"
|
import * as React from "react"
|
||||||
import * as ReactDOM from "react-dom"
|
import * as ReactDOM from "react-dom"
|
||||||
|
import {BuiltinColor} from "../types"
|
||||||
import * as Types from "../types"
|
import * as Types from "../types"
|
||||||
import * as Colors from "../utils/Colors"
|
import * as Colors from "../utils/Colors"
|
||||||
import * as BluelibMapper from "../utils/BluelibMapper"
|
import * as BluelibMapper from "../utils/BluelibMapper"
|
||||||
|
@ -11,18 +12,23 @@ export interface BaseElementProps extends React.HTMLProps<any> {
|
||||||
kind: string,
|
kind: string,
|
||||||
bluelibClassNames?: Types.ClassNames,
|
bluelibClassNames?: Types.ClassNames,
|
||||||
disabled?: boolean,
|
disabled?: boolean,
|
||||||
|
builtinColor?: BuiltinColor,
|
||||||
customColor?: typeof Color,
|
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
|
// Set the Bluelib color
|
||||||
if(customColor) {
|
if(customColor) {
|
||||||
props.style = {...props.style, ...Colors.colorToBluelibStyle("color", customColor)}
|
props.style = {...props.style, ...Colors.colorToBluelibStyle("color", customColor)}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Possibly disable the element
|
// Possibly disable the element
|
||||||
bluelibClassNames = mergeClassNames(bluelibClassNames, disabled ? "status-disabled" : "")
|
bluelibClassNames = mergeClassNames(
|
||||||
|
bluelibClassNames,
|
||||||
|
disabled ? "status-disabled" : "",
|
||||||
|
builtinColor?.length ? `color-${builtinColor}` : ""
|
||||||
|
)
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
props.disabled = disabled
|
props.disabled = disabled
|
||||||
|
|
||||||
|
|
|
@ -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.
|
* - `null` means that the value is in progress of being checked.
|
||||||
*/
|
*/
|
||||||
export type Validity = boolean | null | undefined
|
export type Validity = boolean | null | undefined
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bluelib's builtin colors, as strings.
|
||||||
|
*/
|
||||||
|
export type BuiltinColor = "red" | "orange" | "yellow" | "lime" | "cyan" | "blue" | "magenta" | "gray"
|
||||||
|
|
Loading…
Reference in a new issue