application-amicale/components/CustomMaterialIcon.js

62 lines
1.9 KiB
JavaScript
Raw Normal View History

// @flow
import * as React from 'react';
2019-06-28 11:35:15 +02:00
import {Icon} from "native-base";
import ThemeManager from '../utils/ThemeManager';
type Props = {
active: boolean,
icon: string,
color: ?string,
fontSize: number,
width: number | string,
}
2019-06-29 15:43:57 +02:00
/**
* Custom component defining a material icon using native base
*
* @prop active {boolean} Whether to set the icon color to active
* @prop icon {string} The icon string to use from MaterialCommunityIcons
* @prop color {string} The icon color. Use default theme color if unspecified
* @prop fontSize {number} The icon size. Use 26 if unspecified
* @prop width {number} The icon width. Use 30 if unspecified
*/
export default class CustomMaterialIcon extends React.Component<Props> {
2019-06-28 11:35:15 +02:00
static defaultProps = {
active: false,
color: undefined,
fontSize: 26,
width: 30,
};
2019-06-28 11:35:15 +02:00
2020-02-11 01:05:24 +01:00
shouldComponentUpdate(nextProps: Props): boolean {
return nextProps.icon !== this.props.icon ||
nextProps.active !== this.props.active ||
nextProps.width !== this.props.width ||
nextProps.fontSize !== this.props.fontSize ||
nextProps.color !== this.props.color;
}
2019-06-28 11:35:15 +02:00
render() {
2020-02-11 01:05:24 +01:00
// console.log("rendering icon " + this.props.icon);
2019-06-28 11:35:15 +02:00
return (
<Icon
active
name={this.props.icon}
type={'MaterialCommunityIcons'}
style={{
color:
this.props.color !== undefined ?
this.props.color :
this.props.active ?
ThemeManager.getCurrentThemeVariables().brandPrimary :
ThemeManager.getCurrentThemeVariables().customMaterialIconColor,
fontSize: this.props.fontSize,
width: this.props.width
2019-06-28 11:35:15 +02:00
}}
/>
);
}
}