Skip to content

Commit

Permalink
Add Collapsible Search Input (#1464)
Browse files Browse the repository at this point in the history
* created collapsed input

* resolve icon conflict
  • Loading branch information
joshri authored and jpellizzari committed Feb 25, 2022
1 parent eb18492 commit 2da20b3
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 0 deletions.
4 changes: 4 additions & 0 deletions ui/components/Icon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import NavigateBeforeIcon from "@material-ui/icons/NavigateBefore";
import NavigateNextIcon from "@material-ui/icons/NavigateNext";
import RemoveCircleIcon from "@material-ui/icons/RemoveCircle";
import SaveAltIcon from "@material-ui/icons/SaveAlt";
import SearchIcon from "@material-ui/icons/Search";
import SkipNextIcon from "@material-ui/icons/SkipNext";
import SkipPreviousIcon from "@material-ui/icons/SkipPrevious";
import * as React from "react";
Expand Down Expand Up @@ -42,6 +43,7 @@ export enum IconType {
FilterIcon,
ClearIcon,
Circle,
SearchIcon,
}

type Props = {
Expand Down Expand Up @@ -115,6 +117,8 @@ function getIcon(i: IconType) {
<circle cx="50" cy="50" r="45" />
</svg>
);
case IconType.SearchIcon:
return SearchIcon;

default:
break;
Expand Down
45 changes: 45 additions & 0 deletions ui/components/SearchInput.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import * as React from "react";
import styled from "styled-components";
import Button from "./Button";
import Flex from "./Flex";
import Icon, { IconType } from "./Icon";
import Input from "./Input";
import Spacer from "./Spacer";

export interface Props {
className?: string;
/** function to store input in parent component state */
setSearch: (value: string) => void;
/** customizable text for input placeholder */
placeholder?: string;
}

const CollapsibleInput = styled(Input)`
max-width: 0px;
overflow: hidden;
transition: max-width 0.5s ease;
&.show {
max-width: 250px;
}
`;

function SearchInput({ className, setSearch, placeholder = "SEARCH" }: Props) {
const [show, setShow] = React.useState(false);
return (
<Flex className={className} align start>
<CollapsibleInput
className={show && "show"}
onChange={(e: React.ChangeEvent<HTMLInputElement>) =>
setSearch(e.target.value)
}
placeholder={placeholder}
/>
<Spacer padding="xxs" />
<Button onClick={() => setShow(!show)} variant="text" color="inherit">
<Icon type={IconType.SearchIcon} size="medium" color="neutral30" />
</Button>
</Flex>
);
}

export default styled(SearchInput).attrs({ className: SearchInput.name })``;
23 changes: 23 additions & 0 deletions ui/stories/SearchInput.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Meta, Story } from "@storybook/react";
import React from "react";
import SearchInput, { Props } from "../components/SearchInput";

export default {
title: "SearchInput",
component: SearchInput,
parameters: {
docs: {
description: {
component:
"Series of deletable MUI Chip components: https://mui.com/components/chips/",
},
},
},
} as Meta;

const Template: Story<Props> = (args) => {
return <SearchInput {...args} />;
};

export const Default = Template.bind({});
Default.args = {};

0 comments on commit 2da20b3

Please sign in to comment.