Skip to content

Commit fbc0b31

Browse files
committed
Merge branch 'fix-insight-search' of github.com:MicahMaphet/bitcore
2 parents c464b88 + d6223d1 commit fbc0b31

File tree

2 files changed

+86
-19
lines changed

2 files changed

+86
-19
lines changed

packages/insight/src/components/pill.tsx

Lines changed: 65 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,75 @@
1-
import { FC } from 'react';
1+
import {FC} from 'react';
22
import styled from 'styled-components';
33
import CloseLightSvg from 'src/assets/images/close-light.svg'
4-
import {Black, Slate30} from '../assets/styles/colors';
4+
import {Black, White, Slate30} from '../assets/styles/colors';
5+
import {size} from 'src/utilities/constants';
56

67
const PillBubble = styled.div`
7-
padding: 7px;
8-
margin-right: 10px;
98
display: flex;
109
align-items: center;
11-
height: 40px;
10+
height: 38px;
11+
padding-left: 5px;
12+
margin-right: 10px;
13+
14+
@media screen and (max-width: ${size.mobileL}) {
15+
height: 25px;
16+
padding-left: 6px;
17+
margin-right: 5px;
18+
margin-left: -3px;
19+
}
1220
border-radius: 25px;
13-
background: ${Slate30};
21+
background: ${({theme: {dark}}) => dark ? '#333' : Slate30};
1422
`;
1523

1624
const PillCloseButtonCircle = styled.div`
17-
background-color: #D1D4D7;
25+
background-color: ${({theme: {dark}}) => dark ? '#888' : '#D1D4D7'};
26+
border-radius: 100%;
27+
height: 75%;
28+
align-items: center;
29+
justify-content: center;
30+
display: flex;
31+
aspect-ratio: 1;
32+
cursor: pointer;
33+
34+
@media screen and (max-width: ${size.mobileL}) {
35+
height: 60%;
36+
}
37+
`;
38+
39+
const PillCloseButtonScope = styled.div`
40+
background-color: transparent;
1841
border-radius: 100%;
19-
height: 32px;
20-
width: 32px;
42+
height: 100%;
2143
cursor: pointer;
44+
align-items: center;
45+
justify-content: center;
46+
aspect-ratio: 1;
47+
display: flex;
2248
2349
&:hover {
24-
background-color: #B1B4B7;
50+
background-color: ${({theme: {dark}}) => dark ? '#222' : '#D8DBDD'};
51+
}
52+
53+
&:hover ${PillCloseButtonCircle} {
54+
background-color: ${({theme: {dark}}) => dark ? '#B1B4B7' : '#ECEFF2'};
55+
}
56+
`;
57+
58+
const NetworkLabel = styled.span`
59+
text-transform: capitalize;
60+
padding-left: 4px;
61+
color: ${({theme: {dark}}) => dark ? White : Black};
62+
font-size: 16px;
63+
64+
@media screen and (max-width: ${size.mobileL}) {
65+
font-size: 12px;
66+
}
67+
`;
68+
69+
const CurrencyImg = styled.img`
70+
height: 75%;
71+
@media screen and (max-width: ${size.mobileL}) {
72+
height: 60%;
2573
}
2674
`;
2775

@@ -35,11 +83,13 @@ export const Pill: FC<PillProps> = ({ currency, network, onCloseClick }) => {
3583
return (
3684
currency ?
3785
<PillBubble>
38-
<img src={`https://bitpay.com/img/icon/currencies/${currency}.svg`} alt={currency} style={{height: '120%'}} />
39-
<p style={{textTransform: 'capitalize', color: Black, padding: '5px'}}>{network}</p>
40-
<PillCloseButtonCircle onClick={onCloseClick}>
41-
<img src={CloseLightSvg} alt='Close' style={{height: '100%', padding: '9px'}} />
42-
</PillCloseButtonCircle>
86+
<CurrencyImg src={`https://bitpay.com/img/icon/currencies/${currency}.svg`} alt={currency} />
87+
<NetworkLabel>{network}</NetworkLabel>
88+
<PillCloseButtonScope onClick={onCloseClick}>
89+
<PillCloseButtonCircle>
90+
<img src={CloseLightSvg} alt='Close' style={{height: '50%'}} />
91+
</PillCloseButtonCircle>
92+
</PillCloseButtonScope>
4393
</PillBubble>
4494
: null
4595
);

packages/insight/src/components/search.tsx

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {FC, memo, useMemo} from 'react';
1+
import {FC, memo, useEffect, useMemo, useState} from 'react';
22
import {determineInputType, searchValue} from 'src/utilities/search-helper-methods';
33
import {useNavigate} from 'react-router-dom';
44
import styled, {useTheme} from 'styled-components';
@@ -8,6 +8,7 @@ import {LightBlack, Slate} from '../assets/styles/colors';
88
import {useAppDispatch, useAppSelector} from '../utilities/hooks';
99
import {changeCurrency, changeNetwork} from 'src/store/app.actions';
1010
import {Pill} from './pill';
11+
import {size} from 'src/utilities/constants';
1112

1213
const 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+
3644
interface 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

Comments
 (0)