pf-common-components 1.0.0
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.
- package/components.json +17 -0
- package/dist/assets/Arrow.d.ts +7 -0
- package/dist/assets/Arrow.js +5 -0
- package/dist/assets/CalenderIcon.d.ts +2 -0
- package/dist/assets/CalenderIcon.js +5 -0
- package/dist/assets/ClearAll.d.ts +2 -0
- package/dist/assets/ClearAll.js +5 -0
- package/dist/assets/CrossIcon.d.ts +8 -0
- package/dist/assets/CrossIcon.js +7 -0
- package/dist/assets/DropDown.d.ts +4 -0
- package/dist/assets/DropDown.js +5 -0
- package/dist/global.css +3213 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.js +25 -0
- package/dist/lib/CommonComponentsUtil.d.ts +7 -0
- package/dist/lib/CommonComponentsUtil.js +22 -0
- package/dist/lib/utils.d.ts +2 -0
- package/dist/lib/utils.js +5 -0
- package/dist/ui/BaseTable.d.ts +132 -0
- package/dist/ui/BaseTable.js +330 -0
- package/dist/ui/DateCalendar.d.ts +10 -0
- package/dist/ui/DateCalendar.js +47 -0
- package/dist/ui/DateField.d.ts +35 -0
- package/dist/ui/DateField.js +37 -0
- package/dist/ui/DateOfBirthSelector.d.ts +16 -0
- package/dist/ui/DateOfBirthSelector.js +42 -0
- package/dist/ui/DateRangePicker.d.ts +8 -0
- package/dist/ui/DateRangePicker.js +73 -0
- package/dist/ui/DobCalendar.d.ts +17 -0
- package/dist/ui/DobCalendar.js +86 -0
- package/dist/ui/Formfield.d.ts +12 -0
- package/dist/ui/Formfield.js +36 -0
- package/dist/ui/GetScrollAlert.d.ts +9 -0
- package/dist/ui/GetScrollAlert.js +37 -0
- package/dist/ui/RadioGroupContext/RadioGroupContext.d.ts +8 -0
- package/dist/ui/RadioGroupContext/RadioGroupContext.js +11 -0
- package/dist/ui/SelectCommand.d.ts +69 -0
- package/dist/ui/SelectCommand.js +260 -0
- package/dist/ui/SlashIcon.d.ts +2 -0
- package/dist/ui/SlashIcon.js +5 -0
- package/dist/ui/SortingArrows.d.ts +11 -0
- package/dist/ui/SortingArrows.js +11 -0
- package/dist/ui/TextTags.d.ts +39 -0
- package/dist/ui/TextTags.js +73 -0
- package/dist/ui/accordion.d.ts +10 -0
- package/dist/ui/accordion.js +77 -0
- package/dist/ui/alert-dialog.d.ts +20 -0
- package/dist/ui/alert-dialog.js +62 -0
- package/dist/ui/alert.d.ts +8 -0
- package/dist/ui/alert.js +42 -0
- package/dist/ui/avatar.d.ts +6 -0
- package/dist/ui/avatar.js +32 -0
- package/dist/ui/badge.d.ts +10 -0
- package/dist/ui/badge.js +58 -0
- package/dist/ui/button.d.ts +12 -0
- package/dist/ui/button.js +54 -0
- package/dist/ui/calendar.d.ts +8 -0
- package/dist/ui/calendar.js +45 -0
- package/dist/ui/card.d.ts +8 -0
- package/dist/ui/card.js +45 -0
- package/dist/ui/checkbox.d.ts +12 -0
- package/dist/ui/checkbox.js +44 -0
- package/dist/ui/command.d.ts +47 -0
- package/dist/ui/command.js +67 -0
- package/dist/ui/dialog.d.ts +31 -0
- package/dist/ui/dialog.js +57 -0
- package/dist/ui/dropdown-menu.d.ts +27 -0
- package/dist/ui/dropdown-menu.js +72 -0
- package/dist/ui/form.d.ts +23 -0
- package/dist/ui/form.js +72 -0
- package/dist/ui/hover-card.d.ts +7 -0
- package/dist/ui/hover-card.js +29 -0
- package/dist/ui/input.d.ts +3 -0
- package/dist/ui/input.js +20 -0
- package/dist/ui/label.d.ts +5 -0
- package/dist/ui/label.js +24 -0
- package/dist/ui/multi-select.d.ts +44 -0
- package/dist/ui/multi-select.js +191 -0
- package/dist/ui/navigation-menu.d.ts +11 -0
- package/dist/ui/navigation-menu.js +69 -0
- package/dist/ui/popover.d.ts +6 -0
- package/dist/ui/popover.js +24 -0
- package/dist/ui/radio-group.d.ts +7 -0
- package/dist/ui/radio-group.js +40 -0
- package/dist/ui/radioButtonCard.d.ts +9 -0
- package/dist/ui/radioButtonCard.js +23 -0
- package/dist/ui/scroll-area.d.ts +5 -0
- package/dist/ui/scroll-area.js +29 -0
- package/dist/ui/select.d.ts +57 -0
- package/dist/ui/select.js +148 -0
- package/dist/ui/separator.d.ts +4 -0
- package/dist/ui/separator.js +22 -0
- package/dist/ui/sheet.d.ts +25 -0
- package/dist/ui/sheet.js +65 -0
- package/dist/ui/switch.d.ts +10 -0
- package/dist/ui/switch.js +47 -0
- package/dist/ui/table.d.ts +10 -0
- package/dist/ui/table.js +55 -0
- package/dist/ui/tabs.d.ts +7 -0
- package/dist/ui/tabs.js +33 -0
- package/dist/ui/text.d.ts +11 -0
- package/dist/ui/text.js +45 -0
- package/dist/ui/textarea.d.ts +7 -0
- package/dist/ui/textarea.js +21 -0
- package/dist/ui/tooltip.d.ts +11 -0
- package/dist/ui/tooltip.js +26 -0
- package/package.json +123 -0
- package/postcss.config.js +6 -0
- package/src/assets/Arrow.js +5 -0
- package/src/assets/Arrow.tsx +25 -0
- package/src/assets/CalenderIcon.js +5 -0
- package/src/assets/CalenderIcon.tsx +28 -0
- package/src/assets/ClearAll.js +5 -0
- package/src/assets/ClearAll.tsx +20 -0
- package/src/assets/CrossIcon.js +7 -0
- package/src/assets/CrossIcon.tsx +34 -0
- package/src/assets/DropDown.js +5 -0
- package/src/assets/DropDown.tsx +23 -0
- package/src/global.css +560 -0
- package/src/index.ts +34 -0
- package/src/lib/CommonComponentsUtil.js +22 -0
- package/src/lib/CommonComponentsUtil.ts +30 -0
- package/src/lib/utils.js +5 -0
- package/src/lib/utils.ts +6 -0
- package/src/ui/BaseTable.js +330 -0
- package/src/ui/BaseTable.tsx +987 -0
- package/src/ui/DateCalendar.js +47 -0
- package/src/ui/DateCalendar.tsx +111 -0
- package/src/ui/DateField.js +37 -0
- package/src/ui/DateField.tsx +142 -0
- package/src/ui/DateOfBirthSelector.js +42 -0
- package/src/ui/DateOfBirthSelector.tsx +114 -0
- package/src/ui/DateRangePicker.js +73 -0
- package/src/ui/DateRangePicker.tsx +174 -0
- package/src/ui/DobCalendar.js +86 -0
- package/src/ui/DobCalendar.tsx +172 -0
- package/src/ui/Formfield.js +36 -0
- package/src/ui/Formfield.tsx +55 -0
- package/src/ui/GetScrollAlert.js +37 -0
- package/src/ui/GetScrollAlert.tsx +59 -0
- package/src/ui/RadioGroupContext/RadioGroupContext.js +11 -0
- package/src/ui/RadioGroupContext/RadioGroupContext.tsx +21 -0
- package/src/ui/SelectCommand.js +260 -0
- package/src/ui/SelectCommand.tsx +587 -0
- package/src/ui/SlashIcon.js +5 -0
- package/src/ui/SlashIcon.tsx +22 -0
- package/src/ui/SortingArrows.js +11 -0
- package/src/ui/SortingArrows.tsx +29 -0
- package/src/ui/TextTags.js +73 -0
- package/src/ui/TextTags.tsx +149 -0
- package/src/ui/accordion.js +77 -0
- package/src/ui/accordion.tsx +129 -0
- package/src/ui/alert-dialog.js +62 -0
- package/src/ui/alert-dialog.tsx +141 -0
- package/src/ui/alert.js +42 -0
- package/src/ui/alert.tsx +59 -0
- package/src/ui/avatar.js +32 -0
- package/src/ui/avatar.tsx +50 -0
- package/src/ui/badge.js +58 -0
- package/src/ui/badge.tsx +66 -0
- package/src/ui/button.js +54 -0
- package/src/ui/button.tsx +89 -0
- package/src/ui/calendar.js +45 -0
- package/src/ui/calendar.tsx +88 -0
- package/src/ui/card.js +45 -0
- package/src/ui/card.tsx +83 -0
- package/src/ui/checkbox.js +44 -0
- package/src/ui/checkbox.tsx +56 -0
- package/src/ui/command.js +67 -0
- package/src/ui/command.tsx +166 -0
- package/src/ui/dialog.js +57 -0
- package/src/ui/dialog.tsx +154 -0
- package/src/ui/dropdown-menu.js +72 -0
- package/src/ui/dropdown-menu.tsx +200 -0
- package/src/ui/form.js +72 -0
- package/src/ui/form.tsx +177 -0
- package/src/ui/hover-card.js +29 -0
- package/src/ui/hover-card.tsx +63 -0
- package/src/ui/input.js +20 -0
- package/src/ui/input.tsx +22 -0
- package/src/ui/label.js +24 -0
- package/src/ui/label.tsx +26 -0
- package/src/ui/multi-select.js +191 -0
- package/src/ui/multi-select.tsx +518 -0
- package/src/ui/navigation-menu.js +69 -0
- package/src/ui/navigation-menu.tsx +139 -0
- package/src/ui/popover.js +24 -0
- package/src/ui/popover.tsx +31 -0
- package/src/ui/radio-group.js +40 -0
- package/src/ui/radio-group.tsx +97 -0
- package/src/ui/radioButtonCard.js +23 -0
- package/src/ui/radioButtonCard.tsx +57 -0
- package/src/ui/scroll-area.js +29 -0
- package/src/ui/scroll-area.tsx +48 -0
- package/src/ui/select.js +148 -0
- package/src/ui/select.tsx +343 -0
- package/src/ui/separator.js +22 -0
- package/src/ui/separator.tsx +31 -0
- package/src/ui/sheet.js +65 -0
- package/src/ui/sheet.tsx +136 -0
- package/src/ui/switch.js +47 -0
- package/src/ui/switch.tsx +60 -0
- package/src/ui/table.js +55 -0
- package/src/ui/table.tsx +112 -0
- package/src/ui/tabs.js +33 -0
- package/src/ui/tabs.tsx +55 -0
- package/src/ui/text.js +45 -0
- package/src/ui/text.tsx +49 -0
- package/src/ui/textarea.js +21 -0
- package/src/ui/textarea.tsx +28 -0
- package/src/ui/tooltip.js +26 -0
- package/src/ui/tooltip.tsx +54 -0
- package/tailwind.config.js +214 -0
- package/tsconfig.json +35 -0
- package/tsconfig.tsbuildinfo +1 -0
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
+
var t = {};
|
|
4
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
+
t[p] = s[p];
|
|
6
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
+
t[p[i]] = s[p[i]];
|
|
10
|
+
}
|
|
11
|
+
return t;
|
|
12
|
+
};
|
|
13
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
14
|
+
import CrossIcon from "../../public/assets/CrossIcon";
|
|
15
|
+
import DropDownArrow from "../../public/assets/DropDown";
|
|
16
|
+
import * as PopoverPrimitive from "@radix-ui/react-popover";
|
|
17
|
+
import { Command as CommandPrimitive, useCommandState } from "cmdk";
|
|
18
|
+
import { Search } from "lucide-react";
|
|
19
|
+
import { useTranslation } from "next-i18next";
|
|
20
|
+
import * as React from "react";
|
|
21
|
+
import { useRef } from "react";
|
|
22
|
+
import { cn } from "../lib/utils";
|
|
23
|
+
import { Button } from "./button";
|
|
24
|
+
import { ccn } from "../lib/CommonComponentsUtil";
|
|
25
|
+
import { Input } from "./input";
|
|
26
|
+
// Here we have to create the context for sending the data to child components
|
|
27
|
+
const dropDownContext = React.createContext({
|
|
28
|
+
value: null,
|
|
29
|
+
onChange: () => { },
|
|
30
|
+
selectedLabel: "",
|
|
31
|
+
setSelectedLabel: () => { },
|
|
32
|
+
isFiltering: false,
|
|
33
|
+
searchValue: "",
|
|
34
|
+
setSearchValue: () => { },
|
|
35
|
+
isLoading: false,
|
|
36
|
+
open: false,
|
|
37
|
+
defaultOptions: [],
|
|
38
|
+
triggerRef: null,
|
|
39
|
+
contentWidth: 0,
|
|
40
|
+
setContentWidth: () => { },
|
|
41
|
+
secured: false,
|
|
42
|
+
showSeparator: true,
|
|
43
|
+
});
|
|
44
|
+
const MVPSelect = React.forwardRef((_a, ref) => {
|
|
45
|
+
var { value, onChange, isFiltering, isLoading, secured = false, defaultOptions = [], showSeparator = true } = _a, props = __rest(_a, ["value", "onChange", "isFiltering", "isLoading", "secured", "defaultOptions", "showSeparator"]);
|
|
46
|
+
// to track whether to show the list of options in the dropdown or not
|
|
47
|
+
const [open, setOpen] = React.useState(false);
|
|
48
|
+
const [searchValue, setSearchValue] = React.useState("");
|
|
49
|
+
/**
|
|
50
|
+
* while selecting any item in the options then we have to close the popover
|
|
51
|
+
* @param val
|
|
52
|
+
*/
|
|
53
|
+
const handleClick = (open) => {
|
|
54
|
+
setOpen(open);
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* while selecting any item in the options then we have to store the id of the item and along with we have to close the popover
|
|
58
|
+
* @param val
|
|
59
|
+
*/
|
|
60
|
+
const handleChange = (val) => {
|
|
61
|
+
onChange && onChange(val);
|
|
62
|
+
handleClick(false);
|
|
63
|
+
};
|
|
64
|
+
//we have to take the selected label and store in it to display it in the input
|
|
65
|
+
const [selectedLabel, setSelectedLabel] = React.useState("");
|
|
66
|
+
const triggerRef = useRef(null);
|
|
67
|
+
const [contentWidth, setContentWidth] = React.useState("auto");
|
|
68
|
+
React.useEffect(() => {
|
|
69
|
+
const updateContentWidth = () => {
|
|
70
|
+
var _a;
|
|
71
|
+
setContentWidth(`${(_a = triggerRef.current) === null || _a === void 0 ? void 0 : _a.offsetWidth}px`);
|
|
72
|
+
};
|
|
73
|
+
window.addEventListener("resize", updateContentWidth);
|
|
74
|
+
updateContentWidth(); // Call initially to set the width
|
|
75
|
+
return () => window.removeEventListener("resize", updateContentWidth);
|
|
76
|
+
}, []);
|
|
77
|
+
return (_jsx(dropDownContext.Provider, Object.assign({ value: {
|
|
78
|
+
value,
|
|
79
|
+
onChange: handleChange,
|
|
80
|
+
selectedLabel,
|
|
81
|
+
setSelectedLabel,
|
|
82
|
+
searchValue,
|
|
83
|
+
setSearchValue,
|
|
84
|
+
isLoading,
|
|
85
|
+
isFiltering,
|
|
86
|
+
open,
|
|
87
|
+
defaultOptions,
|
|
88
|
+
triggerRef,
|
|
89
|
+
setContentWidth,
|
|
90
|
+
contentWidth,
|
|
91
|
+
secured,
|
|
92
|
+
showSeparator,
|
|
93
|
+
} }, { children: _jsx(PopoverPrimitive.Root, Object.assign({ open: open, onOpenChange: handleClick }, props)) })));
|
|
94
|
+
});
|
|
95
|
+
MVPSelect.displayName = "MVPSelect";
|
|
96
|
+
const Trigger = PopoverPrimitive.Trigger;
|
|
97
|
+
const MVPSelectTrigger = React.forwardRef((_a, ref) => {
|
|
98
|
+
var { placeholder, error, disable, className, endIcon, crossIcon = true } = _a, props = __rest(_a, ["placeholder", "error", "disable", "className", "endIcon", "crossIcon"]);
|
|
99
|
+
const { selectedLabel, onChange, setSelectedLabel, defaultOptions, triggerRef, setContentWidth, value, } = React.useContext(dropDownContext);
|
|
100
|
+
React.useEffect(() => {
|
|
101
|
+
if (triggerRef && triggerRef.current) {
|
|
102
|
+
setContentWidth(`${triggerRef.current.offsetWidth}px`);
|
|
103
|
+
}
|
|
104
|
+
}, []);
|
|
105
|
+
React.useEffect(() => {
|
|
106
|
+
if (defaultOptions && defaultOptions.length > 0) {
|
|
107
|
+
setSelectedLabel(defaultOptions[0].label);
|
|
108
|
+
}
|
|
109
|
+
else if (defaultOptions.length === 0) {
|
|
110
|
+
setSelectedLabel("");
|
|
111
|
+
}
|
|
112
|
+
}, [JSON.stringify(defaultOptions)]);
|
|
113
|
+
return (_jsx(Trigger, Object.assign({ ref: triggerRef, asChild: true }, { children: _jsxs(Button, Object.assign({ disabled: disable, ref: ref, variant: "outline", type: "button", role: "combobox",
|
|
114
|
+
// aria-expanded={open}
|
|
115
|
+
className: cn("min-w-69 w-full justify-between gap-0 px-3 py-2", className, ccn(error, value)) }, props, { children: [_jsx("div", Object.assign({ className: selectedLabel === "" ||
|
|
116
|
+
selectedLabel === undefined ||
|
|
117
|
+
selectedLabel === null
|
|
118
|
+
? "truncate font-normal text-[#999999]"
|
|
119
|
+
: "truncate" }, { children: selectedLabel || placeholder })), selectedLabel && crossIcon ? (_jsxs("div", Object.assign({ className: "flex items-center gap-1" }, { children: [endIcon && (_jsx("div", Object.assign({ onClick: (e) => {
|
|
120
|
+
e.stopPropagation(); // Prevent the outer button's click event
|
|
121
|
+
} }, { children: endIcon }))), _jsx("button", Object.assign({ onClick: (e) => {
|
|
122
|
+
e.stopPropagation(); // Prevent the outer button's click event
|
|
123
|
+
onChange && onChange("");
|
|
124
|
+
setSelectedLabel(null);
|
|
125
|
+
}, type: "button", className: cn("h-5 w-5 focus:outline-keyboardTab", disable && "cursor-not-allowed") }, { children: _jsx(CrossIcon, { height: 10, className: "text-grey" }) }))] }))) : (_jsx(DropDownArrow, {}))] })) })));
|
|
126
|
+
});
|
|
127
|
+
MVPSelectTrigger.displayName = "MVPSelectTrigger";
|
|
128
|
+
const MVPSelectContent = React.forwardRef((_a, ref) => {
|
|
129
|
+
var { className } = _a, props = __rest(_a, ["className"]);
|
|
130
|
+
const { contentWidth } = React.useContext(dropDownContext);
|
|
131
|
+
return (_jsx(PopoverPrimitive.Content, Object.assign({ ref: ref,
|
|
132
|
+
// align={align}
|
|
133
|
+
// sideOffset={sideOffset}
|
|
134
|
+
className: cn("min-w-69 z-50 mt-0.5 rounded-xl border bg-popover text-popover-foreground shadow-md outline-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2", className), style: { width: contentWidth } }, props, { children: _jsx(CommandPrimitive, Object.assign({ ref: ref, className: cn("flex h-full w-full flex-col overflow-hidden rounded-xl bg-popover text-popover-foreground", className), shouldFilter: false }, props)) })));
|
|
135
|
+
});
|
|
136
|
+
MVPSelectContent.displayName = CommandPrimitive.displayName;
|
|
137
|
+
const MVPSelectLoading = React.forwardRef((_a, ref) => {
|
|
138
|
+
var props = __rest(_a, []);
|
|
139
|
+
return _jsx(CommandPrimitive.Loading, Object.assign({ ref: ref }, props));
|
|
140
|
+
});
|
|
141
|
+
MVPSelectLoading.displayName = CommandPrimitive.Loading.displayName;
|
|
142
|
+
const CommandGroup = React.forwardRef((_a, ref) => {
|
|
143
|
+
var { className } = _a, props = __rest(_a, ["className"]);
|
|
144
|
+
return (_jsx(CommandPrimitive.Group, Object.assign({ ref: ref, className: cn("overflow-hidden p-1 text-foreground [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:py-1.5 [&_[cmdk-group-heading]]:text-xs [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground", className) }, props)));
|
|
145
|
+
});
|
|
146
|
+
CommandGroup.displayName = CommandPrimitive.Group.displayName;
|
|
147
|
+
const MVPSelectInput = React.forwardRef((_a, ref) => {
|
|
148
|
+
var { className, onValueChange } = _a, props = __rest(_a, ["className", "onValueChange"]);
|
|
149
|
+
const { setSearchValue, open } = React.useContext(dropDownContext);
|
|
150
|
+
React.useEffect(() => {
|
|
151
|
+
if (open == false) {
|
|
152
|
+
onValueChange === null || onValueChange === void 0 ? void 0 : onValueChange("");
|
|
153
|
+
setSearchValue("");
|
|
154
|
+
}
|
|
155
|
+
}, [open]);
|
|
156
|
+
const { t } = useTranslation("bx_v1");
|
|
157
|
+
return (_jsxs("div", Object.assign({ className: "flex h-[44px] items-center rounded-[12px] border-b border-gray-200 px-3" }, { children: [_jsx(Input, Object.assign({ ref: ref, className: cn("flex !h-11 w-full rounded-md border-none bg-transparent px-2 py-3 text-sm font-medium text-[#999999] !outline-none placeholder:font-[400] placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50", className), onChange: (value) => {
|
|
158
|
+
setSearchValue(value.target.value);
|
|
159
|
+
onValueChange && onValueChange(value.target.value);
|
|
160
|
+
} }, props, { placeholder: (props === null || props === void 0 ? void 0 : props.placeholder) ? props === null || props === void 0 ? void 0 : props.placeholder : t("bx_v1:cm_search") })), _jsx(Search, { className: "borde-[2px] mr-2 h-4 w-4 shrink-0 text-primary" })] })));
|
|
161
|
+
});
|
|
162
|
+
MVPSelectInput.displayName = CommandPrimitive.Input.displayName;
|
|
163
|
+
const MVPSelectItems = React.forwardRef((_a, ref) => {
|
|
164
|
+
var { className, onBottomReached, minLenToSearch = 1 } = _a, props = __rest(_a, ["className", "onBottomReached", "minLenToSearch"]);
|
|
165
|
+
const listRef = React.useRef(null);
|
|
166
|
+
const { isLoading, isFiltering, searchValue, secured } = React.useContext(dropDownContext);
|
|
167
|
+
const [isLoadingMore, setIsLoadingMore] = React.useState(false);
|
|
168
|
+
const handleScroll = React.useCallback(() => {
|
|
169
|
+
const listElement = listRef.current;
|
|
170
|
+
if (listElement) {
|
|
171
|
+
const { scrollTop, scrollHeight, clientHeight } = listElement;
|
|
172
|
+
const tolerance = 2;
|
|
173
|
+
const isAtBottom = scrollHeight - (scrollTop + clientHeight) <= tolerance;
|
|
174
|
+
if (isAtBottom) {
|
|
175
|
+
setIsLoadingMore(true);
|
|
176
|
+
onBottomReached && onBottomReached();
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}, [onBottomReached]);
|
|
180
|
+
React.useEffect(() => {
|
|
181
|
+
if (isFiltering === false && isLoadingMore) {
|
|
182
|
+
setIsLoadingMore(false);
|
|
183
|
+
}
|
|
184
|
+
}, [isFiltering]);
|
|
185
|
+
React.useEffect(() => {
|
|
186
|
+
const listElement = listRef.current;
|
|
187
|
+
if (listElement) {
|
|
188
|
+
listElement.addEventListener("scroll", handleScroll);
|
|
189
|
+
}
|
|
190
|
+
return () => {
|
|
191
|
+
if (listElement) {
|
|
192
|
+
listElement.removeEventListener("scroll", handleScroll);
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
}, [handleScroll]);
|
|
196
|
+
return (_jsx(CommandPrimitive.List, Object.assign({ ref: (el) => {
|
|
197
|
+
listRef.current = el;
|
|
198
|
+
if (typeof ref === "function") {
|
|
199
|
+
ref(el);
|
|
200
|
+
}
|
|
201
|
+
else if (ref) {
|
|
202
|
+
ref.current = el;
|
|
203
|
+
}
|
|
204
|
+
}, className: cn("max-h-[224px] overflow-y-auto overflow-x-hidden", className) }, props, { children: !(secured && (searchValue === null || searchValue === void 0 ? void 0 : searchValue.length) < minLenToSearch) && (
|
|
205
|
+
/**
|
|
206
|
+
* Ticket #4235: We are using this condition for user security purposes.
|
|
207
|
+
*
|
|
208
|
+
* When the dropdown is in a secured state (secured is true) and the
|
|
209
|
+
* search term is empty (searchValue is ""):
|
|
210
|
+
* - We do not display any items to the user.
|
|
211
|
+
*
|
|
212
|
+
* This prevents exposing all available options without any filtering,
|
|
213
|
+
* ensuring that only relevant items are shown based on the user's input.
|
|
214
|
+
*/
|
|
215
|
+
_jsx(_Fragment, { children: isLoading || (isFiltering && isLoadingMore === false) ? (_jsx("div", Object.assign({ className: "my-[10px] flex max-h-48 items-center justify-center" }, { children: _jsx("div", Object.assign({ className: "loader-small" }, { children: _jsx("div", { className: "loader" }) })) }))) : (_jsxs(_Fragment, { children: [_jsx(MVPSelectEmpty, {}), props.children] })) })) })));
|
|
216
|
+
});
|
|
217
|
+
MVPSelectItems.displayName = CommandPrimitive.List.displayName;
|
|
218
|
+
const MVPSelectEmpty = React.forwardRef((props, ref) => {
|
|
219
|
+
const { searchValue } = React.useContext(dropDownContext);
|
|
220
|
+
const { t } = useTranslation("bx_v1");
|
|
221
|
+
return (_jsx(CommandEmpty, Object.assign({ ref: ref, className: "py-6 text-center text-sm font-medium" }, { children: searchValue
|
|
222
|
+
? t("bx_v1:cm_no_search_results_found")
|
|
223
|
+
: t("bx_v1:cm_no_data") })));
|
|
224
|
+
});
|
|
225
|
+
//Command Empty will not render initially, so we have return a custom function to render initially
|
|
226
|
+
const CommandEmpty = React.forwardRef((_a, forwardedRef) => {
|
|
227
|
+
var { className } = _a, props = __rest(_a, ["className"]);
|
|
228
|
+
const render = useCommandState((state) => state.filtered.count === 0);
|
|
229
|
+
if (!render)
|
|
230
|
+
return null;
|
|
231
|
+
return (_jsx("div", Object.assign({ ref: forwardedRef, className: cn("py-6 text-center text-sm", className), "cmdk-empty": "", role: "presentation" }, props)));
|
|
232
|
+
});
|
|
233
|
+
MVPSelectEmpty.displayName = CommandPrimitive.Empty.displayName;
|
|
234
|
+
const MVPSelectSeparator = React.forwardRef((_a, ref) => {
|
|
235
|
+
var { className } = _a, props = __rest(_a, ["className"]);
|
|
236
|
+
return (_jsx(CommandPrimitive.Separator, Object.assign({ ref: ref, className: cn("mx-[5px] h-[0.8px] bg-border", className) }, props)));
|
|
237
|
+
});
|
|
238
|
+
MVPSelectSeparator.displayName = CommandPrimitive.Separator.displayName;
|
|
239
|
+
const MVPSelectItem = React.forwardRef((_a, ref) => {
|
|
240
|
+
var { className, value, label, children } = _a, props = __rest(_a, ["className", "value", "label", "children"]);
|
|
241
|
+
const { onChange, setSelectedLabel } = React.useContext(dropDownContext);
|
|
242
|
+
const handleSelect = (val) => {
|
|
243
|
+
let selectedValue = val;
|
|
244
|
+
try {
|
|
245
|
+
selectedValue = JSON.parse(selectedValue);
|
|
246
|
+
}
|
|
247
|
+
catch (error) { }
|
|
248
|
+
setSelectedLabel(label);
|
|
249
|
+
onChange && onChange(selectedValue);
|
|
250
|
+
};
|
|
251
|
+
const { showSeparator } = React.useContext(dropDownContext);
|
|
252
|
+
return (_jsxs(_Fragment, { children: [_jsx(CommandPrimitive.Item, Object.assign({ ref: ref, className: cn("relative flex min-h-[44px] cursor-default select-none items-center px-5 py-1.5 text-sm font-semibold text-[#414141] outline-none hover:bg-[#7677F4]/10 aria-selected:text-accent-foreground data-[disabled]:pointer-events-none data-[selected=true]:bg-accent data-[disabled]:opacity-50", className) }, props, { value: typeof value === "string" ? value : JSON.stringify(value), onSelect: handleSelect }, { children: _jsx("div", Object.assign({ className: "line-clamp-2" }, { children: children })) })), showSeparator && _jsx(MVPSelectSeparator, { alwaysRender: true })] }));
|
|
253
|
+
});
|
|
254
|
+
MVPSelectItem.displayName = CommandPrimitive.Item.displayName;
|
|
255
|
+
const CommandShortcut = (_a) => {
|
|
256
|
+
var { className } = _a, props = __rest(_a, ["className"]);
|
|
257
|
+
return (_jsx("span", Object.assign({ className: cn("ml-auto text-xs tracking-widest text-muted-foreground", className) }, props)));
|
|
258
|
+
};
|
|
259
|
+
CommandShortcut.displayName = "CommandShortcut";
|
|
260
|
+
export { CommandShortcut, MVPSelect, MVPSelectContent, MVPSelectEmpty, MVPSelectInput, MVPSelectItem, MVPSelectItems, MVPSelectLoading, MVPSelectSeparator, MVPSelectTrigger, };
|