File size: 2,370 Bytes
f5071ca |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
import React, { useState } from 'react';
import styled from 'styled-components';
import searchBarClearUrl from '../../icons/searchBarClear.svg';
import searchBarEyeGlassUrl from '../../icons/searchBarEyeGlass.svg';
const StyledHeaderSearchBar = styled.div`
margin: 0 4px 0 8px;
height: 28px;
width: ${props => (props.expanded ? '244px' : '144px')};
display: flex;
transition: width 0.2s ease-in-out 0.1s;
background-color: hsla(0, 0%, 100%, 0.1);
border-radius: 3px;
&:focus-within {
width: 244px;
}
.input-wrapper {
margin: 5px 0;
flex: 1 1 auto;
}
input {
padding: 0;
border: 0;
background: 0;
width: 100%;
height: 100%;
outline: none;
white-space: pre-wrap;
overflow-wrap: break-word;
color: #fff;
font-size: 0.85em;
margin: 0 6px;
::placeholder {
color: rgba(255, 255, 255, 0.4);
}
}
.icon-wrapper {
margin: 4px 5px;
width: 18px;
position: relative;
display: flex;
align-items: center;
justify-content: center;
flex: 0 0 auto;
i {
width: 18px;
height: 18px;
display: block;
position: absolute;
opacity: 0;
transition: all 0.1s linear;
z-index: 1;
&.visible {
opacity: 0.3;
z-index: 2;
}
}
.searchBarClear {
cursor: pointer;
background-image: url(${searchBarClearUrl});
&.visible {
transform: rotate(90deg);
}
:hover {
opacity: 0.6;
}
}
.searchBarEyeGlass {
background-image: url(${searchBarEyeGlassUrl});
&.visible {
transform: rotate(0deg);
}
}
}
`;
const HeaderSearchBar = () => {
const [text, setText] = useState('');
const hasText = !!text;
return (
<StyledHeaderSearchBar expanded={hasText}>
<div className="input-wrapper">
<input
type="text"
placeholder="Search"
onChange={(e) => setText(e.target.value)}
value={text}
/>
</div>
<div className="icon-wrapper" role="button">
<i className={`searchBarEyeGlass ${!hasText ? 'visible' : ''}`} />
<i
className={`searchBarClear ${hasText ? 'visible' : ''}`}
onClick={() => setText('')}
/>
</div>
</StyledHeaderSearchBar>
);
}
export default HeaderSearchBar; |