# react-select-city

> React Select City Componet

Latest version **1.0.1** (published 2018-08-05) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install react-select-city
pnpm add react-select-city
yarn add react-select-city
bun add react-select-city
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2018-08-05 |
| First published | 2018-08-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 116.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | BrightChen |
| Maintainers | w3cay |
| Keywords | city-select, react-city-select, react-component, react |

## Links

- npm: https://www.npmjs.com/package/react-select-city
- Repository: git@git.chelun.com:frontend/h5.chelun.com
- Homepage: https://github.com/chelun-h5/react-city-select
- npm.io page: https://npm.io/package/react-select-city

## Dependencies (1)

- [prop-types](https://npm.io/package/prop-types.md) ^15.6.2

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 1.0.1 (latest) — 2018-08-05

## README

# react-city-select
基于 React 的可配置化城市选择组件


示例： https://chelun-h5.github.io/react-city-select/example/

使用：

```javascript
...
// 引入 CitySelect 组件
import CitySelect from 'react-city-select';

// 引入数据
import data from './data.json';

// 引入图标路径
import iconSrc from './location_icon@2x.png';

export default class APP extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      // 结构化城市列表数据
      citysData: data.indexCitys, 
      // 对某项数据定制化配置
      config: {
        pos: {
          icon: iconSrc, // 游标图标
          title: '定位城市',
        },
        hot: {
          title: '热门城市',
          key: '热门',
          style: 'grid', // 展示形式（ line || grid）
        }
      }
    };
  }

  // 选中城市回调
  handleSelectCity(cityData) {
    console.log('选中数据项:', cityData);
  }

  render() {
    return (
      <CitySelect
        // 传入数据
        data={this.state.citysData}
        // 传入配置
        config={this.state.config}
        // 传入回调
        onSelectItem={this.handleSelectCity.bind(this)}>
      </CitySelect>
    )
  }
}
```
### props 参数 

属性 | 值 | 说明
---|---|---
data | 必填；对象；| 城市组件数据JSON对象
config | 可选；对象；| 配置或覆盖某个 key 下的值，详情见下表
onSelectItem | 必填；函数；| 点击单元格数据回调

### config 参数



属性 | 值 | 说明
---|---|---
config['sec-key']['title'] | 可选；字符串；| 索引标题
config['sec-key']['key'] | 可选；字符串；| 游标标题
config['sec-key']['icon'] | 可选；字符串；| 游标图标（替代标题）
config['sec-key']['style'] | 可选；字符串；(line或grid) | 数据项展示方式

sec-key : 对象key


### data 数据格式

```JSON
   
// 定位数据项
"pos": [{
  "id": "110100",
  "name": "北京"
}],
// 热门数据项
"hot": [{
    "id": "110100",
    "name": "北京"
  },
  {
    "id": "120100",
    "name": "天津"
  },
  {
    "id": "130100",
    "name": "石家庄"
  }
],
// 字母数据项
"A": [{
    "id": "152900",
    "name": "阿拉善盟"
  },
  {
    "id": "210300",
    "name": "鞍山"
  }
],
"B": [{
    "id": "110100",
    "name": "北京"
  },
  {
    "id": "130600",
    "name": "保定"
  }
]
...
```

---
_Source: https://npm.io/package/react-select-city · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
