Skip to content

Commit a4d625e

Browse files
ElliotLuke Bowerman
andauthored
feat(InputColor): New ColorPicker base component, major overhaul of InputColor (#2013)
* Initial commit * Utilized basic hsv to string conversion functions from color_format_utils * Added color prop to accept color state piece * Added handle to HueSlider * Added handle to SaturationAndLightnessPreview * Fixed react preemptive state update bug * Added drag to HueSlider * Added drag handler to SaturationAndLightnessPreview * Removed Box from story * Added proper click + grab behavior to HueSlider - Also proper cursor styling * Added point and grab to Preview element * Fixed "too many classes generated" bug * Renamed Light and Saturation preview component * Moved HueSlider and LightSaturationPreview into InputColor * Removed LuminositySlider code * Removed all mentions of ColorWheel code * Revert "Removed LuminositySlider code" This reverts commit 07eda61. * Fixed imports in HueSlider and LSPreview * Removed unnecessary color and backgroundColor props * Added ColorPicker component * Updated InputColor tests * Reexported ColorWheel and LuminositySlider to fix gatsby * Luke feedback * Added comments about transform math * Removed LuminositySlider and ColorWheel components * Moved used util functions to separate files * Renamed color_utils to isValidColor * Renamed color_utils.test to toPercent.test * Removed unused color format util functions * Fixed spelling error on simpleHsvToFormattedColorString name * Be gone ColorWheel docs * Remove unused utils & attributes * Fixed HueSlider color and moved Handle2d to own file * HueSlider - Removed SLIDER_HEIGHT * Consolidated HANDLE_HEIGHT and WIDTH to HANDLE_SIZE in Handle2d * Consolidated types for ColorPicker, HueSlider and LightSatPreview * Consolidated width to originate from InputColor ColorPicker element * Moved HueSliderHandle to own file * DRY-ed up Handle and Handle2d * Renamed handleClick to handleMouseDown - Less confusing since this is fed to onMouseDown in div element * Proposed InputColor test and fix * Revert "Proposed InputColor test and fix" This reverts commit 5d033bf. * Added InputColor click test * Added blur focus test to InputColor * Added xtest for InputColor drag event Co-authored-by: Luke Bowerman <[email protected]>
1 parent aa992e6 commit a4d625e

40 files changed

+720
-2640
lines changed

config/all-components.csv

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ CheckboxGroup,component
3535
Chip,component
3636
Code,component
3737
CodeBlock,component
38-
ColorWheel,component
38+
ColorPicker, component
3939
Comboxbox,component
4040
ComboxboxInput,component
4141
ComboxboxList,component
@@ -111,7 +111,6 @@ Layout,component
111111
Link,component
112112
List,component
113113
ListItem,component
114-
LuminositySlider,component
115114
Menu,component
116115
MenuItem,component
117116
MenuList,component

packages/components/src/Form/Inputs/InputColor/utils/math_utils.test.ts renamed to packages/components/src/Form/Inputs/InputColor/ColorPicker/ColorPicker.tsx

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,17 @@
2424
2525
*/
2626

27-
import { toPercent } from './math_utils'
28-
29-
describe('math_utils', () => {
30-
const correctValues = [60, 24, 10, 13, 25]
31-
test('toPercent', () => {
32-
;[
33-
[60, 100],
34-
[60, 255],
35-
[25, 255],
36-
[32, 255],
37-
[96, 384],
38-
].map((values, index) =>
39-
expect(toPercent(values[0], values[1])).toBe(correctValues[index])
40-
)
41-
})
42-
})
27+
import React, { FC } from 'react'
28+
import styled from 'styled-components'
29+
import { SpaceVertical } from '../../../../Layout'
30+
import { LightSaturationPreview, HueSlider } from '..'
31+
import { ColorPickerProps } from '../types'
32+
33+
const ColorPickerInternal: FC<ColorPickerProps> = ({ hsv, setHsv, width }) => (
34+
<SpaceVertical gap="medium" data-testid="color-picker">
35+
<LightSaturationPreview hsv={hsv} setHsv={setHsv} width={width} />
36+
<HueSlider hsv={hsv} setHsv={setHsv} width={width} />
37+
</SpaceVertical>
38+
)
39+
40+
export const ColorPicker = styled(ColorPickerInternal)``

packages/components/src/Form/Inputs/InputColor/utils/math_utils.ts renamed to packages/components/src/Form/Inputs/InputColor/ColorPicker/index.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,4 @@
2424
2525
*/
2626

27-
/**
28-
* Utility to convert a numerical value to a percent given the value and a max value.
29-
*/
30-
export const toPercent = (value: number, maxValue: number) =>
31-
Math.round((value / maxValue) * 100)
27+
export * from './ColorPicker'

0 commit comments

Comments
 (0)