-
-
Notifications
You must be signed in to change notification settings - Fork 316
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Netease-YY
authored and
Netease-YY
committed
Nov 24, 2024
1 parent
ed5a698
commit a23a182
Showing
3 changed files
with
273 additions
and
1 deletion.
There are no files selected for viewing
111 changes: 111 additions & 0 deletions
111
packages/editor/src/components/FloatingCollector/index.module.less
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
.container { | ||
position: absolute; | ||
padding: 4px; | ||
bottom: 30px; | ||
left: 30px; | ||
z-index: 1000; | ||
display: flex; | ||
flex-direction: column; | ||
align-items: flex-start; | ||
border-radius: 4px; | ||
overflow: hidden; | ||
} | ||
|
||
.collectorContent { | ||
background-color: white; | ||
border-radius: 8px; | ||
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1); | ||
overflow: hidden; | ||
margin-bottom: 10px; | ||
.title { | ||
max-width: 150px; | ||
overflow: hidden; | ||
text-overflow: ellipsis; | ||
} | ||
&.expanded { | ||
width: 220px; | ||
padding: 16px; | ||
|
||
} | ||
} | ||
|
||
.itemList { | ||
display: none; | ||
flex-direction: column; | ||
gap: 8px; | ||
|
||
.expanded & { | ||
display: flex; | ||
} | ||
} | ||
|
||
.item { | ||
background: none; | ||
border: none; | ||
text-align: left; | ||
padding: 8px; | ||
cursor: pointer; | ||
border-radius: 4px; | ||
display: flex; | ||
justify-content: space-between; | ||
transition: background-color 0.2s; | ||
|
||
&:hover { | ||
background-color: #f0f0f0; | ||
border: 1px dashed; | ||
} | ||
|
||
&.active { | ||
color: #7d3fff; | ||
border: 1px solid #7d3fff; | ||
.action { | ||
display: block; | ||
} | ||
} | ||
|
||
.action { | ||
display: none; | ||
} | ||
} | ||
|
||
.relatedItems { | ||
margin-top: 8px; | ||
padding-left: 16px; | ||
border-left: 2px solid #1890ff; | ||
font-size: 0.9em; | ||
color: #666; | ||
} | ||
|
||
.iconContainer { | ||
display: flex; | ||
flex-direction: column; | ||
width: 40px; | ||
padding: 10px 4px 6px 0; | ||
gap: 8px; | ||
align-items: flex-start; | ||
justify-content: center; | ||
background-color: #fff; | ||
overflow: hidden; | ||
border: 1px solid #e1e2e8; | ||
border-radius: 4px; | ||
transition: width 0.2s ease-out; | ||
|
||
&:hover { | ||
width: 80px; | ||
} | ||
} | ||
|
||
.iconButton { | ||
background: none; | ||
border: none; | ||
cursor: pointer; | ||
padding: 8px; | ||
border-radius: 4px; | ||
transition: background-color 0.2s; | ||
|
||
svg { | ||
width: 20px; | ||
height: 20px; | ||
} | ||
} | ||
|
128 changes: 128 additions & 0 deletions
128
packages/editor/src/components/FloatingCollector/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
import React, { useCallback, useState } from 'react'; | ||
import styles from './index.module.less'; | ||
import { Badge, Button, Popconfirm } from 'antd'; | ||
import { CloseCircleFilled, CloseCircleOutlined, DeleteOutlined, QuestionCircleFilled } from '@ant-design/icons'; | ||
|
||
// modalList.push({ | ||
// id: createId(item.type), | ||
// name: item.name, | ||
// type: item.type, | ||
// config, | ||
// events, | ||
// methods, | ||
// elements, | ||
// }); | ||
|
||
interface CollectorItem { | ||
id: string; | ||
name?: string; | ||
type: string; | ||
config?: any; | ||
methods?: any; | ||
events?: any; | ||
elements?: any; | ||
} | ||
|
||
interface FloatingCollectorProps { | ||
modalList: CollectorItem[]; | ||
drawerList: CollectorItem[]; | ||
clickItem: (item: CollectorItem) => void; | ||
} | ||
|
||
const FloatingCollector = (props: FloatingCollectorProps) => { | ||
const [isExpanded, setIsExpanded] = useState(false); | ||
const [selectedItem, setSelectedItem] = useState<string | null>(null); | ||
const [currentItems, setCurrentItems] = useState<CollectorItem[]>([]); | ||
|
||
const { modalList, drawerList } = props; | ||
|
||
const handleTypeClick = useCallback((type: number) => { | ||
setIsExpanded(true); | ||
if (type === 1) { | ||
setCurrentItems(modalList); | ||
} else if (type === 2) { | ||
setCurrentItems(drawerList); | ||
} | ||
|
||
}, [modalList, drawerList]); | ||
|
||
const handleItemClick = useCallback((item: CollectorItem) => { | ||
setSelectedItem(item.id); | ||
props.clickItem(item); | ||
}, []); | ||
|
||
const handleClose = useCallback((item: CollectorItem) => { | ||
setSelectedItem(null); | ||
}, [currentItems]); | ||
|
||
return ( | ||
<div | ||
className={styles.container} | ||
> | ||
<div className={`${styles.collectorContent} ${isExpanded ? styles.expanded : ''}`}> | ||
<div className={styles.itemList}> | ||
{currentItems.map((item) => ( | ||
<Button | ||
key={item.id} | ||
onClick={() => handleItemClick(item)} | ||
className={`${styles.item} ${selectedItem === item.id ? styles.active : ''}`} | ||
> | ||
<span className={styles.title}>{item.name}</span> | ||
<span className={styles.action}> | ||
<CloseCircleOutlined onClick={(e) => { | ||
e.stopPropagation(); | ||
handleClose(item); | ||
}} /> | ||
<Popconfirm | ||
title="警告" | ||
description="将删除此项目及其关联项目" | ||
icon={<QuestionCircleFilled style={{ color: 'red' }} />} | ||
> | ||
<DeleteOutlined style={{marginLeft: '5px'}} /> | ||
</Popconfirm> | ||
</span> | ||
</Button> | ||
))} | ||
</div> | ||
</div> | ||
<div className={styles.iconContainer}> | ||
<Button className={styles.iconButton} onClick={()=> handleTypeClick(1)}> | ||
<Badge count={modalList.length} size='small' color='#7d3fff'> | ||
<ModalIcon /> | ||
</Badge> | ||
<span style={{marginLeft: '5px'}}>弹窗</span> | ||
</Button> | ||
<Button className={styles.iconButton} onClick={()=> handleTypeClick(2)}> | ||
<Badge count={drawerList.length} size='small' color='#7d3fff'> | ||
<DrawerIcon /> | ||
</Badge> | ||
<span style={{marginLeft: '5px'}}>抽屉</span> | ||
</Button> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
const ModalIcon: React.FC = () => ( | ||
<svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"> | ||
<path d="M4 4h16a2 2 0 0 1 2 2v12a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2z" stroke="currentColor" strokeWidth="2" strokeLinecap="round" /> | ||
<path d="M9 4v16M15 4v16" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeDasharray="2 4" /> | ||
</svg> | ||
); | ||
|
||
const DrawerIcon: React.FC = () => ( | ||
<svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"> | ||
<path d="M3 3h18a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H3a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2z" stroke="currentColor" strokeWidth="2" /> | ||
<path d="M15 3v18" stroke="currentColor" strokeWidth="2" strokeLinecap="round" /> | ||
</svg> | ||
); | ||
|
||
const NotificationIcon: React.FC = () => ( | ||
<svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"> | ||
<path d="M4 4h16a2 2 0 0 1 2 2v12a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2z" stroke="currentColor" strokeWidth="2" /> | ||
<path d="M8 9h8M8 13h4" stroke="currentColor" strokeWidth="2" strokeLinecap="round" /> | ||
</svg> | ||
); | ||
|
||
export default FloatingCollector; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters