sea-react-components 1.3.14 → 1.3.16
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/dist/components/accordion/index.d.ts +2 -0
- package/dist/components/accordion/index.d.ts.map +1 -1
- package/dist/components/accordion/index.js +5 -2
- package/dist/components/activity-message/index.d.ts.map +1 -1
- package/dist/components/activity-message/index.js +2 -2
- package/dist/components/auto-complete/auto-complete-context copy.d.ts +16 -0
- package/dist/components/auto-complete/auto-complete-context copy.d.ts.map +1 -0
- package/dist/components/auto-complete/auto-complete-context copy.js +8 -0
- package/dist/components/auto-complete/auto-complete-context.d.ts +22 -0
- package/dist/components/auto-complete/auto-complete-context.d.ts.map +1 -0
- package/dist/components/auto-complete/auto-complete-context.js +9 -0
- package/dist/components/auto-complete/auto-complete-dropdown.d.ts +7 -0
- package/dist/components/auto-complete/auto-complete-dropdown.d.ts.map +1 -0
- package/dist/components/auto-complete/auto-complete-dropdown.js +11 -0
- package/dist/components/auto-complete/auto-complete-input.d.ts +2 -0
- package/dist/components/auto-complete/auto-complete-input.d.ts.map +1 -0
- package/dist/components/auto-complete/auto-complete-input.js +8 -0
- package/dist/components/auto-complete/auto-complete-selected.d.ts +7 -0
- package/dist/components/auto-complete/auto-complete-selected.d.ts.map +1 -0
- package/dist/components/auto-complete/auto-complete-selected.js +9 -0
- package/dist/components/auto-complete/auto-complete.d.ts +19 -0
- package/dist/components/auto-complete/auto-complete.d.ts.map +1 -0
- package/dist/components/auto-complete/auto-complete.js +35 -0
- package/dist/components/auto-complete/component.d.ts +29 -0
- package/dist/components/auto-complete/component.d.ts.map +1 -0
- package/dist/components/auto-complete/component.js +47 -0
- package/dist/components/auto-complete/index.d.ts +7 -0
- package/dist/components/auto-complete/index.d.ts.map +1 -0
- package/dist/components/auto-complete/index.js +6 -0
- package/dist/components/auto-complete/use-autocomplete.d.ts +20 -0
- package/dist/components/auto-complete/use-autocomplete.d.ts.map +1 -0
- package/dist/components/auto-complete/use-autocomplete.js +57 -0
- package/dist/components/auto-complete-input/index.d.ts +2 -1
- package/dist/components/auto-complete-input/index.d.ts.map +1 -1
- package/dist/components/auto-complete-input/index.js +2 -2
- package/dist/components/auto-complete-input copy/index.d.ts +27 -0
- package/dist/components/auto-complete-input copy/index.d.ts.map +1 -0
- package/dist/components/auto-complete-input copy/index.js +75 -0
- package/dist/components/auto-complete-input2/auto-complete-context.d.ts +16 -0
- package/dist/components/auto-complete-input2/auto-complete-context.d.ts.map +1 -0
- package/dist/components/auto-complete-input2/auto-complete-context.js +8 -0
- package/dist/components/auto-complete-input2/auto-complete-dropdown.d.ts +2 -0
- package/dist/components/auto-complete-input2/auto-complete-dropdown.d.ts.map +1 -0
- package/dist/components/auto-complete-input2/auto-complete-dropdown.js +9 -0
- package/dist/components/auto-complete-input2/auto-complete-input copy.d.ts +2 -0
- package/dist/components/auto-complete-input2/auto-complete-input copy.d.ts.map +1 -0
- package/dist/components/auto-complete-input2/auto-complete-input copy.js +9 -0
- package/dist/components/auto-complete-input2/auto-complete-input.d.ts +2 -0
- package/dist/components/auto-complete-input2/auto-complete-input.d.ts.map +1 -0
- package/dist/components/auto-complete-input2/auto-complete-input.js +9 -0
- package/dist/components/auto-complete-input2/auto-complete.d.ts +14 -0
- package/dist/components/auto-complete-input2/auto-complete.d.ts.map +1 -0
- package/dist/components/auto-complete-input2/auto-complete.js +20 -0
- package/dist/components/auto-complete-input2/component.d.ts +29 -0
- package/dist/components/auto-complete-input2/component.d.ts.map +1 -0
- package/dist/components/auto-complete-input2/component.js +47 -0
- package/dist/components/auto-complete-input2/index.d.ts +3 -0
- package/dist/components/auto-complete-input2/index.d.ts.map +1 -0
- package/dist/components/auto-complete-input2/index.js +2 -0
- package/dist/components/auto-complete-input2/use-autocomplete.d.ts +21 -0
- package/dist/components/auto-complete-input2/use-autocomplete.d.ts.map +1 -0
- package/dist/components/auto-complete-input2/use-autocomplete.js +56 -0
- package/dist/components/auto-complete-input2/useAutocomplete.d.ts +21 -0
- package/dist/components/auto-complete-input2/useAutocomplete.d.ts.map +1 -0
- package/dist/components/auto-complete-input2/useAutocomplete.js +59 -0
- package/dist/components/break-line/index.d.ts +7 -0
- package/dist/components/break-line/index.d.ts.map +1 -0
- package/dist/components/break-line/index.js +12 -0
- package/dist/components/button/index.d.ts +4 -1
- package/dist/components/button/index.d.ts.map +1 -1
- package/dist/components/button/index.js +11 -2
- package/dist/components/cards-list/index.d.ts +5 -1
- package/dist/components/cards-list/index.d.ts.map +1 -1
- package/dist/components/cards-list/index.js +6 -2
- package/dist/components/comments-container/comment-event-bus/index.d.ts.map +1 -1
- package/dist/components/comments-container/comment-event-bus/index.js +1 -0
- package/dist/components/comments-container/comment-form/index.d.ts.map +1 -1
- package/dist/components/comments-container/comment-item/index.d.ts.map +1 -1
- package/dist/components/comments-container/comments-list/index.d.ts.map +1 -1
- package/dist/components/comments-container/comments-list/index.js +1 -1
- package/dist/components/comments-container/constants/index.d.ts.map +1 -1
- package/dist/components/comments-container/constants/index.js +1 -0
- package/dist/components/comments-container/index.d.ts.map +1 -1
- package/dist/components/comments-container/index.js +8 -4
- package/dist/components/confirm/index.d.ts +9 -0
- package/dist/components/confirm/index.d.ts.map +1 -0
- package/dist/components/confirm/index.js +40 -0
- package/dist/components/expandable-text/index.d.ts +2 -1
- package/dist/components/expandable-text/index.d.ts.map +1 -1
- package/dist/components/expandable-text/index.js +2 -2
- package/dist/components/icon/index.d.ts.map +1 -1
- package/dist/components/input/index.d.ts +2 -1
- package/dist/components/input/index.d.ts.map +1 -1
- package/dist/components/input/index.js +3 -3
- package/dist/components/modal/index.d.ts +2 -0
- package/dist/components/modal/index.d.ts.map +1 -1
- package/dist/components/modal/index.js +1 -1
- package/dist/components/notifications-menu/index.js +1 -1
- package/dist/components/search-input/index.d.ts.map +1 -1
- package/dist/components/search-input/index.js +1 -2
- package/dist/components/select/index.d.ts +5 -2
- package/dist/components/select/index.d.ts.map +1 -1
- package/dist/components/select/index.js +37 -15
- package/dist/components/tab/index.d.ts +20 -9
- package/dist/components/tab/index.d.ts.map +1 -1
- package/dist/components/tab/index.js +23 -8
- package/dist/components/textarea/index.d.ts +1 -1
- package/dist/components/textarea/index.d.ts.map +1 -1
- package/dist/components/textarea/index.js +2 -2
- package/dist/constants/index.d.ts +1 -0
- package/dist/constants/index.d.ts.map +1 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utils/auth-axios/index.d.ts.map +1 -1
- package/dist/utils/auth-axios/index.js +2 -0
- package/dist/utils/axios/index.d.ts +1 -0
- package/dist/utils/axios/index.d.ts.map +1 -1
- package/dist/utils/axios/index.js +20 -5
- package/dist/utils/cookie/index.d.ts +8 -0
- package/dist/utils/cookie/index.d.ts.map +1 -1
- package/dist/utils/cookie/index.js +31 -0
- package/dist/utils/device/index.d.ts +2 -0
- package/dist/utils/device/index.d.ts.map +1 -0
- package/dist/utils/device/index.js +12 -0
- package/package.json +4 -3
- package/dist/components/comments-container/comments-list copy/index.d.ts +0 -1
- package/dist/components/comments-container/comments-list copy/index.d.ts.map +0 -1
- package/dist/components/comments-container/comments-list copy/index.js +0 -75
- package/dist/hooks/aaaa/useHasApplicationAccess.d.ts +0 -3
- package/dist/hooks/aaaa/useHasApplicationAccess.d.ts.map +0 -1
- package/dist/hooks/aaaa/useHasApplicationAccess.js +0 -8
- package/dist/hooks/user-has-application-access/useHasApplicationAccess.d.ts +0 -3
- package/dist/hooks/user-has-application-access/useHasApplicationAccess.d.ts.map +0 -1
- package/dist/hooks/user-has-application-access/useHasApplicationAccess.js +0 -8
- package/dist/middleware/firebase-token-handler/index.d.ts +0 -8
- package/dist/middleware/firebase-token-handler/index.d.ts.map +0 -1
- package/dist/middleware/firebase-token-handler/index.js +0 -28
- package/dist/utils/firebase/index.d.ts +0 -1
- package/dist/utils/firebase/index.d.ts.map +0 -1
- package/dist/utils/firebase/index.js +0 -0
- package/dist/utils/firebase-client/config.d.ts +0 -1
- package/dist/utils/firebase-client/config.d.ts.map +0 -1
- package/dist/utils/firebase-client/config.js +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/accordion/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,EAIZ,SAAS,EAIV,MAAM,OAAO,CAAC;AAIf,KAAK,WAAW,GAAG;IACjB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,UAAU,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC;CAClC,CAAC;AAIF,KAAK,cAAc,GAAG;IACpB,QAAQ,EAAE,SAAS,CAAC;IACpB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB,CAAC;AAEF,eAAO,MAAM,SAAS,EAAE,KAAK,CAAC,EAAE,CAAC,cAAc,CAe9C,CAAC;AAEF,eAAO,MAAM,YAAY,mBAMxB,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG;IAC/B,KAAK,EAAE,SAAS,CAAC;IACjB,QAAQ,EAAE,SAAS,CAAC;IACpB,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,YAAY,CAAC,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/accordion/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,EAIZ,SAAS,EAIV,MAAM,OAAO,CAAC;AAIf,KAAK,WAAW,GAAG;IACjB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,UAAU,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC;CAClC,CAAC;AAIF,KAAK,cAAc,GAAG;IACpB,QAAQ,EAAE,SAAS,CAAC;IACpB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB,CAAC;AAEF,eAAO,MAAM,SAAS,EAAE,KAAK,CAAC,EAAE,CAAC,cAAc,CAe9C,CAAC;AAEF,eAAO,MAAM,YAAY,mBAMxB,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG;IAC/B,KAAK,EAAE,SAAS,CAAC;IACjB,QAAQ,EAAE,SAAS,CAAC;IACpB,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,YAAY,CAAC,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,IAAI,CAAC;IACzC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,eAAO,MAAM,aAAa,EAAE,KAAK,CAAC,EAAE,CAAC,kBAAkB,CA2DtD,CAAC"}
|
|
@@ -18,7 +18,7 @@ export const useAccordion = () => {
|
|
|
18
18
|
}
|
|
19
19
|
return context;
|
|
20
20
|
};
|
|
21
|
-
export const AccordionItem = ({ title, children, id, onOpenChange, }) => {
|
|
21
|
+
export const AccordionItem = ({ title, children, id, onOpenChange, badgeTitle, className, }) => {
|
|
22
22
|
const generatedId = useId();
|
|
23
23
|
const itemId = id || generatedId;
|
|
24
24
|
const { openItem, toggleItem } = useAccordion();
|
|
@@ -30,7 +30,10 @@ export const AccordionItem = ({ title, children, id, onOpenChange, }) => {
|
|
|
30
30
|
onOpenChange === null || onOpenChange === void 0 ? void 0 : onOpenChange(isOpen);
|
|
31
31
|
}
|
|
32
32
|
}, [isOpen, onOpenChange]);
|
|
33
|
-
return (_jsxs("div", { className: "group", children: [_jsxs("div", { onClick: () => toggleItem(itemId), className:
|
|
33
|
+
return (_jsxs("div", { className: "group", children: [_jsxs("div", { onClick: () => toggleItem(itemId), className: clsx({
|
|
34
|
+
"w-full flex justify-between items-center gap-3 px-4 py-3 bg-white hover:bg-primary/10 custom-animation text-left": className == undefined,
|
|
35
|
+
[className]: className != undefined,
|
|
36
|
+
}), children: [_jsxs("div", { className: "flex gap-2", children: [_jsx("div", { className: "w-full", children: title }), badgeTitle && (_jsx("div", { className: "mt-1 inline-block px-2 py-0.5 bg-gray-200 text-gray-700 text-xs rounded-full", children: badgeTitle }))] }), _jsx(Icon, { icon: "weui:arrow-filled", className: clsx("h-5 w-5 cursor-pointer custom-animation", {
|
|
34
37
|
"-rotate-90": isOpen,
|
|
35
38
|
"rotate-90": !isOpen,
|
|
36
39
|
}) })] }), _jsx("div", { className: `px-4 pb-4 overflow-auto transition-all duration-300 ease-in-out ${isOpen ? "max-h-screen opacity-100" : "max-h-0 opacity-0"}`, children: isOpen && _jsx("div", { className: "pt-2 text-gray-700", children: children }) })] }));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/activity-message/index.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAa,GAAG,EAAS,MAAM,sBAAsB,CAAC;AAG7D,KAAK,KAAK,GAAG;IACX,QAAQ,EAAE,GAAG,CAAC,QAAQ,CAAC,SAAS,CAAC;CAClC,CAAC;AACF,MAAM,CAAC,OAAO,UAAU,eAAe,CAAC,EAAE,QAAQ,EAAE,EAAE,KAAK,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/activity-message/index.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAa,GAAG,EAAS,MAAM,sBAAsB,CAAC;AAG7D,KAAK,KAAK,GAAG;IACX,QAAQ,EAAE,GAAG,CAAC,QAAQ,CAAC,SAAS,CAAC;CAClC,CAAC;AACF,MAAM,CAAC,OAAO,UAAU,eAAe,CAAC,EAAE,QAAQ,EAAE,EAAE,KAAK,2CAoQ1D"}
|
|
@@ -3,7 +3,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
3
3
|
import { CONSTANTS, Utils } from "sea-platform-helpers";
|
|
4
4
|
const NONE = "N/A";
|
|
5
5
|
export default function ActivityMessage({ activity }) {
|
|
6
|
-
var _a, _b, _c, _d, _e, _f
|
|
6
|
+
var _a, _b, _c, _d, _e, _f;
|
|
7
7
|
let message = null;
|
|
8
8
|
switch (activity.type) {
|
|
9
9
|
case CONSTANTS.Activity.ActivityTypes.SystemAction: {
|
|
@@ -46,7 +46,7 @@ export default function ActivityMessage({ activity }) {
|
|
|
46
46
|
}
|
|
47
47
|
case CONSTANTS.Activity.ActivityTypes.TaskGetUpdated: {
|
|
48
48
|
const metadata = activity.metadata;
|
|
49
|
-
message = (_jsxs("div", { className: "flex flex-col gap-[1px]", children: [_jsx("p", { children: "Task updated" }), _jsxs("div", { className: "text-sm", children: [metadata.title && (_jsx("div", { className: "flex gap-1", children: _jsxs("p", { children: ["Title:", " ", _jsx("span", { className: "font-semibold", children: metadata.title.to })] }) })), metadata.description && (_jsx("div", { className: "flex gap-1", children: _jsxs("p", { children: ["Description:", " ", _jsx("span", { className: "font-semibold", children: metadata.description.to })] }) })), metadata.section && (_jsx("div", { className: "flex gap-1", children: _jsxs("p", { children: ["Section:", " ", _jsx("span", { className: "font-semibold", children: (_d = (_c = metadata.section.to) === null || _c === void 0 ? void 0 : _c.name) !== null && _d !== void 0 ? _d : NONE })] }) })), metadata.milestone && (_jsx("div", { className: "flex gap-1", children: _jsxs("p", { children: ["Milestone:", " ", _jsx("span", { className: "font-semibold", children: (_f = (_e = metadata.milestone.to) === null || _e === void 0 ? void 0 : _e.title) !== null && _f !== void 0 ? _f : NONE })] }) })), metadata.priority && (_jsx("div", { className: "flex gap-1", children: _jsxs("p", { children: ["Priority:", " ", _jsx("span", { className: "font-semibold", children: metadata.priority.to })] }) })), metadata.
|
|
49
|
+
message = (_jsxs("div", { className: "flex flex-col gap-[1px]", children: [_jsx("p", { children: "Task updated" }), _jsxs("div", { className: "text-sm", children: [metadata.title && (_jsx("div", { className: "flex gap-1", children: _jsxs("p", { children: ["Title:", " ", _jsx("span", { className: "font-semibold", children: metadata.title.to })] }) })), metadata.description && (_jsx("div", { className: "flex gap-1", children: _jsxs("p", { children: ["Description:", " ", _jsx("span", { className: "font-semibold", children: metadata.description.to })] }) })), metadata.section && (_jsx("div", { className: "flex gap-1", children: _jsxs("p", { children: ["Section:", " ", _jsx("span", { className: "font-semibold", children: (_d = (_c = metadata.section.to) === null || _c === void 0 ? void 0 : _c.name) !== null && _d !== void 0 ? _d : NONE })] }) })), metadata.milestone && (_jsx("div", { className: "flex gap-1", children: _jsxs("p", { children: ["Milestone:", " ", _jsx("span", { className: "font-semibold", children: (_f = (_e = metadata.milestone.to) === null || _e === void 0 ? void 0 : _e.title) !== null && _f !== void 0 ? _f : NONE })] }) })), metadata.priority && (_jsx("div", { className: "flex gap-1", children: _jsxs("p", { children: ["Priority:", " ", _jsx("span", { className: "font-semibold", children: metadata.priority.to })] }) })), metadata.dueDate && (_jsx("div", { className: "flex gap-1", children: _jsxs("p", { children: ["Due date:", " ", _jsx("span", { className: "font-semibold", children: Utils.Moment.formatDate(metadata.dueDate.to) })] }) })), metadata.isCompleted && (_jsx("div", { className: "flex gap-1", children: _jsxs("p", { children: ["Completed:", " ", _jsx("span", { className: "font-semibold", children: metadata.isCompleted.to ? "Yes" : "No" })] }) }))] })] }));
|
|
50
50
|
break;
|
|
51
51
|
}
|
|
52
52
|
case CONSTANTS.Activity.ActivityTypes.TaskGetDeleted: {
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { SelectOption } from "../select";
|
|
2
|
+
export type AutocompleteContextType<T> = {
|
|
3
|
+
inputValue: string;
|
|
4
|
+
setInputValue: (v: string) => void;
|
|
5
|
+
open: boolean;
|
|
6
|
+
setOpen: (v: boolean) => void;
|
|
7
|
+
filteredOptions: SelectOption<T>[];
|
|
8
|
+
select: (option: T) => void;
|
|
9
|
+
remove: (option: T) => void;
|
|
10
|
+
highlightedIndex: number;
|
|
11
|
+
setHighlightedIndex: (i: number) => void;
|
|
12
|
+
selected: T[];
|
|
13
|
+
};
|
|
14
|
+
export declare const AutocompleteContext: import("react").Context<AutocompleteContextType<any>>;
|
|
15
|
+
export declare function useAutocompleteContext<T>(): AutocompleteContextType<T>;
|
|
16
|
+
//# sourceMappingURL=auto-complete-context%20copy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auto-complete-context copy.d.ts","sourceRoot":"","sources":["../../../src/components/auto-complete/auto-complete-context copy.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAEzC,MAAM,MAAM,uBAAuB,CAAC,CAAC,IAAI;IACvC,UAAU,EAAE,MAAM,CAAC;IACnB,aAAa,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;IACnC,IAAI,EAAE,OAAO,CAAC;IACd,OAAO,EAAE,CAAC,CAAC,EAAE,OAAO,KAAK,IAAI,CAAC;IAC9B,eAAe,EAAE,YAAY,CAAC,CAAC,CAAC,EAAE,CAAC;IACnC,MAAM,EAAE,CAAC,MAAM,EAAE,CAAC,KAAK,IAAI,CAAC;IAC5B,MAAM,EAAE,CAAC,MAAM,EAAE,CAAC,KAAK,IAAI,CAAC;IAC5B,gBAAgB,EAAE,MAAM,CAAC;IACzB,mBAAmB,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;IACzC,QAAQ,EAAE,CAAC,EAAE,CAAC;CACf,CAAC;AAEF,eAAO,MAAM,mBAAmB,uDAC0B,CAAC;AAE3D,wBAAgB,sBAAsB,CAAC,CAAC,KAMxB,uBAAuB,CAAC,CAAC,CAAC,CACzC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { createContext, useContext } from "react";
|
|
2
|
+
export const AutocompleteContext = createContext(null);
|
|
3
|
+
export function useAutocompleteContext() {
|
|
4
|
+
const ctx = useContext(AutocompleteContext);
|
|
5
|
+
if (!ctx)
|
|
6
|
+
throw new Error("Autocomplete compound components must be used within <Autocomplete>");
|
|
7
|
+
return ctx;
|
|
8
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export type AutocompleteContextType<T> = {
|
|
2
|
+
inputValue: string;
|
|
3
|
+
setInputValue: (v: string) => void;
|
|
4
|
+
open: boolean;
|
|
5
|
+
setOpen: (v: boolean) => void;
|
|
6
|
+
filteredOptions: T[];
|
|
7
|
+
select: (option: T) => void;
|
|
8
|
+
remove: (option: T) => void;
|
|
9
|
+
highlightedIndex: number;
|
|
10
|
+
setHighlightedIndex: (i: number) => void;
|
|
11
|
+
selected: T[];
|
|
12
|
+
label?: string;
|
|
13
|
+
name?: string;
|
|
14
|
+
loading?: boolean;
|
|
15
|
+
required?: boolean;
|
|
16
|
+
placeholder?: string;
|
|
17
|
+
errorMessage?: string;
|
|
18
|
+
onDebouncedChange?: (val: string) => void;
|
|
19
|
+
};
|
|
20
|
+
export declare const AutocompleteContext: import("react").Context<AutocompleteContextType<any>>;
|
|
21
|
+
export declare function useAutocompleteContext<T>(): AutocompleteContextType<T>;
|
|
22
|
+
//# sourceMappingURL=auto-complete-context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auto-complete-context.d.ts","sourceRoot":"","sources":["../../../src/components/auto-complete/auto-complete-context.tsx"],"names":[],"mappings":"AAIA,MAAM,MAAM,uBAAuB,CAAC,CAAC,IAAI;IACvC,UAAU,EAAE,MAAM,CAAC;IACnB,aAAa,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;IACnC,IAAI,EAAE,OAAO,CAAC;IACd,OAAO,EAAE,CAAC,CAAC,EAAE,OAAO,KAAK,IAAI,CAAC;IAC9B,eAAe,EAAE,CAAC,EAAE,CAAC;IACrB,MAAM,EAAE,CAAC,MAAM,EAAE,CAAC,KAAK,IAAI,CAAC;IAC5B,MAAM,EAAE,CAAC,MAAM,EAAE,CAAC,KAAK,IAAI,CAAC;IAC5B,gBAAgB,EAAE,MAAM,CAAC;IACzB,mBAAmB,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;IACzC,QAAQ,EAAE,CAAC,EAAE,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,iBAAiB,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;CAC3C,CAAC;AAEF,eAAO,MAAM,mBAAmB,uDAC0B,CAAC;AAE3D,wBAAgB,sBAAsB,CAAC,CAAC,KAMxB,uBAAuB,CAAC,CAAC,CAAC,CACzC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { createContext, useContext } from "react";
|
|
3
|
+
export const AutocompleteContext = createContext(null);
|
|
4
|
+
export function useAutocompleteContext() {
|
|
5
|
+
const ctx = useContext(AutocompleteContext);
|
|
6
|
+
if (!ctx)
|
|
7
|
+
throw new Error("Autocomplete compound components must be used within <Autocomplete>");
|
|
8
|
+
return ctx;
|
|
9
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
type DropdownProps<T> = {
|
|
3
|
+
renderOption: (option: T, isHighlighted: boolean) => React.ReactNode;
|
|
4
|
+
};
|
|
5
|
+
export declare function AutocompleteDropdown<T>({ renderOption }: DropdownProps<T>): import("react/jsx-runtime").JSX.Element;
|
|
6
|
+
export {};
|
|
7
|
+
//# sourceMappingURL=auto-complete-dropdown.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auto-complete-dropdown.d.ts","sourceRoot":"","sources":["../../../src/components/auto-complete/auto-complete-dropdown.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,OAAO,CAAC;AAK1B,KAAK,aAAa,CAAC,CAAC,IAAI;IACtB,YAAY,EAAE,CAAC,MAAM,EAAE,CAAC,EAAE,aAAa,EAAE,OAAO,KAAK,KAAK,CAAC,SAAS,CAAC;CACtE,CAAC;AAEF,wBAAgB,oBAAoB,CAAC,CAAC,EAAE,EAAE,YAAY,EAAE,EAAE,aAAa,CAAC,CAAC,CAAC,2CAqCzE"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { useAutocompleteContext } from "./auto-complete-context";
|
|
4
|
+
import clsx from "clsx";
|
|
5
|
+
import Loader from "../loader";
|
|
6
|
+
export function AutocompleteDropdown({ renderOption }) {
|
|
7
|
+
const { open, filteredOptions, highlightedIndex, setHighlightedIndex, select, loading, } = useAutocompleteContext();
|
|
8
|
+
if (!open)
|
|
9
|
+
return null;
|
|
10
|
+
return (_jsx("div", { className: "absolute z-10 w-full mt-1 bg-white border rounded shadow max-h-60 overflow-y-auto", children: loading ? (_jsx("div", { className: "p-4 flex justify-center items-center", children: _jsx(Loader, {}) })) : filteredOptions.length > 0 ? (filteredOptions.map((o, i) => (_jsx("div", { className: clsx("px-4 py-2 cursor-pointer hover:bg-primary hover:bg-opacity-20", highlightedIndex === i && "bg-gray-100"), onMouseEnter: () => setHighlightedIndex(i), onClick: () => select(o), children: renderOption(o, highlightedIndex === i) }, `option-${i}`)))) : (_jsx("div", { className: "p-4 text-center text-gray-400", children: "No options found" })) }));
|
|
11
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auto-complete-input.d.ts","sourceRoot":"","sources":["../../../src/components/auto-complete/auto-complete-input.tsx"],"names":[],"mappings":"AAKA,wBAAgB,iBAAiB,4CA2BhC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { useAutocompleteContext } from "./auto-complete-context";
|
|
4
|
+
import SearchInput from "../search-input";
|
|
5
|
+
export function AutocompleteInput() {
|
|
6
|
+
const { inputValue, setInputValue, setOpen, label, name, required, placeholder, errorMessage, onDebouncedChange, } = useAutocompleteContext();
|
|
7
|
+
return (_jsx(SearchInput, { label: label, name: name, value: inputValue, required: required, onFocus: () => setOpen(true), onChange: (e) => setInputValue(e.target.value), onDebouncedChange: (val) => onDebouncedChange === null || onDebouncedChange === void 0 ? void 0 : onDebouncedChange(val), autoComplete: "off", placeholder: placeholder, errorMessage: errorMessage }));
|
|
8
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
type SelectedProps<T> = {
|
|
3
|
+
render?: (selected: T[], remove: (option: T) => void) => React.ReactNode;
|
|
4
|
+
};
|
|
5
|
+
export declare function AutocompleteSelected<T>({ render }: SelectedProps<T>): import("react/jsx-runtime").JSX.Element;
|
|
6
|
+
export {};
|
|
7
|
+
//# sourceMappingURL=auto-complete-selected.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auto-complete-selected.d.ts","sourceRoot":"","sources":["../../../src/components/auto-complete/auto-complete-selected.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,OAAO,CAAC;AAG1B,KAAK,aAAa,CAAC,CAAC,IAAI;IACtB,MAAM,CAAC,EAAE,CAAC,QAAQ,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,CAAC,MAAM,EAAE,CAAC,KAAK,IAAI,KAAK,KAAK,CAAC,SAAS,CAAC;CAC1E,CAAC;AAEF,wBAAgB,oBAAoB,CAAC,CAAC,EAAE,EAAE,MAAM,EAAE,EAAE,aAAa,CAAC,CAAC,CAAC,2CAKnE"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { useAutocompleteContext } from "./auto-complete-context";
|
|
4
|
+
export function AutocompleteSelected({ render }) {
|
|
5
|
+
const { selected, remove } = useAutocompleteContext();
|
|
6
|
+
if (!selected.length)
|
|
7
|
+
return null;
|
|
8
|
+
return _jsx(_Fragment, { children: render ? render(selected, remove) : null });
|
|
9
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
export type AutocompleteProps<T> = {
|
|
3
|
+
options: T[];
|
|
4
|
+
selected?: T[];
|
|
5
|
+
onSelect?: (selected: T[]) => void;
|
|
6
|
+
multiselect?: boolean;
|
|
7
|
+
loading?: boolean;
|
|
8
|
+
label?: string;
|
|
9
|
+
name?: string;
|
|
10
|
+
required?: boolean;
|
|
11
|
+
placeholder?: string;
|
|
12
|
+
errorMessage?: string;
|
|
13
|
+
onDebouncedChange?: (val: string) => void;
|
|
14
|
+
children: React.ReactNode;
|
|
15
|
+
};
|
|
16
|
+
export declare function Autocomplete<T extends string | number | {
|
|
17
|
+
id: string;
|
|
18
|
+
}>({ options, selected, onSelect, multiselect, loading, label, name, required, placeholder, errorMessage, onDebouncedChange, children, }: AutocompleteProps<T>): import("react/jsx-runtime").JSX.Element;
|
|
19
|
+
//# sourceMappingURL=auto-complete.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auto-complete.d.ts","sourceRoot":"","sources":["../../../src/components/auto-complete/auto-complete.tsx"],"names":[],"mappings":"AAEA,OAAO,KAA4B,MAAM,OAAO,CAAC;AAKjD,MAAM,MAAM,iBAAiB,CAAC,CAAC,IAAI;IACjC,OAAO,EAAE,CAAC,EAAE,CAAC;IACb,QAAQ,CAAC,EAAE,CAAC,EAAE,CAAC;IACf,QAAQ,CAAC,EAAE,CAAC,QAAQ,EAAE,CAAC,EAAE,KAAK,IAAI,CAAC;IACnC,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,iBAAiB,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;IAC1C,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;CAC3B,CAAC;AAEF,wBAAgB,YAAY,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,GAAG;IAAE,EAAE,EAAE,MAAM,CAAA;CAAE,EAAE,EACvE,OAAO,EACP,QAAQ,EACR,QAAQ,EACR,WAAkB,EAClB,OAAe,EACf,KAAK,EACL,IAAI,EACJ,QAAQ,EACR,WAAW,EACX,YAAY,EACZ,iBAAiB,EACjB,QAAQ,GACT,EAAE,iBAAiB,CAAC,CAAC,CAAC,2CAqCtB"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { useRef, useEffect } from "react";
|
|
4
|
+
import { AutocompleteContext } from "./auto-complete-context";
|
|
5
|
+
import { useAutocomplete } from "./use-autocomplete";
|
|
6
|
+
export function Autocomplete({ options, selected, onSelect, multiselect = true, loading = false, label, name, required, placeholder, errorMessage, onDebouncedChange, children, }) {
|
|
7
|
+
const containerRef = useRef(null);
|
|
8
|
+
const ac = useAutocomplete({
|
|
9
|
+
options,
|
|
10
|
+
selected,
|
|
11
|
+
multiselect,
|
|
12
|
+
onSelect,
|
|
13
|
+
});
|
|
14
|
+
// Expose label, name, loading, onDebouncedChange through context if needed
|
|
15
|
+
const contextValue = {
|
|
16
|
+
...ac,
|
|
17
|
+
label,
|
|
18
|
+
name,
|
|
19
|
+
loading,
|
|
20
|
+
required,
|
|
21
|
+
placeholder,
|
|
22
|
+
errorMessage,
|
|
23
|
+
onDebouncedChange,
|
|
24
|
+
};
|
|
25
|
+
useEffect(() => {
|
|
26
|
+
const handler = (e) => {
|
|
27
|
+
var _a;
|
|
28
|
+
if (!((_a = containerRef.current) === null || _a === void 0 ? void 0 : _a.contains(e.target)))
|
|
29
|
+
ac.setOpen(false);
|
|
30
|
+
};
|
|
31
|
+
document.addEventListener("mousedown", handler);
|
|
32
|
+
return () => document.removeEventListener("mousedown", handler);
|
|
33
|
+
}, [ac]);
|
|
34
|
+
return (_jsx(AutocompleteContext.Provider, { value: contextValue, children: _jsx("div", { ref: containerRef, className: "relative w-full", children: children }) }));
|
|
35
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import SearchInput from "../search-input";
|
|
3
|
+
import { SelectOption } from "../select";
|
|
4
|
+
export type Props<T extends string | number | {
|
|
5
|
+
id: string;
|
|
6
|
+
}> = {
|
|
7
|
+
label?: string;
|
|
8
|
+
name?: string;
|
|
9
|
+
options: SelectOption<T>[];
|
|
10
|
+
selectedOptions?: T[];
|
|
11
|
+
setSelectedOptions?: (opts: T[]) => void;
|
|
12
|
+
onOptionSelect?: (option: SelectOption<T>) => void;
|
|
13
|
+
multiselect?: boolean;
|
|
14
|
+
loading?: boolean;
|
|
15
|
+
renderSelectedOptions?: (selected: T[], remove: (option: T) => void) => React.ReactNode;
|
|
16
|
+
renderOption?: (option: SelectOption<T>, isHighlighted: boolean) => React.ReactNode;
|
|
17
|
+
renderContainer?: (content: {
|
|
18
|
+
input: React.ReactNode;
|
|
19
|
+
dropdown: React.ReactNode;
|
|
20
|
+
selected: React.ReactNode;
|
|
21
|
+
multiselect: boolean;
|
|
22
|
+
}) => React.ReactNode;
|
|
23
|
+
} & Omit<React.ComponentProps<typeof SearchInput>, "onDebouncedChange"> & {
|
|
24
|
+
onDebouncedChange?: (val: string) => void;
|
|
25
|
+
};
|
|
26
|
+
export default function AutoCompleteInput<T extends string | number | {
|
|
27
|
+
id: string;
|
|
28
|
+
}>({ label, name, options, selectedOptions, setSelectedOptions, onOptionSelect, value, onChange, onDebouncedChange, loading, multiselect, renderSelectedOptions, renderOption, renderContainer, ...rest }: Props<T>): import("react/jsx-runtime").JSX.Element;
|
|
29
|
+
//# sourceMappingURL=component.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"component.d.ts","sourceRoot":"","sources":["../../../src/components/auto-complete/component.tsx"],"names":[],"mappings":"AAEA,OAAO,KAA4B,MAAM,OAAO,CAAC;AACjD,OAAO,WAAW,MAAM,iBAAiB,CAAC;AAG1C,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAGzC,MAAM,MAAM,KAAK,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,GAAG;IAAE,EAAE,EAAE,MAAM,CAAA;CAAE,IAAI;IAC9D,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,YAAY,CAAC,CAAC,CAAC,EAAE,CAAC;IAC3B,eAAe,CAAC,EAAE,CAAC,EAAE,CAAC;IACtB,kBAAkB,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,EAAE,KAAK,IAAI,CAAC;IACzC,cAAc,CAAC,EAAE,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC;IACnD,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,qBAAqB,CAAC,EAAE,CACtB,QAAQ,EAAE,CAAC,EAAE,EACb,MAAM,EAAE,CAAC,MAAM,EAAE,CAAC,KAAK,IAAI,KACxB,KAAK,CAAC,SAAS,CAAC;IACrB,YAAY,CAAC,EAAE,CACb,MAAM,EAAE,YAAY,CAAC,CAAC,CAAC,EACvB,aAAa,EAAE,OAAO,KACnB,KAAK,CAAC,SAAS,CAAC;IACrB,eAAe,CAAC,EAAE,CAAC,OAAO,EAAE;QAC1B,KAAK,EAAE,KAAK,CAAC,SAAS,CAAC;QACvB,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;QAC1B,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;QAC1B,WAAW,EAAE,OAAO,CAAC;KACtB,KAAK,KAAK,CAAC,SAAS,CAAC;CACvB,GAAG,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,OAAO,WAAW,CAAC,EAAE,mBAAmB,CAAC,GAAG;IACtE,iBAAiB,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;CAC3C,CAAC;AAEJ,MAAM,CAAC,OAAO,UAAU,iBAAiB,CACvC,CAAC,SAAS,MAAM,GAAG,MAAM,GAAG;IAAE,EAAE,EAAE,MAAM,CAAA;CAAE,EAC1C,EACA,KAAK,EACL,IAAI,EACJ,OAAO,EACP,eAAoB,EACpB,kBAAkB,EAClB,cAAc,EACd,KAAK,EACL,QAAQ,EACR,iBAAiB,EACjB,OAAe,EACf,WAAkB,EAClB,qBAAqB,EACrB,YAAY,EACZ,eAAe,EACf,GAAG,IAAI,EACR,EAAE,KAAK,CAAC,CAAC,CAAC,2CAsGV"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useRef, useEffect } from "react";
|
|
4
|
+
import SearchInput from "../search-input";
|
|
5
|
+
import Loader from "../loader";
|
|
6
|
+
import clsx from "clsx";
|
|
7
|
+
import { useAutocomplete } from "./use-autocomplete";
|
|
8
|
+
export default function AutoCompleteInput({ label, name, options, selectedOptions = [], setSelectedOptions, onOptionSelect, value, onChange, onDebouncedChange, loading = false, multiselect = true, renderSelectedOptions, renderOption, renderContainer, ...rest }) {
|
|
9
|
+
const containerRef = useRef(null);
|
|
10
|
+
const { inputValue, setInputValue, open, setOpen, filteredOptions, select, remove, highlightedIndex, setHighlightedIndex, selected, } = useAutocomplete({
|
|
11
|
+
options,
|
|
12
|
+
selected: selectedOptions,
|
|
13
|
+
multiselect,
|
|
14
|
+
onSelect: setSelectedOptions,
|
|
15
|
+
});
|
|
16
|
+
// Click outside to close
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
const handler = (e) => {
|
|
19
|
+
var _a;
|
|
20
|
+
if (!((_a = containerRef.current) === null || _a === void 0 ? void 0 : _a.contains(e.target)))
|
|
21
|
+
setOpen(false);
|
|
22
|
+
};
|
|
23
|
+
document.addEventListener("mousedown", handler);
|
|
24
|
+
return () => document.removeEventListener("mousedown", handler);
|
|
25
|
+
}, []);
|
|
26
|
+
const handleOptionSelect = (option) => {
|
|
27
|
+
select(option.value);
|
|
28
|
+
onOptionSelect === null || onOptionSelect === void 0 ? void 0 : onOptionSelect(option);
|
|
29
|
+
};
|
|
30
|
+
const input = (_jsx(SearchInput, { label: label, name: name, value: inputValue, onFocus: () => setOpen(true), onChange: (e) => {
|
|
31
|
+
setInputValue(e.target.value);
|
|
32
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(e);
|
|
33
|
+
}, onDebouncedChange: (val) => {
|
|
34
|
+
setOpen(true);
|
|
35
|
+
onDebouncedChange === null || onDebouncedChange === void 0 ? void 0 : onDebouncedChange(val);
|
|
36
|
+
}, autoComplete: "off", ...rest }));
|
|
37
|
+
const dropdown = open ? (_jsx("div", { className: "absolute z-10 w-full mt-1 bg-white border rounded shadow max-h-60 overflow-y-auto", children: loading ? (_jsx("div", { className: "p-4 flex justify-center items-center", children: _jsx(Loader, {}) })) : filteredOptions.length > 0 ? (filteredOptions.map((o, i) => (_jsx("div", { className: clsx("px-4 py-2 cursor-pointer custom-animation hover:bg-primary hover:bg-opacity-20", highlightedIndex === i && "bg-gray-100"), onMouseEnter: () => setHighlightedIndex(i), onClick: () => handleOptionSelect(o), children: renderOption ? renderOption(o, highlightedIndex === i) : o.label }, `${name}-option-${i}`)))) : (_jsx("div", { className: "p-4 text-center text-gray-400", children: "No options found" })) })) : null;
|
|
38
|
+
const selectedNode = selected.length
|
|
39
|
+
? renderSelectedOptions === null || renderSelectedOptions === void 0 ? void 0 : renderSelectedOptions(selected, remove)
|
|
40
|
+
: null;
|
|
41
|
+
return (_jsx("div", { ref: containerRef, className: "relative w-full", children: renderContainer ? (renderContainer({
|
|
42
|
+
input,
|
|
43
|
+
dropdown,
|
|
44
|
+
selected: selectedNode,
|
|
45
|
+
multiselect,
|
|
46
|
+
})) : (_jsxs(_Fragment, { children: [selectedNode, input, dropdown] })) }));
|
|
47
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export * from "./auto-complete-context";
|
|
2
|
+
export * from "./auto-complete-dropdown";
|
|
3
|
+
export * from "./auto-complete-input";
|
|
4
|
+
export * from "./auto-complete-selected";
|
|
5
|
+
export * from "./auto-complete";
|
|
6
|
+
export * from "./use-autocomplete";
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/auto-complete/index.tsx"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAC;AACxC,cAAc,0BAA0B,CAAC;AACzC,cAAc,uBAAuB,CAAC;AACtC,cAAc,0BAA0B,CAAC;AACzC,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export declare function useAutocomplete<T extends string | number | {
|
|
2
|
+
id: string;
|
|
3
|
+
}>(props: {
|
|
4
|
+
options: T[];
|
|
5
|
+
selected?: T[];
|
|
6
|
+
multiselect?: boolean;
|
|
7
|
+
onSelect?: (selected: T[]) => void;
|
|
8
|
+
}): {
|
|
9
|
+
inputValue: string;
|
|
10
|
+
setInputValue: import("react").Dispatch<import("react").SetStateAction<string>>;
|
|
11
|
+
open: boolean;
|
|
12
|
+
setOpen: import("react").Dispatch<import("react").SetStateAction<boolean>>;
|
|
13
|
+
filteredOptions: T[];
|
|
14
|
+
select: (option: T) => void;
|
|
15
|
+
remove: (option: T) => void;
|
|
16
|
+
highlightedIndex: number;
|
|
17
|
+
setHighlightedIndex: import("react").Dispatch<import("react").SetStateAction<number>>;
|
|
18
|
+
selected: T[];
|
|
19
|
+
};
|
|
20
|
+
//# sourceMappingURL=use-autocomplete.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-autocomplete.d.ts","sourceRoot":"","sources":["../../../src/components/auto-complete/use-autocomplete.ts"],"names":[],"mappings":"AAGA,wBAAgB,eAAe,CAC7B,CAAC,SAAS,MAAM,GAAG,MAAM,GAAG;IAAE,EAAE,EAAE,MAAM,CAAA;CAAE,EAC1C,KAAK,EAAE;IACP,OAAO,EAAE,CAAC,EAAE,CAAC;IACb,QAAQ,CAAC,EAAE,CAAC,EAAE,CAAC;IACf,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,QAAQ,CAAC,EAAE,CAAC,QAAQ,EAAE,CAAC,EAAE,KAAK,IAAI,CAAC;CACpC;;;;;;qBAyByB,CAAC;qBAWD,CAAC;;;;EA4B1B"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useState, useMemo } from "react";
|
|
3
|
+
export function useAutocomplete(props) {
|
|
4
|
+
const { options, selected = [], multiselect = true, onSelect } = props;
|
|
5
|
+
const [inputValue, setInputValue] = useState("");
|
|
6
|
+
const [open, setOpen] = useState(false);
|
|
7
|
+
const [highlightedIndex, setHighlightedIndex] = useState(0);
|
|
8
|
+
const filteredOptions = useMemo(() => {
|
|
9
|
+
if (!multiselect)
|
|
10
|
+
return options;
|
|
11
|
+
return options.filter((o) => !selected.some((s) => {
|
|
12
|
+
if (typeof s === "string" || typeof s === "number")
|
|
13
|
+
return s === o;
|
|
14
|
+
if (typeof s === "object" &&
|
|
15
|
+
"id" in s &&
|
|
16
|
+
typeof o === "object" &&
|
|
17
|
+
"id" in o)
|
|
18
|
+
return s.id === o.id;
|
|
19
|
+
return false;
|
|
20
|
+
}));
|
|
21
|
+
}, [options, selected, multiselect]);
|
|
22
|
+
const select = (option) => {
|
|
23
|
+
if (multiselect) {
|
|
24
|
+
onSelect === null || onSelect === void 0 ? void 0 : onSelect([...selected, option]);
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
onSelect === null || onSelect === void 0 ? void 0 : onSelect([option]);
|
|
28
|
+
setOpen(false);
|
|
29
|
+
}
|
|
30
|
+
setInputValue("");
|
|
31
|
+
setHighlightedIndex(0);
|
|
32
|
+
};
|
|
33
|
+
const remove = (option) => {
|
|
34
|
+
onSelect === null || onSelect === void 0 ? void 0 : onSelect(selected.filter((s) => {
|
|
35
|
+
if (typeof s === "string" || typeof s === "number")
|
|
36
|
+
return s !== option;
|
|
37
|
+
if (typeof s === "object" &&
|
|
38
|
+
"id" in s &&
|
|
39
|
+
typeof option === "object" &&
|
|
40
|
+
"id" in option)
|
|
41
|
+
return s.id !== option.id;
|
|
42
|
+
return true;
|
|
43
|
+
}));
|
|
44
|
+
};
|
|
45
|
+
return {
|
|
46
|
+
inputValue,
|
|
47
|
+
setInputValue,
|
|
48
|
+
open,
|
|
49
|
+
setOpen,
|
|
50
|
+
filteredOptions,
|
|
51
|
+
select,
|
|
52
|
+
remove,
|
|
53
|
+
highlightedIndex,
|
|
54
|
+
setHighlightedIndex,
|
|
55
|
+
selected,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
@@ -4,6 +4,7 @@ import { SelectOption } from "../select";
|
|
|
4
4
|
export type Props<T extends string | number | {
|
|
5
5
|
id: string;
|
|
6
6
|
}> = {
|
|
7
|
+
label?: string;
|
|
7
8
|
options: SelectOption<T>[];
|
|
8
9
|
selectedOptions?: T[];
|
|
9
10
|
setSelectedOptions?: (opts: T[]) => void;
|
|
@@ -21,5 +22,5 @@ export type Props<T extends string | number | {
|
|
|
21
22
|
};
|
|
22
23
|
export default function AutoCompleteInput<T extends string | number | {
|
|
23
24
|
id: string;
|
|
24
|
-
}>({ name, options, selectedOptions, setSelectedOptions, onOptionSelect, value, onChange, onDebouncedChange, loading, multiselect, renderSelectedOptions, renderContainer, ...rest }: Props<T>): import("react/jsx-runtime").JSX.Element;
|
|
25
|
+
}>({ label, name, options, selectedOptions, setSelectedOptions, onOptionSelect, value, onChange, onDebouncedChange, loading, multiselect, renderSelectedOptions, renderContainer, ...rest }: Props<T>): import("react/jsx-runtime").JSX.Element;
|
|
25
26
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/auto-complete-input/index.tsx"],"names":[],"mappings":"AAEA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/auto-complete-input/index.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAsC,MAAM,OAAO,CAAC;AAC3D,OAAO,WAAW,MAAM,iBAAiB,CAAC;AAC1C,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAIzC,MAAM,MAAM,KAAK,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,GAAG;IAAE,EAAE,EAAE,MAAM,CAAA;CAAE,IAAI;IAC9D,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,YAAY,CAAC,CAAC,CAAC,EAAE,CAAC;IAC3B,eAAe,CAAC,EAAE,CAAC,EAAE,CAAC;IACtB,kBAAkB,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,EAAE,KAAK,IAAI,CAAC;IACzC,cAAc,CAAC,EAAE,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC;IACnD,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,qBAAqB,CAAC,EAAE,CAAC,QAAQ,EAAE,CAAC,EAAE,KAAK,KAAK,CAAC,SAAS,CAAC;IAC3D,eAAe,CAAC,EAAE,CAAC,OAAO,EAAE;QAC1B,KAAK,EAAE,KAAK,CAAC,SAAS,CAAC;QACvB,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;QAC1B,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;KAC3B,KAAK,KAAK,CAAC,SAAS,CAAC;CACvB,GAAG,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,OAAO,WAAW,CAAC,EAAE,mBAAmB,CAAC,GAAG;IACtE,iBAAiB,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;CAC3C,CAAC;AAEJ,MAAM,CAAC,OAAO,UAAU,iBAAiB,CACvC,CAAC,SAAS,MAAM,GAAG,MAAM,GAAG;IAAE,EAAE,EAAE,MAAM,CAAA;CAAE,EAC1C,EACA,KAAK,EACL,IAAI,EACJ,OAAO,EACP,eAAoB,EACpB,kBAAkB,EAClB,cAAc,EACd,KAAK,EACL,QAAQ,EACR,iBAAiB,EACjB,OAAe,EACf,WAAkB,EAClB,qBAAqB,EACrB,eAAe,EACf,GAAG,IAAI,EACR,EAAE,KAAK,CAAC,CAAC,CAAC,2CAgIV"}
|
|
@@ -4,7 +4,7 @@ import { useState, useRef, useEffect } from "react";
|
|
|
4
4
|
import SearchInput from "../search-input";
|
|
5
5
|
import clsx from "clsx";
|
|
6
6
|
import Loader from "../loader";
|
|
7
|
-
export default function AutoCompleteInput({ name, options, selectedOptions = [], setSelectedOptions, onOptionSelect, value, onChange, onDebouncedChange, loading = false, multiselect = true, renderSelectedOptions, renderContainer, ...rest }) {
|
|
7
|
+
export default function AutoCompleteInput({ label, name, options, selectedOptions = [], setSelectedOptions, onOptionSelect, value, onChange, onDebouncedChange, loading = false, multiselect = true, renderSelectedOptions, renderContainer, ...rest }) {
|
|
8
8
|
var _a;
|
|
9
9
|
const [show, setShow] = useState(false);
|
|
10
10
|
const [inputValue, setInputValue] = useState((_a = value === null || value === void 0 ? void 0 : value.toString()) !== null && _a !== void 0 ? _a : "");
|
|
@@ -55,7 +55,7 @@ export default function AutoCompleteInput({ name, options, selectedOptions = [],
|
|
|
55
55
|
var _a;
|
|
56
56
|
setInputValue((_a = value === null || value === void 0 ? void 0 : value.toString()) !== null && _a !== void 0 ? _a : "");
|
|
57
57
|
}, [value]);
|
|
58
|
-
const input = (_jsx(SearchInput, { name: name, value: inputValue, onFocus: () => setShow(true), onChange: (e) => {
|
|
58
|
+
const input = (_jsx(SearchInput, { label: label, name: name, value: inputValue, onFocus: () => setShow(true), onChange: (e) => {
|
|
59
59
|
setInputValue(e.target.value);
|
|
60
60
|
onChange === null || onChange === void 0 ? void 0 : onChange(e);
|
|
61
61
|
}, onDebouncedChange: (val) => {
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import SearchInput from "../search-input";
|
|
3
|
+
import { SelectOption } from "../select";
|
|
4
|
+
export type Props<T extends string | number | {
|
|
5
|
+
id: string;
|
|
6
|
+
}> = {
|
|
7
|
+
label?: string;
|
|
8
|
+
options: SelectOption<T>[];
|
|
9
|
+
selectedOptions?: T[];
|
|
10
|
+
setSelectedOptions?: (opts: T[]) => void;
|
|
11
|
+
onOptionSelect?: (option: SelectOption<T>) => void;
|
|
12
|
+
multiselect?: boolean;
|
|
13
|
+
loading?: boolean;
|
|
14
|
+
renderSelectedOptions?: (selected: T[]) => React.ReactNode;
|
|
15
|
+
renderContainer?: (content: {
|
|
16
|
+
input: React.ReactNode;
|
|
17
|
+
dropdown: React.ReactNode;
|
|
18
|
+
selected: React.ReactNode;
|
|
19
|
+
multiselect: boolean;
|
|
20
|
+
}) => React.ReactNode;
|
|
21
|
+
} & Omit<React.ComponentProps<typeof SearchInput>, "onDebouncedChange"> & {
|
|
22
|
+
onDebouncedChange?: (val: string) => void;
|
|
23
|
+
};
|
|
24
|
+
export default function AutoCompleteInput<T extends string | number | {
|
|
25
|
+
id: string;
|
|
26
|
+
}>({ label, name, options, selectedOptions, setSelectedOptions, onOptionSelect, value, onChange, onDebouncedChange, loading, multiselect, renderSelectedOptions, renderContainer, ...rest }: Props<T>): import("react/jsx-runtime").JSX.Element;
|
|
27
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/auto-complete-input copy/index.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAsC,MAAM,OAAO,CAAC;AAC3D,OAAO,WAAW,MAAM,iBAAiB,CAAC;AAC1C,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAIzC,MAAM,MAAM,KAAK,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,GAAG;IAAE,EAAE,EAAE,MAAM,CAAA;CAAE,IAAI;IAC9D,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,YAAY,CAAC,CAAC,CAAC,EAAE,CAAC;IAC3B,eAAe,CAAC,EAAE,CAAC,EAAE,CAAC;IACtB,kBAAkB,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,EAAE,KAAK,IAAI,CAAC;IACzC,cAAc,CAAC,EAAE,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC;IACnD,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,qBAAqB,CAAC,EAAE,CAAC,QAAQ,EAAE,CAAC,EAAE,KAAK,KAAK,CAAC,SAAS,CAAC;IAC3D,eAAe,CAAC,EAAE,CAAC,OAAO,EAAE;QAC1B,KAAK,EAAE,KAAK,CAAC,SAAS,CAAC;QACvB,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;QAC1B,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;QAC1B,WAAW,EAAE,OAAO,CAAC;KACtB,KAAK,KAAK,CAAC,SAAS,CAAC;CACvB,GAAG,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,OAAO,WAAW,CAAC,EAAE,mBAAmB,CAAC,GAAG;IACtE,iBAAiB,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;CAC3C,CAAC;AAEJ,MAAM,CAAC,OAAO,UAAU,iBAAiB,CACvC,CAAC,SAAS,MAAM,GAAG,MAAM,GAAG;IAAE,EAAE,EAAE,MAAM,CAAA;CAAE,EAC1C,EACA,KAAK,EACL,IAAI,EACJ,OAAO,EACP,eAAoB,EACpB,kBAAkB,EAClB,cAAc,EACd,KAAK,EACL,QAAQ,EACR,iBAAiB,EACjB,OAAe,EACf,WAAkB,EAClB,qBAAqB,EACrB,eAAe,EACf,GAAG,IAAI,EACR,EAAE,KAAK,CAAC,CAAC,CAAC,2CAiIV"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useState, useRef, useEffect } from "react";
|
|
4
|
+
import SearchInput from "../search-input";
|
|
5
|
+
import clsx from "clsx";
|
|
6
|
+
import Loader from "../loader";
|
|
7
|
+
export default function AutoCompleteInput({ label, name, options, selectedOptions = [], setSelectedOptions, onOptionSelect, value, onChange, onDebouncedChange, loading = false, multiselect = true, renderSelectedOptions, renderContainer, ...rest }) {
|
|
8
|
+
var _a;
|
|
9
|
+
const [show, setShow] = useState(false);
|
|
10
|
+
const [inputValue, setInputValue] = useState((_a = value === null || value === void 0 ? void 0 : value.toString()) !== null && _a !== void 0 ? _a : "");
|
|
11
|
+
const containerRef = useRef(null);
|
|
12
|
+
useEffect(() => {
|
|
13
|
+
const handler = (e) => {
|
|
14
|
+
var _a;
|
|
15
|
+
if (!((_a = containerRef.current) === null || _a === void 0 ? void 0 : _a.contains(e.target))) {
|
|
16
|
+
setShow(false);
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
document.addEventListener("mousedown", handler);
|
|
20
|
+
return () => document.removeEventListener("mousedown", handler);
|
|
21
|
+
}, []);
|
|
22
|
+
const isAlreadySelected = (option) => {
|
|
23
|
+
return selectedOptions.some((selected) => {
|
|
24
|
+
if ((typeof selected === "string" || typeof selected === "number") &&
|
|
25
|
+
(typeof option.value === "string" || typeof option.value === "number")) {
|
|
26
|
+
return selected === option.value;
|
|
27
|
+
}
|
|
28
|
+
if (typeof selected === "object" &&
|
|
29
|
+
typeof option.value === "object" &&
|
|
30
|
+
"id" in selected &&
|
|
31
|
+
"id" in option.value) {
|
|
32
|
+
return selected.id === option.value.id;
|
|
33
|
+
}
|
|
34
|
+
return false;
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
const filteredOptions = multiselect
|
|
38
|
+
? options.filter((o) => !isAlreadySelected(o))
|
|
39
|
+
: options;
|
|
40
|
+
const handleSelect = (option) => {
|
|
41
|
+
setInputValue("");
|
|
42
|
+
onChange === null || onChange === void 0 ? void 0 : onChange({ target: { name, value: "" } });
|
|
43
|
+
if (multiselect) {
|
|
44
|
+
if (!isAlreadySelected(option)) {
|
|
45
|
+
setSelectedOptions === null || setSelectedOptions === void 0 ? void 0 : setSelectedOptions([...selectedOptions, option.value]);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
setSelectedOptions === null || setSelectedOptions === void 0 ? void 0 : setSelectedOptions([option.value]); // Only one selection
|
|
50
|
+
setShow(false); // Hide dropdown immediately
|
|
51
|
+
}
|
|
52
|
+
onOptionSelect === null || onOptionSelect === void 0 ? void 0 : onOptionSelect(option);
|
|
53
|
+
};
|
|
54
|
+
useEffect(() => {
|
|
55
|
+
var _a;
|
|
56
|
+
setInputValue((_a = value === null || value === void 0 ? void 0 : value.toString()) !== null && _a !== void 0 ? _a : "");
|
|
57
|
+
}, [value]);
|
|
58
|
+
const input = (_jsx(SearchInput, { label: label, name: name, value: inputValue, onFocus: () => setShow(true), onChange: (e) => {
|
|
59
|
+
setInputValue(e.target.value);
|
|
60
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(e);
|
|
61
|
+
}, onDebouncedChange: (val) => {
|
|
62
|
+
setShow(true);
|
|
63
|
+
onDebouncedChange === null || onDebouncedChange === void 0 ? void 0 : onDebouncedChange(val);
|
|
64
|
+
}, autoComplete: "off", ...rest }));
|
|
65
|
+
const dropdown = show && inputValue.trim() !== "" ? (_jsx("div", { className: "absolute z-10 w-full mt-1 bg-white border rounded shadow max-h-60 overflow-y-auto", children: loading ? (_jsx("div", { className: "p-4 flex justify-center items-center", children: _jsx(Loader, {}) })) : filteredOptions.length > 0 ? (filteredOptions.map((o, i) => (_jsx("div", { className: clsx("px-4 py-2 cursor-pointer custom-animation hover:bg-primary hover:bg-opacity-20"), onClick: () => handleSelect(o), children: o.label }, `${name}-option-${i}`)))) : (_jsx("div", { className: "p-4 text-center text-gray-400", children: "No options found" })) })) : null;
|
|
66
|
+
const selected = selectedOptions.length
|
|
67
|
+
? renderSelectedOptions === null || renderSelectedOptions === void 0 ? void 0 : renderSelectedOptions(selectedOptions)
|
|
68
|
+
: null;
|
|
69
|
+
return (_jsx("div", { ref: containerRef, children: renderContainer ? (_jsx("div", { className: "relative", children: renderContainer({
|
|
70
|
+
input,
|
|
71
|
+
dropdown,
|
|
72
|
+
selected,
|
|
73
|
+
multiselect,
|
|
74
|
+
}) })) : (_jsxs("div", { className: "relative", children: [selected, input, dropdown] })) }));
|
|
75
|
+
}
|