demo.js 2.5 KB
Newer Older
Y
yiminghe 已提交
1
window['css-animation'] = require('css-animation');
2
window['react-router'] = require('react-router');
Y
beta2  
yiminghe 已提交
3
var antd = require('../index');
Y
yiminghe 已提交
4
var React = require('react');
Y
beta2  
yiminghe 已提交
5
var ReactDOM = require('react-dom');
A
afc163 已提交
6
var semver = require('semver');
Y
beta2  
yiminghe 已提交
7 8 9
window.antd = antd;
window.React = React;
window.ReactDOM = ReactDOM;
Y
yiminghe 已提交
10

A
afc163 已提交
11 12
InstantClickChangeFns.push(function () {
  // auto complete for components
Y
yiminghe 已提交
13 14 15
  var Select = antd.Select;
  var Option = Select.Option;
  // 获取搜索数据
Y
beta2  
yiminghe 已提交
16
  var searchData = window.ANT_COMPONENTS.sort(function (a, b) {
Z
zhujun24 已提交
17 18
    return a.title.localeCompare(b.title);
  });
Y
yiminghe 已提交
19 20 21 22

  var AutoComplete = React.createClass({
    getOptions() {
      return searchData.map(function (s) {
A
afc163 已提交
23
        return <Option sData={s} key={s.title} text={'跳转到 ' + s.title}>
Y
yiminghe 已提交
24
          <strong>{s.title}</strong>
Y
beta2  
yiminghe 已提交
25
          &nbsp;
26
          <span className="ant-component-decs">{s.desc}</span>
Y
yiminghe 已提交
27 28 29 30 31
        </Option>;
      });
    },

    handleSelect(value) {
A
afc163 已提交
32
      location.href = rootUrl + '/components/' + value.replace(/([a-z])([A-Z])/g, function (m, m1, m2) {
Y
beta2  
yiminghe 已提交
33 34
          return m1 + '-' + m2;
        }).toLowerCase() + '/';
Y
yiminghe 已提交
35 36 37 38 39 40 41
    },

    filterOption(input, option) {
      return option.props.sData.title.toLowerCase().indexOf(input.toLowerCase()) !== -1 || option.props.sData.desc.indexOf(input) !== -1;
    },

    render() {
A
afc163 已提交
42
      return <Select combobox style={{width: '100%'}}
Y
beta2  
yiminghe 已提交
43 44 45 46 47
                     onSelect={this.handleSelect}
                     optionLabelProp="text"
                     dropdownClassName="autoComplete"
                     searchPlaceholder="搜索组件..."
                     filterOption={this.filterOption}>{this.getOptions()}</Select>;
Y
yiminghe 已提交
48 49 50
    }
  });

Y
yiminghe 已提交
51
  ReactDOM.render(<AutoComplete/>, document.getElementById('autoComplete'));
Y
yiminghe 已提交
52 53
});

54 55
InstantClickChangeFns.push(function () {
  var versionsHistory = {
A
afc163 已提交
56
    '0.9.2': '09x.ant.design'
57 58 59
  };
  versionsHistory[antdVersion.latest] =
    versionsHistory[antdVersion.latest] || 'http://ant.design';
Y
beta2  
yiminghe 已提交
60
  var versions = Object.keys(versionsHistory).sort(function (a, b) {
A
afc163 已提交
61 62
    return semver.lt(a, b);
  });
Y
beta2  
yiminghe 已提交
63
  var options = versions.map(function (version) {
64
    var link = versionsHistory[version];
A
afc163 已提交
65
    return <option key={version} value={version}>{version}</option>;
66
  });
Y
beta2  
yiminghe 已提交
67

68 69
  function onChange(e) {
    if (versionsHistory[e.target.value]) {
A
afc163 已提交
70
      location.href = location.href.replace(location.host, versionsHistory[e.target.value]);
71 72
    }
  }
Y
beta2  
yiminghe 已提交
73

Y
yiminghe 已提交
74
  ReactDOM.render(<select defaultValue={antdVersion.latest}
Y
beta2  
yiminghe 已提交
75
                       onChange={onChange}>{options}</select>, document.getElementById('versions-select'));
76 77
});

Y
fix umd  
yiminghe 已提交
78
module.exports = antd;