Skip to content

Commit 73a25c3

Browse files
chore(site): add InputGroup component (#13597)
1 parent 819bfd3 commit 73a25c3

File tree

3 files changed

+141
-21
lines changed

3 files changed

+141
-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: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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+
display: "flex",
9+
alignItems: "flex-start",
10+
11+
// Overlap borders to avoid displaying double borders between elements.
12+
"& > *:not(:last-child)": {
13+
marginRight: -1,
14+
},
15+
16+
// Ensure the border of the hovered element is visible when borders
17+
// overlap.
18+
"& > *:hover": {
19+
zIndex: 1,
20+
},
21+
22+
// Display border elements when focused or in an error state, both of
23+
// which take priority over hover.
24+
"& .Mui-focused, & .Mui-error": {
25+
zIndex: 2,
26+
},
27+
28+
"& > *:first-child": {
29+
borderTopRightRadius: 0,
30+
borderBottomRightRadius: 0,
31+
32+
"&.MuiFormControl-root .MuiInputBase-root": {
33+
borderTopRightRadius: 0,
34+
borderBottomRightRadius: 0,
35+
},
36+
},
37+
38+
"& > *:last-child": {
39+
borderTopLeftRadius: 0,
40+
borderBottomLeftRadius: 0,
41+
42+
"&.MuiFormControl-root .MuiInputBase-root": {
43+
borderTopLeftRadius: 0,
44+
borderBottomLeftRadius: 0,
45+
},
46+
},
47+
48+
"& > *:not(:first-child):not(:last-child)": {
49+
borderRadius: 0,
50+
51+
"&.MuiFormControl-root .MuiInputBase-root": {
52+
borderRadius: 0,
53+
},
54+
},
55+
}}
56+
/>
57+
);
58+
};

0 commit comments

Comments
 (0)