You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

6.8 KiB

order title
1 Getting Started

Ant Design React is dedicated to providing a good development experience for programmers.


Before delving into Ant Design React, a good knowledge of React and JavaScript ES2015 is needed.

First Example

The following CodePen demo is the simplest usage case, and it's also a good habit to fork this demo to provide a re-producible demo while reporting a bug. Please don't use this demo as a scaffold in real world.

Standard Development Flow

During development, you may need to compile and debug JSX and ES2015 code, and even proxy some of the request to mocked data or some external services. And all of these to be done with a quick feedback provided through hot reloading of changes.

Such features, together with packaging the production version are covered in this work flow.

1. Installation

Please make sure that you had installed Node.js(> v4.x) before using antd-init.

$ npm install antd-init -g

Read the documentation of antd-init and the documentation of ant-tool to explore more features.

Also, you can use scaffold/demo which is provided by community:

2. Create a New Project

A new project can be created using CLI tools.

$ mkdir antd-demo && cd antd-demo
$ antd-init

antd-init will run npm install after a project is created. If it fails, you can run npm install by yourself.

3. Use antd's Components

By default, besides the scaffolding needed to start the development, a fully working Todo application is created. You may study this example later. For now, just follow this guide in order to get some experience working with the result of antd-init.

Replace the content of index.js with the following code. As you can see, there is no difference between antd's components and usual React components.

import React from 'react';
import ReactDOM from 'react-dom';
import { DatePicker, message } from 'antd';

class App extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      date: '',
    };
  }
  handleChange(date) {
    message.info('Selected Date: ' + date.toString());
    this.setState({ date });
  }
  render() {
    return (
      <div style={{ width: 400, margin: '100px auto' }}>
        <DatePicker onChange={value => this.handleChange(value)} />
        <div style={{ marginTop: 20 }}>Date: {this.state.date.toString()}</div>
      </div>
    );
  }
}

ReactDOM.render(<App />, document.getElementById('root'));

All the components in antd are listed in the sidebar.

4. Development & Debugging

Run your project and visit http://127.0.0.1:8000

$ npm start

5. Building & Deployment

$ npm run build

Entry files will be built and generated in dist directory, then we can deploy it to different environments.

This guide is designed to help you to understand how to use antd, so it may not be similar to what you do in the real world. But you can use those tools in your project, depending on your context and needs.

Compatibility

Ant Design React supports all the modern browsers and IE8+.

But we need to provide es5-shim and other polyfills for IE8/9, and babel-polyfill is a better choice. What's more, use react@0.14.x to support IE8.

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <!-- import stylesheet -->
    <link rel="stylesheet" href="/index.css">
    <!-- Polyfills -->
    <!--[if lt IE 10]>
    <script src="https://as.alipayobjects.com/g/component/??console-polyfill/0.2.2/index.js,es5-shim/4.5.7/es5-shim.min.js,es5-shim/4.5.7/es5-sham.min.js,html5shiv/3.7.2/html5shiv.min.js,media-match/2.0.2/media.match.min.js"></script>
    <![endif]-->
  </head>
  <body>
  </body>
  <!-- import common dependencies -->
  <script src="/common.js"></script>
  <!-- import entry file -->
  <script src="/index.js"></script>
</html>

You may encounter problems like #28 and #858, since babel@6.x doesn't support IE8.

antd-init had solved those problems and you can refer to this webpack config.

More about how to use React in IE8: https://github.com/xcatliu/react-ie8

Customized Work Flow

If you want to customize your work flow, we recommend to use webpack to build and debug code.

Also, you can use any scaffold available in React ecosystem. If you encounter problems, you can use our webpack config and modify it.

There are some scaffolds which have already integrated antd, so you can try and start with one of these, and even contribute.

Import on Demand

If we import a component like this import { Button } from 'antd';, then all the components of antd will be imported. But, we can import component on demand:

import Button from 'antd/lib/button';

If you use babel, we recommend to use babel-plugin-import. This plugin will convert the following code to the above form:

import { Button } from 'antd';

And this plugin can also load styles on demand. See the usage for further details.

Customization

Tips

  • You can use any npm modules.
  • We recommend to write code in ES2015 as babel has been integrated in our work flow.