mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-29 20:08:37 +08:00
36d6d3d7f2
* type(mentions): export interface MentionsProps * type: fix
35 lines
792 B
TypeScript
35 lines
792 B
TypeScript
import React, { useState } from 'react';
|
|
import { Mentions } from 'antd';
|
|
import type { MentionsProps } from 'antd';
|
|
|
|
const MOCK_DATA = {
|
|
'@': ['afc163', 'zombiej', 'yesmeck'],
|
|
'#': ['1.0', '2.0', '3.0'],
|
|
};
|
|
|
|
type PrefixType = keyof typeof MOCK_DATA;
|
|
|
|
const App: React.FC = () => {
|
|
const [prefix, setPrefix] = useState<PrefixType>('@');
|
|
|
|
const onSearch: MentionsProps['onSearch'] = (_, newPrefix) => {
|
|
setPrefix(newPrefix as PrefixType);
|
|
};
|
|
|
|
return (
|
|
<Mentions
|
|
style={{ width: '100%' }}
|
|
placeholder="input @ to mention people, # to mention tag"
|
|
prefix={['@', '#']}
|
|
onSearch={onSearch}
|
|
options={(MOCK_DATA[prefix] || []).map((value) => ({
|
|
key: value,
|
|
value,
|
|
label: value,
|
|
}))}
|
|
/>
|
|
);
|
|
};
|
|
|
|
export default App;
|