Skip to content

Commit ff22da3

Browse files
committed
inlined icons
1 parent 12a8305 commit ff22da3

30 files changed

+2896
-841
lines changed

components/SLDSIcons.js

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,15 @@ export const ButtonIcon = React.createClass({
4646
if (this.props.destructive) {
4747
className += ' slds-button__icon--destructive';
4848
}
49+
/*
4950
if(this.props.category === 'utility'){
5051
return <SLDSUtilityIcon name={this.props.name} aria-hidden='true' className={className} />;
5152
}
5253
return <svg aria-hidden='true' className={className} dangerouslySetInnerHTML={{__html: useTag }} />;
54+
*/
55+
return <SLDSUtilityIcon name={this.props.name} category={this.props.category} aria-hidden='true' className={className} />;
56+
57+
5358
}
5459

5560
});
@@ -79,20 +84,26 @@ export const Icon = React.createClass({
7984
className += ' slds-icon--' + this.props.position;
8085
}
8186
className = className + ' slds-icon-' + this.props.category + '-' + (this.props.theme || this.props.name);
82-
if(this.props.category === 'utility'){
83-
return <span className='slds-icon__container'><SLDSUtilityIcon name={this.props.name} aria-hidden='true' className={className} style={this.props.style} /></span>;
84-
}
85-
return <span className='slds-icon__container'><svg aria-hidden='true' className={className} style={this.props.style} dangerouslySetInnerHTML={{__html: useTag }} /></span>;
87+
// if(this.props.category === 'utility'){
88+
return <span className='slds-icon__container'><SLDSUtilityIcon name={this.props.name} category={this.props.category} aria-hidden='true' className={className} style={this.props.style} /></span>;
89+
// }
90+
// return <span className='slds-icon__container'><svg aria-hidden='true' className={className} style={this.props.style} dangerouslySetInnerHTML={{__html: useTag }} /></span>;
8691
}
8792

8893
});
8994

9095
export const InputIcon = React.createClass({
9196

97+
getDefaultProps() {
98+
return {
99+
category: 'utility',
100+
};
101+
},
102+
92103
render() {
93104
const useTag = '<use xlink:href="'+SLDSSettings.getAssetsPath()+'icons/utility-sprite/svg/symbols.svg#' + this.props.name + '" />';
94105
const className = 'slds-input__icon slds-icon-text-default';
95-
return <SLDSUtilityIcon name={this.props.name} aria-hidden='true' className={className} />;
106+
return <SLDSUtilityIcon name={this.props.name} category={this.props.category} aria-hidden='true' className={className} />;
96107
}
97108

98109
});

components/SLDSUtilityIcon/SVG/index.jsx

Lines changed: 86 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,33 +12,109 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
1212
'use strict';
1313

1414
import React from 'react';
15-
import SLDS_ICONS_UTIL from './slds-icons-util';
15+
import SLDS_ICONS_UTILITY from './slds-icons-utility';
16+
import SLDS_ICONS_ACTION from './slds-icons-action';
17+
import SLDS_ICONS_CUSTOM from './slds-icons-custom';
18+
import SLDS_ICONS_DOCTYPE from './slds-icons-doctype';
19+
import SLDS_ICONS_STANDARD from './slds-icons-standard';
1620

1721
module.exports = React.createClass({
1822

1923
getDefaultProps () {
2024
return {
21-
name:'announcenent'
25+
name:'announcenent',
26+
category:'utility'
2227
};
2328
},
2429

25-
getPaths (data) {
26-
if(data instanceof Array){
27-
return data.map((item)=>{
30+
getPaths (paths) {
31+
if(paths instanceof Array){
32+
return paths.map((item)=>{
2833
return <path {...item} />;
2934
});
3035
}
31-
return <path {...data} />;
36+
return <path {...paths} />;
3237
},
3338

34-
getSVG (name) {
35-
const data = SLDS_ICONS_UTIL[name.toLowerCase()];
36-
return <svg {...this.props} viewBox={SLDS_ICONS_UTIL.viewBox}>{this.getPaths(data)}</svg>;
39+
getCircles (circles) {
40+
if(circles instanceof Array){
41+
return circles.map((item)=>{
42+
return <circle {...item} />;
43+
});
44+
}
45+
return <circle {...circles} />;
46+
},
47+
48+
getEllipses (ellipses) {
49+
if(ellipses instanceof Array){
50+
return ellipses.map((item)=>{
51+
return <ellipse {...item} />;
52+
});
53+
}
54+
return <ellipse {...ellipses} />;
55+
},
56+
57+
getGroups (groups) {
58+
if(groups instanceof Array){
59+
return groups.map((item)=>{
60+
return <g>{ this.getShapes(item) }</g>;
61+
});
62+
}
63+
return <g>{ this.getShapes(groups) }</g>;
64+
},
65+
66+
getShapes (data) {
67+
var shapes = [];
68+
if(data.g){
69+
shapes.push(this.getGroups(data.g));
70+
}
71+
if(data.ellipse){
72+
shapes.push(this.getEllipses(data.ellipse));
73+
}
74+
if(data.circle){
75+
shapes.push(this.getCircles(data.circle));
76+
}
77+
if(data.path){
78+
shapes.push(this.getPaths(data.path));
79+
}
80+
return shapes;
81+
},
82+
83+
getSVG (name, category) {
84+
var data;
85+
var viewBox;
86+
switch (category) {
87+
case 'utility':
88+
data = SLDS_ICONS_UTILITY[name.toLowerCase()];
89+
viewBox = SLDS_ICONS_UTILITY.viewBox;
90+
break;
91+
case 'action':
92+
data = SLDS_ICONS_ACTION[name.toLowerCase()];
93+
viewBox = SLDS_ICONS_ACTION.viewBox;
94+
break;
95+
case 'custom':
96+
data = SLDS_ICONS_CUSTOM[name.toLowerCase()];
97+
viewBox = SLDS_ICONS_CUSTOM.viewBox;
98+
break;
99+
case 'doctype':
100+
data = SLDS_ICONS_DOCTYPE[name.toLowerCase()];
101+
viewBox = SLDS_ICONS_DOCTYPE.viewBox;
102+
break;
103+
case 'standard':
104+
data = SLDS_ICONS_STANDARD[name.toLowerCase()];
105+
viewBox = SLDS_ICONS_STANDARD.viewBox;
106+
break;
107+
default:
108+
data = SLDS_ICONS_UTILITY[name.toLowerCase()];
109+
viewBox = SLDS_ICONS_UTILITY.viewBox;
110+
break;
111+
}
112+
return <svg {...this.props} viewBox={viewBox}>{this.getShapes(data)}</svg>;
37113
},
38114

39115
render () {
40116
return (
41-
this.getSVG(this.props.name)
117+
this.getSVG(this.props.name, this.props.category)
42118
);
43119
}
44120
});

0 commit comments

Comments
 (0)