🏷️(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:
@@ -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(
|
||||
|
||||
@@ -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) => {
|
||||
|
||||
@@ -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) => {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user