🏷️(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 { 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/mono";
|
||||||
export * from ":/components/Forms/Select/multi";
|
export * from ":/components/Forms/Select/multi";
|
||||||
@@ -8,6 +9,26 @@ export * from ":/components/Forms/Select/multi";
|
|||||||
export interface SelectHandle {
|
export interface SelectHandle {
|
||||||
blur: () => void;
|
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) => {
|
export const Select = forwardRef<SelectHandle, SelectProps>((props, ref) => {
|
||||||
if (props.defaultValue && props.value) {
|
if (props.defaultValue && props.value) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
|
|||||||
@@ -5,7 +5,8 @@ import { useCunningham } from ":/components/Provider";
|
|||||||
import { Field } from ":/components/Forms/Field";
|
import { Field } from ":/components/Forms/Field";
|
||||||
import { LabelledBox } from ":/components/Forms/LabelledBox";
|
import { LabelledBox } from ":/components/Forms/LabelledBox";
|
||||||
import { Button } from ":/components/Button";
|
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) {
|
export function getOptionsFilter(inputValue?: string) {
|
||||||
return (option: Option) => {
|
return (option: Option) => {
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import {
|
|||||||
SelectMonoAux,
|
SelectMonoAux,
|
||||||
SubProps,
|
SubProps,
|
||||||
} from ":/components/Forms/Select/mono-common";
|
} 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>(
|
export const SelectMonoSearchable = forwardRef<SelectHandle, SubProps>(
|
||||||
(props, ref) => {
|
(props, ref) => {
|
||||||
|
|||||||
@@ -1,15 +1,9 @@
|
|||||||
import React, {
|
import React, { forwardRef, useEffect, useState } from "react";
|
||||||
forwardRef,
|
|
||||||
PropsWithChildren,
|
|
||||||
useEffect,
|
|
||||||
useState,
|
|
||||||
} from "react";
|
|
||||||
import { UseSelectStateChange } from "downshift";
|
import { UseSelectStateChange } from "downshift";
|
||||||
import { FieldProps } from ":/components/Forms/Field";
|
|
||||||
import { optionToValue, SubProps } from ":/components/Forms/Select/mono-common";
|
import { optionToValue, SubProps } from ":/components/Forms/Select/mono-common";
|
||||||
import { SelectMonoSearchable } from ":/components/Forms/Select/mono-searchable";
|
import { SelectMonoSearchable } from ":/components/Forms/Select/mono-searchable";
|
||||||
import { SelectMonoSimple } from ":/components/Forms/Select/mono-simple";
|
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 {
|
export interface Option {
|
||||||
value?: string;
|
value?: string;
|
||||||
@@ -17,26 +11,6 @@ export interface Option {
|
|||||||
disabled?: boolean;
|
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>(
|
export const SelectMono = forwardRef<SelectHandle, SelectProps>(
|
||||||
(props, ref) => {
|
(props, ref) => {
|
||||||
const defaultSelectedItem = props.defaultValue
|
const defaultSelectedItem = props.defaultValue
|
||||||
|
|||||||
@@ -5,7 +5,8 @@ import { Field } from ":/components/Forms/Field";
|
|||||||
import { LabelledBox } from ":/components/Forms/LabelledBox";
|
import { LabelledBox } from ":/components/Forms/LabelledBox";
|
||||||
import { Button } from ":/components/Button";
|
import { Button } from ":/components/Button";
|
||||||
import { useCunningham } from ":/components/Provider";
|
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 {
|
import {
|
||||||
getOptionsFilter,
|
getOptionsFilter,
|
||||||
optionToValue,
|
optionToValue,
|
||||||
|
|||||||
@@ -3,8 +3,8 @@ import { optionToValue } from ":/components/Forms/Select/mono-common";
|
|||||||
import { SelectMultiSearchable } from ":/components/Forms/Select/multi-searchable";
|
import { SelectMultiSearchable } from ":/components/Forms/Select/multi-searchable";
|
||||||
import { SelectMultiSimple } from ":/components/Forms/Select/multi-simple";
|
import { SelectMultiSimple } from ":/components/Forms/Select/multi-simple";
|
||||||
import { SubProps } from ":/components/Forms/Select/multi-common";
|
import { SubProps } from ":/components/Forms/Select/multi-common";
|
||||||
import { Option, SelectProps } from ":/components/Forms/Select/mono";
|
import { Option } from ":/components/Forms/Select/mono";
|
||||||
import { SelectHandle } from ":/components/Forms/Select/index";
|
import { SelectHandle, SelectProps } from ":/components/Forms/Select/index";
|
||||||
|
|
||||||
export type SelectMultiProps = Omit<SelectProps, "onChange"> & {
|
export type SelectMultiProps = Omit<SelectProps, "onChange"> & {
|
||||||
onChange?: (event: { target: { value: string[] } }) => void;
|
onChange?: (event: { target: { value: string[] } }) => void;
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import { Controller, useFormContext } from "react-hook-form";
|
import { Controller, useFormContext } from "react-hook-form";
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { Select } from ":/components/Forms/Select/index";
|
import { Select, SelectProps } from ":/components/Forms/Select/index";
|
||||||
import { SelectProps } from ":/components/Forms/Select/mono";
|
|
||||||
|
|
||||||
export const RhfSelect = (props: SelectProps & { name: string }) => {
|
export const RhfSelect = (props: SelectProps & { name: string }) => {
|
||||||
const { control, setValue } = useFormContext();
|
const { control, setValue } = useFormContext();
|
||||||
|
|||||||
Reference in New Issue
Block a user