UNPKG

@coveord/plasma-mantine

Version:

A Plasma flavoured Mantine theme

128 lines 4.25 kB
import { BoxProps, Factory, MantineSpacing, StylesApiProps, __InputWrapperProps } from '@mantine/core'; import { ReorderPayload } from '@mantine/form/lib/types'; import { ForwardedRef, ReactNode } from 'react'; import { CustomComponentThemeExtend } from '../../utils'; export interface CollectionProps<T> extends __InputWrapperProps, BoxProps, StylesApiProps<CollectionFactory> { /** * The default value each new item should have */ newItem: T; /** * A render function called for each item passed in the `value` prop. * * @param item The current item's value * @param index The current item's index */ children: (item: T, index: number) => ReactNode; /** * The list of items to display inside the collection * * @default [] */ value?: T[]; /** * Defines how each item is uniquely identified. It is highly recommended that you specify this prop to an ID that makes sense. * * This method is required when using this component with ReactHookForm. * * @see {@link https://react-hook-form.com/api/usefieldarray/} for using a collection with ReactHookForm. * * @param originalItem The original item */ getItemId?: (originalItem: T) => string; /** * Unused, has no effect */ onFocus?: () => void; /** * Function called whenever the value needs to be updated * * @param value The whole list of items after the change */ onChange?: (value: T[]) => void; /** * Function called after an item is removed from the collection using the remove button * * @param itemIndex The index of the item that was removed */ onRemoveItem?: (itemIndex: number) => void; /** * Function that gets called whenever a collection item needs to be reordered * * @param payload The origin and destination index of the item to reorder */ onReorderItem?: (payload: ReorderPayload) => void; /** * Function that gets called when a new item needs to be added to the collection * * @param value The value of the item to insert * @param index The index of the new item to insert */ onInsertItem?: (value: T, index: number) => void; /** * Whether the collection should have drag and drop behavior enabled * * @default false */ draggable?: boolean; /** * Whether the collection is disabled, or in other words in read only mode * * @default false */ disabled?: boolean; /** * Whether the collection is readOnly. If true, the collection will not allow adding or removing items * * @default false */ readOnly?: boolean; /** * Function that determines if the add item button should be enabled given the current items of the collection. * The button is always enabled if this props remains undefined * * @param values The current items of the collection */ allowAdd?: (values: T[]) => boolean; /** * The label of the add item button * * @default "Add item" */ addLabel?: string; /** * The tooltip text displayed when hovering over the disabled add item button * * @default 'There is already an empty item' */ addDisabledTooltip?: string; /** * The gap between the colleciton items * * @default 'xs' */ gap?: MantineSpacing; /** * Whether the collection is required. When required is true, the collection will hide the remove button if there is only one item * * @default false */ required?: boolean; } export type CollectionStylesNames = 'root' | 'item' | 'itemDragging' | 'dragHandle'; export type CollectionFactory = Factory<{ props: CollectionProps<unknown>; ref: HTMLDivElement; stylesNames: CollectionStylesNames; }>; export declare const Collection: { <T>(props: CollectionProps<T> & { ref?: ForwardedRef<HTMLDivElement>; }): import("react/jsx-runtime").JSX.Element; extend: CustomComponentThemeExtend<{ props: CollectionProps<unknown>; ref: HTMLDivElement; stylesNames: CollectionStylesNames; }>; }; //# sourceMappingURL=Collection.d.ts.map