Skip to content

Instantly share code, notes, and snippets.

@xnimorz
Created October 29, 2019 15:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xnimorz/8dfe0c5135315c306e3ddf7a9cbf8808 to your computer and use it in GitHub Desktop.
Save xnimorz/8dfe0c5135315c306e3ddf7a9cbf8808 to your computer and use it in GitHub Desktop.
react-icon-loader
const fs = require('fs');
const { getOptions } = require('loader-utils');
module.exports = function(source) {
if (this.cacheable) {
this.cacheable();
}
const options = getOptions(this);
const template = fs.readFileSync(options.template, 'utf8');
return template.replace(
'<icon />',
source
.replace('{width}', 'width={width}')
.replace('{height}', 'height={height}')
.replace('class="{class}"', 'className={classNames}');
);
};
import React from 'react';
import PropTypes from 'prop-types';
import classnames from 'classnames';
import { colors } from './config';
function Icon({ id, color, loading, width = 16, height = 16, highlight, disabledColor }) {
const classNames = classnames('bloko-icon', {
'bloko-icon_loading': loading,
[`bloko-icon_${color}`]: color,
[`bloko-icon_highlight-${highlight}`]: highlight,
[`bloko-icon_disabled`]: disabledColor,
});
return (
<icon />
);
}
Icon.propTypes = {
id: PropTypes.string,
/** Цвет иконки */
color: PropTypes.oneOf(colors.map(({ name }) => name)),
/** Цвет иконки active */
highlight: PropTypes.oneOf(colors.map(({ name }) => name)),
/** Цвет иконки disabled */
disabledColor: PropTypes.oneOf(colors.map(({ name }) => name)),
/** Должна ли быть иконка индикатором загрузки */
loading: PropTypes.bool,
/** Ширина иконки */
width: PropTypes.number,
/** Ширина иконки */
height: PropTypes.number,
};
module.exports = Icon;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment