### Install babel-plugin-import
Source: https://arco.design/react/docs/start
Install the babel-plugin-import package as a development dependency for on-demand loading.
```bash
npm i babel-plugin-import -D
```
--------------------------------
### Uninstall v1 and Install v2 Packages
Source: https://arco.design/react/docs/migrate_to_v2
To begin the migration, uninstall the old ByteDesign package and install the new ArcoDesign package using npm.
```bash
npm remove @bytedesign/web-react && npm i @arco-design/web-react
```
--------------------------------
### Install VChart and Arco Theme
Source: https://arco.design/react/docs/vchart
Install VChart and the @visactor/vchart-arco-theme package using npm or yarn.
```bash
# Install VChart
$ npm install @visactor/react-vchart
# Install @visactor/vchart-arco-theme to adapt arco theme
$ npm install @visactor/vchart-arco-theme
```
```bash
# Install VChart
$ yarn add @visactor/react-vchart
# Install @visactor/vchart-arco-theme to adapt arco theme
$ yarn add @visactor/vchart-arco-theme
```
--------------------------------
### Vertical Steps Example
Source: https://arco.design/react/components/steps
Demonstrates a vertical Steps component with navigation buttons. Use this for sequential processes where vertical space is abundant.
```javascript
import { useState, useRef } from 'react';
import { Steps, Button, Divider } from '@arco-design/web-react';
import { IconLeft, IconRight } from '@arco-design/web-react/icon';
const Step = Steps.Step;
function App() {
const [current, setCurrent] = useState(1);
function renderContent(step) {
return (
Step{step} Content
);
}
return (
{renderContent(current)}
);
}
export default App;
```
--------------------------------
### Basic Select with Options
Source: https://arco.design/react/components/select
Demonstrates how to use the Select component with a predefined list of options for single and multiple selections. Ensure '@arco-design/web-react' is installed.
```javascript
import { Select, Message, Space } from '@arco-design/web-react';
const options = ['Beijing', 'Shanghai', 'Guangzhou', 'Shenzhen', 'Chengdu', 'Wuhan'];
const App = () => {
return (
);
};
export default App;
```
--------------------------------
### Basic Table Usage
Source: https://arco.design/react/components/table
Demonstrates the fundamental setup for rendering a table with columns and data. Ensure you import `Table` and `TableColumnProps` from '@arco-design/web-react'.
```javascript
import React from 'react';
import { Table, TableColumnProps } from '@arco-design/web-react';
const columns: TableColumnProps[] = [
{
title: 'Name',
dataIndex: 'name',
},
{
title: 'Salary',
dataIndex: 'salary',
},
{
title: 'Address',
dataIndex: 'address',
},
{
title: 'Email',
dataIndex: 'email',
},
];
const data = [
{
key: '1',
name: 'Jane Doe',
salary: 23000,
address: '32 Park Road, London',
email: 'jane.doe@example.com',
},
{
key: '2',
name: 'Alisa Ross',
salary: 25000,
address: '35 Park Road, London',
email: 'alisa.ross@example.com',
},
{
key: '3',
name: 'Kevin Sandra',
salary: 22000,
address: '31 Park Road, London',
email: 'kevin.sandra@example.com',
},
{
key: '4',
name: 'Ed Hellen',
salary: 17000,
address: '42 Park Road, London',
email: 'ed.hellen@example.com',
},
{
key: '5',
name: 'William Smith',
salary: 27000,
address: '62 Park Road, London',
email: 'william.smith@example.com',
},
];
const App = () => {
return
;
};
export default App;
```
--------------------------------
### Spin with Custom Description
Source: https://arco.design/react/components/spin
Customize the loading text using the `tip` prop. This example wraps a Card component with a custom tip.
```javascript
import { Spin, Card, Link } from '@arco-design/web-react';
function App() {
return (
More }>
ByteDance's core product, Toutiao ('Headlines'), is a content platform in China and around
the world. Toutiao started out as a news recommendation engine and gradually evolved into a
platform delivering content in various formats.
);
}
export default App;
```
--------------------------------
### Time Formatting Example
Source: https://arco.design/react/components/statistic
Displays a timestamp formatted using dayjs. The `format` prop accepts dayjs format strings.
```javascript
import { Statistic, Grid } from '@arco-design/web-react';
const Row = Grid.Row;
const Col = Grid.Col;
const App = () => {
return ;
};
export default App;
```
--------------------------------
### Nested Drawers
Source: https://arco.design/react/components/drawer
This example shows how to implement multiple drawers stacked on top of each other. A button in the first drawer opens a second, nested drawer.
```javascript
import { useState } from 'react';
import { Drawer, Button } from '@arco-design/web-react';
function App() {
const [visible, setVisible] = useState(false);
const [visible2, setVisible2] = useState(false);
return (
);
}
export default App;
```
--------------------------------
### Grid Offset Example
Source: https://arco.design/react/components/grid
Demonstrates how to use the 'offset' prop to create space between columns in a grid layout. Ensure the Grid component is imported.
```jsx
import { Grid } from '@arco-design/web-react';
const Row = Grid.Row;
const Col = Grid.Col;
const App = () => {
return (
col - 8
col - 8 | offset - 8
col - 6 | offset - 8
col - 6 | offset - 4
col - 12 | offset - 8
);
};
export default App;
```
--------------------------------
### Adaptive Long Button Examples
Source: https://arco.design/react/components/button
Shows how to create buttons that automatically adjust their width to fit their container. Useful for full-width actions.
```javascript
import { Button, Space } from '@arco-design/web-react';
import { IconUpload } from '@arco-design/web-react/icon';
const App = () => {
return (
);
};
export default App;
```
--------------------------------
### Popconfirm Positioning Examples
Source: https://arco.design/react/components/popconfirm
Demonstrates the 12 different positions available for the Popconfirm component. Each position is shown with a corresponding button trigger.
```javascript
import { Popconfirm, Button, Message } from '@arco-design/web-react';
const props = {
title: 'Are you sure you want to delete? ',
onOk: () => {
Message.info({
content: 'ok',
});
},
onCancel: () => {
Message.error({
content: 'cancel',
});
},
};
const App = () => {
return (
);
};
export default App;
```
--------------------------------
### Button Group Examples
Source: https://arco.design/react/components/button
Demonstrates various combinations of buttons within a group, including different types and icon placements. Useful for related actions.
```javascript
import React from 'react';
import { Button, Space } from '@arco-design/web-react';
import {
IconLeft,
IconRight,
IconMore,
IconStar,
IconSettings,
IconMessage,
IconDown,
} from '@arco-design/web-react/icon';
const ButtonGroup = Button.Group;
const App = () => {
return (
} />
} />
} />
}
shape='round'
style={{ padding: '0 8px' }}
>
Prev
} />
} />
} />
}>
Favorite
}>
Setting
);
};
export default App;
```
--------------------------------
### Custom Icon Result Example
Source: https://arco.design/react/components/result
Demonstrates how to use the `icon` prop to provide a custom icon for the Result component. This allows for more flexible visual feedback.
```javascript
import { Result, Button } from '@arco-design/web-react';
import { IconFaceSmileFill } from '@arco-design/web-react/icon';
const App = () => {
return (
}
title='Your operation has been performed.'
extra={}
>
);
};
export default App;
```
--------------------------------
### Loading State Example
Source: https://arco.design/react/components/statistic
Shows how to control the loading state of the Statistic component using the `loading` prop. A switch is provided to toggle the loading status.
```javascript
import { useState } from 'react';
import { Statistic, Switch, Typography } from '@arco-design/web-react';
function App() {
const [loading, setLoading] = useState(true);
return (
Loading
);
}
export default App;
```
--------------------------------
### Basic Steps Usage
Source: https://arco.design/react/components/steps
Demonstrates the fundamental implementation of the Steps component with titles for each step.
```javascript
import { Steps, Divider } from '@arco-design/web-react';
const Step = Steps.Step;
const App = () => {
return (
Step 2 Content
);
};
export default App;
```
--------------------------------
### Reversing Slider Direction
Source: https://arco.design/react/components/slider
Set `reverse={true}` to swap the start and end points of the slider. This example uses a `Switch` to toggle the reverse state and displays marks for specific values.
```javascript
import { useState } from 'react';
import { Slider, Switch, Typography, Space } from '@arco-design/web-react';
import { IconSound, IconMute } from '@arco-design/web-react/icon';
function App() {
const [reverse, setReverse] = useState(true);
return (
<>
Reversed
>
);
}
export default App;
```
--------------------------------
### Steps with Descriptions
Source: https://arco.design/react/components/steps
Illustrates adding descriptive text to each step using the `description` prop.
```javascript
import { Steps } from '@arco-design/web-react';
const Step = Steps.Step;
const App = () => {
return (
);
};
export default App;
```
--------------------------------
### Countdown Timer Examples
Source: https://arco.design/react/components/statistic
Demonstrates various configurations for the Countdown component, including basic countdown, custom render format, millisecond precision, day formatting, and triggering on finish.
```javascript
import React from 'react';
import { Statistic, Message, Button, Space } from '@arco-design/web-react';
const Countdown = Statistic.Countdown;
const now = Date.now();
function App() {
const [start, setStart] = React.useState(false);
const _now = Date.now();
return (
{
const minutes = Math.floor(_diff / (1000 * 60));
const seconds = Math.floor(_diff / 1000);
let diffTimes = '';
if (minutes) {
diffTimes = `${minutes}min 后`;
} else {
diffTimes = `${seconds}s 后`;
}
return ;
}}
/>
);
}
export default App;
```
--------------------------------
### Dynamic Loading Tree Example
Source: https://arco.design/react/components/tree
Shows how to implement dynamic loading for tree nodes using the `loadMore` prop. This is useful for large trees where nodes are loaded on demand to improve performance.
```javascript
import React from 'react';
import { Tree } from '@arco-design/web-react';
const TreeNode = Tree.Node;
const defaultTreeData = [
{
title: 'Trunk 0-0',
key: '0-0'
},
{
title: 'Trunk 0-1',
key: '0-1',
children: [
{
title: 'Branch 0-1-1',
key: '0-1-1'
},
],
},
];
function App() {
const [treeData, setTreeData] = React.useState(defaultTreeData);
const loadMore = (treeNode) => {
return new Promise((resolve) => {
setTimeout(() => {
treeNode.props.dataRef.children = [
{
title: `leaf`,
key: `${treeNode.props._key}-1`,
isLeaf: true,
},
];
setTreeData([...treeData]);
resolve();
}, 1000);
});
};
return ;
}
export default App;
```
--------------------------------
### Install Arco Design React
Source: https://arco.design/react/docs/start
Install the Arco Design React library using npm or yarn. Requires React version 16.8 or higher.
```bash
// npm
npm i @arco-design/web-react
// yarn
yarn add @arco-design/web-react
```
--------------------------------
### Steps with Custom Icons
Source: https://arco.design/react/components/steps
Demonstrates how to replace default step icons with custom ones using the `icon` prop.
```javascript
import { Steps } from '@arco-design/web-react';
import { IconHome, IconLoading, IconThumbUp } from '@arco-design/web-react/icon';
const Step = Steps.Step;
const App = () => {
return (
} title='Succeeded' description='This is a description' />
} title='Processing' description='This is a description' />
} title='Pending' description='This is a description' />
);
};
export default App;
```
--------------------------------
### Controlled Ellipsis Example
Source: https://arco.design/react/components/typography
Demonstrates how to control ellipsis behavior with various configurations like rows, expandable, suffix, and ellipsis string. This example showcases dynamic updates based on user interactions.
```jsx
import { useState } from 'react';
import {
Typography,
Button,
Switch,
Input,
Form,
Descriptions,
Space,
} from '@arco-design/web-react';
const defaultText = `A design is a plan or specification for the construction of an object or system or for the
implementation of an activity or process. A design is a plan or specification for the
construction of an object or system or for the implementation of an activity or process. `;
const defaultConfig = {
ellipsisStr: '...',
};
const App = () => {
const [config, setConfig] = useState(defaultConfig);
const [rows, setRows] = useState(1);
const [text, setText] = useState(defaultText);
const { ellipsis, ellipsisStr, expandable, suffix } = config;
return (