Skip to content

Commit 51923da

Browse files
committed
Add lib/SLDSIcons/Icon
1 parent ebd6a88 commit 51923da

File tree

1 file changed

+109
-0
lines changed

1 file changed

+109
-0
lines changed

lib/SLDSIcons/Icon/index.js

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
/*
2+
Copyright (c) 2015, salesforce.com, inc. All rights reserved.
3+
4+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
5+
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
6+
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
7+
Neither the name of salesforce.com, inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
8+
9+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
10+
*/
11+
12+
'use strict';
13+
14+
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
15+
16+
var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; desc = parent = getter = undefined; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } };
17+
18+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
19+
20+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
21+
22+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
23+
24+
function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
25+
26+
var _react = require('react');
27+
28+
var _react2 = _interopRequireDefault(_react);
29+
30+
var _SLDSUtilityIcon = require('../../SLDSUtilityIcon');
31+
32+
var _SLDSUtilityIcon2 = _interopRequireDefault(_SLDSUtilityIcon);
33+
34+
var classNames = require("classnames");
35+
36+
var displayName = "Icon";
37+
var propTypes = {
38+
assistiveText: _react2['default'].PropTypes.string,
39+
category: _react2['default'].PropTypes.string,
40+
name: _react2['default'].PropTypes.string,
41+
position: _react2['default'].PropTypes.oneOf(["left", "right"]),
42+
size: _react2['default'].PropTypes.string,
43+
theme: _react2['default'].PropTypes.string
44+
};
45+
var defaultProps = {
46+
category: 'standard' };
47+
48+
// standard Icon Reference: https://www.lightningdesignsystem.com/resources/icons
49+
50+
var Icon = (function (_React$Component) {
51+
_inherits(Icon, _React$Component);
52+
53+
function Icon(props) {
54+
_classCallCheck(this, Icon);
55+
56+
_get(Object.getPrototypeOf(Icon.prototype), 'constructor', this).call(this, props);
57+
this.state = {};
58+
}
59+
60+
_createClass(Icon, [{
61+
key: 'getContainerClassName',
62+
value: function getContainerClassName() {
63+
var _classNames;
64+
65+
var name = this.props.name ? this.props.name.replace(/_/g, '-') : '';
66+
var renderName = this.props.category === "action";
67+
68+
return classNames((_classNames = {}, _defineProperty(_classNames, "slds-icon__container", this.props.category !== "utility"), _defineProperty(_classNames, 'slds-icon-' + this.props.category + '-' + (this.props.theme || name), renderName), _classNames));
69+
}
70+
}, {
71+
key: 'getClassName',
72+
value: function getClassName() {
73+
var _classNames2;
74+
75+
var name = this.props.name ? this.props.name.replace(/_/g, '-') : '';
76+
var customName = this.props.name ? this.props.name.replace("custom", "custom-") : null;
77+
78+
return classNames(this.props.className, "slds-icon", (_classNames2 = {}, _defineProperty(_classNames2, 'slds-icon--' + this.props.size, this.props.size), _defineProperty(_classNames2, 'slds-icon--' + this.props.position, this.props.position), _defineProperty(_classNames2, 'slds-icon-' + customName, this.props.category === "custom"), _defineProperty(_classNames2, 'slds-icon-' + this.props.category + '-' + (this.props.theme || name), this.props.category === "standard"), _classNames2));
79+
}
80+
}, {
81+
key: 'render',
82+
value: function render() {
83+
var label = null;
84+
var styles = this.props.category === "action" ? { padding: "0.5rem" } : null;
85+
86+
if (this.props.assistiveText) {
87+
label = _react2['default'].createElement(
88+
'span',
89+
{ className: 'slds-assistive-text' },
90+
this.props.assistiveText
91+
);
92+
}
93+
return _react2['default'].createElement(
94+
'span',
95+
{ className: this.getContainerClassName(), style: styles },
96+
label,
97+
_react2['default'].createElement(_SLDSUtilityIcon2['default'], { className: this.getClassName(), name: this.props.name, category: this.props.category, 'aria-hidden': 'true' })
98+
);
99+
}
100+
}]);
101+
102+
return Icon;
103+
})(_react2['default'].Component);
104+
105+
Icon.displayName = displayName;
106+
Icon.propTypes = propTypes;
107+
Icon.defaultProps = defaultProps;
108+
109+
module.exports = Icon;

0 commit comments

Comments
 (0)