@tecsinapse/cortex-react 2.1.2-beta.1 → 2.2.0-beta.1
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/cjs/components/Autocomplete/Autocomplete.js +103 -0
- package/dist/cjs/index.js +2 -0
- package/dist/esm/components/Autocomplete/Autocomplete.js +101 -0
- package/dist/esm/index.js +1 -0
- package/dist/types/components/Autocomplete/Autocomplete.d.ts +11 -0
- package/dist/types/components/Autocomplete/index.d.ts +1 -0
- package/dist/types/components/index.d.ts +1 -0
- package/dist/types/hooks/useFileUpload.d.ts +4 -4
- package/dist/types/provider/ManagerContext.d.ts +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
4
|
+
var React = require('react');
|
|
5
|
+
var index = require('../Popover/index.js');
|
|
6
|
+
var index$1 = require('../Input/index.js');
|
|
7
|
+
var react = require('@floating-ui/react');
|
|
8
|
+
|
|
9
|
+
const selectOptions = [
|
|
10
|
+
{ label: "Brasil", value: "brasil" },
|
|
11
|
+
{ label: "Alemanha", value: "alemanha" },
|
|
12
|
+
{ label: "Jap\xE3o", value: "japao" },
|
|
13
|
+
{ label: "Canad\xE1", value: "canada" },
|
|
14
|
+
{ label: "Austr\xE1lia", value: "australia" },
|
|
15
|
+
{ label: "Fran\xE7a", value: "franca" },
|
|
16
|
+
{ label: "It\xE1lia", value: "italia" },
|
|
17
|
+
{ label: "M\xE9xico", value: "mexico" },
|
|
18
|
+
{ label: "Portugal", value: "portugal" },
|
|
19
|
+
{ label: "Argentina", value: "argentina" }
|
|
20
|
+
];
|
|
21
|
+
const Autocomplete = ({
|
|
22
|
+
inputValue,
|
|
23
|
+
setInputValue,
|
|
24
|
+
label,
|
|
25
|
+
onChange,
|
|
26
|
+
disabled
|
|
27
|
+
}) => {
|
|
28
|
+
const [triggerWidth, setTriggerWidth] = React.useState();
|
|
29
|
+
const [selectedValue, setSelectedValue] = React.useState({
|
|
30
|
+
label: "",
|
|
31
|
+
value: ""
|
|
32
|
+
});
|
|
33
|
+
const [open, setOpen] = React.useState(true);
|
|
34
|
+
const filteredOptions = React.useMemo(() => {
|
|
35
|
+
const optionsList = (selectOptions ?? []).filter(
|
|
36
|
+
(op) => op.label.toLowerCase().includes(inputValue.toLowerCase())
|
|
37
|
+
);
|
|
38
|
+
return optionsList;
|
|
39
|
+
}, [selectOptions, inputValue]);
|
|
40
|
+
const handleSelect = (option) => {
|
|
41
|
+
if (!(selectedValue.value === option.value)) {
|
|
42
|
+
setSelectedValue(option);
|
|
43
|
+
}
|
|
44
|
+
setInputValue("");
|
|
45
|
+
setOpen(false);
|
|
46
|
+
};
|
|
47
|
+
const handleChange = (event) => {
|
|
48
|
+
onChange(event);
|
|
49
|
+
if (event.target.value.length > 0) {
|
|
50
|
+
setOpen(true);
|
|
51
|
+
} else {
|
|
52
|
+
setOpen(false);
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
const triggerRef = React.useRef(void 0);
|
|
56
|
+
React.useEffect(() => {
|
|
57
|
+
if (triggerRef.current && setTriggerWidth) {
|
|
58
|
+
const width = triggerRef.current.getBoundingClientRect().width;
|
|
59
|
+
setTriggerWidth(width);
|
|
60
|
+
}
|
|
61
|
+
}, [triggerRef.current, setTriggerWidth]);
|
|
62
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
63
|
+
index.Popover.Root,
|
|
64
|
+
{
|
|
65
|
+
placement: "bottom-start",
|
|
66
|
+
controlled: true,
|
|
67
|
+
isOpen: open,
|
|
68
|
+
setIsOpen: setOpen,
|
|
69
|
+
children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "relative w-full h-full", children: [
|
|
70
|
+
/* @__PURE__ */ jsxRuntime.jsx(index.Popover.Trigger, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
71
|
+
index$1.Input.Root,
|
|
72
|
+
{
|
|
73
|
+
label: label ?? "Selecione uma op\xE7\xE3o",
|
|
74
|
+
value: inputValue,
|
|
75
|
+
onChange: handleChange,
|
|
76
|
+
disabled,
|
|
77
|
+
ref: triggerRef
|
|
78
|
+
}
|
|
79
|
+
) }),
|
|
80
|
+
/* @__PURE__ */ jsxRuntime.jsx(react.FloatingPortal, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
81
|
+
index.Popover.Content,
|
|
82
|
+
{
|
|
83
|
+
className: "w-full bg-white shadow-md rounded-md overflow-hidden max-h-[30vh] outline-none z-9999",
|
|
84
|
+
style: {
|
|
85
|
+
width: triggerWidth ? `${triggerWidth}px` : "auto"
|
|
86
|
+
},
|
|
87
|
+
initialFocus: -1,
|
|
88
|
+
children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full flex flex-col overflow-y-auto", children: filteredOptions.map((op) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
89
|
+
"div",
|
|
90
|
+
{
|
|
91
|
+
className: "flex w-full h-[3rem] items-center gap-centi p-centi cursor-pointer hover:bg-secondary-xlight bg-inherit",
|
|
92
|
+
onClick: () => handleSelect(op),
|
|
93
|
+
children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-base truncate", children: op.label })
|
|
94
|
+
}
|
|
95
|
+
)) })
|
|
96
|
+
}
|
|
97
|
+
) })
|
|
98
|
+
] })
|
|
99
|
+
}
|
|
100
|
+
);
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
exports.Autocomplete = Autocomplete;
|
package/dist/cjs/index.js
CHANGED
|
@@ -44,6 +44,7 @@ var TimeFieldInput = require('./components/TimePicker/TimeFieldInput.js');
|
|
|
44
44
|
var Toggle = require('./components/Toggle.js');
|
|
45
45
|
var Tooltip = require('./components/Tooltip.js');
|
|
46
46
|
var index$7 = require('./components/Uploader/index.js');
|
|
47
|
+
var Autocomplete = require('./components/Autocomplete/Autocomplete.js');
|
|
47
48
|
var useCalendar = require('./hooks/useCalendar.js');
|
|
48
49
|
var useCalendarCell = require('./hooks/useCalendarCell.js');
|
|
49
50
|
var useCalendarGrid = require('./hooks/useCalendarGrid.js');
|
|
@@ -127,6 +128,7 @@ exports.TimeFieldInput = TimeFieldInput.TimeFieldInput;
|
|
|
127
128
|
exports.Toggle = Toggle.Toggle;
|
|
128
129
|
exports.Tooltip = Tooltip.Tooltip;
|
|
129
130
|
exports.Uploader = index$7.Uploader;
|
|
131
|
+
exports.Autocomplete = Autocomplete.Autocomplete;
|
|
130
132
|
exports.useCalendar = useCalendar.useCalendar;
|
|
131
133
|
exports.useCalendarCell = useCalendarCell.useCalendarCell;
|
|
132
134
|
exports.useCalendarGrid = useCalendarGrid.useCalendarGrid;
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
2
|
+
import { useState, useMemo, useRef, useEffect } from 'react';
|
|
3
|
+
import { Popover } from '../Popover/index.js';
|
|
4
|
+
import { Input } from '../Input/index.js';
|
|
5
|
+
import { FloatingPortal } from '@floating-ui/react';
|
|
6
|
+
|
|
7
|
+
const selectOptions = [
|
|
8
|
+
{ label: "Brasil", value: "brasil" },
|
|
9
|
+
{ label: "Alemanha", value: "alemanha" },
|
|
10
|
+
{ label: "Jap\xE3o", value: "japao" },
|
|
11
|
+
{ label: "Canad\xE1", value: "canada" },
|
|
12
|
+
{ label: "Austr\xE1lia", value: "australia" },
|
|
13
|
+
{ label: "Fran\xE7a", value: "franca" },
|
|
14
|
+
{ label: "It\xE1lia", value: "italia" },
|
|
15
|
+
{ label: "M\xE9xico", value: "mexico" },
|
|
16
|
+
{ label: "Portugal", value: "portugal" },
|
|
17
|
+
{ label: "Argentina", value: "argentina" }
|
|
18
|
+
];
|
|
19
|
+
const Autocomplete = ({
|
|
20
|
+
inputValue,
|
|
21
|
+
setInputValue,
|
|
22
|
+
label,
|
|
23
|
+
onChange,
|
|
24
|
+
disabled
|
|
25
|
+
}) => {
|
|
26
|
+
const [triggerWidth, setTriggerWidth] = useState();
|
|
27
|
+
const [selectedValue, setSelectedValue] = useState({
|
|
28
|
+
label: "",
|
|
29
|
+
value: ""
|
|
30
|
+
});
|
|
31
|
+
const [open, setOpen] = useState(true);
|
|
32
|
+
const filteredOptions = useMemo(() => {
|
|
33
|
+
const optionsList = (selectOptions ?? []).filter(
|
|
34
|
+
(op) => op.label.toLowerCase().includes(inputValue.toLowerCase())
|
|
35
|
+
);
|
|
36
|
+
return optionsList;
|
|
37
|
+
}, [selectOptions, inputValue]);
|
|
38
|
+
const handleSelect = (option) => {
|
|
39
|
+
if (!(selectedValue.value === option.value)) {
|
|
40
|
+
setSelectedValue(option);
|
|
41
|
+
}
|
|
42
|
+
setInputValue("");
|
|
43
|
+
setOpen(false);
|
|
44
|
+
};
|
|
45
|
+
const handleChange = (event) => {
|
|
46
|
+
onChange(event);
|
|
47
|
+
if (event.target.value.length > 0) {
|
|
48
|
+
setOpen(true);
|
|
49
|
+
} else {
|
|
50
|
+
setOpen(false);
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
const triggerRef = useRef(void 0);
|
|
54
|
+
useEffect(() => {
|
|
55
|
+
if (triggerRef.current && setTriggerWidth) {
|
|
56
|
+
const width = triggerRef.current.getBoundingClientRect().width;
|
|
57
|
+
setTriggerWidth(width);
|
|
58
|
+
}
|
|
59
|
+
}, [triggerRef.current, setTriggerWidth]);
|
|
60
|
+
return /* @__PURE__ */ jsx(
|
|
61
|
+
Popover.Root,
|
|
62
|
+
{
|
|
63
|
+
placement: "bottom-start",
|
|
64
|
+
controlled: true,
|
|
65
|
+
isOpen: open,
|
|
66
|
+
setIsOpen: setOpen,
|
|
67
|
+
children: /* @__PURE__ */ jsxs("div", { className: "relative w-full h-full", children: [
|
|
68
|
+
/* @__PURE__ */ jsx(Popover.Trigger, { children: /* @__PURE__ */ jsx(
|
|
69
|
+
Input.Root,
|
|
70
|
+
{
|
|
71
|
+
label: label ?? "Selecione uma op\xE7\xE3o",
|
|
72
|
+
value: inputValue,
|
|
73
|
+
onChange: handleChange,
|
|
74
|
+
disabled,
|
|
75
|
+
ref: triggerRef
|
|
76
|
+
}
|
|
77
|
+
) }),
|
|
78
|
+
/* @__PURE__ */ jsx(FloatingPortal, { children: /* @__PURE__ */ jsx(
|
|
79
|
+
Popover.Content,
|
|
80
|
+
{
|
|
81
|
+
className: "w-full bg-white shadow-md rounded-md overflow-hidden max-h-[30vh] outline-none z-9999",
|
|
82
|
+
style: {
|
|
83
|
+
width: triggerWidth ? `${triggerWidth}px` : "auto"
|
|
84
|
+
},
|
|
85
|
+
initialFocus: -1,
|
|
86
|
+
children: /* @__PURE__ */ jsx("div", { className: "w-full flex flex-col overflow-y-auto", children: filteredOptions.map((op) => /* @__PURE__ */ jsx(
|
|
87
|
+
"div",
|
|
88
|
+
{
|
|
89
|
+
className: "flex w-full h-[3rem] items-center gap-centi p-centi cursor-pointer hover:bg-secondary-xlight bg-inherit",
|
|
90
|
+
onClick: () => handleSelect(op),
|
|
91
|
+
children: /* @__PURE__ */ jsx("span", { className: "text-base truncate", children: op.label })
|
|
92
|
+
}
|
|
93
|
+
)) })
|
|
94
|
+
}
|
|
95
|
+
) })
|
|
96
|
+
] })
|
|
97
|
+
}
|
|
98
|
+
);
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
export { Autocomplete };
|
package/dist/esm/index.js
CHANGED
|
@@ -42,6 +42,7 @@ export { TimeFieldInput } from './components/TimePicker/TimeFieldInput.js';
|
|
|
42
42
|
export { Toggle } from './components/Toggle.js';
|
|
43
43
|
export { Tooltip } from './components/Tooltip.js';
|
|
44
44
|
export { Uploader } from './components/Uploader/index.js';
|
|
45
|
+
export { Autocomplete } from './components/Autocomplete/Autocomplete.js';
|
|
45
46
|
export { useCalendar } from './hooks/useCalendar.js';
|
|
46
47
|
export { useCalendarCell } from './hooks/useCalendarCell.js';
|
|
47
48
|
export { useCalendarGrid } from './hooks/useCalendarGrid.js';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import React, { ChangeEventHandler } from 'react';
|
|
2
|
+
interface AutocompleteProps {
|
|
3
|
+
inputValue: string;
|
|
4
|
+
setInputValue: React.Dispatch<React.SetStateAction<string>>;
|
|
5
|
+
onChange: ChangeEventHandler<HTMLInputElement>;
|
|
6
|
+
label?: string;
|
|
7
|
+
placeholder?: string;
|
|
8
|
+
disabled?: boolean;
|
|
9
|
+
}
|
|
10
|
+
export declare const Autocomplete: ({ inputValue, setInputValue, label, onChange, disabled, }: AutocompleteProps) => import("react/jsx-runtime").JSX.Element;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './Autocomplete';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type DropEvent, type FileRejection } from 'react-dropzone';
|
|
2
2
|
import { AcceptSpecificMap, UseDropzoneProps, type FileUpload } from '../components/Uploader/types';
|
|
3
|
-
interface UseFileUploadOptions
|
|
3
|
+
interface UseFileUploadOptions {
|
|
4
4
|
accept?: {
|
|
5
5
|
IMAGE?: (typeof AcceptSpecificMap.IMAGE)[number][];
|
|
6
6
|
APPLICATION?: (typeof AcceptSpecificMap.APPLICATION)[number][];
|
|
@@ -8,7 +8,7 @@ interface UseFileUploadOptions<T> {
|
|
|
8
8
|
VIDEO?: (typeof AcceptSpecificMap.VIDEO)[number][];
|
|
9
9
|
TEXT?: (typeof AcceptSpecificMap.TEXT)[number][];
|
|
10
10
|
};
|
|
11
|
-
onAccept?: (files: FileUpload<
|
|
11
|
+
onAccept?: (files: FileUpload<unknown>[]) => Promise<FileUpload<unknown>[]>;
|
|
12
12
|
onOpenManager?: () => void;
|
|
13
13
|
onFileRejected?: (fileRejections: FileRejection[], event: DropEvent) => void;
|
|
14
14
|
maxSize?: number;
|
|
@@ -22,7 +22,7 @@ interface UseFileUploadOptions<T> {
|
|
|
22
22
|
noClick?: boolean;
|
|
23
23
|
ignoreRejections?: boolean;
|
|
24
24
|
}
|
|
25
|
-
export declare const useFileUpload: <T>({ accept, onAccept, onOpenManager, onFileRejected, maxSize, allowMultiple, preventDuplicates, onDuplicate, hasManager, isFolder, noClick, ignoreRejections, uploadProgressText, uploadSuccessText, }: UseFileUploadOptions
|
|
25
|
+
export declare const useFileUpload: <T>({ accept, onAccept, onOpenManager, onFileRejected, maxSize, allowMultiple, preventDuplicates, onDuplicate, hasManager, isFolder, noClick, ignoreRejections, uploadProgressText, uploadSuccessText, }: UseFileUploadOptions) => {
|
|
26
26
|
onOpen: () => void;
|
|
27
27
|
onClose: () => void;
|
|
28
28
|
onDelete: (index: number) => void;
|
|
@@ -31,7 +31,7 @@ export declare const useFileUpload: <T>({ accept, onAccept, onOpenManager, onFil
|
|
|
31
31
|
openManager: () => void;
|
|
32
32
|
closeManager: () => void;
|
|
33
33
|
isManagerOpen: boolean;
|
|
34
|
-
files: FileUpload<
|
|
34
|
+
files: FileUpload<unknown>[];
|
|
35
35
|
duplicates: File[];
|
|
36
36
|
onClearFiles: () => void;
|
|
37
37
|
};
|
|
@@ -16,5 +16,5 @@ interface ManagerContextProps<T> {
|
|
|
16
16
|
export declare const ManagerProvider: ({ children }: {
|
|
17
17
|
children: ReactNode;
|
|
18
18
|
}) => import("react/jsx-runtime").JSX.Element;
|
|
19
|
-
export declare const useManager: () => ManagerContextProps<
|
|
19
|
+
export declare const useManager: () => ManagerContextProps<unknown>;
|
|
20
20
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tecsinapse/cortex-react",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.0-beta.1",
|
|
4
4
|
"description": "React components based in @tecsinapse/cortex-core",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "dist/esm/index.js",
|
|
@@ -48,5 +48,5 @@
|
|
|
48
48
|
"react-icons": ">=5.2.0",
|
|
49
49
|
"tailwindcss": "^4.1.16"
|
|
50
50
|
},
|
|
51
|
-
"gitHead": "
|
|
51
|
+
"gitHead": "80ce93ff1ec0f76af43695b205dd2d2db73e1792"
|
|
52
52
|
}
|