All files / components/inputs/InputText InputText.tsx

100% Statements 7/7
54.54% Branches 6/11
100% Functions 1/1
100% Lines 7/7

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97    2x                 2x   2x   2x                                                                 18x                                                                                         2x   2x  
/* eslint-disable no-ternary, max-lines-per-function */
 
import {
  ErrorText,
  InfoText,
  Input,
  Label,
  LoadingWrapper,
  SuccessText,
  Wrapper
} from "./styled"
import { ForwardedRef, forwardRef } from "react"
import { ComponentProps } from "."
import Loading from "components/Loading"
 
const InputText = forwardRef(
  (
    {
      className,
      defaultValue,
      disabled,
      error,
      errorText,
      hasContent,
      infoText,
      inputId,
      inputProps,
      isFullBorder,
      label,
      labelId,
      loading,
      max,
      min,
      name,
      onBlur,
      onChange,
      onInput,
      onKeyDown,
      required,
      size,
      step,
      success,
      successText,
      type = "text",
      value
    }: ComponentProps,
    ref: ForwardedRef<HTMLInputElement>
  ) => (
    <Wrapper className={className}>
      <Input
        {...inputProps}
        $error={error}
        $hasContent={hasContent}
        $isFullBorder={isFullBorder}
        $loading={loading}
        $success={success}
        aria-invalid={error ? "true" : "false"}
        defaultValue={defaultValue}
        disabled={disabled}
        id={inputId}
        max={max}
        min={min}
        name={name}
        onBlur={onBlur}
        onChange={onChange}
        onInput={onInput}
        onKeyDown={onKeyDown}
        ref={ref}
        required={required}
        size={size}
        step={step}
        type={type}
        value={value}
      />
      <Label htmlFor={inputId} id={labelId} isFullBorder={isFullBorder}>
        {label}
      </Label>
 
      {loading ? (
        <LoadingWrapper>
          <Loading />
        </LoadingWrapper>
      ) : null}
 
      {errorText ? <ErrorText role="alert">{errorText}</ErrorText> : null}
      {infoText ? <InfoText aria-live="polite">{infoText}</InfoText> : null}
      {successText ? (
        <SuccessText aria-live="polite">{successText}</SuccessText>
      ) : null}
    </Wrapper>
  )
)
 
InputText.displayName = "InputText"
 
export default InputText