This commit is contained in:
parent
5289ae69d5
commit
14b977b28a
|
@ -1,4 +1,4 @@
|
|||
import { Card, Button, Input, Space } from 'antd';
|
||||
import { Input, Button, Space } from 'antd';
|
||||
import React, { useState } from 'react';
|
||||
|
||||
type InfoCardProps = {
|
||||
|
@ -6,24 +6,32 @@ type InfoCardProps = {
|
|||
}
|
||||
const InfoCard: React.FC<InfoCardProps> = ({ onAdd }) => {
|
||||
const [content, setContent] = useState('');
|
||||
const [addedContents, setAddedContents] = useState<string[]>([]);
|
||||
|
||||
const handleAdd = () => {
|
||||
if (content) {
|
||||
onAdd(content);
|
||||
setAddedContents([...addedContents, content]);
|
||||
setContent('');
|
||||
}
|
||||
}
|
||||
return (
|
||||
<Card >
|
||||
// 增大内边距,避免内容被覆盖
|
||||
<div style={{ border: '1px solid #d9d9d9', padding: '24px' }}>
|
||||
<Space>
|
||||
<Input
|
||||
placeholder='请输入内容'
|
||||
value={content}
|
||||
onChange={(e) => setContent(e.target.value)}
|
||||
>
|
||||
</Input>
|
||||
/>
|
||||
<Button type='primary' onClick={handleAdd}>添加</Button>
|
||||
</Space>
|
||||
</Card>
|
||||
<div style={{ marginTop: '24px' }}>
|
||||
{addedContents.map((item, index) => (
|
||||
<div key={index}>{item}</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
export default InfoCard;
|
Loading…
Reference in New Issue