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 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import React from 'react';
  2. import { Image, View, ViewStyle } 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 BaseTheme from '../../../base/ui/components/BaseTheme.native';
  8. import styles from './styles';
  9. interface IProps extends AbstractButtonProps {
  10. backgroundColor?: string;
  11. icon: any;
  12. id?: string;
  13. isToolboxButton?: boolean;
  14. text?: string;
  15. }
  16. /**
  17. * Component that renders a custom button.
  18. *
  19. * @returns {Component}
  20. */
  21. class CustomOptionButton extends AbstractButton<IProps> {
  22. backgroundColor = this.props.backgroundColor;
  23. iconSrc = this.props.icon;
  24. id = this.props.id;
  25. text = this.props.text;
  26. /**
  27. * Custom icon component.
  28. *
  29. * @returns {React.Component}
  30. */
  31. icon = () => {
  32. let iconComponent;
  33. if (!this.iconSrc) {
  34. return null;
  35. }
  36. if (this.iconSrc?.includes('svg')) {
  37. iconComponent = (
  38. <SvgCssUri
  39. height = { BaseTheme.spacing[4] }
  40. uri = { this.iconSrc }
  41. width = { BaseTheme.spacing[4] } />
  42. );
  43. } else {
  44. iconComponent = (
  45. <Image
  46. height = { BaseTheme.spacing[4] }
  47. resizeMode = { 'contain' }
  48. source = {{ uri: this.iconSrc }}
  49. width = { BaseTheme.spacing[4] } />
  50. );
  51. }
  52. return (
  53. <View
  54. style = { this.props.isToolboxButton && [
  55. styles.toolboxButtonIconContainer,
  56. { backgroundColor: this.backgroundColor } ] as ViewStyle }>
  57. { iconComponent }
  58. </View>
  59. );
  60. };
  61. label = this.text || '';
  62. }
  63. export default translate(connect()(CustomOptionButton));