Skip to content

Commit 0b29432

Browse files
committed
Polymorph type are easyer to manipulate
1 parent ac4f30c commit 0b29432

File tree

1 file changed

+21
-19
lines changed

1 file changed

+21
-19
lines changed

src/Input.tsx

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,28 @@ import { fr } from "./fr";
1515
import { cx } from "./tools/cx";
1616
import type { FrIconClassName, RiIconClassName } from "./fr/generatedFromCss/classNames";
1717

18-
export type InputProps = {
19-
className?: string;
20-
label: ReactNode;
21-
hintText?: ReactNode;
22-
hideLabel?: boolean;
23-
/** default: false */
24-
disabled?: boolean;
25-
iconId?: FrIconClassName | RiIconClassName;
26-
classes?: Partial<
27-
Record<"root" | "label" | "description" | "nativeInputOrTextArea" | "message", string>
28-
>;
29-
style?: CSSProperties;
30-
/** Default: "default" */
31-
state?: "success" | "error" | "default";
32-
/** The message won't be displayed if state is "default" */
33-
stateRelatedMessage?: ReactNode;
34-
} & (InputProps.WithoutTextArea | InputProps.WithTextArea);
18+
export type InputProps = InputProps.RegularInput | InputProps.TextArea;
3519

3620
export namespace InputProps {
37-
export type WithoutTextArea = {
21+
export type Common = {
22+
className?: string;
23+
label: ReactNode;
24+
hintText?: ReactNode;
25+
hideLabel?: boolean;
26+
/** default: false */
27+
disabled?: boolean;
28+
iconId?: FrIconClassName | RiIconClassName;
29+
classes?: Partial<
30+
Record<"root" | "label" | "description" | "nativeInputOrTextArea" | "message", string>
31+
>;
32+
style?: CSSProperties;
33+
/** Default: "default" */
34+
state?: "success" | "error" | "default";
35+
/** The message won't be displayed if state is "default" */
36+
stateRelatedMessage?: ReactNode;
37+
};
38+
39+
export type RegularInput = Common & {
3840
/** Default: false */
3941
textArea?: false;
4042
/** Props forwarded to the underlying <input /> element */
@@ -46,7 +48,7 @@ export namespace InputProps {
4648
nativeTextAreaProps?: never;
4749
};
4850

49-
export type WithTextArea = {
51+
export type TextArea = Common & {
5052
/** Default: false */
5153
textArea: true;
5254
/** Props forwarded to the underlying <textarea /> element */

0 commit comments

Comments
 (0)