Website for showcasing all features of Tesseract Web.
Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 

149 linhas
3.8 KiB

  1. import * as React from 'react';
  2. import * as ButtonBase from '@tesseract-design/web-base-button';
  3. import * as CheckControlBase from '@tesseract-design/web-base-checkcontrol';
  4. export type RadioButtonProps = Omit<React.HTMLProps<HTMLInputElement>, 'size' | 'type' | 'style'> & {
  5. /**
  6. * Size of the component.
  7. */
  8. size?: ButtonBase.ButtonSize,
  9. /**
  10. * Variant of the component.
  11. */
  12. variant?: ButtonBase.ButtonVariant,
  13. /**
  14. * Should the component display a border?
  15. */
  16. border?: boolean,
  17. /**
  18. * Should the component occupy the whole width of its parent?
  19. */
  20. block?: boolean,
  21. /**
  22. * Does the component need to conserve space?
  23. */
  24. compact?: boolean,
  25. /**
  26. * Complementary content of the component.
  27. */
  28. subtext?: React.ReactNode,
  29. /**
  30. * Short complementary content displayed at the edge of the component.
  31. */
  32. badge?: React.ReactNode,
  33. }
  34. /**
  35. * Component for performing an action upon activation (e.g. when clicked).
  36. *
  37. * This component functions as a regular button.
  38. */
  39. export const RadioButton = React.forwardRef<HTMLInputElement, RadioButtonProps>(
  40. (
  41. {
  42. size = ButtonBase.ButtonSize.MEDIUM,
  43. variant = ButtonBase.ButtonVariant.OUTLINE,
  44. border = false,
  45. children,
  46. block = false,
  47. disabled = false,
  48. compact = false,
  49. subtext,
  50. badge,
  51. className: _className,
  52. as: _as,
  53. ...etcProps
  54. }: RadioButtonProps,
  55. ref,
  56. ) => {
  57. const styleProps = React.useMemo<ButtonBase.ButtonBaseArgs & CheckControlBase.CheckControlBaseArgs>(() => ({
  58. size,
  59. block,
  60. variant,
  61. border,
  62. compact,
  63. menuItem: false,
  64. disabled,
  65. appearance: CheckControlBase.CheckControlAppearance.BUTTON,
  66. type: 'radio',
  67. }), [size, block, variant, border, compact, disabled]);
  68. return (
  69. <div
  70. className={CheckControlBase.ClickAreaWrapper(styleProps)}
  71. >
  72. <label
  73. className={CheckControlBase.ClickArea()}
  74. >
  75. <input
  76. {...etcProps}
  77. disabled={disabled}
  78. type="radio"
  79. ref={ref}
  80. className={CheckControlBase.CheckStateContainer(styleProps)}
  81. />
  82. <span
  83. className={ButtonBase.Button(styleProps)}
  84. >
  85. <span
  86. className={ButtonBase.Border(styleProps)}
  87. />
  88. <span
  89. className={CheckControlBase.CheckIndicatorArea(styleProps)}
  90. >
  91. <span
  92. className={CheckControlBase.CheckIndicatorWrapper(styleProps)}
  93. />
  94. </span>
  95. <span
  96. className={ButtonBase.Label(styleProps)}
  97. >
  98. <span
  99. className={ButtonBase.MainText()}
  100. >
  101. <span
  102. className={ButtonBase.OverflowText()}
  103. >
  104. {children}
  105. </span>
  106. </span>
  107. {
  108. subtext
  109. && (
  110. <>
  111. {' '}
  112. <span
  113. className={ButtonBase.Subtext()}
  114. >
  115. <span
  116. className={ButtonBase.OverflowText()}
  117. >
  118. {subtext}
  119. </span>
  120. </span>
  121. </>
  122. )
  123. }
  124. </span>
  125. {
  126. badge
  127. && (
  128. <>
  129. {' '}
  130. <span
  131. className={ButtonBase.BadgeContainer(styleProps)}
  132. >
  133. {badge}
  134. </span>
  135. </>
  136. )
  137. }
  138. </span>
  139. </label>
  140. </div>
  141. );
  142. },
  143. );
  144. RadioButton.displayName = 'ActionButton';