(react) add select mono option custom render

We want to be able to render the options in a customized manner.
This commit is contained in:
Nathan Vasse
2023-10-06 16:54:55 +02:00
committed by NathanVss
parent 611eebf0a4
commit 48e4e56a44
11 changed files with 358 additions and 21 deletions

View File

@@ -1,11 +1,27 @@
import React, { forwardRef, PropsWithChildren } from "react";
import React, { forwardRef, PropsWithChildren, ReactNode } from "react";
import { SelectMulti } from ":/components/Forms/Select/multi";
import { Option, SelectMono } from ":/components/Forms/Select/mono";
import { SelectMono } from ":/components/Forms/Select/mono";
import { FieldProps } from ":/components/Forms/Field";
export * from ":/components/Forms/Select/mono";
export * from ":/components/Forms/Select/multi";
export type OptionWithRender = {
disabled?: boolean;
value: string;
label: string;
render: () => ReactNode;
};
export type Option =
| {
disabled?: boolean;
value?: string;
label: string;
render?: undefined;
}
| OptionWithRender;
export interface SelectHandle {
blur: () => void;
}
@@ -28,6 +44,7 @@ export type SelectProps = PropsWithChildren &
disabled?: boolean;
clearable?: boolean;
multi?: boolean;
showLabelWhenSelected?: boolean;
};
export const Select = forwardRef<SelectHandle, SelectProps>((props, ref) => {
if (props.defaultValue && props.value) {