@@ -2,13 +2,17 @@ import React from 'react';
2
2
import propTypes from 'prop-types' ;
3
3
4
4
import styled , { css } from 'styled-components' ;
5
- import { focusOutline } from '../common' ;
6
5
import useControlledOrUncontrolled from '../common/hooks/useControlledOrUncontrolled' ;
7
- import Button from '../Button/Button' ;
8
- import Bar from '../Bar/Bar' ;
6
+ import { focusOutline } from '../common' ;
7
+ import { StyledButton } from '../Button/Button' ;
8
+ import Divider from '../Divider/Divider' ;
9
+
10
+ const Trigger = styled ( StyledButton ) `
11
+ padding-left: 8px;
12
+ ` ;
9
13
10
- const StyledBar = styled ( Bar ) `
11
- height: 23px ;
14
+ const StyledDivider = styled ( Divider ) `
15
+ height: 21px ;
12
16
position: relative;
13
17
top: 0;
14
18
` ;
@@ -27,10 +31,10 @@ export const StyledColorInput = styled.input`
27
31
// TODO replace with SVG icon
28
32
const ColorPreview = styled . div `
29
33
box-sizing: border-box;
30
- height: 21px ;
34
+ height: 19px ;
31
35
display: inline-block;
32
36
width: 35px;
33
- margin-right: 7px ;
37
+ margin-right: 5px ;
34
38
35
39
background: ${ ( { color } ) => color } ;
36
40
@@ -45,6 +49,16 @@ const ColorPreview = styled.div`
45
49
: css `
46
50
border: 2px solid ${ ( { theme } ) => theme . text } ;
47
51
` }
52
+ ${ StyledColorInput } :focus:not(:active) + &:after {
53
+ content: '';
54
+ position: absolute;
55
+ left: 0;
56
+ top: 0;
57
+ width: 100%;
58
+ height: 100%;
59
+ ${ focusOutline }
60
+ outline-offset: -8px;
61
+ }
48
62
` ;
49
63
50
64
const ChevronIcon = styled . span `
@@ -75,9 +89,6 @@ const ChevronIcon = styled.span`
75
89
width: 16px;
76
90
height: 19px;
77
91
}
78
- ${ StyledColorInput } :focus + &:after {
79
- ${ focusOutline }
80
- }
81
92
` ;
82
93
83
94
// TODO make sure all aria and role attributes are in place
@@ -105,14 +116,15 @@ const ColorInput = React.forwardRef(function ColorInput(props, ref) {
105
116
} ;
106
117
107
118
return (
108
- // we only need button styles, so we display it as a div and reset type attribute
109
- < Button isDisabled = { disabled } as = 'div' type = { null } variant = { variant } >
110
- < ColorPreview
111
- color = { valueDerived }
112
- isDisabled = { disabled }
113
- role = 'presentation'
114
- />
115
- { variant === 'default' && < StyledBar /> }
119
+ // we only need button styles, so we display
120
+ // it as a div and reset type attribute
121
+ < Trigger
122
+ isDisabled = { disabled }
123
+ as = 'div'
124
+ type = { null }
125
+ variant = { variant }
126
+ size = 'md'
127
+ >
116
128
< StyledColorInput
117
129
onChange = { handleChange }
118
130
readOnly = { disabled }
@@ -122,8 +134,14 @@ const ColorInput = React.forwardRef(function ColorInput(props, ref) {
122
134
ref = { ref }
123
135
{ ...otherProps }
124
136
/>
137
+ < ColorPreview
138
+ color = { valueDerived }
139
+ isDisabled = { disabled }
140
+ role = 'presentation'
141
+ />
142
+ { variant === 'default' && < StyledDivider vertical /> }
125
143
< ChevronIcon isDisabled = { disabled } variant = { variant } />
126
- </ Button >
144
+ </ Trigger >
127
145
) ;
128
146
} ) ;
129
147
0 commit comments