Skip to main content

Introduction to Ant Design

ant design

Introduction

In a discussion about top frontend design languages, Material Design by Google is one of the most popular contenders for the favorite spot, but there is a close, maybe lesser-known, competitor, that is Ant Design. With some of the big players in their respective industries like AlibabaTencentBaidu all using Ant Design, let’s explore some of the key features that make Ant Design special compared to others.

The design principles of Ant Design

Ant design, according to its own design values page, focusses on a user experience that is:
  • Natural — a visual interaction that is devoid of complexity and feels natural to use
  • Certain —  establish design rules such that it avoids low-efficiency & difficult-to-maintain products
  • Meaningful —  design interfaces keeping the needs of the end-user in mind
  • Growing — design interfaces that improve the discoverability of functions and values of the product

Strongly opinionated

While providing guides on most of the styling needs for user interface design like colorslayoutfonticons, Ant Design also lays down certain best practices with respect to several visual design principles and clearly marks out the good from the badones. Here are a couple of examples from their reference docs:

Text alignment

alignment

Contrast

contrast

Iconography & typography

Ant Design also provides full-fledged in-house support for iconsand typography and it’s quite easy to incorporate in the project too. For instance, in order to use the provided icons in your project, all that needs to be done is:
npm install --save @ant-design/icons
to install the icon pack:
import { HomeOutlined } from '@ant-design/icons'
ReactDOM.render(<div><HomeOutlined /></div>, mountNode);

Layout support

Ant Design provides its own alternatives to CSS Flexbox implementation for laying out UI items and to maintain a fluid and responsive user interface. For the same purpose, Ant Design provides row and column components that can be used as alternatives to equivalent divs with flex-direction row and column respectively. For managing size, it accepts a span prop similar to what Bootstrap does:
<Row>
  <Col span={12}>col-12</Col>
  <Col span={12}>col-12</Col>
</Row>
In addition to that, Ant design provides some of the most common layouts, with Navigation Bar, Side Menu, BreadCrumbs, and the main layout area (with different styles) as standard boilerplate that one can use straight away in the project. For example, the layout below can be easily achieved by copying the boilerplate code from their official docs page.

Extensive component support

 Common components

Some of the most widely used form elements are of course available for use with a huge variety of customization options. Here are a few examples along with the code to create generic versions of them.

Text input

text input
// component code
<Input 
  size="large" 
  value={this.state.inputVal}
  placeholder="large size"
  onChange={(e) => this.setState({ inputVal: e.target.value })}
  prefix={<UserOutlined />} // prefixes the user image at the beginning
/>

Checkbox

check box

// on change handler
onChange = e => {
  this.setState({
    checked: e.target.checked,
  });
};
// checkbox component
<Checkbox
checked={this.state.checked}
disabled={this.state.disabled} // can be managed via state independently
onChange={this.onChange}
>
{label}
</Checkbox>

Radio buttons

radio buttons
// on change handler
onChange = e => {
  this.setState({
    value: e.target.value,
  });
};

// radio component, manage the ‘disabled’ boolean separately
<>
  <Radio value={1} disabled={this.state.disabled}>
    Value 1
  </Radio>
  <br />
  <Radio value={2} disabled={this.state.disabled}>
    Value 2
  </Radio>
</>

Slider

slider
// on change handler
onChange = value => {
  this.setState({
    inputValue: value,
  });
};

// slider component
<Slider
  min={1} // define a range
  max={20}
  disabled={this.state.disabled} // manage ‘disabled’ separately 
  onChange={this.onChange}
  value={typeof inputValue === 'number' ? inputValue : 0}
/>
And, the best part is, all the code for using any variation of these components is available on the same page. You can easily access it by clicking the <> button like so:
select

Compound components

In addition to the basic components mentioned above, there is also a broad range of compound components that Ant Design provides, which supports rapid prototyping and development. These are the components which are widely used in modern user interfaces but take quite an effort to code from scratch. Here are some examples along with Ant Design equivalent code:

Comment

comment
<Comment
  actions={actions} // the action button settings
  author={<a>Han Solo</a>} // the name of comment author
  avatar={
    <Avatar src="source_for_avatar.png" alt="Han Solo"/>
  }
  content={// content here} // main comment
/>

Card

cards

<div className="site-card-border-less-wrapper"> // the css class
  <Card title="Card title" bordered={false} style={{ width: 300 }}>
    <p>Card content</p>
    <p>Card content</p>
    <p>Card content</p>
  </Card>
</div>

 Carousel

carousel
// Carousel with autoplay enabled
<Carousel autoplay> 
  <div>
    <h3>1</h3>
  </div>
  <div>
    <h3>2</h3>
  </div>
  <div>
    <h3>2</h3>
  </div>
</Carousel>

Timeline

timeline
<Timeline>
  <Timeline.Item>Create a services site 2015-09-01</Timeline.Item>
  <Timeline.Item>Solve initial network problems 2015-09-01</Timeline.Item>
  <Timeline.Item>Technical testing 2015-09-01</Timeline.Item>
  <Timeline.Item>Network problems being solved 2015-09-01</Timeline.Item>
</Timeline>

React support & documentation

The Ant design framework is designed from the ground up keeping in mind the React methodologies. All the components mentioned above have direct support for incorporation with React components available. Also, support for other popular frameworks like Angular and Vue are being developed by the community.

Comments

Popular posts from this blog

How to use Ngx-Charts in Angular ?

Charts helps us to visualize large amount of data in an easy to understand and interactive way. This helps businesses to grow more by taking important decisions from the data. For example, e-commerce can have charts or reports for product sales, with various categories like product type, year, etc. In angular, we have various charting libraries to create charts.  Ngx-charts  is one of them. Check out the list of  best angular chart libraries .  In this article, we will see data visualization with ngx-charts and how to use ngx-charts in angular application ? We will see, How to install ngx-charts in angular ? Create a vertical bar chart Create a pie chart, advanced pie chart and pie chart grid Introduction ngx-charts  is an open-source and declarative charting framework for angular2+. It is maintained by  Swimlane . It is using Angular to render and animate the SVG elements with all of its binding and speed goodness and uses d3 for the excellent math functio...

Understand Angular’s forRoot and forChild

  forRoot   /   forChild   is a pattern for singleton services that most of us know from routing. Routing is actually the main use case for it and as it is not commonly used outside of it, I wouldn’t be surprised if most Angular developers haven’t given it a second thought. However, as the official Angular documentation puts it: “Understanding how  forRoot()  works to make sure a service is a singleton will inform your development at a deeper level.” So let’s go. Providers & Injectors Angular comes with a dependency injection (DI) mechanism. When a component depends on a service, you don’t manually create an instance of the service. You  inject  the service and the dependency injection system takes care of providing an instance. import { Component, OnInit } from '@angular/core'; import { TestService } from 'src/app/services/test.service'; @Component({ selector: 'app-test', templateUrl: './test.component.html', styleUrls: ['./test.compon...

How to solve Puppeteer TimeoutError: Navigation timeout of 30000 ms exceeded

During the automation of multiple tasks on my job and personal projects, i decided to move on  Puppeteer  instead of the old school PhantomJS. One of the most usual problems with pages that contain a lot of content, because of the ads, images etc. is the load time, an exception is thrown (specifically the TimeoutError) after a page takes more than 30000ms (30 seconds) to load totally. To solve this problem, you will have 2 options, either to increase this timeout in the configuration or remove it at all. Personally, i prefer to remove the limit as i know that the pages that i work with will end up loading someday. In this article, i'll explain you briefly 2 ways to bypass this limitation. A. Globally on the tab The option that i prefer, as i browse multiple pages in the same tab, is to remove the timeout limit on the tab that i use to browse. For example, to remove the limit you should add: await page . setDefaultNavigationTimeout ( 0 ) ;  COPY SNIPPET The setDefaultNav...