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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. import React, { useRef } from 'react';
  2. type Size = 'sm' | 'md' | 'lg' | 'xl';
  3. type Type = 'button' | 'submit' | 'reset';
  4. type TextTransform = 'uppercase' | 'capitalize';
  5. type MinWidth = 'auto' | 'none';
  6. interface ButtonProps {
  7. variant?: string;
  8. size?: Size;
  9. children?: React.ReactNode;
  10. authButton?: boolean;
  11. type?: Type;
  12. onClick?: () => void;
  13. textTransform?: TextTransform;
  14. className?: string;
  15. disabled?: boolean;
  16. hidden?: boolean;
  17. minWidth?: MinWidth;
  18. }
  19. const Button: React.FC<ButtonProps> = ({
  20. variant,
  21. size,
  22. children,
  23. authButton,
  24. type,
  25. onClick,
  26. textTransform,
  27. className,
  28. disabled,
  29. hidden,
  30. minWidth,
  31. ...restProps
  32. }) => {
  33. const buttonRef = useRef<HTMLButtonElement>(null);
  34. function styles() {
  35. let style = 'c-btn';
  36. if (variant) {
  37. style += ` c-btn--${variant}`;
  38. }
  39. if (size) {
  40. style += ` c-btn--${size}`;
  41. }
  42. if (textTransform) {
  43. style += ` c-btn--${textTransform}`;
  44. }
  45. if (authButton) {
  46. style += ` c-btn--auth`;
  47. }
  48. if (minWidth) {
  49. style += ` c-btn--${minWidth}`;
  50. }
  51. if (hidden) {
  52. style += ` c-btn--hidden`;
  53. }
  54. if (className) {
  55. style += ` ${className}`;
  56. }
  57. return style;
  58. }
  59. function handleClick() {
  60. if (buttonRef.current != null) {
  61. buttonRef.current.blur();
  62. }
  63. if (typeof onClick === 'function') {
  64. onClick();
  65. }
  66. }
  67. return (
  68. <button
  69. ref={buttonRef}
  70. className={styles()}
  71. onClick={handleClick}
  72. type={type}
  73. disabled={disabled}
  74. {...restProps}
  75. >
  76. {children}
  77. </button>
  78. );
  79. };
  80. Button.defaultProps = {
  81. type: 'button',
  82. };
  83. export default Button;