Skip to content
This repository has been archived by the owner on Jul 15, 2022. It is now read-only.

Commit

Permalink
Merge pull request #3 from arthurdenner/fix/setColor-fn
Browse files Browse the repository at this point in the history
fix: pass current color to setColor when used as a function
  • Loading branch information
junhoyeo authored Jul 11, 2021
2 parents d3af392 + 498819a commit f03ee13
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ color.rgb // { r: 34, g: 114, b: 235 }
color.rgba // { r: 34, g: 114, b: 235, a: 1 }

const [color] = useColor('rgb(34, 114, 235)')
color.string.hex // #2272eb
color.strings.hex // #2272eb

const [color] = useColor('rgba(34, 114, 235, 0.5)')
color.string.hex // #2272eb80
color.strings.hex // #2272eb80
color.rgb // { r: 34, g: 114, b: 235 }
color.rgba // { r: 34, g: 114, b: 235, a: 0.5 }
```
Expand All @@ -45,9 +45,9 @@ color.rgba // { r: 34, g: 114, b: 235, a: 0.5 }
```tsx
const [color] = useColor({ r: 255, g: 255, b: 255 })

color.string.hex // '#ffffff'
color.string.rgb // 'rgb(255, 255, 255)'
color.string.rgba // 'rgb(255, 255, 255, 1)'
color.strings.hex // '#ffffff'
color.strings.rgb // 'rgb(255, 255, 255)'
color.strings.rgba // 'rgb(255, 255, 255, 1)'
```

### Stringify Options
Expand Down
3 changes: 1 addition & 2 deletions src/useColor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ export const useColor = <Str extends string>(
| ((prevColor: RgbaObject) => ColorInput<NewString>),
) => {
if (typeof nextColor === 'function') {
const nextColorInput = nextColor(color.rgba)
setColor(parseColor(nextColorInput))
setColor((currentColor) => parseColor(nextColor(currentColor.rgba)))
return
}
setColor(parseColor(nextColor, config))
Expand Down

0 comments on commit f03ee13

Please sign in to comment.