Skip to content

Commit

Permalink
feat: CityPicker 新增 defaultCityName
Browse files Browse the repository at this point in the history
  • Loading branch information
lijinke666 committed Dec 25, 2018
1 parent f7c9b7e commit b0772ef
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ exports[`<Calendar/> should render a <Calendar/> components 1`] = `
/>
</span>
<span
class="cuke-calendar-item cuke-calendar-current-month cuke-calendar-selected-date"
class="cuke-calendar-item cuke-calendar-current-month"
>
11
<div
Expand Down Expand Up @@ -296,7 +296,7 @@ exports[`<Calendar/> should render a <Calendar/> components 1`] = `
/>
</span>
<span
class="cuke-calendar-item cuke-calendar-current-month"
class="cuke-calendar-item cuke-calendar-current-month cuke-calendar-selected-date"
>
25
<div
Expand Down
5 changes: 4 additions & 1 deletion components/cityPicker/CityPicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default class CityPicker extends PureComponent {
visible: null,
selectedCityGroup:
this.props.defaultActiveGroup || this.props.activeGroup || 0,
selectedCityName: ""
selectedCityName: this.props.defaultCityName || this.props.cityName || ""
};
static defaultProps = {
prefixCls: "cuke-city-picker",
Expand All @@ -33,6 +33,8 @@ export default class CityPicker extends PureComponent {
PropTypes.string,
PropTypes.number
]),
defaultCityName: PropTypes.string,
cityName: PropTypes.string,
disabledGroups: PropTypes.array,
activeGroup: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
disabled: PropTypes.bool,
Expand Down Expand Up @@ -138,6 +140,7 @@ export default class CityPicker extends PureComponent {
cityList={cityList}
onCityChange={this.onCityChange}
defaultActiveGroup={selectedCityGroup}
defaultCityName={selectedCityName}
onCityGroupChange={this.onCityGroupChange}
disabledGroups={disabledGroups}
loading={loading}
Expand Down
2 changes: 1 addition & 1 deletion components/cityPicker/CityPickerCore.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export default class CityPickerCore extends PureComponent {
state = {
selectedCityGroup:
this.props.defaultActiveGroup || this.props.activeGroup || 0,
selectedCityName: ""
selectedCityName: this.props.defaultCityName || this.props.cityName || ""
};

onCityGroupChange = (selectedCityGroup, index) => () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ exports[`<CityPicker/> should render CityPicker 1`] = `
>
<div
class="cuke-city-picker-core"
defaultcityname=""
>
<div
class="cuke-city-picker-core-panel"
Expand Down
21 changes: 20 additions & 1 deletion components/cityPicker/__tests__/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,32 @@ describe("<CityPicker/>", () => {
assert(wrapper.find(CityPickerCore).length === 1);
});

it("should render custom number active city group", () => {
it("should render custom default active city group", () => {
const wrapper = shallow(
<CityPicker cityList={cityList} defaultActiveGroup={2} />
);
assert(wrapper.state().selectedCityGroup === 2);
});

it("should render custom active city group", () => {
const wrapper = shallow(<CityPicker cityList={cityList} activeGroup={2} />);
assert(wrapper.state().selectedCityGroup === 2);
});

it("should render custom default city name", () => {
const wrapper = shallow(
<CityPicker cityList={cityList} defaultCityName={"成都"} />
);
assert(wrapper.state().selectedCityName === "成都");
});

it("should render custom city name", () => {
const wrapper = shallow(
<CityPicker cityList={cityList} cityName={"成都"} />
);
assert(wrapper.state().selectedCityName === "成都");
});

it("should render custom string active city group ", () => {
const wrapper = shallow(
<CityPicker cityList={cityList} defaultActiveGroup={"热门"} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ exports[`<DatePicker/> should render a <DatePicker/> components 1`] = `
10
</span>
<span
class="cuke-date-picker-item cuke-date-picker-current-month cuke-date-picker-selected-date"
class="cuke-date-picker-item cuke-date-picker-current-month"
>
11
</span>
Expand Down Expand Up @@ -627,7 +627,7 @@ exports[`<DatePicker/> should render a <DatePicker/> components 1`] = `
24
</span>
<span
class="cuke-date-picker-item cuke-date-picker-current-month"
class="cuke-date-picker-item cuke-date-picker-current-month cuke-date-picker-selected-date"
>
25
</span>
Expand Down
3 changes: 3 additions & 0 deletions stories/dataDisplay.js
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,9 @@ storiesOf("数据展示", module)
<h2>默认选中分组</h2>
<CityPicker defaultActiveGroup={1} cityList={cityList} />

<h2>默认选中城市</h2>
<CityPicker defaultActiveGroup={1} cityList={cityList} defaultCityName="成都"/>

<h2>加载中</h2>
<CityPicker cityList={cityList} loading />

Expand Down
7 changes: 0 additions & 7 deletions stories/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,6 @@ storiesOf("综述", module).add("介绍", () => (
/>
</a>
{" "}
<a href="https://www.npmjs.com/package/cuke-ui" title="npm">
<img
src="https://img.shields.io/npm/l/cuke-ui.svg?style=for-the-badge"
alt="npm"
/>
</a>
{" "}
<a href="https://isitmaintained.com/project/cuke-ui/cuke-ui">
<img src="https://img.shields.io/github/issues/cuke-ui/cuke-ui.svg?style=for-the-badge" />
</a>
Expand Down

0 comments on commit b0772ef

Please sign in to comment.