1
- import { useEffect , useRef , useState } from "react" ;
1
+ import { useEffect , useMemo , useRef , useState } from "react" ;
2
2
import styled , { css } from "styled-components" ;
3
3
import { RecordConstructorToView } from "lowcoder-core" ;
4
4
import { styleControl } from "comps/controls/styleControl" ;
@@ -34,8 +34,10 @@ import { AssetType, IconscoutControl } from "@lowcoder-ee/comps/controls/iconsco
34
34
import { dropdownControl } from "../controls/dropdownControl" ;
35
35
36
36
const Container = styled . div < {
37
+ $sourceMode : string ;
37
38
$style : IconStyleType | undefined ;
38
- $animationStyle :AnimationStyleType } > `
39
+ $animationStyle :AnimationStyleType ;
40
+ } > `
39
41
display: flex;
40
42
align-items: center;
41
43
justify-content: center;
@@ -59,6 +61,15 @@ const Container = styled.div<{
59
61
pointer-events: auto;
60
62
}
61
63
` }
64
+ ${ ( props ) => props . $sourceMode === 'asset-library' && `
65
+ img {
66
+ max-width: 100%;
67
+ max-height: 100%;
68
+ width: 100%;
69
+ height: 100%;
70
+ object-fit: contain;
71
+ }
72
+ ` }
62
73
` ;
63
74
64
75
const EventOptions = [ clickEvent ] as const ;
@@ -101,17 +112,28 @@ const IconView = (props: RecordConstructorToView<typeof childrenMap>) => {
101
112
onResize,
102
113
} ) ;
103
114
115
+ const style = useMemo ( ( ) => {
116
+ if ( props . sourceMode === 'standard' ) {
117
+ return {
118
+ fontSize : props . autoHeight
119
+ ? `${ height < width ? height : width } px`
120
+ : props . iconSize ,
121
+ background : props . style . background ,
122
+ }
123
+ }
124
+ return {
125
+ width : props . autoHeight ? '' : props . iconSize ,
126
+ background : props . style . background ,
127
+ }
128
+ } , [ width , height , props . autoHeight , props . iconSize , props . sourceMode , props . style . background ] ) ;
129
+
104
130
return (
105
131
< Container
106
132
ref = { conRef }
107
133
$style = { props . style }
134
+ $sourceMode = { props . sourceMode }
108
135
$animationStyle = { props . animationStyle }
109
- style = { {
110
- fontSize : props . autoHeight
111
- ? `${ height < width ? height : width } px`
112
- : props . iconSize ,
113
- background : props . style . background ,
114
- } }
136
+ style = { style }
115
137
onClick = { ( ) => props . onEvent ( "click" ) }
116
138
>
117
139
{ props . sourceMode === 'standard'
0 commit comments