11
11
*/
12
12
13
13
import { action } from '@storybook/addon-actions' ;
14
- import { ColorArea , ColorSlider } from '../' ;
14
+ import { ColorArea , ColorField , ColorSlider } from '../' ;
15
15
import { ColorChannel , SpectrumColorAreaProps } from '@react-types/color' ;
16
16
import { Flex } from '@adobe/react-spectrum' ;
17
17
import { Meta , Story } from '@storybook/react' ;
18
18
import { parseColor } from '@react-stately/color' ;
19
- import React , { useState } from 'react' ;
19
+ import React , { useRef , useState } from 'react' ;
20
20
import { Text } from '@react-spectrum/text' ;
21
21
22
22
@@ -39,8 +39,9 @@ function ColorAreaExample(props: SpectrumColorAreaProps) {
39
39
let channels = new Set ( [ xChannel , yChannel ] ) ;
40
40
let zChannel : ColorChannel = difference ( RGB , channels ) . keys ( ) . next ( ) . value ;
41
41
let [ color , setColor ] = useState ( props . defaultValue || parseColor ( '#ff00ff' ) ) ;
42
+ let colorFieldRef = useRef ( null ) ;
42
43
return ( < div role = "group" aria-label = "RGB Color Picker" >
43
- < Flex gap = "size-500 " alignItems = "center " >
44
+ < Flex gap = "size-200 " alignItems = "start " >
44
45
< Flex direction = "column" gap = "size-50" alignItems = "center" >
45
46
< ColorArea
46
47
{ ...props }
@@ -50,7 +51,8 @@ function ColorAreaExample(props: SpectrumColorAreaProps) {
50
51
props . onChange ( e ) ;
51
52
}
52
53
setColor ( e ) ;
53
- } } />
54
+ } }
55
+ onChangeEnd = { props . onChangeEnd } />
54
56
< ColorSlider
55
57
value = { color }
56
58
onChange = { ( e ) => {
@@ -63,9 +65,26 @@ function ColorAreaExample(props: SpectrumColorAreaProps) {
63
65
channel = { zChannel }
64
66
isDisabled = { isDisabled } />
65
67
</ Flex >
66
- < Flex direction = "column" alignItems = "center" gap = "size-100 " minWidth = { 'size-2000' } >
68
+ < Flex direction = "column" alignItems = "center" gap = "size-200 " minWidth = { 'size-2000' } >
67
69
< div role = "img" aria-label = { `color swatch: ${ color . toString ( 'rgb' ) } ` } title = { `${ color . toString ( 'hex' ) } ` } style = { { width : '100px' , height : '100px' , background : color . toString ( 'css' ) } } />
68
- < Text > { color . toString ( 'hex' ) } </ Text >
70
+ < ColorField
71
+ ref = { colorFieldRef }
72
+ aria-label = "RGB Color"
73
+ value = { color }
74
+ onChange = { ( e ) => {
75
+ if ( e && props . onChange ) {
76
+ props . onChange ( e ) ;
77
+ }
78
+ setColor ( e || color ) ;
79
+ } }
80
+ onKeyDown = { e => {
81
+ let newColor = parseColor ( ( e . target as HTMLInputElement ) . value ) ;
82
+ if ( e . key === 'Enter' && newColor ) {
83
+ setColor ( newColor ) ;
84
+ }
85
+ } }
86
+ isDisabled = { isDisabled }
87
+ width = "100px" />
69
88
</ Flex >
70
89
</ Flex >
71
90
</ div > ) ;
@@ -77,42 +96,42 @@ XBlueYGreen.args = {xChannel: 'blue', yChannel: 'green', onChange: action('onCha
77
96
78
97
export let XGreenYBlue = Template . bind ( { } ) ;
79
98
XGreenYBlue . storyName = 'RGB xChannel="green", yChannel="blue"' ;
80
- XGreenYBlue . args = { xChannel : 'green' , yChannel : 'blue' , onChange : action ( 'onChange' ) } ;
99
+ XGreenYBlue . args = { xChannel : 'green' , yChannel : 'blue' , onChange : action ( 'onChange' ) , onChangeEnd : action ( 'onChangeEnd' ) } ;
81
100
82
101
export let XBlueYRed = Template . bind ( { } ) ;
83
102
XBlueYRed . storyName = 'RGB xChannel="blue", yChannel="red"' ;
84
- XBlueYRed . args = { xChannel : 'blue' , yChannel : 'red' , onChange : action ( 'onChange' ) } ;
103
+ XBlueYRed . args = { xChannel : 'blue' , yChannel : 'red' , onChange : action ( 'onChange' ) , onChangeEnd : action ( 'onChangeEnd' ) } ;
85
104
86
105
export let XRedYBlue = Template . bind ( { } ) ;
87
106
XRedYBlue . storyName = 'GB xChannel="red", yChannel="blue"' ;
88
- XRedYBlue . args = { xChannel : 'red' , yChannel : 'blue' , onChange : action ( 'onChange' ) } ;
107
+ XRedYBlue . args = { xChannel : 'red' , yChannel : 'blue' , onChange : action ( 'onChange' ) , onChangeEnd : action ( 'onChangeEnd' ) } ;
89
108
90
109
export let XRedYGreen = Template . bind ( { } ) ;
91
110
XRedYGreen . storyName = 'RGB xChannel="red", yChannel="green"' ;
92
- XRedYGreen . args = { xChannel : 'red' , yChannel : 'green' , onChange : action ( 'onChange' ) } ;
111
+ XRedYGreen . args = { xChannel : 'red' , yChannel : 'green' , onChange : action ( 'onChange' ) , onChangeEnd : action ( 'onChangeEnd' ) } ;
93
112
94
113
export let XGreenYRed = Template . bind ( { } ) ;
95
114
XGreenYRed . storyName = 'RGB xChannel="green", yChannel="red"' ;
96
- XGreenYRed . args = { xChannel : 'green' , yChannel : 'red' , onChange : action ( 'onChange' ) } ;
115
+ XGreenYRed . args = { xChannel : 'green' , yChannel : 'red' , onChange : action ( 'onChange' ) , onChangeEnd : action ( 'onChangeEnd' ) } ;
97
116
98
117
export let XBlueYGreenStep16 = Template . bind ( { } ) ;
99
118
XBlueYGreenStep16 . storyName = 'RGB xChannel="blue", yChannel="green", step="16"' ;
100
- XBlueYGreenStep16 . args = { ...XBlueYGreen . args , xChannelStep : 16 , yChannelStep : 16 } ;
119
+ XBlueYGreenStep16 . args = { ...XBlueYGreen . args , xChannelStep : 16 , yChannelStep : 16 , onChange : action ( 'onChange' ) , onChangeEnd : action ( 'onChangeEnd' ) } ;
101
120
102
121
/* TODO: what does a disabled color area look like? */
103
122
export let XBlueYGreenisDisabled = Template . bind ( { } ) ;
104
123
XBlueYGreenisDisabled . storyName = 'RGB xChannel="blue", yChannel="green", isDisabled' ;
105
- XBlueYGreenisDisabled . args = { ...XBlueYGreen . args , isDisabled : true } ;
124
+ XBlueYGreenisDisabled . args = { ...XBlueYGreen . args , isDisabled : true , onChange : action ( 'onChange' ) , onChangeEnd : action ( 'onChangeEnd' ) } ;
106
125
107
126
/* TODO: how do we visually label and how to do we aria-label */
108
127
export let XBlueYGreenAriaLabelled = Template . bind ( { } ) ;
109
128
XBlueYGreenAriaLabelled . storyName = 'RGB xChannel="blue", yChannel="green", aria-label="foo"' ;
110
- XBlueYGreenAriaLabelled . args = { ...XBlueYGreen . args , label : undefined , ariaLabel : 'foo' } ;
129
+ XBlueYGreenAriaLabelled . args = { ...XBlueYGreen . args , label : undefined , ariaLabel : 'foo' , onChange : action ( 'onChange' ) , onChangeEnd : action ( 'onChangeEnd' ) } ;
111
130
112
131
export let XBlueYGreenSize3000 = Template . bind ( { } ) ;
113
132
XBlueYGreenSize3000 . storyName = 'RGB xChannel="blue", yChannel="green", size="size-3000"' ;
114
- XBlueYGreenSize3000 . args = { ...XBlueYGreen . args , size : 'size-3000' } ;
133
+ XBlueYGreenSize3000 . args = { ...XBlueYGreen . args , size : 'size-3000' , onChange : action ( 'onChange' ) , onChangeEnd : action ( 'onChangeEnd' ) } ;
115
134
116
135
export let XBlueYGreenSize600 = Template . bind ( { } ) ;
117
136
XBlueYGreenSize600 . storyName = 'RGB xChannel="blue", yChannel="green", size="size-600"' ;
118
- XBlueYGreenSize600 . args = { ...XBlueYGreen . args , size : 'size-600' } ;
137
+ XBlueYGreenSize600 . args = { ...XBlueYGreen . args , size : 'size-600' , onChange : action ( 'onChange' ) , onChangeEnd : action ( 'onChangeEnd' ) } ;
0 commit comments