|
9 | 9 | import '../index.less'; |
10 | 10 |
|
11 | 11 | import { SearchOutlined } from '@ant-design/icons'; |
12 | | -import { Button, Input, Select } from 'antd'; |
| 12 | +import { Button, Image, Input, Select } from 'antd'; |
13 | 13 | import classNames from 'classnames'; |
14 | 14 | import React from 'react'; |
15 | 15 |
|
16 | 16 | import Icon from '@/components/Icon'; |
17 | 17 |
|
18 | 18 | import { defaultComponentIcon } from '../configs'; |
19 | 19 |
|
| 20 | +function checkStringType(str: string | React.ReactSVG | undefined) { |
| 21 | + if (typeof str !== 'string') { |
| 22 | + return 'NULL'; |
| 23 | + } |
| 24 | + const trimmed = str.trim(); |
| 25 | + |
| 26 | + // 检查是否是 SVG 标签 |
| 27 | + const svgPattern = /^\s*<svg[^>]*>[\s\S]*<\/svg>\s*$/iu; |
| 28 | + if (svgPattern.test(trimmed)) { |
| 29 | + return 'SVG'; |
| 30 | + } |
| 31 | + |
| 32 | + // 检查是否是 URL |
| 33 | + const urlPattern = /^https?:\/\/\S+$/iu; |
| 34 | + if (urlPattern.test(trimmed)) { |
| 35 | + return 'URL'; |
| 36 | + } |
| 37 | + |
| 38 | + return 'INVALID'; |
| 39 | +} |
| 40 | + |
20 | 41 | export interface SelectorProps<ValueType> { |
21 | 42 | openPanel?: boolean; |
22 | 43 | floatPanel?: boolean; |
@@ -84,7 +105,16 @@ function Selector<ValueType,>(props: SelectorProps<ValueType>) { |
84 | 105 | props.onChange(option.value); |
85 | 106 | }} |
86 | 107 | > |
87 | | - <Icon className="jfe-drip-table-generator-components-bar-component-icon" svg={option.icon || defaultComponentIcon} /> |
| 108 | + { |
| 109 | + ['SVG', 'NULL'].includes(checkStringType(option.icon)) && ( |
| 110 | + <Icon className="jfe-drip-table-generator-components-bar-component-icon" svg={option.icon || defaultComponentIcon} /> |
| 111 | + ) |
| 112 | + } |
| 113 | + { |
| 114 | + checkStringType(option.icon) === 'URL' && ( |
| 115 | + <Image src={option.icon as string} width={18} height={18} wrapperStyle={{ height: 24, margin: '0 3px' }} preview={false} /> |
| 116 | + ) |
| 117 | + } |
88 | 118 | <span className="jfe-drip-table-generator-components-bar-component-text">{ option.label }</span> |
89 | 119 | </Button> |
90 | 120 | )) |
|
0 commit comments