Skip to content

Commit

Permalink
Merge pull request #234 from justdlabs/uprizingFaze/main
Browse files Browse the repository at this point in the history
Update color-swatch, remove type any and add type
  • Loading branch information
irsyadadl authored Oct 24, 2024
2 parents b5a8a3e + 351aa85 commit 2ce4105
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions components/ui/color-swatch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,13 @@ const luminance = (r: number, g: number, b: number): number => {
return a[0] * 0.2126 + a[1] * 0.7152 + a[2] * 0.0722
}

const isBrightColor = (color: any): boolean => {
type HSBColor = {
hue: number
saturation: number
brightness: number
}

const isBrightColor = (color: string | HSBColor): boolean => {
let r, g, b

if (typeof color === "string") {
Expand Down Expand Up @@ -103,7 +109,8 @@ const isBrightColor = (color: any): boolean => {
const defaultColor = parseColor("hsl(216, 98%, 52%)")

const ColorSwatch = ({ className, ...props }: ColorSwatchProps) => {
const needRing = props.color ? isBrightColor(props.color) : false
const color = props.color?.toString() ?? ""
const needRing = color ? isBrightColor(color) : false
return (
<ColorSwatchPrimitive
data-slot="color-swatch"
Expand Down

0 comments on commit 2ce4105

Please sign in to comment.