Website for showcasing all features of Tesseract Web.
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 

110 Zeilen
2.8 KiB

  1. import * as React from 'react';
  2. import * as CheckControlBase from '@tesseract-design/web-base-checkcontrol';
  3. export type ToggleSwitchProps = 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 ToggleSwitch = React.forwardRef<HTMLInputElement, ToggleSwitchProps>(
  23. (
  24. {
  25. children,
  26. block = false,
  27. compact = false,
  28. subtext,
  29. className: _className,
  30. as: _as,
  31. ...etcProps
  32. }: ToggleSwitchProps,
  33. ref,
  34. ) => {
  35. const styleProps = React.useMemo<CheckControlBase.CheckControlBaseArgs>(() => ({
  36. block,
  37. compact,
  38. menuItem: false,
  39. appearance: CheckControlBase.CheckControlAppearance.SWITCH,
  40. type: 'checkbox',
  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="checkbox"
  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. <svg
  64. className={CheckControlBase.CheckIndicator(styleProps)}
  65. viewBox="0 0 24 24"
  66. role="presentation"
  67. >
  68. <polyline
  69. points="20 6 9 17 4 12"
  70. />
  71. </svg>
  72. <svg
  73. className={CheckControlBase.CheckIndicator(styleProps)}
  74. viewBox="0 0 24 24"
  75. role="presentation"
  76. >
  77. <polyline
  78. points="20 12 4 12"
  79. />
  80. </svg>
  81. </span>
  82. </span>
  83. <span>
  84. {children}
  85. {
  86. subtext
  87. && (
  88. <>
  89. <br />
  90. <span
  91. className={CheckControlBase.Subtext()}
  92. >
  93. {subtext}
  94. </span>
  95. </>
  96. )
  97. }
  98. </span>
  99. </span>
  100. </label>
  101. </div>
  102. );
  103. },
  104. );
  105. ToggleSwitch.displayName = 'ActionButton';