Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Collapsible Search Input #1464

Merged
merged 2 commits into from
Feb 18, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions ui/components/Icon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,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 @@ -40,6 +41,7 @@ export enum IconType {
FilterIcon,
ClearIcon,
Circle,
SearchIcon,
}

type Props = {
Expand Down Expand Up @@ -110,6 +112,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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

馃槏

&.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 = {};