Hue Picker
A React Native colour picker built from plain Views, with a hue strip, a lightness strip for the chosen hue, one-tap swatches and a live preview.
A colour picker built from plain Views, with no gradient or SVG packages. Drag the hue strip, then the lightness strip, which runs dark to light in the hue you chose, or tap a swatch. Hue, saturation and lightness are kept as numbers while you drag and only turned into hex on the way out, so the hex never drifts and the hue survives passing through black or white. Built for React Native and Expo with react-native only; this page previews it in the browser through react-native-web.
Installation
CLI
npx @modus-ui/cli add hue-pickerManual
- Copy the code from the component tab.
- Create a file at
components/ui/hue-picker.tsx. - Paste the code.
It needs no packages beyond react-native, which your Expo or React Native app already has.
Usage
value is expected to echo onChange. If you set it to something else, the picker adopts it.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
value | string | - | The colour as a hex string such as #4f46e5. |
onChange | (hex: string) => void | - | Called with a lowercase #rrggbb string as the colour changes. |
swatches | string[] | eight hues | Colours offered as one-tap swatches. |
showValue | boolean | true | Show the hex text next to the preview. |
colors | Partial<HuePickerColors> | - | Overrides ring and text. |
style | StyleProp<ViewStyle> | - | Style for the container. |
Comments