From f8a4fb1b0e578a9147805632e8bc3adc5bda0cb6 Mon Sep 17 00:00:00 2001 From: BafS Date: Mon, 17 Jan 2022 23:49:09 +0100 Subject: [PATCH] Add color formaters --- src/ColorsPanel.js | 9 +++++---- src/Settings.js | 18 ++++++++++++++++++ src/atoms.js | 1 + src/utils.js | 29 +++++++++++++++++++++++++++++ 4 files changed, 53 insertions(+), 4 deletions(-) create mode 100644 src/utils.js diff --git a/src/ColorsPanel.js b/src/ColorsPanel.js index 88670ad..a04ad15 100644 --- a/src/ColorsPanel.js +++ b/src/ColorsPanel.js @@ -7,9 +7,7 @@ import { TouchableOpacity, ScrollView, } from 'react-native'; - -const luminosity = hexStr => - parseInt(hexStr[0], 16) + parseInt(hexStr[2], 16) + parseInt(hexStr[4], 16); +import {getFormater, luminosity} from './utils'; /** * @param {{name: string, color: string, formatter: (color: string) => string}} param0 @@ -55,6 +53,9 @@ const ColorBox = ({name, color, formatter}) => { ); }; +/** + * @param {{style: any, palette: {[name: string]: {hex: string}}, name: string, colorFormat: string}} param0 + */ export default ({style, palette, name, colorFormat}) => { const [isScroll, setIsScroll] = useState(false); const springAnim = useRef(new Animated.Value(0)).current; @@ -79,7 +80,7 @@ export default ({style, palette, name, colorFormat}) => { const getColorItemSize = e => e.nativeEvent.layout.height / paletteKeys.length; - const formatter = hex => `#${hex}`; + const formatter = getFormater(colorFormat); const inner = ( { ))} + + Color format + + setSettings({...settings, colorFormat})}> + + + + + +