Skip to content

Commit cbf62b5

Browse files
feat: icon support url
1 parent 7032b61 commit cbf62b5

File tree

1 file changed

+32
-2
lines changed
  • packages/drip-table-generator/src/layouts/table-workstation/editable-table/components/components-selector/selector

1 file changed

+32
-2
lines changed

packages/drip-table-generator/src/layouts/table-workstation/editable-table/components/components-selector/selector/index.tsx

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,35 @@
99
import '../index.less';
1010

1111
import { SearchOutlined } from '@ant-design/icons';
12-
import { Button, Input, Select } from 'antd';
12+
import { Button, Image, Input, Select } from 'antd';
1313
import classNames from 'classnames';
1414
import React from 'react';
1515

1616
import Icon from '@/components/Icon';
1717

1818
import { defaultComponentIcon } from '../configs';
1919

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+
2041
export interface SelectorProps<ValueType> {
2142
openPanel?: boolean;
2243
floatPanel?: boolean;
@@ -84,7 +105,16 @@ function Selector<ValueType,>(props: SelectorProps<ValueType>) {
84105
props.onChange(option.value);
85106
}}
86107
>
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+
}
88118
<span className="jfe-drip-table-generator-components-bar-component-text">{ option.label }</span>
89119
</Button>
90120
))

0 commit comments

Comments
 (0)