From 168d909c87c2f2aa54ff35f917e0714aa984f454 Mon Sep 17 00:00:00 2001 From: BrunoQuaresma Date: Tue, 18 Jun 2024 18:34:32 +0000 Subject: [PATCH 1/2] chore(site): add InputGroup component --- site/src/components/Filter/filter.tsx | 25 +----- .../InputGroup/InputGroup.stories.tsx | 79 +++++++++++++++++++ site/src/components/InputGroup/InputGroup.tsx | 55 +++++++++++++ 3 files changed, 138 insertions(+), 21 deletions(-) create mode 100644 site/src/components/InputGroup/InputGroup.stories.tsx create mode 100644 site/src/components/InputGroup/InputGroup.tsx diff --git a/site/src/components/Filter/filter.tsx b/site/src/components/Filter/filter.tsx index 91d8d78ee1cf4..29fb34ee4c251 100644 --- a/site/src/components/Filter/filter.tsx +++ b/site/src/components/Filter/filter.tsx @@ -22,6 +22,7 @@ import { hasError, isApiValidationError, } from "api/errors"; +import { InputGroup } from "components/InputGroup/InputGroup"; import { Loader } from "components/Loader/Loader"; import { Search, @@ -212,7 +213,7 @@ export const Filter: FC = ({ skeleton ) : ( <> -
+ filter.update(query)} presets={presets} @@ -221,7 +222,7 @@ export const Filter: FC = ({ learnMoreLink2={learnMoreLink2} /> = ({ setQueryCopy(filter.query); } }, - sx: { - borderRadius: "6px", - borderTopLeftRadius: 0, - borderBottomLeftRadius: 0, - marginLeft: "-1px", - "&:hover": { - zIndex: 2, - }, - "&.Mui-error": { - zIndex: 3, - }, - }, }} /> -
+ {options} )} @@ -288,12 +277,6 @@ const PresetMenu: FC = ({ + + + ), + }, +}; + +export const FocusedTextField: Story = { + args: { + children: ( + <> + + + + ), + }, +}; + +export const ErroredTextField: Story = { + args: { + children: ( + <> + + + + ), + }, +}; + +export const FocusedErroredTextField: Story = { + args: { + children: ( + <> + + + + ), + }, +}; + +export const WithThreeElements: Story = { + args: { + children: ( + <> + + + + + ), + }, +}; diff --git a/site/src/components/InputGroup/InputGroup.tsx b/site/src/components/InputGroup/InputGroup.tsx new file mode 100644 index 0000000000000..732479d3bbac4 --- /dev/null +++ b/site/src/components/InputGroup/InputGroup.tsx @@ -0,0 +1,55 @@ +import type { FC, HTMLProps } from "react"; + +export const InputGroup: FC> = (props) => { + return ( +
*:hover": { + zIndex: 1, + }, + + "& > *:not(:last-child)": { + marginRight: -1, + }, + + "& > *: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, + }, + }, + + "& .Mui-focused, & .Mui-error": { + zIndex: 2, + }, + }} + /> + ); +}; From f01f8cf4ef4dccec84abec837146922ad8cc04df Mon Sep 17 00:00:00 2001 From: BrunoQuaresma Date: Fri, 21 Jun 2024 13:41:00 +0000 Subject: [PATCH 2/2] Add comments explaing stylings --- site/src/components/InputGroup/InputGroup.tsx | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/site/src/components/InputGroup/InputGroup.tsx b/site/src/components/InputGroup/InputGroup.tsx index 732479d3bbac4..d6965442ee96a 100644 --- a/site/src/components/InputGroup/InputGroup.tsx +++ b/site/src/components/InputGroup/InputGroup.tsx @@ -5,17 +5,24 @@ export const InputGroup: FC> = (props) => {
*:not(:last-child)": { + marginRight: -1, }, + // Ensure the border of the hovered element is visible when borders + // overlap. "& > *:hover": { zIndex: 1, }, - "& > *:not(:last-child)": { - marginRight: -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": { @@ -45,10 +52,6 @@ export const InputGroup: FC> = (props) => { borderRadius: 0, }, }, - - "& .Mui-focused, & .Mui-error": { - zIndex: 2, - }, }} /> );