1- import { FC , memo , useMemo } from 'react' ;
1+ import { FC , memo , useEffect , useMemo , useState } from 'react' ;
22import { determineInputType , searchValue } from 'src/utilities/search-helper-methods' ;
33import { useNavigate } from 'react-router-dom' ;
44import styled , { useTheme } from 'styled-components' ;
@@ -8,6 +8,7 @@ import {LightBlack, Slate} from '../assets/styles/colors';
88import { useAppDispatch , useAppSelector } from '../utilities/hooks' ;
99import { changeCurrency , changeNetwork } from 'src/store/app.actions' ;
1010import { Pill } from './pill' ;
11+ import { size } from 'src/utilities/constants' ;
1112
1213const SearchInput = styled . input `
1314 background: none;
@@ -33,6 +34,13 @@ const SearchForm = styled.form<{ borderBottom?: boolean }>`
3334 borderBottom ? `1px solid ${ colors . borderColor } ` : 'none' } ;
3435` ;
3536
37+ const SearchImg = styled . img `
38+ padding: 7px;
39+ @media screen and (max-width: ${ size . mobileL } ) {
40+ margin-left: -8px;
41+ }
42+ ` ;
43+
3644interface SearchProps {
3745 borderBottom ?: boolean ;
3846 id ?: string ;
@@ -44,15 +52,21 @@ const Search: FC<SearchProps> = ({borderBottom, id, setErrorMessage}) => {
4452 const theme = useTheme ( ) ;
4553 const dispatch = useAppDispatch ( ) ;
4654 const { currency, network} = useAppSelector ( ( { APP } ) => APP ) ;
55+ const [ isMobile , setIsMobile ] = useState ( window . innerWidth < Number ( size . mobileL . slice ( 0 , - 2 ) ) ) ;
4756
4857 const searchIcon = theme . dark ? SearchDarkSvg : SearchLightSvg ;
4958 const searchId = id || 'search' ;
5059
60+ useEffect ( ( ) => {
61+ window . addEventListener ( 'resize' , ( ) => {
62+ setIsMobile ( window . innerWidth < Number ( size . mobileL . slice ( 0 , - 2 ) ) ) ;
63+ } ) ;
64+ } , [ ] ) ;
65+
5166 const search = async ( event : any ) => {
5267 event . preventDefault ( ) ;
5368 setErrorMessage ( '' ) ;
5469 const searchVal = event . target [ searchId ] . value . replace ( / \s / g, '' ) ;
55-
5670 const searchInputs = await determineInputType ( searchVal ) ;
5771 if ( searchInputs . length ) {
5872 try {
@@ -155,15 +169,18 @@ const Search: FC<SearchProps> = ({borderBottom, id, setErrorMessage}) => {
155169 const searchInputPlaceholder = useMemo ( ( ) => {
156170 let placeholder = 'Search for block, transaction, or address' ;
157171 if ( currency && network ) {
172+ if ( isMobile ) {
173+ placeholder = 'Search' ;
174+ }
158175 placeholder = `${ placeholder } on ${ currency } ${ network } ` ;
159176 }
160177 return placeholder ;
161- } , [ currency , network ] ) ;
178+ } , [ currency , network , isMobile ] ) ;
162179
163180 return (
164181 < SearchForm onSubmit = { search } borderBottom = { borderBottom } >
165182 < span style = { { display : 'flex' , alignItems : 'center' } } >
166- < img src = { searchIcon } alt = 'Search' style = { { padding : 7 } } > </ img >
183+ < SearchImg src = { searchIcon } alt = 'Search' / >
167184 < Pill currency = { currency } network = { network } onCloseClick = { handlePillCloseButtonClick } />
168185 < SearchInput
169186 id = { id || 'search' }
0 commit comments