Website for showcasing all features of Tesseract Web.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

118 line
2.9 KiB

  1. import * as React from 'react';
  2. import * as TextControlBase from '@tesseract-design/web-base-textcontrol';
  3. export type MaskedTextInputProps = Omit<React.HTMLProps<HTMLInputElement>, 'size' | 'type' | 'style'> & {
  4. /**
  5. * Short textual description indicating the nature of the component's value.
  6. */
  7. label?: React.ReactNode,
  8. /**
  9. * Short textual description as guidelines for valid input values.
  10. */
  11. hint?: React.ReactNode,
  12. /**
  13. * Size of the component.
  14. */
  15. size?: TextControlBase.TextControlSize,
  16. /**
  17. * Additional description, usually graphical, indicating the nature of the component's value.
  18. */
  19. indicator?: React.ReactNode,
  20. /**
  21. * Should the component display a border?
  22. */
  23. border?: boolean,
  24. /**
  25. * Should the component occupy the whole width of its parent?
  26. */
  27. block?: boolean,
  28. /**
  29. * Style of the component.
  30. */
  31. style?: TextControlBase.TextControlStyle,
  32. /**
  33. * Is the label hidden?
  34. */
  35. hiddenLabel?: boolean,
  36. }
  37. /**
  38. * Component for inputting textual values.
  39. *
  40. * This component supports multiline input and adjusts its layout accordingly.
  41. */
  42. export const MaskedTextInput = React.forwardRef<HTMLInputElement, MaskedTextInputProps>(
  43. (
  44. {
  45. label = '',
  46. hint = '',
  47. indicator = null,
  48. size = TextControlBase.TextControlSize.MEDIUM,
  49. border = false,
  50. block = false,
  51. style = TextControlBase.TextControlStyle.DEFAULT,
  52. hiddenLabel = false,
  53. className: _className,
  54. placeholder: _placeholder,
  55. as: _as,
  56. ...etcProps
  57. }: MaskedTextInputProps,
  58. ref,
  59. ) => {
  60. const textInputBaseArgs = React.useMemo<TextControlBase.TextControlBaseArgs>(() => ({
  61. block,
  62. border,
  63. size,
  64. indicator: Boolean(indicator),
  65. style,
  66. resizable: false,
  67. predefinedValues: false,
  68. }), [block, border, size, indicator, style]);
  69. return (
  70. <div
  71. className={TextControlBase.ComponentBase(textInputBaseArgs)}
  72. >
  73. <input
  74. {...etcProps}
  75. className={TextControlBase.Input(textInputBaseArgs)}
  76. ref={ref}
  77. aria-label={label}
  78. type="password"
  79. data-testid="input"
  80. />
  81. {border && <span />}
  82. {
  83. label && !hiddenLabel && (
  84. <div
  85. className={TextControlBase.LabelWrapper(textInputBaseArgs)}
  86. >
  87. {label}
  88. </div>
  89. )
  90. }
  91. {hint && (
  92. <div
  93. className={TextControlBase.HintWrapper(textInputBaseArgs)}
  94. >
  95. <div
  96. className={TextControlBase.Hint()}
  97. >
  98. {hint}
  99. </div>
  100. </div>
  101. )}
  102. {indicator && (
  103. <div
  104. className={TextControlBase.IndicatorWrapper(textInputBaseArgs)}
  105. >
  106. {indicator}
  107. </div>
  108. )}
  109. </div>
  110. );
  111. },
  112. );
  113. MaskedTextInput.displayName = 'MaskedTextInput';