@majapisoftwares/ui 4.1.13 → 4.1.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -127,8 +127,7 @@ function FileInput({ error, className, helpText, onChange, name, limit, label, i
|
|
|
127
127
|
<div className={clsx("flex flex-col gap-4", {
|
|
128
128
|
"md:grid md:grid-cols-2": !!innerValue.length,
|
|
129
129
|
"min-h-[140px]": !!innerValue.length || !readOnly,
|
|
130
|
-
|
|
131
|
-
})}>
|
|
130
|
+
}, filesClassName)}>
|
|
132
131
|
{paginatedValue.map((file, index) => (<PreviewFileComponent key={index} file={file} readOnly={readOnly} handleDeleteClick={handleDeleteClick(file)} downloadText={downloadText} display={fileDisplay} openText={openText} additionalInfo={fileAdditionalInfo} index={index} className={previewFileClassName} filesPerPage={filesPerPage} currentPage={currentPage} {...previewFileProps}/>))}
|
|
133
132
|
{innerValue.length > filesPerPage && (<Pagination className="mx-auto md:col-span-2" currentPage={currentPage} totalItems={innerValue.length} onChangePage={setCurrentPage} itemsPerPage={filesPerPage}/>)}
|
|
134
133
|
{readOnly && !innerValue.length && (<Text variant="secondary">{emptyText}</Text>)}
|
|
@@ -7,7 +7,7 @@ import { isEqual, take } from "lodash-es";
|
|
|
7
7
|
import { CheckIcon, ChevronUpDownIcon } from "@heroicons/react/20/solid";
|
|
8
8
|
import { useDeepCompareEffect } from "react-use";
|
|
9
9
|
import { getValue, MultiSelectInput } from "./MultiSelectInput";
|
|
10
|
-
const defaultMenuItemsClassName = "z-10 rounded-md bg-white shadow-lg ring-1 ring-black ring-
|
|
10
|
+
const defaultMenuItemsClassName = "z-10 rounded-md bg-white shadow-lg ring-1 ring-black/5 dark:ring-zinc-700 focus:outline-hidden dark:bg-zinc-800";
|
|
11
11
|
export default function MultiSelect({ placeholder, emptyText = "No item found.", items = [], renderProperty = "title", renderFunction, filterProperty = "title", filterFunction, onChange, query: defaultQuery = "", onChangeQuery, loading, inputInnerClassName, inputElementClassName, as, trailing, trailingClassName, trailingInputClassName, leadingInputClassName, static: isStatic,
|
|
12
12
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
13
13
|
displayValue = (item) => item?.[renderProperty] || "", value, labelClassName, creatable, getCreateLabel = (query) => `+ create "${query}"`, itemsRenderLimit, className, valueProperty = "_id", label, required, readOnly, error, ...props }) {
|
|
@@ -74,11 +74,11 @@ displayValue = (item) => item?.[renderProperty] || "", value, labelClassName, cr
|
|
|
74
74
|
return (<div className={clsx("relative", className)}>
|
|
75
75
|
<Combobox
|
|
76
76
|
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
|
|
77
|
-
onChange={setSelectedItems} value={selectedItems} multiple>
|
|
77
|
+
onChange={setSelectedItems} value={selectedItems.map((item) => getValue(valueProperty, item))} multiple>
|
|
78
78
|
{({ open }) => (<div>
|
|
79
79
|
<ComponentInput
|
|
80
80
|
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
|
|
81
|
-
{...props} as={MultiSelectInput} placeholder={!readOnly ? placeholder : undefined} value={query} onChange={(event) => setQuery(event.target.value)} trailing={trailing} trailingClassName={clsx(defaultTrailingClassName, trailingClassName)} inputClassName={inputClassName} innerClassName={inputInnerClassName} trailingInputClassName={clsx(defaultTrailingInputClassName, trailingInputClassName)} leadingInputClassName={clsx(defaultLeadingInputClassName, leadingInputClassName)} displayValue={displayValue} labelClassName={clsx(defaultLabelClassName, labelClassName)} selectedItems={selectedItems} doRender={doRender} removeItem={removeItem} required={required && !selectedItems.length} label={label} readOnly={readOnly} valueProperty={valueProperty} helpTextClassName={helpTextClassName}/>
|
|
81
|
+
{...props} as={MultiSelectInput} placeholder={!readOnly ? placeholder : undefined} value={query} onChange={(event) => setQuery(event.target.value)} trailing={trailing} trailingClassName={clsx(defaultTrailingClassName, trailingClassName)} inputClassName={inputClassName} innerClassName={inputInnerClassName} trailingInputClassName={clsx(defaultTrailingInputClassName, trailingInputClassName)} leadingInputClassName={clsx(defaultLeadingInputClassName, leadingInputClassName)} displayValue={displayValue} labelClassName={clsx(defaultLabelClassName, labelClassName)} selectedItems={selectedItems} doRender={doRender} removeItem={removeItem} required={required && !selectedItems.length} label={label} readOnly={readOnly} valueProperty={valueProperty} helpTextClassName={helpTextClassName} items={items}/>
|
|
82
82
|
|
|
83
83
|
{!readOnly &&
|
|
84
84
|
((creatable && query) || filteredItems.length > 0) && (<Combobox.Options static={isStatic} className={clsx(defaultMenuItemsClassName, "absolute z-10 mt-1 max-h-72 w-full scroll-py-2 overflow-y-auto py-2 text-sm text-zinc-800 dark:text-zinc-200")}>
|
|
@@ -92,7 +92,7 @@ displayValue = (item) => item?.[renderProperty] || "", value, labelClassName, cr
|
|
|
92
92
|
{selected ? query : getCreateLabel(query)}
|
|
93
93
|
</div>)}
|
|
94
94
|
</Combobox.Option>)}
|
|
95
|
-
{renderedItems.map((item) => (<Combobox.Option key={getValue(valueProperty, item)} value={item} className={({ active }) => clsx("cursor-default px-4 py-2 select-none", {
|
|
95
|
+
{renderedItems.map((item) => (<Combobox.Option key={getValue(valueProperty, item)} value={getValue(valueProperty, item)} className={({ active }) => clsx("cursor-default px-4 py-2 select-none", {
|
|
96
96
|
"bg-primary-600 text-white": active,
|
|
97
97
|
})}>
|
|
98
98
|
{({ selected }) => (<div className="flex">
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { ReactNode } from "react";
|
|
2
2
|
export declare function getValue<Id extends string | number, T extends object | string>(id: Id, item: T): string | number;
|
|
3
|
-
export declare function MultiSelectInput<Id extends string | number, T extends object | string>({ className, selectedItems, doRender, removeItem, valueProperty, readOnly, ...props }: {
|
|
3
|
+
export declare function MultiSelectInput<Id extends string | number, T extends object | string>({ className, selectedItems, doRender, removeItem, valueProperty, readOnly, items, ...props }: {
|
|
4
4
|
className?: string;
|
|
5
|
-
selectedItems:
|
|
5
|
+
selectedItems: string[];
|
|
6
6
|
doRender: (item: T) => ReactNode;
|
|
7
7
|
removeItem: (item: T) => () => void;
|
|
8
8
|
valueProperty: Id;
|
|
9
9
|
readOnly?: boolean;
|
|
10
10
|
error?: boolean;
|
|
11
|
+
items?: T[];
|
|
11
12
|
}): import("react").JSX.Element;
|
|
@@ -7,13 +7,18 @@ export function getValue(id, item) {
|
|
|
7
7
|
? item
|
|
8
8
|
: item[id];
|
|
9
9
|
}
|
|
10
|
-
export function MultiSelectInput({ className, selectedItems, doRender, removeItem, valueProperty, readOnly, ...props }) {
|
|
10
|
+
export function MultiSelectInput({ className, selectedItems, doRender, removeItem, valueProperty, readOnly, items, ...props }) {
|
|
11
11
|
const ref = useRef(null);
|
|
12
12
|
return (<div className={clsx("focus-within:border-primary-500 focus-within:ring-primary-500 dark:focus-within:border-primary-500 flex flex-wrap border focus-within:ring-1", className)} onClick={() => ref.current?.focus()}>
|
|
13
13
|
{!!selectedItems.length && (<div className="flex flex-wrap items-center gap-1 p-1.5 pb-0">
|
|
14
|
-
{selectedItems.map((
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
{selectedItems.map((selectedItem) => {
|
|
15
|
+
const item = items?.find((item) => getValue(valueProperty, item) === selectedItem);
|
|
16
|
+
if (!item)
|
|
17
|
+
return null;
|
|
18
|
+
return (<Badge key={getValue(valueProperty, item)} onActionClick={!readOnly ? removeItem(item) : undefined}>
|
|
19
|
+
{doRender(item)}
|
|
20
|
+
</Badge>);
|
|
21
|
+
})}
|
|
17
22
|
</div>)}
|
|
18
23
|
{!readOnly && (<Combobox.Input
|
|
19
24
|
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
|