Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

Button.tsx 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. import React from 'react';
  2. import { useTranslation } from 'react-i18next';
  3. import {
  4. Button as NativePaperButton,
  5. Text,
  6. TouchableRipple
  7. } from 'react-native-paper';
  8. import { BUTTON_MODES, BUTTON_TYPES } from '../../constants';
  9. import BaseTheme from '../BaseTheme.native';
  10. import { IButtonProps } from '../types';
  11. import styles from './buttonStyles';
  12. export interface IProps extends IButtonProps {
  13. color?: string;
  14. contentStyle?: Object | undefined;
  15. labelStyle?: Object | undefined;
  16. style?: Object | undefined;
  17. }
  18. const Button: React.FC<IProps> = ({
  19. accessibilityLabel,
  20. color: buttonColor,
  21. contentStyle,
  22. disabled,
  23. icon,
  24. labelKey,
  25. labelStyle,
  26. onClick: onPress,
  27. style,
  28. type
  29. }: IProps) => {
  30. const { t } = useTranslation();
  31. const { CONTAINED } = BUTTON_MODES;
  32. const { DESTRUCTIVE, PRIMARY, SECONDARY, TERTIARY } = BUTTON_TYPES;
  33. let buttonLabelStyles;
  34. let buttonStyles;
  35. let color;
  36. let mode;
  37. if (type === PRIMARY) {
  38. buttonLabelStyles = styles.buttonLabelPrimary;
  39. color = BaseTheme.palette.action01;
  40. mode = CONTAINED;
  41. } else if (type === SECONDARY) {
  42. buttonLabelStyles = styles.buttonLabelSecondary;
  43. color = BaseTheme.palette.action02;
  44. mode = CONTAINED;
  45. } else if (type === DESTRUCTIVE) {
  46. color = BaseTheme.palette.actionDanger;
  47. buttonLabelStyles = styles.buttonLabelDestructive;
  48. mode = CONTAINED;
  49. } else {
  50. color = buttonColor;
  51. buttonLabelStyles = styles.buttonLabel;
  52. }
  53. if (disabled) {
  54. buttonLabelStyles = styles.buttonLabelDisabled;
  55. buttonStyles = styles.buttonDisabled;
  56. } else {
  57. buttonStyles = styles.button;
  58. }
  59. if (type === TERTIARY) {
  60. return (
  61. <TouchableRipple
  62. accessibilityLabel = { accessibilityLabel }
  63. disabled = { disabled }
  64. onPress = { onPress }
  65. rippleColor = 'transparent'
  66. style = { [
  67. buttonStyles,
  68. style
  69. ] }>
  70. <Text
  71. style = { [
  72. buttonLabelStyles,
  73. labelStyle
  74. ] }>{ t(labelKey ?? '') }</Text>
  75. </TouchableRipple>
  76. );
  77. }
  78. return (
  79. <NativePaperButton
  80. accessibilityLabel = { t(accessibilityLabel ?? '') }
  81. children = { t(labelKey ?? '') }
  82. color = { color }
  83. contentStyle = { [
  84. styles.buttonContent,
  85. contentStyle
  86. ] }
  87. disabled = { disabled }
  88. // @ts-ignore
  89. icon = { icon }
  90. labelStyle = { [
  91. buttonLabelStyles,
  92. labelStyle
  93. ] }
  94. mode = { mode }
  95. onPress = { onPress }
  96. style = { [
  97. buttonStyles,
  98. style
  99. ] } />
  100. );
  101. };
  102. export default Button;