Design system.
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 

92 řádky
2.3 KiB

  1. import * as React from 'react';
  2. import * as CheckControlBase from '@tesseract-design/web-base-checkcontrol';
  3. export type RadioTickBoxProps = Omit<React.HTMLProps<HTMLInputElement>, 'size' | 'type' | 'style'> & {
  4. /**
  5. * Should the component occupy the whole width of its parent?
  6. */
  7. block?: boolean,
  8. /**
  9. * Does the component need to conserve space?
  10. */
  11. compact?: boolean,
  12. /**
  13. * Complementary content of the component.
  14. */
  15. subtext?: React.ReactNode,
  16. }
  17. /**
  18. * Component for performing an action upon activation (e.g. when clicked).
  19. *
  20. * This component functions as a regular button.
  21. */
  22. export const RadioTickBox = React.forwardRef<HTMLInputElement, RadioTickBoxProps>(
  23. (
  24. {
  25. children,
  26. block = false,
  27. compact = false,
  28. subtext,
  29. className: _className,
  30. as: _as,
  31. ...etcProps
  32. }: RadioTickBoxProps,
  33. ref,
  34. ) => {
  35. const styleProps = React.useMemo<CheckControlBase.CheckControlBaseArgs>(() => ({
  36. block,
  37. compact,
  38. appearance: CheckControlBase.CheckControlAppearance.TICK_BOX,
  39. type: CheckControlBase.CheckControlType.RADIO,
  40. uncheckedLabel: false,
  41. }), [block, compact]);
  42. return (
  43. <div
  44. className={CheckControlBase.ClickAreaWrapper(styleProps)}
  45. >
  46. <label
  47. className={CheckControlBase.ClickArea()}
  48. >
  49. <input
  50. {...etcProps}
  51. type="radio"
  52. ref={ref}
  53. className={CheckControlBase.CheckStateContainer(styleProps)}
  54. />
  55. <span>
  56. <span />
  57. <span
  58. className={CheckControlBase.CheckIndicatorArea(styleProps)}
  59. >
  60. <span
  61. className={CheckControlBase.CheckIndicatorWrapper(styleProps)}
  62. />
  63. </span>
  64. <span>
  65. {children}
  66. {
  67. subtext
  68. && (
  69. <>
  70. <br />
  71. <span
  72. className={CheckControlBase.Subtext()}
  73. data-testid="subtext"
  74. >
  75. {subtext}
  76. </span>
  77. </>
  78. )
  79. }
  80. </span>
  81. </span>
  82. </label>
  83. </div>
  84. );
  85. },
  86. );
  87. RadioTickBox.displayName = 'ActionButton';