1- import React , { useEffect , useState } from "react" ;
1+ import React , { useEffect , useState , useContext } from "react" ;
22import { default as Button } from "antd/es/button" ;
3- // 渲染组件到编辑器
43import {
54 changeChildAction ,
65 DispatchType ,
76 CompAction ,
87 RecordConstructorToView ,
98} from "lowcoder-core" ;
10- // 文字国际化转换api
119import { trans } from "i18n" ;
12- // 右侧属性栏总框架
1310import { UICompBuilder , withDefault } from "../../generators" ;
14- // 右侧属性子框架
1511import { Section , sectionNames } from "lowcoder-design" ;
16- // 指示组件是否隐藏的开关
1712import { hiddenPropertyView } from "comps/utils/propertyUtils" ;
18- // 右侧属性开关
19-
2013import { BoolControl } from "comps/controls/boolControl" ;
21- import { stringExposingStateControl } from "comps/controls/codeStateControl" ; //文本并暴露值
14+ import { stringExposingStateControl } from "comps/controls/codeStateControl" ;
2215import { dropdownControl } from "comps/controls/dropdownControl" ;
23- import { styleControl } from "comps/controls/styleControl" ; //样式输入框
16+ import { styleControl } from "comps/controls/styleControl" ;
2417import { alignControl } from "comps/controls/alignControl" ;
2518import { AutoHeightControl } from "comps/controls/autoHeightControl" ;
2619import { jsonValueExposingStateControl } from "comps/controls/codeStateControl" ;
@@ -34,35 +27,25 @@ import {
3427 NumberControl ,
3528 StringControl ,
3629} from "comps/controls/codeControl" ;
37- // 事件控制
3830import {
3931 clickEvent ,
4032 eventHandlerControl ,
4133} from "comps/controls/eventHandlerControl" ;
42-
43- // 引入样式
4434import {
4535 TimeLineStyle ,
4636 heightCalculator ,
4737 widthCalculator ,
4838 marginCalculator ,
4939} from "comps/controls/styleControlConstants" ;
50- // 初始化暴露值
5140import { stateComp , valueComp } from "comps/generators/simpleGenerators" ;
52- // 组件对外暴露属性的api
5341import {
5442 NameConfig ,
5543 NameConfigHidden ,
5644 withExposingConfigs ,
5745} from "comps/generators/withExposing" ;
58-
5946import { timelineDate , timelineNode , TimelineDataTooltip } from "./timelineConstants" ;
6047import { convertTimeLineData } from "./timelineUtils" ;
6148import { default as Timeline } from "antd/es/timeline" ;
62-
63- import { ANTDICON } from "./antIcon" ; // todo: select icons to not import all icons
64-
65- import { useContext } from "react" ;
6649import { EditorContext } from "comps/editorState" ;
6750
6851const EventOptions = [
@@ -86,18 +69,44 @@ const childrenMap = {
8669 clickedIndex : valueComp < number > ( 0 ) ,
8770} ;
8871
72+ // Utility function to dynamically load Ant Design icons
73+ const loadIcon = async ( iconName : string ) => {
74+ if ( ! iconName ) return null ;
75+ try {
76+ const module = await import ( `@ant-design/icons` ) ;
77+ const IconComponent = ( module as any ) [ iconName ] ;
78+ return IconComponent ? < IconComponent /> : null ;
79+ } catch ( error ) {
80+ console . error ( `Error loading icon ${ iconName } :` , error ) ;
81+ return null ;
82+ }
83+ } ;
84+
8985const TimelineComp = (
9086 props : RecordConstructorToView < typeof childrenMap > & {
9187 dispatch : ( action : CompAction ) => void ;
9288 }
9389) => {
9490 const { value, dispatch, style, mode, reverse, onEvent } = props ;
91+ const [ icons , setIcons ] = useState < React . ReactNode [ ] > ( [ ] ) ;
92+
93+ useEffect ( ( ) => {
94+ const loadIcons = async ( ) => {
95+ const iconComponents = await Promise . all (
96+ value . map ( ( node ) =>
97+ node . dot ? loadIcon ( node . dot ) : Promise . resolve ( null )
98+ )
99+ ) ;
100+ setIcons ( iconComponents ) ;
101+ } ;
102+
103+ loadIcons ( ) ;
104+ } , [ value ] ) ;
105+
95106 const timelineItems = value . map ( ( value : timelineNode , index : number ) => ( {
96107 key : index ,
97108 color : value ?. color ,
98- dot : value ?. dot && ANTDICON . hasOwnProperty ( value ?. dot . toLowerCase ( ) )
99- ? ANTDICON [ value ?. dot . toLowerCase ( ) as keyof typeof ANTDICON ]
100- : "" ,
109+ dot : icons [ index ] || "" ,
101110 label : (
102111 < span style = { { color : value ?. lableColor || style ?. lableColor } } >
103112 { value ?. label }
@@ -125,10 +134,8 @@ const TimelineComp = (
125134 </ p >
126135 </ >
127136 )
128- }
129- ) )
137+ } ) ) ;
130138
131- // TODO:parse px string
132139 return (
133140 < div
134141 style = { {
0 commit comments