2019-02-19 11:42:05 +08:00
|
|
|
---
|
|
|
|
order: 3
|
|
|
|
title:
|
|
|
|
zh-CN: 可交互
|
|
|
|
en-US: Interactive
|
|
|
|
---
|
|
|
|
|
|
|
|
## zh-CN
|
|
|
|
|
2019-12-06 11:08:28 +08:00
|
|
|
提供可编辑和可复制等额外的交互能力。
|
2019-02-19 11:42:05 +08:00
|
|
|
|
|
|
|
## en-US
|
|
|
|
|
2019-12-06 11:08:28 +08:00
|
|
|
Provide additional interactive capacity of editable and copyable.
|
2019-02-19 11:42:05 +08:00
|
|
|
|
|
|
|
```jsx
|
2020-08-09 12:56:35 +08:00
|
|
|
import React, { useState } from 'react';
|
2019-02-19 11:42:05 +08:00
|
|
|
import { Typography } from 'antd';
|
2020-08-09 12:56:35 +08:00
|
|
|
import { HighlightOutlined, SmileOutlined, SmileFilled } from '@ant-design/icons';
|
2019-02-19 11:42:05 +08:00
|
|
|
|
2020-07-30 16:54:49 +08:00
|
|
|
const { Paragraph } = Typography;
|
2019-02-19 11:42:05 +08:00
|
|
|
|
2020-08-09 12:56:35 +08:00
|
|
|
const Demo: React.FC = () => {
|
|
|
|
const [editableStr, setEditableStr] = useState('This is an editable text.');
|
|
|
|
const [customIconStr, setCustomIconStr] = useState('Custom Edit icon and replace tooltip text.');
|
|
|
|
const [hideTooltipStr, setHideTooltipStr] = useState('Hide Edit tooltip.');
|
|
|
|
const [lengthLimitedStr, setLengthLimitedStr] = useState(
|
|
|
|
'This is an editable text with limited length.',
|
|
|
|
);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<Paragraph editable={{ onChange: setEditableStr }}>{editableStr}</Paragraph>
|
|
|
|
<Paragraph
|
|
|
|
editable={{
|
|
|
|
icon: <HighlightOutlined />,
|
|
|
|
tooltip: 'click to edit text',
|
|
|
|
onChange: setCustomIconStr,
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{customIconStr}
|
|
|
|
</Paragraph>
|
|
|
|
<Paragraph editable={{ tooltip: false, onChange: setHideTooltipStr }}>
|
|
|
|
{hideTooltipStr}
|
|
|
|
</Paragraph>
|
|
|
|
<Paragraph
|
|
|
|
editable={{
|
|
|
|
onChange: setLengthLimitedStr,
|
|
|
|
maxLength: 50,
|
|
|
|
autoSize: { maxRows: 5, minRows: 3 },
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{lengthLimitedStr}
|
|
|
|
</Paragraph>
|
|
|
|
<Paragraph copyable>This is a copyable text.</Paragraph>
|
|
|
|
<Paragraph copyable={{ text: 'Hello, Ant Design!' }}>Replace copy text.</Paragraph>
|
|
|
|
<Paragraph
|
|
|
|
copyable={{
|
|
|
|
icon: [<SmileOutlined key="copy-icon" />, <SmileFilled key="copied-icon" />],
|
|
|
|
tooltips: ['click here', 'you clicked!!'],
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
Custom Copy icon and replace tooltips text.
|
|
|
|
</Paragraph>
|
|
|
|
<Paragraph copyable={{ tooltips: false }}>Hide Copy tooltips.</Paragraph>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|
2019-02-19 11:42:05 +08:00
|
|
|
|
|
|
|
ReactDOM.render(<Demo />, mountNode);
|
|
|
|
```
|