Вёрстка сайта с использованием Ant Design
Ant Design — компонентная система от Alibaba/Ant Group, де-факто стандарт для enterprise React-приложений на рынках СНГ и Азии. Версия 5.x перешла с Less на CSS-in-JS (через @ant-design/cssinjs), что дало поддержку runtime-тем и токенов дизайна без пересборки.
Установка
npm install antd @ant-design/icons
// src/main.tsx
import { ConfigProvider, App as AntApp } from 'antd';
import ruRU from 'antd/locale/ru_RU';
import theme from './antd-theme';
function Root() {
return (
<ConfigProvider locale={ruRU} theme={theme}>
<AntApp>
<App />
</AntApp>
</ConfigProvider>
);
}
Кастомизация темы через Design Tokens
В Ant Design 5 тема задаётся через систему алгоритмов и токенов. Не нужно переопределять Less-переменные:
// src/antd-theme.ts
import { ThemeConfig, theme as antTheme } from 'antd';
const { defaultAlgorithm, darkAlgorithm } = antTheme;
const lightTheme: ThemeConfig = {
algorithm: defaultAlgorithm,
token: {
// Базовые цвета
colorPrimary: '#2563eb',
colorSuccess: '#16a34a',
colorWarning: '#d97706',
colorError: '#dc2626',
colorInfo: '#0891b2',
// Типографика
fontFamily: '"Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif',
fontSize: 14,
fontSizeLG: 16,
fontSizeHeading1: 38,
fontSizeHeading2: 30,
fontSizeHeading3: 24,
// Отступы
padding: 16,
paddingLG: 24,
paddingXL: 32,
margin: 16,
marginLG: 24,
// Форма
borderRadius: 8,
borderRadiusLG: 12,
// Цвета фона
colorBgContainer: '#ffffff',
colorBgLayout: '#f5f7fa',
colorBorderSecondary: '#e5e7eb',
},
components: {
Button: {
controlHeight: 40,
controlHeightLG: 48,
controlHeightSM: 32,
paddingContentHorizontal: 20,
borderRadius: 8,
},
Card: {
paddingLG: 24,
borderRadius: 12,
},
Table: {
headerBg: '#f9fafb',
borderColor: '#f3f4f6',
},
Form: {
labelColor: '#374151',
labelFontSize: 14,
},
Menu: {
itemBorderRadius: 8,
},
},
};
export default lightTheme;
Структура страницы с Ant Design Layout
import { Layout, Menu, Breadcrumb, Avatar, Badge, Space } from 'antd';
import { BellOutlined, UserOutlined, MenuFoldOutlined } from '@ant-design/icons';
import { useState } from 'react';
const { Header, Sider, Content, Footer } = Layout;
const AppLayout: FC<{ children: ReactNode }> = ({ children }) => {
const [collapsed, setCollapsed] = useState(false);
return (
<Layout style={{ minHeight: '100vh' }}>
<Sider
collapsible
collapsed={collapsed}
onCollapse={setCollapsed}
theme="light"
style={{
boxShadow: '1px 0 8px rgba(0,0,0,0.06)',
overflow: 'auto',
position: 'sticky',
top: 0,
height: '100vh',
}}
>
<div style={{ padding: '16px 24px', fontWeight: 700, fontSize: 18 }}>
{collapsed ? 'L' : 'Logo'}
</div>
<Menu
mode="inline"
defaultSelectedKeys={['dashboard']}
items={menuItems}
/>
</Sider>
<Layout>
<Header
style={{
background: '#fff',
padding: '0 24px',
display: 'flex',
alignItems: 'center',
justifyContent: 'space-between',
borderBottom: '1px solid #f3f4f6',
}}
>
<Breadcrumb items={breadcrumbItems} />
<Space size={16}>
<Badge count={3}>
<BellOutlined style={{ fontSize: 18 }} />
</Badge>
<Avatar icon={<UserOutlined />} />
</Space>
</Header>
<Content style={{ margin: 24 }}>
{children}
</Content>
<Footer style={{ textAlign: 'center', color: '#9ca3af' }}>
© 2025 Company. All rights reserved.
</Footer>
</Layout>
</Layout>
);
};
Формы с валидацией
import { Form, Input, Select, Button, message } from 'antd';
interface ContactFormValues {
name: string;
email: string;
department: string;
message: string;
}
const ContactForm = () => {
const [form] = Form.useForm<ContactFormValues>();
const [loading, setLoading] = useState(false);
const onFinish = async (values: ContactFormValues) => {
setLoading(true);
try {
await submitContact(values);
message.success('Сообщение отправлено');
form.resetFields();
} catch {
message.error('Ошибка отправки');
} finally {
setLoading(false);
}
};
return (
<Form
form={form}
layout="vertical"
onFinish={onFinish}
requiredMark="optional"
>
<Form.Item
name="name"
label="Имя"
rules={[{ required: true, message: 'Введите имя' }]}
>
<Input placeholder="Иван Иванов" size="large" />
</Form.Item>
<Form.Item
name="email"
label="Email"
rules={[
{ required: true, message: 'Введите email' },
{ type: 'email', message: 'Некорректный email' },
]}
>
<Input type="email" placeholder="[email protected]" size="large" />
</Form.Item>
<Form.Item name="department" label="Отдел">
<Select
size="large"
placeholder="Выберите отдел"
options={[
{ value: 'sales', label: 'Продажи' },
{ value: 'support', label: 'Поддержка' },
]}
/>
</Form.Item>
<Form.Item
name="message"
label="Сообщение"
rules={[{ required: true, min: 10, message: 'Минимум 10 символов' }]}
>
<Input.TextArea rows={4} placeholder="Опишите запрос..." showCount maxLength={500} />
</Form.Item>
<Form.Item>
<Button
type="primary"
htmlType="submit"
size="large"
loading={loading}
block
>
Отправить
</Button>
</Form.Item>
</Form>
);
};
Таблица с сортировкой и фильтрацией
import { Table, Tag, Space } from 'antd';
import type { ColumnsType } from 'antd/es/table';
interface DataItem {
key: string;
name: string;
status: 'active' | 'inactive' | 'pending';
created: string;
}
const columns: ColumnsType<DataItem> = [
{
title: 'Название',
dataIndex: 'name',
sorter: (a, b) => a.name.localeCompare(b.name),
},
{
title: 'Статус',
dataIndex: 'status',
filters: [
{ text: 'Активен', value: 'active' },
{ text: 'Неактивен', value: 'inactive' },
],
onFilter: (value, record) => record.status === value,
render: (status) => (
<Tag color={status === 'active' ? 'green' : status === 'pending' ? 'orange' : 'red'}>
{status === 'active' ? 'Активен' : status === 'pending' ? 'Ожидание' : 'Неактивен'}
</Tag>
),
},
{
title: 'Дата создания',
dataIndex: 'created',
sorter: (a, b) => new Date(a.created).getTime() - new Date(b.created).getTime(),
},
];
Сроки
Настройка ConfigProvider и темы: 2–4 часа. Ant Design значительно ускоряет разработку страниц с формами, таблицами и admin-интерфейсами за счёт готовых компонентов. Полный admin-panel с CRUD-операциями: 5–10 дней в зависимости от количества сущностей.







