Skip to content

chore(site): add InputGroup component #13597

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 4 additions & 21 deletions site/src/components/Filter/filter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
hasError,
isApiValidationError,
} from "api/errors";
import { InputGroup } from "components/InputGroup/InputGroup";
import { Loader } from "components/Loader/Loader";
import {
Search,
Expand Down Expand Up @@ -212,7 +213,7 @@ export const Filter: FC<FilterProps> = ({
skeleton
) : (
<>
<div css={{ display: "flex", width: "100%" }}>
<InputGroup css={{ width: "100%" }}>
<PresetMenu
onSelect={(query) => filter.update(query)}
presets={presets}
Expand All @@ -221,7 +222,7 @@ export const Filter: FC<FilterProps> = ({
learnMoreLink2={learnMoreLink2}
/>
<SearchField
fullWidth
css={{ flex: 1 }}
error={shouldDisplayError}
helperText={
shouldDisplayError
Expand All @@ -242,21 +243,9 @@ export const Filter: FC<FilterProps> = ({
setQueryCopy(filter.query);
}
},
sx: {
borderRadius: "6px",
borderTopLeftRadius: 0,
borderBottomLeftRadius: 0,
marginLeft: "-1px",
"&:hover": {
zIndex: 2,
},
"&.Mui-error": {
zIndex: 3,
},
},
}}
/>
</div>
</InputGroup>
{options}
</>
)}
Expand Down Expand Up @@ -288,12 +277,6 @@ const PresetMenu: FC<PresetMenuProps> = ({
<Button
onClick={() => setIsOpen(true)}
ref={anchorRef}
css={{
borderTopRightRadius: 0,
borderBottomRightRadius: 0,
flexShrink: 0,
zIndex: 1,
}}
endIcon={<KeyboardArrowDown />}
>
Filters
Expand Down
79 changes: 79 additions & 0 deletions site/src/components/InputGroup/InputGroup.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import Button from "@mui/material/Button";
import TextField from "@mui/material/TextField";
import type { Meta, StoryObj } from "@storybook/react";
import { InputGroup } from "./InputGroup";

const meta: Meta<typeof InputGroup> = {
title: "components/InputGroup",
component: InputGroup,
};

export default meta;
type Story = StoryObj<typeof InputGroup>;

export const Default: Story = {
args: {
children: (
<>
<Button>Menu</Button>
<TextField size="small" placeholder="Search..." />
</>
),
},
};

export const FocusedTextField: Story = {
args: {
children: (
<>
<Button>Menu</Button>
<TextField autoFocus size="small" placeholder="Search..." />
</>
),
},
};

export const ErroredTextField: Story = {
args: {
children: (
<>
<Button>Menu</Button>
<TextField
error
size="small"
placeholder="Search..."
helperText="Some error message..."
/>
</>
),
},
};

export const FocusedErroredTextField: Story = {
args: {
children: (
<>
<Button>Menu</Button>
<TextField
autoFocus
error
size="small"
placeholder="Search..."
helperText="Some error message..."
/>
</>
),
},
};

export const WithThreeElements: Story = {
args: {
children: (
<>
<Button>Menu</Button>
<TextField size="small" placeholder="Search..." />
<Button>Submit</Button>
</>
),
},
};
58 changes: 58 additions & 0 deletions site/src/components/InputGroup/InputGroup.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import type { FC, HTMLProps } from "react";

export const InputGroup: FC<HTMLProps<HTMLDivElement>> = (props) => {
return (
<div
{...props}
css={{
display: "flex",
alignItems: "flex-start",

// Overlap borders to avoid displaying double borders between elements.
"& > *:not(:last-child)": {
marginRight: -1,
},

// Ensure the border of the hovered element is visible when borders
// overlap.
"& > *:hover": {
zIndex: 1,
},

// Display border elements when focused or in an error state, both of
// which take priority over hover.
"& .Mui-focused, & .Mui-error": {
zIndex: 2,
},

"& > *:first-child": {
borderTopRightRadius: 0,
borderBottomRightRadius: 0,

"&.MuiFormControl-root .MuiInputBase-root": {
borderTopRightRadius: 0,
borderBottomRightRadius: 0,
},
},

"& > *:last-child": {
borderTopLeftRadius: 0,
borderBottomLeftRadius: 0,

"&.MuiFormControl-root .MuiInputBase-root": {
borderTopLeftRadius: 0,
borderBottomLeftRadius: 0,
},
},

"& > *:not(:first-child):not(:last-child)": {
borderRadius: 0,

"&.MuiFormControl-root .MuiInputBase-root": {
borderRadius: 0,
},
},
}}
/>
);
};
Loading