Skip to content

Commit c186039

Browse files
杨国璇杨国璇
杨国璇
authored and
杨国璇
committed
feat: checkbox svg icon
1 parent d4f0de9 commit c186039

File tree

12 files changed

+70
-26
lines changed

12 files changed

+70
-26
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/CheckboxEditor/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,11 @@ class CheckboxEditor extends Component {
6666
};
6767

6868
renderIcon = (symbol, color) => {
69-
const className = classnames('dtable-ui-checkbox-check-mark', { 'dtable-ui-checkbox-check-svg': !symbol?.startsWith('dtable-icon') });
69+
let className = 'dtable-ui-checkbox-check-mark';
7070
if (symbol.startsWith('dtable-icon')) {
7171
return (<span className={`dtable-font ${symbol} ${className || ''}`} style={{ color }} />);
7272
}
73+
className = classnames(className, { 'dtable-ui-checkbox-check-svg': !symbol?.startsWith('dtable-icon'), 'scale-icon': isMobile });
7374
return (<SvgIcon className={className} symbol={symbol} color={color} />);
7475
};
7576

src/CheckboxFormatter/index.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
@import url('../css/cell-formatter.css');
22

3-
.dtable-ui.checkbox-formatter .checkbox-checked-mark {
3+
.dtable-ui.checkbox-formatter .dtable-ui-checkbox-check-mark {
44
color: #20c933;
55
display: flex;
66
align-items: center;

src/CheckboxFormatter/index.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import PropTypes from 'prop-types';
33
import classnames from 'classnames';
44
import SvgIcon from '../SvgIcon';
55
import { DEFAULT_CHECKBOX_MARK_STYLE } from '../constants';
6+
import { isMobile } from '../utils/utils';
67

78
import './index.css';
89

@@ -17,6 +18,15 @@ class CheckboxFormatter extends React.PureComponent {
1718
value: false
1819
};
1920

21+
renderIcon = (symbol, color) => {
22+
let className = 'dtable-ui-checkbox-check-mark';
23+
if (symbol.startsWith('dtable-icon')) {
24+
return (<span className={`dtable-font ${symbol} ${className || ''}`} style={{ color }} />);
25+
}
26+
className = classnames(className, { 'dtable-ui-checkbox-check-svg': !symbol?.startsWith('dtable-icon'), 'scale-icon': isMobile });
27+
return (<SvgIcon className={className} symbol={symbol} color={color} />);
28+
};
29+
2030
render() {
2131
let { value, containerClassName, checkboxStyle } = this.props;
2232
if (!checkboxStyle || !('type' in checkboxStyle && 'color' in checkboxStyle)) {
@@ -28,10 +38,7 @@ class CheckboxFormatter extends React.PureComponent {
2838
const classname = classnames('dtable-ui cell-formatter-container checkbox-formatter d-flex align-items-center justify-content-center', containerClassName);
2939
return (
3040
<div className={classname}>
31-
{checkboxStyle.type.startsWith('dtable-icon') ?
32-
<span className={`dtable-font ${checkboxStyle.type} checkbox-checked-mark`} style={{ color: checkboxStyle.color }}></span> :
33-
<SvgIcon className="dtable-ui-checkbox-check-svg" symbol={checkboxStyle.type} color={checkboxStyle.color} />
34-
}
41+
{this.renderIcon(checkboxStyle.type, checkboxStyle.color)}
3542
</div>
3643
);
3744
}

src/GeolocationEditor/country-editor.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ class CountryEditor extends Component {
177177

178178
getLocationData = () => {
179179
const { config } = this.props;
180-
const { mediaUrl } = { ...window.dtable, ...config };
180+
const { mediaUrl } = { ...window?.dtable, ...config };
181181
let geoFileName = 'en-region-location';
182182
if (this.lang === 'cn') {
183183
geoFileName = 'cn-region-location';

src/GeolocationEditor/map-editor-utils.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const MINE_MAP_ONLINE_SERVICE = {
1616
};
1717

1818
export const getMineMapUrl = (config = {}) => {
19-
const { dtableMineMapCustomConfig = {} } = { ...window.dtable, ...config };
19+
const { dtableMineMapCustomConfig = {} } = { ...window?.dtable, ...config };
2020
const { domain_url = '', data_domain_url = '', server_domain_url = '',
2121
sprite_url = '', service_url = '' } = dtableMineMapCustomConfig;
2222
return {
@@ -44,7 +44,7 @@ export const getInitCenter = (isSelectionEditor = false) => {
4444
};
4545

4646
export const getMapInfo = (config = {}) => {
47-
const { dtableBaiduMapKey: baiduMapKey, dtableGoogleMapKey: googleMapKey, dtableMineMapKey: mineMapKey } = { ...window.dtable, ...config };
47+
const { dtableBaiduMapKey: baiduMapKey, dtableGoogleMapKey: googleMapKey, dtableMineMapKey: mineMapKey } = { ...window?.dtable, ...config };
4848
let mapType;
4949
let mapKey;
5050
if (baiduMapKey) {

src/RowExpandEditor/RowExpandGeolocationEditor/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,8 @@ class RowExpandGeolocationEditor extends React.Component {
123123
};
124124

125125
getLocationInfo = (value) => {
126-
const { column } = this.props;
127-
const { dtableBaiduMapKey, dtableMineMapKey } = window.dtable;
126+
const { column, config } = this.props;
127+
const { dtableBaiduMapKey, dtableMineMapKey } = { ...window?.dtable, ...config };
128128
const isBaiduMap = !!(dtableBaiduMapKey || dtableMineMapKey);
129129
return getGeolocationDisplayString(value, column.data, { isBaiduMap, hyphen: ' ' });
130130
};

src/SvgIcon/index.js

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,22 @@ import PropTypes from 'prop-types';
33

44
import './index.css';
55

6-
const needScaleIcons = ['check', 'dot', 'cross'];
6+
const iconComponents = {};
7+
const requireContext = require.context('../assets/icons', false, /\.svg$/);
78

8-
const SvgIcon = (props) => {
9-
const { className, symbol, color } = props;
10-
let iconClass = `dtable-ui-multicolor-icon multicolor-icon-${symbol} ${className || ''}`;
11-
if (needScaleIcons.includes(symbol) && window.isMobile) {
12-
iconClass += ' scale-icon';
13-
}
14-
return (
15-
<svg className={iconClass} aria-hidden="true">
16-
<use fill={color} xlinkHref={`#${symbol}`} />
17-
</svg>
18-
);
9+
requireContext.keys().forEach(path => {
10+
const iconName = path.replace(/^\.\/(.*?)\.svg$/, '$1').toLowerCase();
11+
iconComponents[iconName] = requireContext(path).default;
12+
});
13+
14+
const SvgIcon = ({ className, symbol, color }) => {
15+
if (!symbol) return null;
16+
const iconClass = `dtable-ui-multicolor-icon multicolor-icon-${symbol} ${className || ''}`;
17+
const props = { className: iconClass, style: { fill: color }, ariaHidden: 'true' };
18+
19+
const IconComponent = iconComponents[symbol];
20+
if (!IconComponent) return null;
21+
return (<IconComponent { ...props } />);
1922
};
2023

2124
SvgIcon.propTypes = {

src/assets/icons/check.svg

Lines changed: 12 additions & 0 deletions
Loading

src/assets/icons/cross.svg

Lines changed: 13 additions & 0 deletions
Loading

src/assets/icons/dot.svg

Lines changed: 9 additions & 0 deletions
Loading

src/index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,3 @@ export { default as IconButton } from './IconButton';
103103
// upload
104104
export { default as UploadProgress } from './UploadProgress';
105105

106-
export { default as SvgIcon } from './SvgIcon';

0 commit comments

Comments
 (0)