|
1 |
| -import{AnimationStyle,BoolCodeControl,ButtonEventHandlerControl,CommonNameConfig,DropdownOptionControl,IconControl,LinkStyle,NameConfig,NameConfigDisabled,RefControl,Section,SelectOptionControl,StringControl,TabsOptionControl,TagsOptionControl,UICompBuilder,blurMethod,clickMethod,focusWithOptions,migrateOldData,refMethods,sectionNames,stringExposingStateControl,styleControl,withDefault,withExposingConfigs}from"@lowcoder-ee/index.sdk"; |
2 |
| -importReactfrom"react"; |
| 1 | +import{ |
| 2 | +BoolCodeControl, |
| 3 | +ButtonEventHandlerControl, |
| 4 | +InputLikeStyle, |
| 5 | +NameConfig, |
| 6 | +Section, |
| 7 | +UICompBuilder, |
| 8 | +hiddenPropertyView, |
| 9 | +sectionNames, |
| 10 | +showDataLoadingIndicatorsPropertyView, |
| 11 | +styleControl, |
| 12 | +withExposingConfigs |
| 13 | +}from"@lowcoder-ee/index.sdk"; |
| 14 | +importstyledfrom"styled-components"; |
| 15 | +importReact,{useContext}from"react"; |
3 | 16 | import{trans}from"i18n";
|
4 |
| -import{buttonRefMethods}from"../buttonComp/buttonCompConstants"; |
5 | 17 | import{Tag}from"antd";
|
6 |
| -import{autoCompleteRefMethods}from"../autoCompleteComp/autoCompleteConstants"; |
| 18 | +import{EditorContext}from"comps/editorState"; |
| 19 | +import{PresetStatusColorTypes}from"antd/es/_util/colors"; |
| 20 | +import{hashToNum}from"util/stringUtils"; |
| 21 | +import{TagsCompOptionsControl}from"comps/controls/optionsControl"; |
| 22 | +import{useCompClickEventHandler}from"@lowcoder-ee/comps/utils/useCompClickEventHandler"; |
7 | 23 |
|
| 24 | +constcolors=PresetStatusColorTypes; |
8 | 25 |
|
9 |
| -// const TagsCompView = (function () { |
10 |
| -// // const childrenMap = { |
11 |
| -// // text: withDefault(StringControl, trans("link.link")), |
12 |
| -// // onEvent: ButtonEventHandlerControl, |
13 |
| -// // disabled: BoolCodeControl, |
14 |
| -// // loading: BoolCodeControl, |
15 |
| - |
16 |
| -// // // style: migrateOldData(styleControl(LinkStyle, 'style')), |
17 |
| -// // animationStyle: styleControl(AnimationStyle, 'animationStyle'), |
18 |
| -// // prefixIcon: IconControl, |
19 |
| -// // suffixIcon: IconControl, |
20 |
| -// // viewRef: RefControl<HTMLElement>, |
21 |
| -// //}; |
| 26 | +// These functions are used for individual tag styling |
| 27 | +functiongetTagColor(tagText :any,tagOptions:any[]){ |
| 28 | +constfoundOption=tagOptions.find((option:{label:any;})=>option.label===tagText); |
| 29 | +if(foundOption){ |
| 30 | +if(foundOption.colorType==="preset"){ |
| 31 | +returnfoundOption.presetColor; |
| 32 | +}elseif(foundOption.colorType==="custom"){ |
| 33 | +returnundefined; |
| 34 | +} |
| 35 | +returnfoundOption.color; |
| 36 | +} |
| 37 | +constindex=Math.abs(hashToNum(tagText))%colors.length; |
| 38 | +returncolors[index]; |
| 39 | +} |
22 | 40 |
|
23 |
| -// const childrenMap = { |
24 |
| -// text: stringExposingStateControl("text", "world"), |
25 |
| -// // options: TabsOptionControl, |
26 |
| -// }; |
27 |
| -// return new UICompBuilder(childrenMap, (props) => { |
28 |
| -// return ( |
29 |
| -// <Tag>Tag 1</Tag> |
30 |
| -// ) |
31 |
| -// }) |
32 |
| -// .setPropertyViewFn((children) => { |
33 |
| -// return( |
34 |
| -// <Section name={sectionNames.basic}> |
35 |
| -// {/* {children.options.propertyView({})} */} |
36 |
| -// {children.text.propertyView({ label: trans("text") })} |
37 |
| -// </Section> |
38 |
| -// ) |
39 |
| -// }) |
40 |
| -// .build(); |
41 |
| -// })(); |
| 41 | +constgetTagStyle=(tagText:any,tagOptions:any[],baseStyle:any={})=>{ |
| 42 | +constfoundOption=tagOptions.find((option:{label:any;})=>option.label===tagText); |
| 43 | +if(foundOption){ |
| 44 | +conststyle:any={ ...baseStyle}; |
| 45 | + |
| 46 | +if(foundOption.colorType==="custom"){ |
| 47 | +style.backgroundColor=foundOption.color; |
| 48 | +style.color=foundOption.textColor; |
| 49 | +style.border=`1px solid${foundOption.color}`; |
| 50 | +} |
| 51 | + |
| 52 | +if(foundOption.border){ |
| 53 | +style.borderColor=foundOption.border; |
| 54 | +if(!foundOption.colorType||foundOption.colorType!=="custom"){ |
| 55 | +style.border=`1px solid${foundOption.border}`; |
| 56 | +} |
| 57 | +} |
| 58 | + |
| 59 | +if(foundOption.radius){ |
| 60 | +style.borderRadius=foundOption.radius; |
| 61 | +} |
| 62 | + |
| 63 | +if(foundOption.margin){ |
| 64 | +style.margin=foundOption.margin; |
| 65 | +} |
| 66 | + |
| 67 | +if(foundOption.padding){ |
| 68 | +style.padding=foundOption.padding; |
| 69 | +} |
| 70 | + |
| 71 | +returnstyle; |
| 72 | +} |
| 73 | +returnbaseStyle; |
| 74 | +}; |
| 75 | + |
| 76 | +functiongetTagIcon(tagText:any,tagOptions:any[]){ |
| 77 | +constfoundOption=tagOptions.find(option=>option.label===tagText); |
| 78 | +returnfoundOption ?foundOption.icon :undefined; |
| 79 | +} |
42 | 80 |
|
43 | 81 | constmultiTags=(function(){
|
| 82 | + |
| 83 | +constStyledTag=styled(Tag)<{$style:any,$bordered:boolean,$customStyle:any}>` |
| 84 | + display: flex; |
| 85 | + justify-content: center; |
| 86 | + align-items: center; |
| 87 | + width: 100%; |
| 88 | + background:${(props)=>props.$customStyle?.backgroundColor||props.$style?.background}; |
| 89 | + color:${(props)=>props.$customStyle?.color||props.$style?.text}; |
| 90 | + border-radius:${(props)=>props.$customStyle?.borderRadius||props.$style?.borderRadius}; |
| 91 | + border:${(props)=>{ |
| 92 | +if(props.$customStyle?.border)returnprops.$customStyle.border; |
| 93 | +returnprops.$bordered ?`${props.$style?.borderStyle}${props.$style?.borderWidth}${props.$style?.border}` :'none'; |
| 94 | +}}; |
| 95 | + padding:${(props)=>props.$customStyle?.padding||props.$style?.padding}; |
| 96 | + margin:${(props)=>props.$customStyle?.margin||props.$style?.margin}; |
| 97 | + font-size:${(props)=>props.$style?.textSize}; |
| 98 | + font-weight:${(props)=>props.$style?.fontWeight}; |
| 99 | + cursor: pointer; |
| 100 | + `; |
| 101 | + |
| 102 | +constStyledTagContainer=styled.div` |
| 103 | + display: flex; |
| 104 | + gap: 5px; |
| 105 | + padding: 5px; |
| 106 | + `; |
| 107 | + |
44 | 108 | constchildrenMap={
|
45 |
| -text:stringExposingStateControl("text","world"), |
46 |
| -options:TagsOptionControl, |
| 109 | +options:TagsCompOptionsControl, |
| 110 | +style:styleControl(InputLikeStyle,'style'), |
| 111 | +onEvent:ButtonEventHandlerControl, |
| 112 | +borderless:BoolCodeControl, |
| 113 | +enableIndividualStyling:BoolCodeControl, |
47 | 114 | };
|
48 | 115 |
|
49 | 116 | returnnewUICompBuilder(childrenMap,(props)=>{
|
50 |
| -consttext=props.text.value; |
51 |
| -console.log(props.options) |
| 117 | +consthandleClickEvent=useCompClickEventHandler({onEvent:props.onEvent}); |
| 118 | + |
52 | 119 | return(
|
53 |
| -<> |
54 |
| -{props.options.map(tag=>( |
55 |
| -<Tag>{tag.label}</Tag> |
56 |
| -))} |
57 |
| -</> |
58 |
| -); |
| 120 | +<StyledTagContainer> |
| 121 | +{props.options.map((tag,index)=>{ |
| 122 | + |
| 123 | +// Use individual styling only if enableIndividualStyling is true |
| 124 | +consttagColor=props.enableIndividualStyling ?getTagColor(tag.label,props.options) :undefined; |
| 125 | +consttagIcon=props.enableIndividualStyling ?getTagIcon(tag.label,props.options) :tag.icon; |
| 126 | +consttagStyle=props.enableIndividualStyling ?getTagStyle(tag.label,props.options,props.style) :{}; |
| 127 | + |
| 128 | +return( |
| 129 | +<StyledTag |
| 130 | +key={`tag-${index}`} |
| 131 | +$style={props.style} |
| 132 | +$bordered={!props.borderless} |
| 133 | +$customStyle={tagStyle} |
| 134 | +icon={tagIcon} |
| 135 | +color={tagColor} |
| 136 | +onClick={()=>handleClickEvent()} |
| 137 | +> |
| 138 | +{tag.label} |
| 139 | +</StyledTag> |
| 140 | +); |
| 141 | +})} |
| 142 | +</StyledTagContainer> |
| 143 | +); |
59 | 144 | })
|
60 | 145 | .setPropertyViewFn((children:any)=>{
|
61 | 146 | return(
|
62 |
| -<Sectionname="Basic"> |
63 |
| -{children.options.propertyView({})} |
64 |
| -{children.text.propertyView({label:"Text"})} |
65 |
| -</Section> |
| 147 | +<> |
| 148 | +<Sectionname="Basic"> |
| 149 | +{children.options.propertyView({})} |
| 150 | +</Section> |
| 151 | + |
| 152 | +{["logic","both"].includes(useContext(EditorContext).editorModeStatus)&&( |
| 153 | +<Sectionname={sectionNames.interaction}> |
| 154 | +{children.onEvent.getPropertyView()} |
| 155 | +{hiddenPropertyView(children)} |
| 156 | +{showDataLoadingIndicatorsPropertyView(children)} |
| 157 | +</Section> |
| 158 | +)} |
| 159 | + |
| 160 | +{["layout","both"].includes( |
| 161 | +useContext(EditorContext).editorModeStatus |
| 162 | +)&&( |
| 163 | +<Sectionname={sectionNames.style}> |
| 164 | +{children.enableIndividualStyling.propertyView({ |
| 165 | +label:trans("style.individualStyling"), |
| 166 | +tooltip:trans("style.individualStylingTooltip") |
| 167 | +})} |
| 168 | +{children.borderless.propertyView({label:trans("style.borderless")})} |
| 169 | +{children.style.getPropertyView()} |
| 170 | +</Section> |
| 171 | +)} |
| 172 | +</> |
66 | 173 | )
|
67 | 174 | })
|
68 | 175 | .build();
|
69 | 176 | })()
|
70 | 177 |
|
71 |
| - |
72 |
| -// const childrenMap = { |
73 |
| -// text: stringExposingStateControl("text", "world"), |
74 |
| -// options: TagsOptionControl, |
75 |
| -// }; |
76 |
| - |
77 |
| -// const TagsCompView = new UICompBuilder(childrenMap, (props: any) => { |
78 |
| -// const text = props.text.value; |
79 |
| -// return <div>Hello {text}</div>; |
80 |
| -// }) |
81 |
| -// .setPropertyViewFn((children: any) => { |
82 |
| -// return ( |
83 |
| -// <Section name="Basic"> |
84 |
| -// {children.options.propertyView({})} |
85 |
| -// {children.text.propertyView({ label: "Text" })} |
86 |
| -// </Section> |
87 |
| -// ) |
88 |
| -// }) |
89 |
| -// .build(); |
90 |
| - |
91 |
| -exportconstMultiTagsComp=withExposingConfigs(multiTags,[newNameConfig("text","")]); |
| 178 | +exportconstMultiTagsComp=withExposingConfigs(multiTags,[newNameConfig("options","")]); |
92 | 179 |
|