You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CustomOptionButton.tsx 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import React from 'react';
  2. import { Image } from 'react-native';
  3. import { SvgCssUri } from 'react-native-svg';
  4. import { connect } from 'react-redux';
  5. import { translate } from '../../../base/i18n/functions';
  6. import AbstractButton, { IProps as AbstractButtonProps } from '../../../base/toolbox/components/AbstractButton';
  7. import styles from './styles';
  8. interface IProps extends AbstractButtonProps {
  9. backgroundColor?: string;
  10. icon: any;
  11. id?: string;
  12. text: string;
  13. }
  14. /**
  15. * Component that renders a custom button.
  16. *
  17. * @returns {Component}
  18. */
  19. class CustomOptionButton extends AbstractButton<IProps> {
  20. backgroundColor = this.props.backgroundColor;
  21. iconSrc = this.props.icon;
  22. id = this.props.id;
  23. text = this.props.text;
  24. /**
  25. * Custom icon component.
  26. *
  27. * @returns {React.Component}
  28. */
  29. icon = () => {
  30. let iconComponent;
  31. if (!this.iconSrc) {
  32. return null;
  33. }
  34. if (this.iconSrc?.includes('svg')) {
  35. iconComponent
  36. = (
  37. <SvgCssUri
  38. style = { styles.iconImageStyles }
  39. uri = { this.iconSrc } />);
  40. } else {
  41. iconComponent
  42. = (
  43. <Image
  44. source = {{ uri: this.iconSrc }}
  45. style = { styles.iconImageStyles } />);
  46. }
  47. return iconComponent;
  48. };
  49. label = this.text;
  50. }
  51. export default translate(connect()(CustomOptionButton));