hxf31891 / react-gradient-color-picker

An easy to use color/gradient picker for React.js
MIT License
126 stars 39 forks source link

Expose `config` object to enable overwriting default colors and other settings #90

Open LinusBF opened 4 months ago

LinusBF commented 4 months ago

This PR allows the user to supply their own config object to override the defaults set it src/constants.ts

Main reason for this is I wanted to set the default gradient that is chosen when the user switch modes.

What has changed is config is now typed to:

export type Config = {
  barSize: number
  crossSize: number
  inputSize: number
  delay: number
  defaultColor: string
  defaultGradient: string
}

and I have put a config object in both the <PickerContext /> as well as the useColorPicker hook as I believe those are the only two places where the user would reasonable input these options. Both of these components fallback to the original options object if none is provided.

Ideally I would like the option to only be set at one place as now you would need to supply the same config object to both the <ColorPicker> component and the useColorPicker hook if you use both 🥴

LinusBF commented 4 months ago

Ok I have tried it locally in my own project using yarn patch and it seems to work like expected :tada: