@bigfishtv/cockpit
Version:
113 lines (99 loc) • 3.8 kB
JavaScript
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
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; }
import React, { Component } from 'react';
import * as iconRegistry from '../iconRegistry';
import { titleCase } from '../utils/stringUtils';
import Icon from './Icon';
import InfoTooltip from './InfoTooltip';
import Button from './button/Button';
/**
* Internal component used for displaying all icons in iconRegistry with a search filter
*/
var IconsHelper = function (_Component) {
_inherits(IconsHelper, _Component);
function IconsHelper(props) {
_classCallCheck(this, IconsHelper);
var _this = _possibleConstructorReturn(this, _Component.call(this, props));
_this.state = {
iconSearch: '',
show: false
};
return _this;
}
IconsHelper.prototype.render = function render() {
var _this2 = this;
if (!this.state.show) {
return React.createElement(Button, { text: 'Show Icons', onClick: function onClick() {
return _this2.setState({ show: true });
} });
}
var iconCategories = iconRegistry.getCategories();
var categories = Object.keys(iconCategories);
var iconSearch = (this.state.iconSearch || '').toLowerCase();
var uncategorizedKeys = iconRegistry.getUncategorizedKeys();
var uncategorizedIcons = iconSearch ? uncategorizedKeys.filter(function (key) {
return key.indexOf(iconSearch) >= 0;
}) : uncategorizedKeys;
return React.createElement(
'div',
null,
React.createElement(
'div',
{ className: 'form-input' },
React.createElement(
'label',
null,
'Filter Icons'
),
React.createElement('input', { value: iconSearch, onChange: function onChange(event) {
return _this2.setState({ iconSearch: event.target.value });
} })
),
categories.map(function (category, i) {
var categoryIcons = iconSearch ? iconCategories[category].filter(function (key) {
return key.indexOf(iconSearch) >= 0;
}) : iconCategories[category];
return categoryIcons.length ? React.createElement(
'div',
{ key: i },
React.createElement(
'h5',
null,
titleCase(category)
),
categoryIcons.map(function (key, n) {
return React.createElement(
InfoTooltip,
{ key: n, text: key },
React.createElement(Icon, { name: key, onClick: function onClick() {
return window.prompt('Copy to clipboard', key);
} })
);
}),
React.createElement('hr', null)
) : null;
}),
uncategorizedIcons.length ? React.createElement(
'div',
null,
React.createElement(
'h5',
null,
'Uncategorized / Legacy'
),
uncategorizedIcons.map(function (key, n) {
return React.createElement(
InfoTooltip,
{ key: n, text: key },
React.createElement(Icon, { name: key, onClick: function onClick() {
return window.prompt('Copy to clipboard', key);
} })
);
})
) : null
);
};
return IconsHelper;
}(Component);
export { IconsHelper as default };