2022-02-16 21:14:05 +08:00
|
|
|
---
|
|
|
|
order: 8
|
|
|
|
title:
|
|
|
|
zh-CN: 自定义状态
|
|
|
|
en-US: Status
|
|
|
|
---
|
|
|
|
|
|
|
|
## zh-CN
|
|
|
|
|
|
|
|
使用 `status` 为 Mentions 添加状态。可选 `error` 或者 `warning`。
|
|
|
|
|
|
|
|
## en-US
|
|
|
|
|
|
|
|
Add status to Mentions with `status`, which could be `error` or `warning`。
|
|
|
|
|
2022-05-19 09:46:26 +08:00
|
|
|
```tsx
|
2022-02-16 21:14:05 +08:00
|
|
|
import { Mentions, Space } from 'antd';
|
2022-05-19 09:46:26 +08:00
|
|
|
import type { OptionProps } from 'antd/es/mentions';
|
2022-05-21 22:14:15 +08:00
|
|
|
import React from 'react';
|
2022-02-16 21:14:05 +08:00
|
|
|
|
|
|
|
const { Option } = Mentions;
|
|
|
|
|
2022-05-19 09:46:26 +08:00
|
|
|
const onChange = (value: string) => {
|
2022-02-16 21:14:05 +08:00
|
|
|
console.log('Change:', value);
|
2022-05-19 09:46:26 +08:00
|
|
|
};
|
2022-02-16 21:14:05 +08:00
|
|
|
|
2022-05-19 09:46:26 +08:00
|
|
|
const onSelect = (option: OptionProps) => {
|
2022-02-16 21:14:05 +08:00
|
|
|
console.log('select', option);
|
2022-05-19 09:46:26 +08:00
|
|
|
};
|
2022-02-16 21:14:05 +08:00
|
|
|
|
2022-05-19 09:46:26 +08:00
|
|
|
const App: React.FC = () => {
|
2022-02-16 21:14:05 +08:00
|
|
|
const options = (
|
|
|
|
<>
|
|
|
|
<Option value="afc163">afc163</Option>
|
|
|
|
<Option value="zombieJ">zombieJ</Option>
|
|
|
|
<Option value="yesmeck">yesmeck</Option>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Space direction="vertical">
|
|
|
|
<Mentions onChange={onChange} onSelect={onSelect} defaultValue="@afc163" status="error">
|
|
|
|
{options}
|
|
|
|
</Mentions>
|
|
|
|
<Mentions onChange={onChange} onSelect={onSelect} defaultValue="@afc163" status="warning">
|
|
|
|
{options}
|
|
|
|
</Mentions>
|
|
|
|
</Space>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2022-05-19 09:46:26 +08:00
|
|
|
export default App;
|
2022-02-16 21:14:05 +08:00
|
|
|
```
|