Giter Site home page Giter Site logo

1520306916 / react-address-picker Goto Github PK

View Code? Open in Web Editor NEW

This project forked from shenghanqin/react-address-picker-cc

0.0 1.0 0.0 2.68 MB

仿京东移动端地址选择组件 mobile/pc

Home Page: https://www.xiaoxili.com/react-address-picker/

License: MIT License

HTML 1.07% JavaScript 86.62% CSS 12.32%

react-address-picker's Introduction

react-address-picker-cc

  • 仿京东移动端地址选择组件
  • 适配触屏和PC
  • 有异步获取收货地址的方法

NPM JavaScript Style Guide

Install

npm install --save react-address-picker-cc

Example

cd examples
npm start

Usage

import React, { Component } from 'react'
import AddressPicker from 'react-address-picker-cc'
import { district } from './district';


export default class Sync extends Component {
  state = {
    address: '',
    dataSource: district,
    selectedIdList: [340000, 341800, 341824]

  }

  showPicker = () => {
    this.ecRef.show()
  }
  
  hidePicker = () => {
    this.ecRef.hide()
  }

  onAddressChange = (selectedRows) => {
    this.setState({
      address: selectedRows.map(item => item.areaName).join(','),
      selectedIdList: selectedRows.map(item => item.id),
    })
    console.log('选择值:', selectedRows)
  }

  
  render () {
    const { dataSource } = this.state
    return (
      <div>
        <h1>同步获取</h1>
        <input onClick={this.showPicker} value={this.state.address} placeholder="请选择地区" readOnly style={{ width: '100%' }} />
        <AddressPicker 
          dataSource={dataSource}
          text='这是收货地址组件'
          ref={e => (this.ecRef = e)}
          onAddressChange={this.onAddressChange}
          onClose={this.hidePicker}
        />
      </div>
    )
  }
}

Props

属性名 类型 默认值 描述
title String | node 配送至 标题
className String 跟节点class
dataSource array 数据源
onClose Function 关闭时回调函数
onAddressChange Function 选择完闭时的回调函数; (selectedRows) => {}
navTips string 请选择 下一项的提示文字
pickerStatusChange Function Picker展开收齐的回调;(status) => {}
selectedIdList array 初始化地址的id数组
isAsyncData boolean 是否异步获取数据
asyncIdOne Number 异步数据返回的一级id,isAsyncData后有效
getOneLevelData Function 获取第二、三层数据的方法,isAsyncData后有效

参考链接

借鉴了同行的组件 (https://github.com/LANIF-UI/react-picker-address)

License

MIT © https://github.com/shenghanqin/

react-address-picker's People

Contributors

shenghanqin avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.