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.

IconButton.tsx 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import React from 'react';
  2. import { TouchableHighlight, ViewStyle } from 'react-native';
  3. import Icon from '../../../icons/components/Icon';
  4. import styles from '../../../react/components/native/styles';
  5. import { IIconButtonProps } from '../../../react/types';
  6. import { BUTTON_TYPES } from '../../constants.native';
  7. import BaseTheme from '../BaseTheme.native';
  8. const IconButton: React.FC<IIconButtonProps> = ({
  9. accessibilityLabel,
  10. color: iconColor,
  11. disabled,
  12. id,
  13. onPress,
  14. size,
  15. src,
  16. style,
  17. tapColor,
  18. type
  19. }: IIconButtonProps) => {
  20. const { PRIMARY, SECONDARY, TERTIARY } = BUTTON_TYPES;
  21. let color;
  22. let underlayColor;
  23. let iconButtonContainerStyles;
  24. if (type === PRIMARY) {
  25. color = BaseTheme.palette.icon01;
  26. iconButtonContainerStyles = styles.iconButtonContainerPrimary;
  27. underlayColor = BaseTheme.palette.action01;
  28. } else if (type === SECONDARY) {
  29. color = BaseTheme.palette.icon04;
  30. iconButtonContainerStyles = styles.iconButtonContainerSecondary;
  31. underlayColor = BaseTheme.palette.action02;
  32. } else if (type === TERTIARY) {
  33. color = iconColor;
  34. iconButtonContainerStyles = styles.iconButtonContainer;
  35. underlayColor = BaseTheme.palette.action03;
  36. } else {
  37. color = iconColor;
  38. underlayColor = tapColor;
  39. }
  40. if (disabled) {
  41. color = BaseTheme.palette.icon03;
  42. iconButtonContainerStyles = styles.iconButtonContainerDisabled;
  43. underlayColor = 'transparent';
  44. }
  45. return (
  46. <TouchableHighlight
  47. accessibilityLabel = { accessibilityLabel }
  48. disabled = { disabled }
  49. id = { id }
  50. onPress = { onPress }
  51. style = { [
  52. iconButtonContainerStyles,
  53. style
  54. ] as ViewStyle }
  55. underlayColor = { underlayColor }>
  56. <Icon
  57. color = { color }
  58. size = { size ?? 20 }
  59. src = { src } />
  60. </TouchableHighlight>
  61. );
  62. };
  63. export default IconButton;