Skip to content

Commit 5fa7301

Browse files
authored
feat: display incorrect color using border red in Colorbutton and Colorbox (#128)
1 parent 5e083c8 commit 5fa7301

File tree

2 files changed

+28
-8
lines changed

2 files changed

+28
-8
lines changed

src/components/ColorBox/index.jsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,19 @@ const useStyles = makeStyles(theme => ({
6666
colorboxColor: {
6767
width: 48,
6868
height: 48,
69-
backgroundColor: props => props.backgroundColor,
69+
background: props =>
70+
props.colorError
71+
? `repeating-linear-gradient(
72+
135deg,
73+
transparent,
74+
transparent 29px,
75+
#f44336 29px,
76+
#f44336 32px
77+
)`
78+
: 'none',
79+
backgroundColor: props => (props.colorError ? 'transparent' : props.backgroundColor),
7080
borderRadius: 4,
81+
border: props => (props.colorError ? '2px solid #f44336' : 'none'),
7182
},
7283
colorboxControls: {
7384
display: 'flex',
@@ -100,7 +111,7 @@ const ColorBox = ({ value, palette, inputFormats, deferred, onChange: _onChange,
100111
const cssColor = getCssColor(color, 'hex', true);
101112
const { backgroundColor } = color.css;
102113
const boxWidth = 320;
103-
const classes = useStyles({ boxWidth, backgroundColor });
114+
const classes = useStyles({ boxWidth, backgroundColor, colorError: !!color.error });
104115

105116
const handleSet = () => {
106117
onDeferredChange(color);

src/components/ColorButton.jsx

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import useTranslate from '../helpers/useTranslate';
1818
const useStyles = makeStyles({
1919
root: {
2020
backgroundImage: props =>
21-
props.alpha < 1
21+
props.colorError || props.alpha < 1
2222
? `
2323
linear-gradient(45deg, #ccc 25%, transparent 25%),
2424
linear-gradient(135deg, #ccc 25%, transparent 25%),
@@ -39,14 +39,22 @@ const useStyles = makeStyles({
3939
height: props => props.height,
4040
'& div': {
4141
content: '" "',
42-
backgroundColor: props => props.backgroundColor || '#fff',
43-
backgroundSize: '8px 8px',
42+
background: props =>
43+
props.colorError
44+
? `repeating-linear-gradient(
45+
135deg,
46+
transparent,
47+
transparent ${props.width / 2 + 2}px,
48+
#f44336 ${props.width / 2 + 2}px,
49+
#f44336 ${props.width / 2 + 4}px
50+
)`
51+
: 'none',
52+
backgroundColor: props => (props.colorError ? 'transparent' : props.backgroundColor || '#fff'),
4453
width: props => props.width,
4554
minWidth: props => props.minWidth,
4655
height: props => props.height,
47-
borderColor: props => props.borderColor || '#767676',
48-
borderStyle: 'solid',
49-
borderWidth: props => props.borderWidth || 0,
56+
border: props =>
57+
props.colorError ? '2px solid #f44336' : `${props.borderWidth || 0}px solid ${props.borderColor || '#767676'}`,
5058
borderRadius: 4,
5159
padding: 0,
5260
},
@@ -98,6 +106,7 @@ const ColorButton = ({
98106
borderColor,
99107
borderWidth,
100108
alpha: a,
109+
colorError: !!color.error,
101110
...cssColor,
102111
});
103112
const component = (

0 commit comments

Comments
 (0)