Skip to content

Commit 20879d6

Browse files
committed
remove unused code,add logic of hidden search
1 parent 15c096f commit 20879d6

7 files changed

+197
-316
lines changed

package-lock.json

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
"@types/react-transition-group": "^2.0.11",
6969
"@types/react-virtualized": "^9.7.10",
7070
"@types/webpack-env": "^1.13.6",
71+
"@types/lodash": "^4.14.116",
7172
"babel-core": "^6.26.3",
7273
"fontfaceobserver": "^2.0.13",
7374
"history": "^4.7.2",

src/CountryData.ts

Whitespace-only changes.

src/OldCode.tsx

-173
This file was deleted.

src/country-menu-item.tsx

-50
This file was deleted.

src/countryMenuItem.tsx

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import * as React from "react";
2+
import MenuItem from "@material-ui/core/MenuItem/MenuItem"
3+
import Grid from "@material-ui/core/Grid/Grid"
4+
import Icon from "@material-ui/core/Icon/Icon"
5+
import Typography from "@material-ui/core/Typography"
6+
7+
const styles = {
8+
countryName: {
9+
fontSize: "1em",
10+
paddingLeft: "0.5em",
11+
fontFamily: "AvertaCY"
12+
},
13+
dialNumber: {
14+
marginLeft: "auto",
15+
fontSize: "1em",
16+
fontFamily: "AvertaCY",
17+
},
18+
countryCode: {
19+
color: "#1D0047",
20+
fontSize: "1em",
21+
},
22+
countryNameList: {
23+
color: "#1D0047", fontSize: "1em", fontWeight: 300
24+
}
25+
}
26+
27+
export interface CountryItemProps extends CountryDataItem {
28+
flagSVG: string;
29+
name: string;
30+
search: string;
31+
32+
onClick: (event: any) => void
33+
}
34+
35+
export interface CountryDataItem {
36+
countryCode: number;
37+
}
38+
39+
export class CountryMenuItem extends React.Component<CountryItemProps, {}> {
40+
41+
state = {
42+
value: this.props.countryCode
43+
}
44+
45+
highlightSearch(name: string, search: string) {
46+
if (search) {
47+
const parts = name.split(new RegExp(`(${search})`, "gi"))
48+
return <Typography style={styles.countryNameList}>
49+
{parts.map((part, index) => part.toLowerCase() === search.toLowerCase() ?
50+
<b key={index}>{part}</b> : part)}</Typography>
51+
}
52+
return <Typography style={styles.countryNameList}>{name}</Typography>
53+
}
54+
55+
render() {
56+
const {onClick, flagSVG, countryCode, name, search} = this.props
57+
return name.toLowerCase().indexOf(search.toLowerCase()) != -1 &&
58+
<MenuItem onClick={onClick} key={countryCode} style={{padding: "0.5em"}}>
59+
<Grid container direction="row">
60+
<Grid item>
61+
<Icon>{flagSVG}</Icon>
62+
</Grid>
63+
<Grid item style={styles.countryName}>
64+
{this.highlightSearch(name, search)}
65+
</Grid>
66+
<Grid item style={styles.dialNumber}>
67+
<Typography style={styles.countryCode}>{countryCode}</Typography>
68+
</Grid>
69+
</Grid>
70+
</MenuItem>
71+
}
72+
73+
}

0 commit comments

Comments
 (0)