Skip to content

Commit

Permalink
Update InputText prop type exports to improve usability of the types …
Browse files Browse the repository at this point in the history
…with the legacy version of InputText
  • Loading branch information
MichaelParadis committed Jan 16, 2025
1 parent 2472fd8 commit f494860
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
4 changes: 2 additions & 2 deletions packages/components/src/InputText/InputText.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React, { Ref, forwardRef, useImperativeHandle, useRef } from "react";
import { InputTextPropOptions, InputTextRef } from "./InputText.types";
import { InputTextRef, LegacyInputTextProps } from "./InputText.types";
import { useTextAreaResize } from "./useTextAreaResize";
import { FieldActionsRef, FormField } from "../FormField";

function InputTextInternal(
props: InputTextPropOptions,
props: LegacyInputTextProps,
ref: Ref<InputTextRef>,
) {
const inputRef = useRef<HTMLTextAreaElement | HTMLInputElement>(null);
Expand Down
4 changes: 2 additions & 2 deletions packages/components/src/InputText/InputText.types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Clearable } from "@jobber/hooks/src";
import { Clearable } from "@jobber/hooks";
import { XOR } from "ts-xor";
import {
AutocompleteTypes,
Expand Down Expand Up @@ -127,4 +127,4 @@ interface MultilineProps extends BaseProps {
readonly rows?: number | RowRange;
}

export type InputTextPropOptions = XOR<BaseProps, MultilineProps>;
export type LegacyInputTextProps = XOR<BaseProps, MultilineProps>;
11 changes: 6 additions & 5 deletions packages/components/src/InputText/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,22 @@ import React, { ForwardedRef, forwardRef } from "react";
import { InputText as InputTextLegacy } from "./InputText";
import { InputTextSPAR } from "./InputText.rebuilt";
import {
InputTextPropOptions,
InputTextRebuiltProps,
InputTextRef,
LegacyInputTextProps,
} from "./InputText.types";

export type InputTextProps = InputTextPropOptions | InputTextRebuiltProps;
export type InputTextShimProps = LegacyInputTextProps | InputTextRebuiltProps;
export type InputTextProps = LegacyInputTextProps;

function isNewInputTextProps(
props: InputTextProps,
props: InputTextShimProps,
): props is InputTextRebuiltProps {
return props.version === 2;
}

export const InputText = forwardRef(function InputTextShim(
props: InputTextProps,
props: InputTextShimProps,
ref: ForwardedRef<HTMLTextAreaElement | HTMLInputElement | InputTextRef>,
) {
if (isNewInputTextProps(props)) {
Expand All @@ -33,4 +34,4 @@ export const InputText = forwardRef(function InputTextShim(
}
});

export { InputTextRef };
export { InputTextRef, InputTextRebuiltProps };

0 comments on commit f494860

Please sign in to comment.