-
Notifications
You must be signed in to change notification settings - Fork 312
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3816 from ivanko22/searchBoxStorybook
Search box storybook
- Loading branch information
Showing
10 changed files
with
185 additions
and
102 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file was deleted.
Oops, something went wrong.
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,25 @@ | ||
import React from 'react'; | ||
import styled from 'styled-components'; | ||
import BaseSearchbox from '../../components/Search/BaseSearchbox'; | ||
|
||
export default { | ||
title: 'Design System/Inputs', | ||
component: BaseSearchbox, | ||
parameters: { | ||
layout: 'centered', | ||
}, | ||
}; | ||
|
||
const Container = styled.div` | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
height: 100vh; | ||
width: 340px; | ||
`; | ||
|
||
export const Searchbox = () => ( | ||
<Container> | ||
<BaseSearchbox placeholder="Search by name, office or state"/> | ||
</Container> | ||
); |
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
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,122 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import styled from 'styled-components'; | ||
import colors from '../../common/components/Style/Colors'; | ||
import searchIcon from '../../../img/global/icons/search.svg'; | ||
import closeIcon from '../../../img/global/icons/cross.svg'; | ||
|
||
const SearchWrapper = styled.div` | ||
position: relative; | ||
display: inline-block; | ||
width: 100%; | ||
`; | ||
|
||
const SearchIcon = styled.div` | ||
position: absolute; | ||
top: 50%; | ||
right: 10px; | ||
transform: translateY(-50%); | ||
color: gray; | ||
background-image: url(${searchIcon}); | ||
background-repeat: no-repeat; | ||
background-position: center; | ||
background-size: contain; | ||
width: 24px; | ||
height: 24px; | ||
`; | ||
|
||
const ClearButton = styled.div` | ||
position: absolute; | ||
right: 12px; | ||
top: 50%; | ||
transform: translateY(-50%); | ||
background-image: url(${closeIcon}); | ||
background-repeat: no-repeat; | ||
background-position: center; | ||
background-size: contain; | ||
width: 18px; | ||
height: 18px; | ||
cursor: pointer; | ||
`; | ||
|
||
const SearchInput = styled.input` | ||
&::-webkit-search-decoration, | ||
&::-webkit-search-cancel-button, | ||
&::-webkit-search-results-button, | ||
&::-webkit-search-results-decoration { | ||
display: none; | ||
} | ||
border: none; | ||
height: 38px; | ||
width: 100%; | ||
border: 1px solid rgb(206, 212, 218); | ||
border-radius: 0.25rem; | ||
padding-right: 40px; | ||
padding-left: 12px; | ||
border-radius: 0.25rem; | ||
padding-right: 40px; | ||
&:focus-visible { | ||
border: none; | ||
outline: ${colors.primary} solid 2px !important; | ||
} | ||
`; | ||
|
||
class BaseSearchbox extends React.Component { | ||
constructor(props) { | ||
super(props); | ||
this.state = { searchText: '' }; | ||
} | ||
|
||
handleInputChange = (event) => { | ||
this.setState({ searchText: event.target.value }, () => { | ||
if (this.props.onChange) { | ||
this.props.onChange(event); | ||
} | ||
if (this.props.onKeyDown) { | ||
this.props.onKeyDown(event); | ||
} | ||
if(this.props.onFocus) { | ||
this.props.onFocus(event); | ||
} | ||
}); | ||
} | ||
|
||
handleClear = () => { | ||
this.setState({ searchText: '' }, () => { | ||
if (this.props.onClear) { | ||
this.props.onClear(); | ||
} | ||
}); | ||
} | ||
|
||
render() { | ||
return ( | ||
<SearchWrapper> | ||
{!this.state.searchText && <SearchIcon />} | ||
<SearchInput | ||
type="search" | ||
placeholder={this.props.placeholder} | ||
value={this.state.searchText} | ||
onChange={this.handleInputChange} | ||
onClear={this.handleClear} | ||
maxLength={50} | ||
/> | ||
{this.state.searchText && <ClearButton onClick={this.handleClear}/>} | ||
</SearchWrapper> | ||
); | ||
} | ||
} | ||
|
||
BaseSearchbox.propTypes = { | ||
placeholder: PropTypes.string, | ||
onChange: PropTypes.func, | ||
onKeyDown: PropTypes.func, | ||
onFocus: PropTypes.func, | ||
onBlur: PropTypes.func, | ||
onClear: PropTypes.func, | ||
}; | ||
|
||
export default BaseSearchbox; |
Oops, something went wrong.