Skip to content

Commit 8e896d1

Browse files
authored
Merge pull request #73 from gmonte/master
feat: added "disabled" prop
2 parents bd1aea4 + a9e52f8 commit 8e896d1

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export interface InputColorProps {
1616
initialValue: string;
1717
placement?: string;
1818
onChange?(color: Color): void;
19+
disabled?: boolean;
1920
}
2021

2122
export default function InputColor(props: InputColorProps);

src/color-picker.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { rgba2hex } from './utils';
1414

1515
const KEY_ENTER = 13;
1616

17-
const ColorPicker = ({ color, onChange }) => {
17+
const ColorPicker = ({ color, onChange, disabled }) => {
1818
const { r, g, b, a, h, s, v } = color;
1919

2020
function changeColor(color) {
@@ -80,6 +80,7 @@ const ColorPicker = ({ color, onChange }) => {
8080
y={100 - v}
8181
ymax={100}
8282
onChange={({ x, y }) => changeHSV(h, x, 100 - y)}
83+
disabled={disabled}
8384
styles={{
8485
track: { width: '100%', height: '100%', background: 'none' },
8586
thumb: {
@@ -107,6 +108,7 @@ const ColorPicker = ({ color, onChange }) => {
107108
x={h}
108109
xmax={359}
109110
onChange={({ x }) => changeHSV(x, s, v)}
111+
disabled={disabled}
110112
styles={{
111113
track: {
112114
width: '100%',
@@ -148,6 +150,7 @@ const ColorPicker = ({ color, onChange }) => {
148150
},
149151
}}
150152
onChange={({ x }) => changeAlpha(x)}
153+
disabled={disabled}
151154
/>
152155
</div>
153156
<div
@@ -163,6 +166,7 @@ const ColorPicker = ({ color, onChange }) => {
163166
value={color.hex}
164167
onChange={(e) => changeHex(e.target.value)}
165168
onKeyUp={handleHexKeyUp}
169+
disabled={disabled}
166170
/>
167171
<div>Hex</div>
168172
</div>
@@ -173,6 +177,7 @@ const ColorPicker = ({ color, onChange }) => {
173177
max={255}
174178
value={r}
175179
onChange={(r) => changeRGB(r, g, b)}
180+
disabled={disabled}
176181
/>
177182
<div>R</div>
178183
</div>
@@ -182,6 +187,7 @@ const ColorPicker = ({ color, onChange }) => {
182187
max={255}
183188
value={g}
184189
onChange={(g) => changeRGB(r, g, b)}
190+
disabled={disabled}
185191
/>
186192
<div>G</div>
187193
</div>
@@ -191,6 +197,7 @@ const ColorPicker = ({ color, onChange }) => {
191197
max={255}
192198
value={b}
193199
onChange={(b) => changeRGB(r, g, b)}
200+
disabled={disabled}
194201
/>
195202
<div>B</div>
196203
</div>
@@ -201,6 +208,7 @@ const ColorPicker = ({ color, onChange }) => {
201208
max={100}
202209
value={a}
203210
onChange={(a) => changeAlpha(a)}
211+
disabled={disabled}
204212
/>
205213
<div>A</div>
206214
</div>
@@ -211,6 +219,7 @@ const ColorPicker = ({ color, onChange }) => {
211219

212220
ColorPicker.defaultProps = {
213221
initialValue: '#5e72e4',
222+
disabled: false
214223
};
215224

216225
const styles = {

src/input-color.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import Popover from '@xkit/popover';
55
import ColorPicker from './color-picker';
66
import { parseColor } from './utils';
77

8-
const InputColor = ({ initialValue, onChange, placement, ...props }) => {
8+
const InputColor = ({ initialValue, onChange, placement, disabled, ...props }) => {
99
const [color, setColor] = useState(parseColor(initialValue));
1010

1111
useEffect(() => {
@@ -22,7 +22,7 @@ const InputColor = ({ initialValue, onChange, placement, ...props }) => {
2222
return (
2323
<Popover
2424
placement={placement}
25-
body={<ColorPicker color={color} onChange={changeColor} />}
25+
body={<ColorPicker color={color} onChange={changeColor} disabled={ disabled } />}
2626
>
2727
<span
2828
{...props}
@@ -55,6 +55,7 @@ const InputColor = ({ initialValue, onChange, placement, ...props }) => {
5555

5656
InputColor.defaultProps = {
5757
placement: 'bottom',
58+
disabled: false
5859
};
5960

6061
export default InputColor;

0 commit comments

Comments
 (0)