-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fbff5fb
commit c77e261
Showing
5 changed files
with
217 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import React, { PureComponent } from "react"; | ||
import cls from "classnames"; | ||
|
||
export default class CityPicker extends PureComponent { | ||
static defaultProps = { | ||
prefixCls: "cuke-city-picker", | ||
cityList: [] | ||
}; | ||
state = { | ||
selectedCityGroup: "热门", | ||
selectedCityName: "" | ||
}; | ||
|
||
onCityGroupChange = selectedCityGroup => () => { | ||
this.setState({ selectedCityGroup }); | ||
|
||
if (this.props.onCityGroupChange) { | ||
this.props.onCityGroupChange(selectedCityGroup); | ||
} | ||
}; | ||
onCityChange = selectedCity => () => { | ||
this.setState({ selectedCityName: selectedCity.name }); | ||
if (this.props.onCityChange) { | ||
this.props.onCityChange(selectedCity); | ||
} | ||
}; | ||
|
||
render() { | ||
const { cityList, prefixCls } = this.props; | ||
const { selectedCityGroup, selectedCityName } = this.state; | ||
const cityGroups = | ||
cityList.length >= 1 ? cityList.map(({ group }) => group) : []; | ||
|
||
return ( | ||
<div className={`${prefixCls}`}> | ||
<div className={cls(`${prefixCls}-panel`)}> | ||
<div className={cls(`${prefixCls}-panel-header`)}> | ||
<ul className={cls(`${prefixCls}-panel-header-wrap`)}> | ||
{cityGroups.map((cityGroup, i) => { | ||
return ( | ||
<li | ||
onClick={this.onCityGroupChange(cityGroup)} | ||
className={cls("item", { | ||
active: selectedCityGroup === cityGroup | ||
})} | ||
key={i} | ||
> | ||
<span>{cityGroup}</span> | ||
</li> | ||
); | ||
})} | ||
</ul> | ||
</div> | ||
<div className={cls(`${prefixCls}-panel-content`)}> | ||
<ul className={cls(`${prefixCls}-panel-content-wrap`)}> | ||
{cityList.length >= 1 && | ||
cityList | ||
.find(item => item.group === selectedCityGroup) | ||
.resources.map((city, i) => { | ||
return ( | ||
<li | ||
className={cls("city", { | ||
selected: selectedCityName === city.name | ||
})} | ||
key={i} | ||
onClick={this.onCityChange(city)} | ||
> | ||
{city.name} | ||
</li> | ||
); | ||
})} | ||
</ul> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
} | ||
} |
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,93 @@ | ||
@import "../styles/vars.less"; | ||
|
||
@prefixCls : cuke-city-picker; | ||
.@{prefixCls} { | ||
width: 379px; | ||
border: 1px solid @border-color; | ||
box-shadow: @default-shadow; | ||
&-title { | ||
padding: 16px 0 5px; | ||
text-align: center; | ||
} | ||
&-panel { | ||
@address-select-section-header-height: 42px; | ||
min-height: 221px; | ||
background-color: #fff; | ||
padding: 5px 17px 10px 17px; | ||
|
||
&-header { | ||
height: @address-select-section-header-height; | ||
line-height: @address-select-section-header-height; | ||
color: @font-color; | ||
position: relative; | ||
|
||
&::before { | ||
content: ' '; | ||
position: absolute; | ||
width: 100%; | ||
height: 1px; | ||
transform: scaleY(.5); | ||
transform-origin: 50% 100%; | ||
background-color: @border-color; | ||
left: 0; | ||
top: 100%; | ||
} | ||
|
||
&-wrap { | ||
display: flex; | ||
align-items: center; | ||
justify-content: space-between; | ||
.item { | ||
cursor: pointer; | ||
transition: all @default-transition; | ||
position: relative; | ||
|
||
&:hover { | ||
color: @primary-color; | ||
} | ||
|
||
&.active { | ||
color: @primary-color; | ||
|
||
&::after { | ||
content: ' '; | ||
position: absolute; | ||
width: 100%; | ||
height: 2px; | ||
background-color: @primary-color; | ||
left: 0; | ||
bottom: -1px; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
&-content { | ||
|
||
&-wrap { | ||
padding-top: 25px; | ||
display: flex; | ||
flex-wrap: wrap; | ||
align-items: center; | ||
|
||
.city { | ||
cursor: pointer; | ||
margin-bottom: 16px; | ||
transition: all @default-transition; | ||
|
||
&:not(:nth-child(5n)) { | ||
margin-right: 51px; | ||
} | ||
|
||
&:hover { | ||
color: @primary-color; | ||
} | ||
|
||
&.selected { | ||
color: @primary-color; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
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