@payfit/unity-components
Version:
65 lines (64 loc) • 2.44 kB
TypeScript
import { ForwardedRef } from 'react';
import { MultiSelectComponent, MultiSelectProps as CoreMultiSelectProps } from '../../../../core/components/multi-select/MultiselectTypes.js';
export type MultiSelectProps<TItems = undefined> = Omit<CoreMultiSelectProps<TItems>, 'value' | 'defaultValue' | 'onChange' | 'onBlur' | 'isInvalid'> & {
children?: CoreMultiSelectProps<TItems>['children'];
};
/**
* `MultiSelect` is a controlled multi-select component wired to the Form field context.
* It is based on the Unity `MultiSelect` component and handles selection state automatically through the form.
*
* The component supports both static and dynamic APIs:
* - **Static API**: Options defined as direct children using `MultiSelectOption` components
* - **Dynamic API**: Options generated from a collection using a render function with `items` prop
*
* Example (Static API):
* ```tsx
* function ExampleField() {
* const form = useUnityForm<{ fruits: Set<string | number> }>({ validators: {} })
* return (
* <form>
* <form.AppField name="fruits">
* {() => (
* <MultiSelect placeholder="Select fruits...">
* <MultiSelectOption value="apple">Apple</MultiSelectOption>
* <MultiSelectOption value="banana">Banana</MultiSelectOption>
* </MultiSelect>
* )}
* </form.AppField>
* </form>
* )
* }
* ```
*
* Example (Dynamic API):
* ```tsx
* interface Fruit { id: string; name: string }
* const fruits = new Set<Fruit>([...])
*
* function ExampleField() {
* const form = useUnityForm<{ fruits: Set<string | number> }>({ validators: {} })
* return (
* <form>
* <form.AppField name="fruits">
* {() => (
* <MultiSelect
* items={fruits}
* getItemValue={fruit => fruit.id}
* renderValue={items => Array.from(items).map(i => i.name).join(', ')}
* >
* {fruit => (
* <MultiSelectOption value={fruit.id}>{fruit.name}</MultiSelectOption>
* )}
* </MultiSelect>
* )}
* </form.AppField>
* </form>
* )
* }
* ```
*/
declare const MultiSelectComponent: <TItems = undefined>(props: MultiSelectProps<TItems>, ref: ForwardedRef<HTMLButtonElement>) => import('react/jsx-runtime').JSX.Element;
export declare const MultiSelect: MultiSelectComponent & {
displayName: string;
};
export {};