Skip to content

Commit 168d909

Browse files
committed
chore(site): add InputGroup component
1 parent d0b2f61 commit 168d909

File tree

3 files changed

+138
-21
lines changed

3 files changed

+138
-21
lines changed

site/src/components/Filter/filter.tsx

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222
hasError,
2323
isApiValidationError,
2424
} from "api/errors";
25+
import { InputGroup } from "components/InputGroup/InputGroup";
2526
import { Loader } from "components/Loader/Loader";
2627
import {
2728
Search,
@@ -212,7 +213,7 @@ export const Filter: FC<FilterProps> = ({
212213
skeleton
213214
) : (
214215
<>
215-
<div css={{ display: "flex", width: "100%" }}>
216+
<InputGroup css={{ width: "100%" }}>
216217
<PresetMenu
217218
onSelect={(query) => filter.update(query)}
218219
presets={presets}
@@ -221,7 +222,7 @@ export const Filter: FC<FilterProps> = ({
221222
learnMoreLink2={learnMoreLink2}
222223
/>
223224
<SearchField
224-
fullWidth
225+
css={{ flex: 1 }}
225226
error={shouldDisplayError}
226227
helperText={
227228
shouldDisplayError
@@ -242,21 +243,9 @@ export const Filter: FC<FilterProps> = ({
242243
setQueryCopy(filter.query);
243244
}
244245
},
245-
sx: {
246-
borderRadius: "6px",
247-
borderTopLeftRadius: 0,
248-
borderBottomLeftRadius: 0,
249-
marginLeft: "-1px",
250-
"&:hover": {
251-
zIndex: 2,
252-
},
253-
"&.Mui-error": {
254-
zIndex: 3,
255-
},
256-
},
257246
}}
258247
/>
259-
</div>
248+
</InputGroup>
260249
{options}
261250
</>
262251
)}
@@ -288,12 +277,6 @@ const PresetMenu: FC<PresetMenuProps> = ({
288277
<Button
289278
onClick={() => setIsOpen(true)}
290279
ref={anchorRef}
291-
css={{
292-
borderTopRightRadius: 0,
293-
borderBottomRightRadius: 0,
294-
flexShrink: 0,
295-
zIndex: 1,
296-
}}
297280
endIcon={<KeyboardArrowDown />}
298281
>
299282
Filters
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import Button from "@mui/material/Button";
2+
import TextField from "@mui/material/TextField";
3+
import type { Meta, StoryObj } from "@storybook/react";
4+
import { InputGroup } from "./InputGroup";
5+
6+
const meta: Meta<typeof InputGroup> = {
7+
title: "components/InputGroup",
8+
component: InputGroup,
9+
};
10+
11+
export default meta;
12+
type Story = StoryObj<typeof InputGroup>;
13+
14+
export const Default: Story = {
15+
args: {
16+
children: (
17+
<>
18+
<Button>Menu</Button>
19+
<TextField size="small" placeholder="Search..." />
20+
</>
21+
),
22+
},
23+
};
24+
25+
export const FocusedTextField: Story = {
26+
args: {
27+
children: (
28+
<>
29+
<Button>Menu</Button>
30+
<TextField autoFocus size="small" placeholder="Search..." />
31+
</>
32+
),
33+
},
34+
};
35+
36+
export const ErroredTextField: Story = {
37+
args: {
38+
children: (
39+
<>
40+
<Button>Menu</Button>
41+
<TextField
42+
error
43+
size="small"
44+
placeholder="Search..."
45+
helperText="Some error message..."
46+
/>
47+
</>
48+
),
49+
},
50+
};
51+
52+
export const FocusedErroredTextField: Story = {
53+
args: {
54+
children: (
55+
<>
56+
<Button>Menu</Button>
57+
<TextField
58+
autoFocus
59+
error
60+
size="small"
61+
placeholder="Search..."
62+
helperText="Some error message..."
63+
/>
64+
</>
65+
),
66+
},
67+
};
68+
69+
export const WithThreeElements: Story = {
70+
args: {
71+
children: (
72+
<>
73+
<Button>Menu</Button>
74+
<TextField size="small" placeholder="Search..." />
75+
<Button>Submit</Button>
76+
</>
77+
),
78+
},
79+
};
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import type { FC, HTMLProps } from "react";
2+
3+
export const InputGroup: FC<HTMLProps<HTMLDivElement>> = (props) => {
4+
return (
5+
<div
6+
{...props}
7+
css={{
8+
"&": {
9+
display: "flex",
10+
alignItems: "flex-start",
11+
},
12+
13+
"& > *:hover": {
14+
zIndex: 1,
15+
},
16+
17+
"& > *:not(:last-child)": {
18+
marginRight: -1,
19+
},
20+
21+
"& > *:first-child": {
22+
borderTopRightRadius: 0,
23+
borderBottomRightRadius: 0,
24+
25+
"&.MuiFormControl-root .MuiInputBase-root": {
26+
borderTopRightRadius: 0,
27+
borderBottomRightRadius: 0,
28+
},
29+
},
30+
31+
"& > *:last-child": {
32+
borderTopLeftRadius: 0,
33+
borderBottomLeftRadius: 0,
34+
35+
"&.MuiFormControl-root .MuiInputBase-root": {
36+
borderTopLeftRadius: 0,
37+
borderBottomLeftRadius: 0,
38+
},
39+
},
40+
41+
"& > *:not(:first-child):not(:last-child)": {
42+
borderRadius: 0,
43+
44+
"&.MuiFormControl-root .MuiInputBase-root": {
45+
borderRadius: 0,
46+
},
47+
},
48+
49+
"& .Mui-focused, & .Mui-error": {
50+
zIndex: 2,
51+
},
52+
}}
53+
/>
54+
);
55+
};

0 commit comments

Comments
 (0)