This commit is contained in:
linfeng 2025-03-26 10:39:24 +08:00
parent 5289ae69d5
commit 14b977b28a
1 changed files with 18 additions and 10 deletions

View File

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