Website for showcasing all features of Tesseract Web.
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

127 lines
3.0 KiB

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