Skip to content

Commit fa4b017

Browse files
committed
indicate wrong inputs
1 parent b719876 commit fa4b017

File tree

2 files changed

+33
-15
lines changed

2 files changed

+33
-15
lines changed

src/components/VectorLineComparer/VectorInput.tsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,28 @@
11
import React from 'react';
22
import styles from './styles.module.scss';
33
import clsx from 'clsx';
4+
import { parseNumber } from './helper';
45

56
interface Props {
67
value: [string, string, string];
78
onChange: (value: [string, string, string]) => void;
89
}
910

1011
const VectorInput = ({ value, onChange }: Props) => {
12+
const [invalidInput, setInvalidInput] = React.useState<Set<number>>(new Set());
1113
const handleChange = (index: number, newValue: string) => {
1214
const newVector = [...value] as [string, string, string];
1315
newVector[index] = newValue;
1416
onChange(newVector);
17+
if (Number.isNaN(parseNumber(newValue))) {
18+
setInvalidInput((prev) => new Set(prev.add(index)));
19+
} else if (invalidInput.has(index)) {
20+
setInvalidInput((prev) => {
21+
const newSet = new Set(prev);
22+
newSet.delete(index);
23+
return newSet;
24+
});
25+
}
1526
};
1627

1728
return (
@@ -24,7 +35,7 @@ const VectorInput = ({ value, onChange }: Props) => {
2435
type="text"
2536
value={component}
2637
onChange={(e) => handleChange(index, e.target.value)}
27-
style={{ width: '50px', margin: '0 5px' }}
38+
className={clsx(styles.input, invalidInput.has(index) && styles.invalid)}
2839
/>
2940
))}
3041
</div>
@@ -33,4 +44,4 @@ const VectorInput = ({ value, onChange }: Props) => {
3344
);
3445
};
3546

36-
export default VectorInput;
47+
export default VectorInput;

src/components/VectorLineComparer/styles.module.scss

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,15 @@
3030
.content {
3131
display: flex;
3232
flex-direction: column;
33-
input {
33+
gap: 1.1px;
34+
.input {
3435
text-align: center;
36+
width: 50px;
37+
margin: 0 5px;
38+
&.invalid {
39+
color: var(--ifm-color-danger);
40+
outline-color: var(--ifm-color-danger);
41+
}
3542
}
3643
}
3744
}
@@ -45,20 +52,20 @@
4552
position: relative;
4653
padding-top: 5px; /* Padding to adjust the arrow over the text */
4754
margin-left: 15px;
55+
&::before {
56+
content: ''; /* Unicode for right arrow */
57+
position: absolute;
58+
top: 0;
59+
left: 0;
60+
right: 0;
61+
margin: auto;
62+
text-align: center;
63+
font-size: 24px; /* Adjust size as needed */
64+
line-height: 0; /* Removes extra space typically added by characters */
65+
transform: translateX(-2px) translateY(15px);
66+
}
4867
}
4968

50-
.vectorText::before {
51-
content: ''; /* Unicode for right arrow */
52-
position: absolute;
53-
top: 0;
54-
left: 0;
55-
right: 0;
56-
margin: auto;
57-
text-align: center;
58-
font-size: 24px; /* Adjust size as needed */
59-
line-height: 0; /* Removes extra space typically added by characters */
60-
transform: translateX(-2px) translateY(15px);
61-
}
6269
.equals {
6370
margin: 0 10px;
6471
}

0 commit comments

Comments
 (0)