🏷️(react) move SelectProps to index.tsx

It makes more sense for this type to be next to the Select component.
This commit is contained in:
Nathan Vasse
2023-10-04 15:48:22 +02:00
committed by NathanVss
parent 1c7a114b6e
commit b5c91d429d
7 changed files with 33 additions and 37 deletions

View File

@@ -1,6 +1,7 @@
import React, { forwardRef } from "react";
import React, { forwardRef, PropsWithChildren } from "react";
import { SelectMulti } from ":/components/Forms/Select/multi";
import { SelectMono, SelectProps } from ":/components/Forms/Select/mono";
import { Option, SelectMono } from ":/components/Forms/Select/mono";
import { FieldProps } from ":/components/Forms/Field";
export * from ":/components/Forms/Select/mono";
export * from ":/components/Forms/Select/multi";
@@ -8,6 +9,26 @@ export * from ":/components/Forms/Select/multi";
export interface SelectHandle {
blur: () => void;
}
export type SelectProps = PropsWithChildren &
FieldProps & {
label: string;
hideLabel?: boolean;
options: Option[];
searchable?: boolean;
name?: string;
defaultValue?: string | number | string[];
value?: string | number | string[];
onChange?: (event: {
target: { value: string | number | undefined | string[] };
}) => void;
onBlur?: (event: {
target: { value: string | number | undefined | string[] };
}) => void;
disabled?: boolean;
clearable?: boolean;
multi?: boolean;
};
export const Select = forwardRef<SelectHandle, SelectProps>((props, ref) => {
if (props.defaultValue && props.value) {
throw new Error(

View File

@@ -5,7 +5,8 @@ import { useCunningham } from ":/components/Provider";
import { Field } from ":/components/Forms/Field";
import { LabelledBox } from ":/components/Forms/LabelledBox";
import { Button } from ":/components/Button";
import { Option, SelectProps } from ":/components/Forms/Select/mono";
import { Option } from ":/components/Forms/Select/mono";
import { SelectProps } from ":/components/Forms/Select";
export function getOptionsFilter(inputValue?: string) {
return (option: Option) => {

View File

@@ -14,7 +14,7 @@ import {
SelectMonoAux,
SubProps,
} from ":/components/Forms/Select/mono-common";
import { SelectHandle } from ":/components/Forms/Select/index";
import { SelectHandle } from ":/components/Forms/Select";
export const SelectMonoSearchable = forwardRef<SelectHandle, SubProps>(
(props, ref) => {

View File

@@ -1,15 +1,9 @@
import React, {
forwardRef,
PropsWithChildren,
useEffect,
useState,
} from "react";
import React, { forwardRef, useEffect, useState } from "react";
import { UseSelectStateChange } from "downshift";
import { FieldProps } from ":/components/Forms/Field";
import { optionToValue, SubProps } from ":/components/Forms/Select/mono-common";
import { SelectMonoSearchable } from ":/components/Forms/Select/mono-searchable";
import { SelectMonoSimple } from ":/components/Forms/Select/mono-simple";
import { SelectHandle } from ":/components/Forms/Select/index";
import { SelectHandle, SelectProps } from ":/components/Forms/Select";
export interface Option {
value?: string;
@@ -17,26 +11,6 @@ export interface Option {
disabled?: boolean;
}
export type SelectProps = PropsWithChildren &
FieldProps & {
label: string;
hideLabel?: boolean;
options: Option[];
searchable?: boolean;
name?: string;
defaultValue?: string | number | string[];
value?: string | number | string[];
onChange?: (event: {
target: { value: string | number | undefined | string[] };
}) => void;
onBlur?: (event: {
target: { value: string | number | undefined | string[] };
}) => void;
disabled?: boolean;
clearable?: boolean;
multi?: boolean;
};
export const SelectMono = forwardRef<SelectHandle, SelectProps>(
(props, ref) => {
const defaultSelectedItem = props.defaultValue

View File

@@ -5,7 +5,8 @@ import { Field } from ":/components/Forms/Field";
import { LabelledBox } from ":/components/Forms/LabelledBox";
import { Button } from ":/components/Button";
import { useCunningham } from ":/components/Provider";
import { Option, SelectProps } from ":/components/Forms/Select/mono";
import { Option } from ":/components/Forms/Select/mono";
import { SelectProps } from ":/components/Forms/Select";
import {
getOptionsFilter,
optionToValue,

View File

@@ -3,8 +3,8 @@ import { optionToValue } from ":/components/Forms/Select/mono-common";
import { SelectMultiSearchable } from ":/components/Forms/Select/multi-searchable";
import { SelectMultiSimple } from ":/components/Forms/Select/multi-simple";
import { SubProps } from ":/components/Forms/Select/multi-common";
import { Option, SelectProps } from ":/components/Forms/Select/mono";
import { SelectHandle } from ":/components/Forms/Select/index";
import { Option } from ":/components/Forms/Select/mono";
import { SelectHandle, SelectProps } from ":/components/Forms/Select/index";
export type SelectMultiProps = Omit<SelectProps, "onChange"> & {
onChange?: (event: { target: { value: string[] } }) => void;

View File

@@ -1,7 +1,6 @@
import { Controller, useFormContext } from "react-hook-form";
import React from "react";
import { Select } from ":/components/Forms/Select/index";
import { SelectProps } from ":/components/Forms/Select/mono";
import { Select, SelectProps } from ":/components/Forms/Select/index";
export const RhfSelect = (props: SelectProps & { name: string }) => {
const { control, setValue } = useFormContext();