From 5ce0782e9eb963ee10ce5c9f91bd44091a2cb231 Mon Sep 17 00:00:00 2001 From: Julie Wongbandue Date: Wed, 19 Oct 2022 16:01:28 -0400 Subject: [PATCH] Remove HSL input, add option to hide slider, update rgb input (#189) --- .../inputs/ColorSelect/ColorSelect.tsx | 22 +++++---- .../inputs/ColorSelect/ColorSelect.types.ts | 4 ++ src/components/inputs/ColorSelect/Inputs.tsx | 48 +++---------------- 3 files changed, 22 insertions(+), 52 deletions(-) diff --git a/src/components/inputs/ColorSelect/ColorSelect.tsx b/src/components/inputs/ColorSelect/ColorSelect.tsx index 14780c4b0..b4385e16f 100755 --- a/src/components/inputs/ColorSelect/ColorSelect.tsx +++ b/src/components/inputs/ColorSelect/ColorSelect.tsx @@ -53,6 +53,7 @@ function ColorSelectComponent({ value, width = 360, attach = 'bottom', + showHueSlider = true, ...props }: Props) { const childrenRef = useRef(); @@ -128,16 +129,17 @@ function ColorSelectComponent({ {...state} {...props} /> - - + {showHueSlider && ( + + )} ; diff --git a/src/components/inputs/ColorSelect/Inputs.tsx b/src/components/inputs/ColorSelect/Inputs.tsx index 4e7444343..0279db924 100755 --- a/src/components/inputs/ColorSelect/Inputs.tsx +++ b/src/components/inputs/ColorSelect/Inputs.tsx @@ -1,6 +1,6 @@ import React, { useEffect, useRef } from 'react'; import styled from 'styled-components'; -import { grayscale, parseToHsl, parseToRgb } from 'polished'; +import { grayscale, parseToRgb } from 'polished'; import { Input } from '../Input/Input'; import { Button } from '../../Button/Button'; @@ -17,7 +17,7 @@ export function ColorInputs({ ...props }) { const ref = useRef(); - const { HEX, HSL, RGB } = colorMeta; + const { HEX, RGB } = colorMeta; useEffect(() => { if (editing) ref?.current?.focus(); @@ -28,14 +28,12 @@ export function ColorInputs({ function cycle() { const type = 'SET_COLORSPACE'; if (colorSpace === 'HEX') dispatch({ type, payload: 'RGB' }); - if (colorSpace === 'RGB') dispatch({ type, payload: 'HSL' }); - if (colorSpace === 'HSL') dispatch({ type, payload: 'HEX' }); + if (colorSpace === 'RGB') dispatch({ type, payload: 'HEX' }); } let value; if (colorSpace === 'HEX') value = HEX; if (colorSpace === 'RGB') value = toRGBString(RGB); - if (colorSpace === 'HSL') value = toHSLString(HSL); const propsInput = { colorMeta, onClick: edit }; @@ -65,7 +63,6 @@ export function ColorInputs({ <> {colorSpace === 'HEX' && } {colorSpace === 'RGB' && } - {colorSpace === 'HSL' && } )} @@ -103,7 +100,6 @@ function InputEdit({ value, dispatch, error, forwardRef, onChange }) { let payload; if (color.type === 'HEX') payload = color.value; if (color.type === 'RGB') payload = parseToRgb(color.value); - if (color.type === 'HSL') payload = parseToHsl(color.value); const type = 'SET_' + color.type; dispatch({ type, payload }); @@ -150,9 +146,7 @@ function InputHEX({ colorMeta, onClick }) { } function InputRGB({ colorMeta, onClick }) { - const { - RGB: { red, blue, green }, - } = colorMeta; + const { RGB } = colorMeta; const props = { onClick, @@ -164,54 +158,24 @@ function InputRGB({ colorMeta, onClick }) { return ( <> - - - + ); } -function InputHSL({ colorMeta, onClick }) { - const { - HSL: { hue, saturation, lightness }, - } = colorMeta; - - const props = { - onClick, - type: 'text', - min: 0, - max: 100, - readOnly: true, - } as const; - - return ( - <> - - - - - ); -} - -function toHSLString(HSL) { - const [hue, saturation, lightness] = roundValues(HSL); - return `hsl(${hue}, ${saturation}, ${lightness})`; -} - function toRGBString(RGB) { const [red, green, blue] = roundValues(RGB); return `rgb(${red}, ${green}, ${blue})`; } function validate(color) { - let type: 'HEX' | 'HSL' | 'RGB'; + let type: 'HEX' | 'RGB'; let valid = false; const value = color.replace(/\s+/g, '').replace(';', ''); if (value.startsWith('#')) type = 'HEX'; if (value.startsWith('rgb')) type = 'RGB'; - if (value.startsWith('hsl')) type = 'HSL'; try { grayscale(value);