@tecsinapse/cortex-react 2.1.1-beta.3 → 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/cjs/service/SnackbarSonner.js +0 -32
- package/dist/esm/components/Autocomplete/Autocomplete.js +101 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/service/SnackbarSonner.js +0 -32
- 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/service/SnackbarSonner.d.ts +0 -19
- 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;
|
|
@@ -35,38 +35,6 @@ class SnackbarSonner {
|
|
|
35
35
|
{ ...this._options, ...options }
|
|
36
36
|
);
|
|
37
37
|
}
|
|
38
|
-
async promise(promise, config) {
|
|
39
|
-
const { loading, success, error } = config;
|
|
40
|
-
const id = this.show(loading.type ?? "info", loading.message, {
|
|
41
|
-
...loading.options,
|
|
42
|
-
duration: loading.options?.duration ?? Infinity
|
|
43
|
-
});
|
|
44
|
-
try {
|
|
45
|
-
await promise;
|
|
46
|
-
if (!success) {
|
|
47
|
-
sonner.toast.dismiss(id);
|
|
48
|
-
} else {
|
|
49
|
-
const msg = success?.message ?? "Opera\xE7\xE3o conclu\xEDda com sucesso.";
|
|
50
|
-
this.show(success?.type ?? "success", msg, {
|
|
51
|
-
...success?.options,
|
|
52
|
-
id,
|
|
53
|
-
duration: success?.options?.duration ?? this._options?.duration ?? 5e3
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
} catch (err) {
|
|
57
|
-
if (!error) {
|
|
58
|
-
sonner.toast.dismiss(id);
|
|
59
|
-
} else {
|
|
60
|
-
const msg = error?.message ?? "Ocorreu um erro inesperado.";
|
|
61
|
-
this.show(error?.type ?? "error", msg, {
|
|
62
|
-
...error?.options,
|
|
63
|
-
id,
|
|
64
|
-
duration: error?.options?.duration ?? this._options?.duration ?? 5e3
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
return promise;
|
|
69
|
-
}
|
|
70
38
|
}
|
|
71
39
|
|
|
72
40
|
exports.SnackbarSonner = SnackbarSonner;
|
|
@@ -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';
|
|
@@ -33,38 +33,6 @@ class SnackbarSonner {
|
|
|
33
33
|
{ ...this._options, ...options }
|
|
34
34
|
);
|
|
35
35
|
}
|
|
36
|
-
async promise(promise, config) {
|
|
37
|
-
const { loading, success, error } = config;
|
|
38
|
-
const id = this.show(loading.type ?? "info", loading.message, {
|
|
39
|
-
...loading.options,
|
|
40
|
-
duration: loading.options?.duration ?? Infinity
|
|
41
|
-
});
|
|
42
|
-
try {
|
|
43
|
-
await promise;
|
|
44
|
-
if (!success) {
|
|
45
|
-
toast.dismiss(id);
|
|
46
|
-
} else {
|
|
47
|
-
const msg = success?.message ?? "Opera\xE7\xE3o conclu\xEDda com sucesso.";
|
|
48
|
-
this.show(success?.type ?? "success", msg, {
|
|
49
|
-
...success?.options,
|
|
50
|
-
id,
|
|
51
|
-
duration: success?.options?.duration ?? this._options?.duration ?? 5e3
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
} catch (err) {
|
|
55
|
-
if (!error) {
|
|
56
|
-
toast.dismiss(id);
|
|
57
|
-
} else {
|
|
58
|
-
const msg = error?.message ?? "Ocorreu um erro inesperado.";
|
|
59
|
-
this.show(error?.type ?? "error", msg, {
|
|
60
|
-
...error?.options,
|
|
61
|
-
id,
|
|
62
|
-
duration: error?.options?.duration ?? this._options?.duration ?? 5e3
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
return promise;
|
|
67
|
-
}
|
|
68
36
|
}
|
|
69
37
|
|
|
70
38
|
export { SnackbarSonner };
|
|
@@ -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';
|
|
@@ -2,28 +2,9 @@ import React from 'react';
|
|
|
2
2
|
import { ExternalToast } from 'sonner';
|
|
3
3
|
import { ISnackbar, TypeSnack } from './ISnackbar';
|
|
4
4
|
import { IExternalToast } from './IExternalToast';
|
|
5
|
-
interface PromiseSnackConfig<T = unknown> {
|
|
6
|
-
loading: {
|
|
7
|
-
message: string;
|
|
8
|
-
type?: TypeSnack;
|
|
9
|
-
options?: Omit<IExternalToast, 'className' | 'style'>;
|
|
10
|
-
};
|
|
11
|
-
success?: {
|
|
12
|
-
message?: string;
|
|
13
|
-
type?: TypeSnack;
|
|
14
|
-
options?: Omit<IExternalToast, 'className' | 'style'>;
|
|
15
|
-
};
|
|
16
|
-
error?: {
|
|
17
|
-
message?: string;
|
|
18
|
-
type?: TypeSnack;
|
|
19
|
-
options?: Omit<IExternalToast, 'className' | 'style'>;
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
5
|
export declare class SnackbarSonner implements ISnackbar<IExternalToast> {
|
|
23
6
|
_options?: IExternalToast;
|
|
24
7
|
constructor(options?: IExternalToast);
|
|
25
8
|
custom(Component: React.ReactElement, options?: ExternalToast): string | number;
|
|
26
9
|
show(type: TypeSnack, message: string, options?: Omit<IExternalToast, 'className' | 'style'>): string | number;
|
|
27
|
-
promise<T>(promise: Promise<T>, config: PromiseSnackConfig<T>): Promise<T>;
|
|
28
10
|
}
|
|
29
|
-
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
|
}
|