Ant Design: Complete Component Framework Cheatsheet

Introduction: What is Ant Design & Why It Matters

Ant Design is a comprehensive UI design language and React component library created by Alibaba’s Ant Financial team. It provides a set of high-quality React components, development tools, and design resources that follow established design principles, helping developers build elegant, consistent, and accessible enterprise-level applications quickly and efficiently.

Why Ant Design matters:

  • Provides a complete design system with consistent UI components
  • Saves development time with ready-to-use, customizable components
  • Ensures responsive, accessible interfaces out of the box
  • Backed by a large community and the Alibaba ecosystem
  • Offers comprehensive documentation and design resources

Core Concepts & Principles

PrincipleDescription
CertaintyCreating clear visual hierarchy and predictable patterns
MeaningfulnessEvery design element has a purpose and clear intention
GrowthAdaptable to various scenarios while maintaining consistency
NaturalIntuitive interactions that feel familiar to users

Design Values

  • Nature: Organic, flowing visual language derived from natural patterns
  • Certainty: Clear, predictable patterns and consistent behaviors
  • Meaningfulness: Purposeful design choices for intuitive interfaces
  • Growth: Scalable design system that evolves with changing needs

Getting Started with Ant Design

Installation

# Using npm
npm install antd

# Using yarn
yarn add antd

Basic Setup

// Import style
import 'antd/dist/antd.css';
// Import component
import { Button } from 'antd';

const App = () => (
  <Button type="primary">Hello Ant Design</Button>
);

Customization

// Custom theme
import { ConfigProvider } from 'antd';

const App = () => (
  <ConfigProvider
    theme={{
      token: {
        colorPrimary: '#00b96b',
        borderRadius: 2,
      },
    }}
  >
    {/* Your components */}
  </ConfigProvider>
);

Key Components by Category

Layout Components

ComponentDescriptionKey Props
LayoutBasic structural frameworkhasSider, className
GridFlexible 24-column grid systemRow: gutter, justify, align <br> Col: span, offset, pull, push
SpaceManage spacing between componentssize, direction, align, wrap
FlexCSS Flexbox implementationjustify, align, gap, vertical
DividerSeparate content sectionstype, orientation, dashed

Navigation Components

ComponentDescriptionKey Props
MenuApplication navigation structuremode, theme, selectedKeys, openKeys
BreadcrumbShow location/hierarchyitems, separator
PaginationNavigate through pagescurrent, total, pageSize, onChange
StepsGuide users through stepscurrent, direction, size, status
DropdownToggle contextual overlaysmenu, placement, trigger, arrow

Data Entry Components

ComponentDescriptionKey Props
FormData collection and validationlayout, initialValues, onFinish
InputText input controlsplaceholder, disabled, prefix, suffix
SelectDropdown selectionoptions, mode, allowClear, showSearch
DatePickerDate selectionpicker, format, showTime, disabledDate
Checkbox/RadioSelection controlschecked, disabled, onChange
SwitchToggle between stateschecked, disabled, loading, size
UploadFile uploadsaction, fileList, onChange, multiple

Data Display Components

ComponentDescriptionKey Props
TableDisplay tabular datacolumns, dataSource, pagination, loading
ListVertical listsdataSource, renderItem, size, grid
CardContent containerstitle, cover, actions, bordered
DescriptionsDisplay multiple fieldsitems, layout, column, bordered
TreeHierarchical datatreeData, checkable, defaultExpandAll
TabsSwitch between viewsitems, activeKey, type, centered
TagCategorize contentcolor, closable, icon, bordered

Feedback Components

ComponentDescriptionKey Props
ModalDialog windowsopen, title, onOk, onCancel
MessageNon-intrusive feedbacksuccess, error, info, warning
NotificationSystem notificationstype, message, description, placement
AlertContextual feedbacktype, message, description, showIcon
ProgressDisplay progresspercent, status, type, showInfo
SkeletonLoading placeholdersactive, avatar, paragraph, loading
ResultOperation feedbackstatus, title, subTitle, extra

Advanced Features & Patterns

Form Validation

<Form
  name="basic"
  initialValues={{ remember: true }}
  onFinish={onFinish}
  onFinishFailed={onFinishFailed}
>
  <Form.Item
    label="Username"
    name="username"
    rules={[{ required: true, message: 'Please input your username!' }]}
  >
    <Input />
  </Form.Item>
  
  <Form.Item
    label="Password"
    name="password"
    rules={[
      { required: true, message: 'Please input your password!' },
      { min: 8, message: 'Password must be at least 8 characters' }
    ]}
  >
    <Input.Password />
  </Form.Item>
  
  <Form.Item>
    <Button type="primary" htmlType="submit">Submit</Button>
  </Form.Item>
</Form>

Data Table with Filtering & Sorting

const columns = [
  {
    title: 'Name',
    dataIndex: 'name',
    sorter: (a, b) => a.name.localeCompare(b.name),
    filters: [
      { text: 'Joe', value: 'Joe' },
      { text: 'Jim', value: 'Jim' },
    ],
    onFilter: (value, record) => record.name.includes(value),
  },
  {
    title: 'Age',
    dataIndex: 'age',
    sorter: (a, b) => a.age - b.age,
  }
];

<Table dataSource={data} columns={columns} />

Responsive Design with Grid

<Row gutter={[16, 16]}>
  <Col xs={24} sm={12} md={8} lg={6} xl={4}>
    <div>Responsive Column</div>
  </Col>
  {/* More columns */}
</Row>

Common Challenges & Solutions

Challenge: Component Style Customization

Solution 1: CSS-in-JS with ConfigProvider

<ConfigProvider theme={{
  token: {
    colorPrimary: '#00b96b',
    colorLink: '#1890ff',
    borderRadius: 4,
  },
  components: {
    Button: {
      colorPrimary: '#f5222d',
      algorithm: true, // Enable algorithm
    },
  },
}}>
  {/* Your components */}
</ConfigProvider>

Solution 2: CSS Modules or Less

// YourComponent.module.css
.customButton :global(.ant-btn) {
  background-color: #f5222d;
  border-color: #f5222d;
}

// Usage
import styles from './YourComponent.module.css';

<div className={styles.customButton}>
  <Button type="primary">Custom Button</Button>
</div>

Challenge: Form Complex Validation

Solution: Custom Validator Functions

<Form.Item
  name="password"
  rules={[
    { required: true },
    ({ getFieldValue }) => ({
      validator(_, value) {
        if (!value || getFieldValue('password') === value) {
          return Promise.resolve();
        }
        return Promise.reject(new Error('The passwords do not match!'));
      },
    }),
  ]}
>
  <Input.Password />
</Form.Item>

Challenge: Server-Side Table Pagination

Solution: Custom Pagination Handler

const [data, setData] = useState([]);
const [loading, setLoading] = useState(false);
const [pagination, setPagination] = useState({
  current: 1,
  pageSize: 10,
  total: 0,
});

const fetchData = async (params) => {
  setLoading(true);
  try {
    const response = await api.getData({
      page: params.pagination.current,
      pageSize: params.pagination.pageSize,
      // Other params
    });
    setData(response.data);
    setPagination({
      ...params.pagination,
      total: response.total,
    });
  } finally {
    setLoading(false);
  }
};

<Table
  columns={columns}
  dataSource={data}
  pagination={pagination}
  loading={loading}
  onChange={(pagination, filters, sorter) => {
    fetchData({
      pagination,
      filters,
      sorter,
    });
  }}
/>

Best Practices & Tips

Performance Optimization

  • Use Dynamic Imports: Load components only when needed

    const OtherComponent = React.lazy(() => import('./OtherComponent'));
    
  • Virtual Lists: For rendering large datasets

    import { List } from 'antd';
    import VirtualList from 'rc-virtual-list';
    
    <List>
      <VirtualList
        data={listData}
        height={400}
        itemHeight={47}
        itemKey="id"
      >
        {(item) => <List.Item>{item.name}</List.Item>}
      </VirtualList>
    </List>
    
  • Debounce Input Handlers: Prevent excessive re-renders

    import { debounce } from 'lodash';
    
    const handleSearch = debounce((value) => {
      // Search logic
    }, 300);
    
    <Input onChange={(e) => handleSearch(e.target.value)} />
    

Accessibility (a11y)

  • Use semantic HTML elements with Ant Design components
  • Ensure sufficient color contrast for text and UI elements
  • Include proper ARIA attributes when necessary
  • Test keyboard navigation through your interface
  • Use Form.Item labels properly for screen readers

Design Consistency

  • Maintain consistent spacing using the Space component or grid system
  • Use token-based theming to ensure visual consistency
  • Follow Ant Design’s spacing recommendations (8px grid system)
  • Use their official design tokens for colors, typography, and spacing

Responsive Development

// Responsive Form Layout
<Form
  labelCol={{
    xs: { span: 24 },
    sm: { span: 8 },
  }}
  wrapperCol={{
    xs: { span: 24 },
    sm: { span: 16 },
  }}
>
  {/* Form items */}
</Form>

// Responsive Table
<Table
  columns={columns}
  dataSource={data}
  scroll={{ x: 'max-content' }}
  responsive
/>

Comparison with Other UI Libraries

FeatureAnt DesignMaterial-UIChakra UIBootstrap
Component Count60+50+40+30+
FrameworkReact-focusedReact-focusedReact-focusedFramework-agnostic
StylingLess/CSS-in-JSCSS-in-JSCSS-in-JSSass/CSS
Theme CustomizationHighHighVery HighModerate
Bundle SizeMedium-LargeMedium-LargeSmall-MediumSmall
Enterprise FocusVery HighMediumMediumLow
EcosystemLarge, integratedVery LargeGrowingVery Large
AccessibilityGoodExcellentExcellentGood

Resources for Further Learning

Official Resources

Community Resources

Learning Resources

  • Ant Design YouTube Tutorials
  • UI/UX courses featuring Ant Design on Udemy and Coursera
  • Ant Design Discord/Slack communities

Tools

This cheatsheet provides a comprehensive overview of Ant Design, but the library is continually evolving. Always refer to the official documentation for the most up-to-date information and best practices.

Scroll to Top