Skip to content

Instantly share code, notes, and snippets.

@xnimorz

xnimorz/icon.jsx Secret

Created October 29, 2019 15:10
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/543dc894ce0c98168f4cb3dd6b7c3e2e to your computer and use it in GitHub Desktop.
Save xnimorz/543dc894ce0c98168f4cb3dd6b7c3e2e to your computer and use it in GitHub Desktop.
inline-svg + use
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 }) {
// eslint-disable-next-line
const classNames = classnames('bloko-icon', {
'bloko-icon_loading': loading,
[`bloko-icon_${color}`]: color,
[`bloko-icon_highlight-${highlight}`]: highlight,
[`bloko-icon_disabled`]: disabledColor,
});
return (
<svg width={width} height={height} className={classNames}>
<use href={`#${id}`} />
</svg>
);
}
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