Skip to content

Commit f6df4fa

Browse files
committed
Add error state
1 parent d7a4be0 commit f6df4fa

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

site/src/components/NewFilter/NewFilter.stories.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@ export const DefaultValue: Story = {
2727
},
2828
};
2929

30+
export const Error: Story = {
31+
args: {
32+
value: "number_of_users:7",
33+
error: `"number_of_users" is not a valid query param`,
34+
},
35+
};
36+
3037
export const Focused: Story = {
3138
args: {
3239
value: "",

site/src/components/NewFilter/NewFilter.tsx

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { useTheme } from "@emotion/react";
22
import CloseOutlined from "@mui/icons-material/CloseOutlined";
33
import SearchOutlined from "@mui/icons-material/SearchOutlined";
4+
import FormHelperText from "@mui/material/FormHelperText";
45
import IconButton from "@mui/material/IconButton";
56
import InputBase from "@mui/material/InputBase";
67
import Tooltip from "@mui/material/Tooltip";
@@ -13,26 +14,29 @@ const inputSidePadding = 12;
1314

1415
type NewFilterProps = {
1516
value: string;
17+
error?: string;
1618
onChange: (value: string) => void;
1719
};
1820

1921
export const NewFilter: FC<NewFilterProps> = (props) => {
2022
const theme = useTheme();
21-
const { value, onChange } = props;
23+
const { value, error, onChange } = props;
2224
const isEmpty = value.length === 0;
2325

26+
const outlineCSS = (color: string) => ({
27+
outline: `2px solid ${color}`,
28+
outlineOffset: -1, // Overrides the border
29+
});
30+
2431
return (
2532
<div
2633
css={{
2734
borderRadius: inputBorderRadius,
2835
border: `1px solid ${theme.palette.divider}`,
2936
height: inputHeight,
3037
padding: `0 ${inputSidePadding}px`,
31-
32-
"&:focus-within": {
33-
outline: `2px solid ${theme.palette.primary.main}`,
34-
outlineOffset: -1, // Overrides the border
35-
},
38+
"&:focus-within": error ? "" : outlineCSS(theme.palette.primary.main),
39+
...(error ? outlineCSS(theme.palette.error.main) : {}),
3640
}}
3741
>
3842
<InputBase
@@ -76,6 +80,7 @@ export const NewFilter: FC<NewFilterProps> = (props) => {
7680
onChange(e.currentTarget.value);
7781
}}
7882
/>
83+
{error && <FormHelperText error>{error}</FormHelperText>}
7984
</div>
8085
);
8186
};

0 commit comments

Comments
 (0)