react-best-gradient-color-picker
Version:
An easy to use color/gradient picker for React.js
35 lines (29 loc) • 1.01 kB
text/typescript
import { ColorsProps } from '../shared/types.js'
import { gradientParser } from './gradientParser.js'
export const low = (color: ColorsProps) => {
return color.value.toLowerCase()
}
export const high = (color: ColorsProps) => {
return color.value.toUpperCase()
}
export const getColors = (value: string, defaultColor: string, defaultGradient: string) => {
const isGradient = value?.includes('gradient')
if (isGradient) {
const isConic = value?.includes('conic')
const safeValue = !isConic ? value : defaultGradient
if (isConic) {
console.log('Sorry we cant handle conic gradients yet')
}
const obj = gradientParser(safeValue)
return obj?.colorStops
} else {
const safeValue = value || defaultColor
return [{ value: safeValue }]
}
}
export const formatInputValues = (value: number, min: number, max: number) => {
return isNaN(value) ? min : value < min ? min : value > max ? max : value
}
export const round = (val: number) => {
return Math.round(val)
}