import React, { memo } from 'react'; import { StyleProp, StyleSheet, View, ViewStyle } from 'react-native'; import { DEFAULT_COLORS } from '../../constants'; import ColorButton from './ColorButton'; export interface ColorPickerProps { /** * Brush color, one from the colors provided */ color: string; /** * Callback when a color is selected * @param newColor - New selected color */ onColorChange: (newColor: string) => void; /** * Color picker colors, specifying the color picker sections each * containing rows of colors. First array defines the sections, second * one defines the rows, and the last one defines the columns. * @default DEFAULT_COLORS */ colors?: string[][][]; /** * Style of the container */ style?: StyleProp; } /** * Color picker component displaying a grid of colors triggering a * callback when a color is selected and being able to select a color */ const ColorPicker: React.FC = ({ color, onColorChange, colors = DEFAULT_COLORS, style, }) => ( {colors.map((section, gKey) => ( {section.map((row, rKey) => ( {row.map((buttonColor, colorKey) => ( ))} ))} ))} ); const styles = StyleSheet.create({ row: { flexDirection: 'row', }, content: { borderRadius: 10, flex: 1, }, container: { borderRadius: 10, left: 0, right: 0, alignItems: 'center', justifyContent: 'center', }, divider: { marginBottom: 3, }, }); export default memo(ColorPicker);