-
Notifications
You must be signed in to change notification settings - Fork 142
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Collapsible Search Input (#1464)
* created collapsed input * resolve icon conflict
- Loading branch information
1 parent
eb18492
commit 2da20b3
Showing
3 changed files
with
72 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 })``; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = {}; |