Design system.
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 

121 satır
3.2 KiB

  1. import * as React from 'react';
  2. import clsx from 'clsx';
  3. import { Button } from '@tesseract-design/web-base';
  4. export type ActionButtonDerivedElement = HTMLButtonElement;
  5. export interface ActionButtonProps extends Omit<React.HTMLProps<ActionButtonDerivedElement>, 'type' | 'size'> {
  6. type?: Button.Type;
  7. variant: Button.Variant;
  8. block?: boolean;
  9. subtext?: React.ReactNode;
  10. badge?: React.ReactNode;
  11. menuItem?: boolean;
  12. size?: Button.Size;
  13. compact?: boolean;
  14. }
  15. export const ActionButton = React.forwardRef<ActionButtonDerivedElement, ActionButtonProps>(({
  16. type = 'button' as const,
  17. variant,
  18. subtext,
  19. badge,
  20. menuItem = false,
  21. children,
  22. size = 'medium' as const,
  23. compact = false,
  24. className,
  25. block = false,
  26. ...etcProps
  27. }, forwardedRef) => (
  28. <button
  29. {...etcProps}
  30. type={type}
  31. ref={forwardedRef}
  32. className={clsx(
  33. 'items-center justify-center rounded overflow-hidden ring-secondary/50 leading-none select-none',
  34. 'focus:outline-0 focus:ring-4',
  35. 'active:ring-tertiary/50',
  36. 'disabled:opacity-50 disabled:cursor-not-allowed',
  37. {
  38. 'flex w-full': block,
  39. 'inline-flex max-w-full align-middle': !block,
  40. },
  41. {
  42. 'pl-2 gap-2': compact,
  43. 'pl-4 gap-4': !compact,
  44. 'pr-4': !(compact || menuItem),
  45. 'pr-2': compact || menuItem,
  46. },
  47. {
  48. 'border-2 border-primary disabled:border-primary focus:border-secondary active:border-tertiary' : variant !== 'bare',
  49. 'bg-negative text-primary disabled:text-primary focus:text-secondary active:text-tertiary': variant !== 'filled',
  50. 'bg-primary text-negative disabled:bg-primary focus:bg-secondary active:bg-tertiary': variant === 'filled',
  51. },
  52. {
  53. 'h-10': size === 'small',
  54. 'h-12': size === 'medium',
  55. 'h-16': size === 'large',
  56. },
  57. className,
  58. )}
  59. >
  60. <span
  61. className={clsx(
  62. 'flex-auto min-w-0',
  63. {
  64. 'text-left': compact || menuItem,
  65. 'text-center': !(compact || menuItem),
  66. },
  67. )}
  68. >
  69. <span
  70. className="block uppercase font-bold h-[1.1em] w-full whitespace-nowrap overflow-hidden text-ellipsis font-semi-expanded"
  71. data-testid="children"
  72. >
  73. {children}
  74. </span>
  75. {subtext && (
  76. <>
  77. <span className="sr-only">
  78. {' - '}
  79. </span>
  80. <span
  81. className="block h-[1.3em] w-full whitespace-nowrap overflow-hidden text-ellipsis font-semi-expanded font-bold text-xs"
  82. data-testid="subtext"
  83. >
  84. {subtext}
  85. </span>
  86. </>
  87. )}
  88. </span>
  89. {badge && (
  90. <>
  91. <span className="sr-only">
  92. {' - '}
  93. </span>
  94. <span
  95. data-testid="badge"
  96. >
  97. {badge}
  98. </span>
  99. </>
  100. )}
  101. {menuItem && (
  102. <span
  103. data-testid="menuItemIndicator"
  104. >
  105. <svg
  106. className="w-6 h-6 fill-none stroke-current stroke-2 linejoin-round linecap-round"
  107. viewBox="0 0 24 24"
  108. role="presentation"
  109. >
  110. <polyline points="9 18 15 12 9 6"/>
  111. </svg>
  112. </span>
  113. )}
  114. </button>
  115. ));
  116. ActionButton.displayName = 'ActionButton';