Skip to main content

Tree Multi Selector

v.0.0.2

Installation

yarn add @mercell/tree-multi-selector-react

Usage

Using the Tree Multi Selector component is as simple as importing it like this.

import { TreeMultiSelector } from '@mercell/tree-multi-selector-react';
Live Editor
Result

Types, definitions, etc.

TMSProps
interface TMSProps {
allowToSelectOnlyOne?: boolean;
ariaCollapseChevronLabel?: string;
ariaExpandChevronLabel?: string;
ariaLabelClearSearch?: string;
baseURI?: string;
data?: ItemsInterface;
displayId?: boolean;
disabledIds?: string[];
isLoading?: boolean;
isModalVisible?: boolean;
modal?: boolean;
modalProps?: Omit<ModalProps, 'isModalVisible' | 'onCloseCallback'> &
JSX.IntrinsicElements['div'];
noItemsFoundText?: string;
onCloseModalCallback?: () => void;
onItemsListChange: (selectedIds: string[]) => void;
searchPlaceholder?: string;
selectedIds?: string[];
selectedItemsText?: string;
title?: string;
}

type ItemsInterface = Record<
string,
{ description: string; children: string[]; parents: string[] }
>;
NameTypeDefaultRequiredDescription
allowToSelectOnlyOnebooleanfalsenoSwitch from checkbox to radio for item selection
ariaCollapseChevronLabelstingCollapsenoCollapse text for aria-label
ariaExpandChevronLabelstringExpandnoExpand text for aria-label
ariaLabelClearSearchstringClear searchnoClear search text for aria-label
baseURIstring-noURI for data auto-fetching
dataRecord<string, { description: string; children: string[]; parents: string[]}>-noAn object of treenodes (does not trigger if baseURI is set)
displayIdbooleanfalsenoWhether to display item's id
disabledIdsstring[]-noInitial ids which should be disabled
isLoadingboolean-noWhether to display loading spinner (does not trigger if baseURI is set)
isModalVisiblebooleanfalsenoSpecifies the visibility of the modal (does not trigger if baseURI is set)
modalboolean-noToggle modal mode based on value
modalPropsModalProps{}noPass through props for Modal
noItemsFoundTextstringCould not find any results matching your searchnoText where search function could not find any match
onCloseModalCallback() => void-noCallback method to close modal (trigger only for modal mode)
onItemsListChange(selectedIds: string[]) => void-yesFunction to catch any change of codes based on user action
searchPlaceholderstringSearchnoSearch placeholder text
selectedIdsstring[]-noInitial ids which can be selected by default
selectedItemsTextstringSelected itemsnoText near the counter
titlestringSelect categoriesnoTitle of the compoment