Design system.
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.
 
 
 

125 linhas
2.9 KiB

  1. import * as React from 'react';
  2. import * as TextControlBase from '@tesseract-design/web-base-textcontrol';
  3. export type PhoneNumberInputProps = Omit<React.HTMLProps<HTMLInputElement>, 'size' | '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 phone number values.
  39. */
  40. export const PhoneNumberInput = React.forwardRef<HTMLInputElement, PhoneNumberInputProps>(
  41. (
  42. {
  43. label = '',
  44. hint = '',
  45. indicator = null,
  46. size = TextControlBase.TextControlSize.MEDIUM,
  47. border = false,
  48. block = false,
  49. style = TextControlBase.TextControlStyle.DEFAULT,
  50. hiddenLabel = false,
  51. type: _type,
  52. className: _className,
  53. placeholder: _placeholder,
  54. as: _as,
  55. ...etcProps
  56. }: PhoneNumberInputProps,
  57. ref,
  58. ) => {
  59. const styleArgs = React.useMemo<TextControlBase.TextControlBaseArgs>(() => ({
  60. block,
  61. border,
  62. size,
  63. indicator: Boolean(indicator),
  64. style,
  65. resizable: false,
  66. predefinedValues: false,
  67. }), [block, border, size, indicator, style]);
  68. return (
  69. <div
  70. className={TextControlBase.Root(styleArgs)}
  71. >
  72. <input
  73. {...etcProps}
  74. className={TextControlBase.Input(styleArgs)}
  75. ref={ref}
  76. aria-label={label}
  77. type="tel"
  78. data-testid="input"
  79. />
  80. {
  81. border && (
  82. <span
  83. data-testid="border"
  84. />
  85. )
  86. }
  87. {
  88. label && !hiddenLabel && (
  89. <div
  90. data-testid="label"
  91. className={TextControlBase.LabelWrapper(styleArgs)}
  92. >
  93. {label}
  94. </div>
  95. )
  96. }
  97. {hint && (
  98. <div
  99. className={TextControlBase.HintWrapper(styleArgs)}
  100. data-testid="hint"
  101. >
  102. <div
  103. className={TextControlBase.Hint()}
  104. >
  105. {hint}
  106. </div>
  107. </div>
  108. )}
  109. {indicator && (
  110. <div
  111. className={TextControlBase.IndicatorWrapper(styleArgs)}
  112. >
  113. {indicator}
  114. </div>
  115. )}
  116. </div>
  117. );
  118. }
  119. );
  120. PhoneNumberInput.displayName = 'PhoneNumberInput';