-
-
Save xnimorz/543dc894ce0c98168f4cb3dd6b7c3e2e to your computer and use it in GitHub Desktop.
inline-svg + use
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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