11import React from "react" ;
2- import { Input } from "antd" ;
2+ import { Button , Col , Popover , Row } from "antd" ;
3+ import { Icon } from "@flow-engine/flow-pc-ui" ;
4+ import { icons } from "@flow-engine/flow-types" ;
35
4-
5- interface ActionIconProps {
6- value ?:string ;
7- onChange ?:( value :string ) => void ;
6+ interface ActionIconProps {
7+ value ?: string ;
8+ onChange ?: ( value : string ) => void ;
89}
910
10- export const ActionIcon :React . FC < ActionIconProps > = ( props ) => {
11+
12+ export const ActionIcon : React . FC < ActionIconProps > = ( props ) => {
13+ const { value, onChange } = props ;
14+
15+ const options = React . useMemo ( ( ) => {
16+ return icons . groups ;
17+ } , [ ] ) ;
18+
19+ const handleSelectIcon = ( iconType : string ) => {
20+ onChange ?.( iconType ) ;
21+ } ;
22+
23+ const content = ( ) => {
24+ return (
25+ < div
26+ style = { {
27+ maxHeight : 400 ,
28+ width : 500 ,
29+ overflowY : 'auto' , // 添加滚动
30+ padding : '4px'
31+ } }
32+ >
33+ < Row gutter = { [ 12 , 12 ] } >
34+ { options . map ( ( group ) => (
35+ < React . Fragment key = { group . label } >
36+ < Col span = { 24 } >
37+ < div style = { {
38+ fontWeight : 500 ,
39+ marginBottom : 8 ,
40+ color : '#666' ,
41+ fontSize : 13
42+ } } >
43+ { group . label }
44+ </ div >
45+ </ Col >
46+
47+ { group . icons . map ( ( iconType ) => (
48+ < Col span = { 4 } key = { iconType } >
49+ < div
50+ onClick = { ( ) => handleSelectIcon ( iconType ) }
51+ style = { {
52+ padding : '12px 8px' ,
53+ borderRadius : 6 ,
54+ cursor : 'pointer' ,
55+ display : 'flex' ,
56+ justifyContent : 'center' ,
57+ alignItems : 'center' ,
58+ backgroundColor : value === iconType ? '#e6f7ff' : 'transparent' ,
59+ border : value === iconType ? '1px solid #1890ff' : '1px solid transparent' ,
60+ transition : 'all 0.3s'
61+ } }
62+ onMouseEnter = { ( e ) => {
63+ if ( value !== iconType ) {
64+ e . currentTarget . style . backgroundColor = '#f5f5f5' ;
65+ e . currentTarget . style . borderColor = '#d9d9d9' ;
66+ }
67+ } }
68+ onMouseLeave = { ( e ) => {
69+ if ( value !== iconType ) {
70+ e . currentTarget . style . backgroundColor = 'transparent' ;
71+ e . currentTarget . style . borderColor = 'transparent' ;
72+ }
73+ } }
74+ >
75+ < Icon type = { iconType } style = { { fontSize : 24 } } />
76+ </ div >
77+ </ Col >
78+ ) ) }
79+ </ React . Fragment >
80+ ) ) }
81+ </ Row >
82+ </ div >
83+ ) ;
84+ } ;
85+
1186 return (
12- < >
13- < Input placeholder = { "请输入按钮图标" } />
14- </ >
15- )
16- }
87+ < Popover
88+ content = { content }
89+ title = "选择图标"
90+ trigger = "click"
91+ placement = "bottomLeft"
92+ >
93+ < Button >
94+ { value ? (
95+ < >
96+ < Icon type = { value } style = { { marginRight : 8 } } />
97+ 更换图标
98+ </ >
99+ ) : (
100+ '选择图标'
101+ ) }
102+ </ Button >
103+ </ Popover >
104+ ) ;
105+ } ;
0 commit comments