Run the ChatUI demo project
masterTo run the local demo environment for development, navigate to the demo directory, install dependencies, and start the development server.
cd demo
npm i
npm run devrepository·master·Indexed 26 days ago
https://github.com/alibaba/chatuiA React library and UI design language for creating Conversational User Interfaces (CUI). ChatUI provides a core library (@chatui/core) featuring components like Chat, Bubble, Checkbox, Radio, Filter, and Empty, along with the useMessages hook for state management. It includes built-in support for responsive design, accessibility, internationalization (i18n), and theme customization.
To run the local demo environment for development, navigate to the demo directory, install dependencies, and start the development server.
cd demo
npm i
npm run devInstall the ChatUI core library using npm or yarn to start building conversational interfaces.
npm install @chatui/core --saveyarn add @chatui/coreThe Tabs component allows users to switch between different views within the same context, preventing frequent page jumps. It is suitable for switching page content, displaying categorized information, or showing multiple views.
To use it, wrap multiple Tab components inside a Tabs component. You can control the active tab using the index prop and respond to changes via the onChange callback.
To run the local development environment using Storybook, navigate to the storybook directory, install dependencies, and start the storybook server.
cd storybook
npm i
npm run storybookThe Empty component is used to display placeholder images and messages when data is empty, loading fails, or other exceptional states occur (e.g., network errors, insufficient permissions, or system maintenance). You can customize the visual state using the type prop or provide a custom image via the image prop. You can also include interactive elements like buttons as children.
import React from 'react';
import { Empty, Button } from '@chatui/core';
export default function() {
return (
<div>
{/* Basic usage */}
<Empty tip="暂无数据" />
{/* Error state with a button */}
<Empty type="error" tip="网络拥挤,排队中" desc="待会回来再试试呢">
<Button color="primary">刷新</Button>
</Empty>
{/* Permission issue */}
<Empty type="error_permission" desc="您没有权限查看相关内容">
<Button color="primary">申请权限</Button>
</Empty>
{/* Custom image */}
<Empty
image="//gw.alicdn.com/tfs/TB1uYH4QoY1gK0jSZFMXXaWcVXa-218-56.svg"
tip="自定义图片"
/>
</div>
);
}The Filter component provides filtering functionality, allowing users to select different options to filter data. It supports nested options (hierarchical filtering) and can be used in both uncontrolled and controlled modes.
Common use cases include product filtering, data filtering, category selection, and multi-condition filtering.
import React, { useState } from 'react';
import { Filter } from '@chatui/core';
const options = [
{
label: '红包状态',
children: [
{ label: '可使用' },
{ label: '已使用' },
{ label: '已过期' },
],
},
{
label: '红包面额',
children: [
{ label: '0-10' },
{ label: '11-50' },
{ label: '51-100' },
{ label: '100以上' },
],
},
];
export default function() {
const [value, setValue] = useState({});
return (
<div>
{/* Uncontrolled usage */}
<Filter
options={options}
onChange={(value) => console.log('筛选值:', value)}
/>
{/* Controlled usage */}
<Filter
options={options}
value={value}
onChange={(value) => setValue(value)}
/>
{/* Large size */}
<Filter
options={options}
size="lg"
onChange={(value) => console.log('筛选值:', value)}
/>
{/* Specify items per row */}
<Filter
options={options}
itemsPerRow={2}
onChange={(value) => console.log('筛选值:', value)}
/>
</div>
);
}You can control how RadioGroup options are positioned and aligned using the following props:
block prop to stack options vertically. This ignores maxPerRow and flex.align="left" or align="right" to set text alignment. The default is centered.maxPerRow={n} to specify the maximum number of items per row. For example, if you have 4 options and maxPerRow={3}, they will wrap into two rows (3 + 1).flex prop to make all options share the container width equally. This is useful when the number of options is dynamic.The Ribbon component is used to display decorative badges in the corner of a card or container. It is ideal for labeling statuses (e.g., 'Used', 'Expiring soon'), product states (e.g., 'Hot Sale', 'New'), or content types (e.g., 'Recommended', 'Featured').
Note: To ensure the Ribbon displays correctly within a container, the parent container should have position: 'relative' set in its style.
import React from 'react';
import { Ribbon, Card } from '@chatui/core';
export default function() {
return (
<div style={{ position: 'relative', width: '160px', height: '80px' }}>
<Ribbon>推荐</Ribbon>
</div>
);
}You can control how CheckboxGroup options are arranged using maxPerRow and flex.
maxPerRow: Controls the maximum number of options per row. The width of each option is dynamically calculated using the CSS variable --max-per-row.flex: Enables an equal distribution layout where options evenly divide the container width.flex has higher priority than maxPerRow. If both are set, flex takes effect.block: When block is set, options are arranged vertically and ignore maxPerRow and flex settings.The spacing between radio options is controlled by the CSS variable --radio-gap. The default value is 8px. You can override this in your CSS to adjust the layout density.
.RadioGroup {
--radio-gap: 12px; /* Custom spacing */
}