@tecsinapse/cortex-react 2.2.0-beta.6 → 2.3.0-beta.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.
Files changed (113) hide show
  1. package/dist/cjs/components/Accordion/Trigger.js +6 -6
  2. package/dist/cjs/components/Avatar.js +1 -1
  3. package/dist/cjs/components/Breadcrumbs/BreadcrumbItem.js +1 -1
  4. package/dist/cjs/components/Calendar/CalendarGrid.js +1 -1
  5. package/dist/cjs/components/ColorPicker.js +18 -9
  6. package/dist/cjs/components/Kanban.js +1 -1
  7. package/dist/cjs/components/PhoneInput/FlagIcon.js +46 -0
  8. package/dist/cjs/components/PhoneInput/Option.js +29 -0
  9. package/dist/cjs/components/PhoneInput/Options.js +118 -0
  10. package/dist/cjs/components/PhoneInput/Popover.js +22 -0
  11. package/dist/cjs/components/PhoneInput/Root.js +61 -0
  12. package/dist/cjs/components/PhoneInput/Trigger.js +112 -0
  13. package/dist/cjs/components/PhoneInput/context.js +19 -0
  14. package/dist/cjs/components/PhoneInput/index.js +17 -0
  15. package/dist/cjs/components/Popover/Content.js +1 -1
  16. package/dist/cjs/components/Select/Popover.js +1 -1
  17. package/dist/cjs/components/Skeleton.js +1 -1
  18. package/dist/cjs/components/Stepper/Root.js +1 -1
  19. package/dist/cjs/components/TimePicker/TimePickerInput.js +1 -1
  20. package/dist/cjs/components/Uploader/Dropzone.js +3 -3
  21. package/dist/cjs/components/Uploader/Files.js +1 -1
  22. package/dist/cjs/components/Uploader/Manager.js +1 -1
  23. package/dist/cjs/components/Uploader/Modal.js +1 -1
  24. package/dist/cjs/index.js +2 -2
  25. package/dist/cjs/provider/ManagerContext.js +5 -3
  26. package/dist/cjs/service/SnackbarSonner.js +32 -0
  27. package/dist/cjs/styles/calendar-cell.js +2 -2
  28. package/dist/cjs/styles/date-picker-input-base.js +1 -1
  29. package/dist/cjs/styles/date-segment.js +2 -2
  30. package/dist/cjs/styles/groupButton.js +3 -3
  31. package/dist/cjs/styles/menubar.js +8 -8
  32. package/dist/cjs/styles/progressBar.js +1 -1
  33. package/dist/cjs/styles/stepNodeVariants.js +2 -2
  34. package/dist/cjs/styles/time-field-input.js +1 -1
  35. package/dist/esm/components/Accordion/Trigger.js +6 -6
  36. package/dist/esm/components/Avatar.js +1 -1
  37. package/dist/esm/components/Breadcrumbs/BreadcrumbItem.js +1 -1
  38. package/dist/esm/components/Calendar/CalendarGrid.js +1 -1
  39. package/dist/esm/components/ColorPicker.js +18 -9
  40. package/dist/esm/components/Kanban.js +1 -1
  41. package/dist/esm/components/PhoneInput/FlagIcon.js +25 -0
  42. package/dist/esm/components/PhoneInput/Option.js +27 -0
  43. package/dist/esm/components/PhoneInput/Options.js +116 -0
  44. package/dist/esm/components/PhoneInput/Popover.js +20 -0
  45. package/dist/esm/components/PhoneInput/Root.js +59 -0
  46. package/dist/esm/components/PhoneInput/Trigger.js +110 -0
  47. package/dist/esm/components/PhoneInput/context.js +16 -0
  48. package/dist/esm/components/PhoneInput/index.js +15 -0
  49. package/dist/esm/components/Popover/Content.js +1 -1
  50. package/dist/esm/components/Select/Popover.js +1 -1
  51. package/dist/esm/components/Skeleton.js +1 -1
  52. package/dist/esm/components/Stepper/Root.js +1 -1
  53. package/dist/esm/components/TimePicker/TimePickerInput.js +1 -1
  54. package/dist/esm/components/Uploader/Dropzone.js +3 -3
  55. package/dist/esm/components/Uploader/Files.js +1 -1
  56. package/dist/esm/components/Uploader/Manager.js +1 -1
  57. package/dist/esm/components/Uploader/Modal.js +1 -1
  58. package/dist/esm/index.js +1 -1
  59. package/dist/esm/provider/ManagerContext.js +5 -3
  60. package/dist/esm/service/SnackbarSonner.js +32 -0
  61. package/dist/esm/styles/calendar-cell.js +2 -2
  62. package/dist/esm/styles/date-picker-input-base.js +1 -1
  63. package/dist/esm/styles/date-segment.js +2 -2
  64. package/dist/esm/styles/groupButton.js +3 -3
  65. package/dist/esm/styles/menubar.js +8 -8
  66. package/dist/esm/styles/progressBar.js +1 -1
  67. package/dist/esm/styles/stepNodeVariants.js +2 -2
  68. package/dist/esm/styles/time-field-input.js +1 -1
  69. package/dist/types/components/PhoneInput/FlagIcon.d.ts +8 -0
  70. package/dist/types/components/PhoneInput/Option.d.ts +6 -0
  71. package/dist/types/components/PhoneInput/Options.d.ts +3 -0
  72. package/dist/types/components/PhoneInput/Popover.d.ts +4 -0
  73. package/dist/types/components/PhoneInput/Root.d.ts +2 -0
  74. package/dist/types/components/PhoneInput/Trigger.d.ts +2 -0
  75. package/dist/types/components/PhoneInput/context.d.ts +15 -0
  76. package/dist/types/components/PhoneInput/index.d.ts +16 -0
  77. package/dist/types/components/PhoneInput/types.d.ts +13 -0
  78. package/dist/types/components/index.d.ts +1 -1
  79. package/dist/types/hooks/useFileUpload.d.ts +4 -4
  80. package/dist/types/provider/ManagerContext.d.ts +1 -1
  81. package/dist/types/service/SnackbarSonner.d.ts +19 -0
  82. package/package.json +5 -3
  83. package/dist/cjs/components/Autocomplete/GroupedOptions.js +0 -32
  84. package/dist/cjs/components/Autocomplete/Option.js +0 -38
  85. package/dist/cjs/components/Autocomplete/Options.js +0 -31
  86. package/dist/cjs/components/Autocomplete/Popover.js +0 -34
  87. package/dist/cjs/components/Autocomplete/Root.js +0 -34
  88. package/dist/cjs/components/Autocomplete/Trigger.js +0 -48
  89. package/dist/cjs/components/Autocomplete/context.js +0 -9
  90. package/dist/cjs/components/Autocomplete/index.js +0 -19
  91. package/dist/cjs/hooks/useAutocompleteGroupedOptions.js +0 -35
  92. package/dist/cjs/hooks/useAutocompleteOptions.js +0 -35
  93. package/dist/esm/components/Autocomplete/GroupedOptions.js +0 -30
  94. package/dist/esm/components/Autocomplete/Option.js +0 -36
  95. package/dist/esm/components/Autocomplete/Options.js +0 -29
  96. package/dist/esm/components/Autocomplete/Popover.js +0 -32
  97. package/dist/esm/components/Autocomplete/Root.js +0 -32
  98. package/dist/esm/components/Autocomplete/Trigger.js +0 -46
  99. package/dist/esm/components/Autocomplete/context.js +0 -7
  100. package/dist/esm/components/Autocomplete/index.js +0 -17
  101. package/dist/esm/hooks/useAutocompleteGroupedOptions.js +0 -33
  102. package/dist/esm/hooks/useAutocompleteOptions.js +0 -33
  103. package/dist/types/components/Autocomplete/GroupedOptions.d.ts +0 -2
  104. package/dist/types/components/Autocomplete/Option.d.ts +0 -2
  105. package/dist/types/components/Autocomplete/Options.d.ts +0 -2
  106. package/dist/types/components/Autocomplete/Popover.d.ts +0 -2
  107. package/dist/types/components/Autocomplete/Root.d.ts +0 -2
  108. package/dist/types/components/Autocomplete/Trigger.d.ts +0 -2
  109. package/dist/types/components/Autocomplete/context.d.ts +0 -9
  110. package/dist/types/components/Autocomplete/index.d.ts +0 -9
  111. package/dist/types/components/Autocomplete/types.d.ts +0 -46
  112. package/dist/types/hooks/useAutocompleteGroupedOptions.d.ts +0 -10
  113. package/dist/types/hooks/useAutocompleteOptions.d.ts +0 -10
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tecsinapse/cortex-react",
3
- "version": "2.2.0-beta.6",
3
+ "version": "2.3.0-beta.0",
4
4
  "description": "React components based in @tecsinapse/cortex-core",
5
5
  "license": "MIT",
6
6
  "main": "dist/esm/index.js",
@@ -20,14 +20,16 @@
20
20
  "dependencies": {
21
21
  "@floating-ui/react": "^0.26.18",
22
22
  "@internationalized/date": "3.7.0",
23
- "@tecsinapse/cortex-core": "2.0.0",
23
+ "@tecsinapse/cortex-core": "2.1.0-beta.0",
24
24
  "clsx": "2.1.1",
25
+ "country-flag-icons": "^1.6.4",
25
26
  "currency.js": "2.0.4",
26
27
  "embla-carousel-autoplay": "^8.0.0",
27
28
  "embla-carousel-react": "^8.6.0",
28
29
  "react-aria": "3.38.1",
29
30
  "react-dropzone": "14.3.8",
30
31
  "react-imask": "7.6.1",
32
+ "react-international-phone": "^4.6.1",
31
33
  "react-spring": "9.7.5",
32
34
  "react-stately": "3.36.1",
33
35
  "sonner": "1.7.3",
@@ -48,5 +50,5 @@
48
50
  "react-icons": ">=5.2.0",
49
51
  "tailwindcss": "^4.1.16"
50
52
  },
51
- "gitHead": "dc4acfa02813924f4707075b33eec14db030b521"
53
+ "gitHead": "a28d6b7a49fa7466507b9a5e3d5c8114e9224e83"
52
54
  }
@@ -1,32 +0,0 @@
1
- 'use strict';
2
-
3
- var jsxRuntime = require('react/jsx-runtime');
4
- var cortexCore = require('@tecsinapse/cortex-core');
5
- var Option = require('./Option.js');
6
- var useAutocompleteGroupedOptions = require('../../hooks/useAutocompleteGroupedOptions.js');
7
- var SkeletonOptions = require('../Select/SkeletonOptions.js');
8
-
9
- const { groupedTitle, list } = cortexCore.selectVariants();
10
- const AutocompleteGroupedOptions = ({
11
- onSelect,
12
- groupedLabelExtractor,
13
- options
14
- }) => {
15
- const { options: _options, isLoading } = useAutocompleteGroupedOptions.useAutocompleteGroupedOptions({
16
- options
17
- });
18
- return isLoading ? /* @__PURE__ */ jsxRuntime.jsx(SkeletonOptions.SkeletonOptions, {}) : /* @__PURE__ */ jsxRuntime.jsx("ul", { role: "listbox", className: list(), children: [..._options ?? []].map(([key, value]) => /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
19
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: groupedTitle(), children: groupedLabelExtractor?.(key) }),
20
- value.map((option) => /* @__PURE__ */ jsxRuntime.jsx(
21
- Option.AutocompleteOption,
22
- {
23
- grouped: true,
24
- option,
25
- onSelect
26
- },
27
- option.value
28
- ))
29
- ] }, key)) });
30
- };
31
-
32
- exports.AutocompleteGroupedOptions = AutocompleteGroupedOptions;
@@ -1,38 +0,0 @@
1
- 'use strict';
2
-
3
- var jsxRuntime = require('react/jsx-runtime');
4
- var cortexCore = require('@tecsinapse/cortex-core');
5
- var React = require('react');
6
- var context = require('./context.js');
7
-
8
- const AutocompleteOption = ({
9
- option,
10
- onSelect,
11
- grouped = false
12
- }) => {
13
- const context$1 = React.useContext(context.AutocompleteContext);
14
- if (!context$1)
15
- throw new Error("AutocompleteOptions must be used within AutocompleteRoot");
16
- const { setOpen } = context$1;
17
- const handleSelect = React.useCallback(
18
- (option2) => {
19
- setOpen(false);
20
- onSelect?.(option2);
21
- },
22
- [onSelect, setOpen]
23
- );
24
- return /* @__PURE__ */ jsxRuntime.jsx(
25
- "li",
26
- {
27
- onClick: () => handleSelect(option),
28
- className: cortexCore.option({
29
- selected: false,
30
- grouped
31
- }),
32
- role: "option",
33
- children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "truncate flex-1", children: option.label })
34
- }
35
- );
36
- };
37
-
38
- exports.AutocompleteOption = AutocompleteOption;
@@ -1,31 +0,0 @@
1
- 'use strict';
2
-
3
- var jsxRuntime = require('react/jsx-runtime');
4
- var cortexCore = require('@tecsinapse/cortex-core');
5
- var React = require('react');
6
- var Option = require('./Option.js');
7
- var useAutocompleteOptions = require('../../hooks/useAutocompleteOptions.js');
8
- var SkeletonOptions = require('../Select/SkeletonOptions.js');
9
-
10
- const { list } = cortexCore.selectVariants();
11
- const AutocompleteOptions = ({
12
- options,
13
- onSelect,
14
- children
15
- }) => {
16
- const { options: _options, isLoading } = useAutocompleteOptions.useAutocompleteOptions({ options });
17
- const defaultOptions = React.useMemo(
18
- () => _options?.map((option) => /* @__PURE__ */ jsxRuntime.jsx(
19
- Option.AutocompleteOption,
20
- {
21
- option,
22
- onSelect
23
- },
24
- option.value
25
- )) ?? [],
26
- [_options, onSelect]
27
- );
28
- return isLoading ? /* @__PURE__ */ jsxRuntime.jsx(SkeletonOptions.SkeletonOptions, {}) : /* @__PURE__ */ jsxRuntime.jsx("ul", { role: "listbox", className: list(), children: children ?? defaultOptions });
29
- };
30
-
31
- exports.AutocompleteOptions = AutocompleteOptions;
@@ -1,34 +0,0 @@
1
- 'use strict';
2
-
3
- var jsxRuntime = require('react/jsx-runtime');
4
- var React = require('react');
5
- var react = require('@floating-ui/react');
6
- var index = require('../Popover/index.js');
7
- var context = require('./context.js');
8
- var clsx = require('clsx');
9
-
10
- const AutocompletePopover = ({
11
- children,
12
- className
13
- }) => {
14
- const context$1 = React.useContext(context.AutocompleteContext);
15
- if (!context$1)
16
- throw new Error("AutocompletePopover must be used within AutocompleteRoot");
17
- const { triggerWidth } = context$1;
18
- return /* @__PURE__ */ jsxRuntime.jsx(react.FloatingPortal, { children: /* @__PURE__ */ jsxRuntime.jsx(
19
- index.Popover.Content,
20
- {
21
- className: clsx(
22
- "bg-white shadow-md rounded-md overflow-y-auto max-h-[30vh] outline-none z-9999",
23
- className
24
- ),
25
- style: {
26
- width: triggerWidth ? `${triggerWidth}px` : "auto"
27
- },
28
- initialFocus: -1,
29
- children
30
- }
31
- ) });
32
- };
33
-
34
- exports.AutocompletePopover = AutocompletePopover;
@@ -1,34 +0,0 @@
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 context = require('./context.js');
7
-
8
- const AutocompleteRoot = ({ children }) => {
9
- const [triggerWidth, setTriggerWidth] = React.useState();
10
- const [open, setOpen] = React.useState(false);
11
- return /* @__PURE__ */ jsxRuntime.jsx(
12
- context.AutocompleteContext.Provider,
13
- {
14
- value: {
15
- open,
16
- setOpen,
17
- triggerWidth,
18
- setTriggerWidth
19
- },
20
- children: /* @__PURE__ */ jsxRuntime.jsx(
21
- index.Popover.Root,
22
- {
23
- placement: "bottom-start",
24
- controlled: true,
25
- isOpen: open,
26
- setIsOpen: setOpen,
27
- children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "relative w-full h-full", children })
28
- }
29
- )
30
- }
31
- );
32
- };
33
-
34
- exports.AutocompleteRoot = AutocompleteRoot;
@@ -1,48 +0,0 @@
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 context = require('./context.js');
8
-
9
- const AutocompleteTrigger = ({
10
- inputValue,
11
- onChange,
12
- label,
13
- disabled,
14
- placeholder
15
- }) => {
16
- const context$1 = React.useContext(context.AutocompleteContext);
17
- if (!context$1)
18
- throw new Error("AutocompleteTrigger must be used within AutocompleteRoot");
19
- const { setTriggerWidth, setOpen } = context$1;
20
- const triggerRef = React.useRef(null);
21
- React.useEffect(() => {
22
- if (triggerRef.current && setTriggerWidth) {
23
- const width = triggerRef.current.getBoundingClientRect().width;
24
- setTriggerWidth(width);
25
- }
26
- }, [triggerRef.current, setTriggerWidth]);
27
- const handleChange = (event) => {
28
- onChange(event);
29
- if (event.target.value.length > 0) {
30
- setOpen(true);
31
- } else {
32
- setOpen(false);
33
- }
34
- };
35
- return /* @__PURE__ */ jsxRuntime.jsx(index.Popover.Trigger, { children: /* @__PURE__ */ jsxRuntime.jsx(
36
- index$1.Input.Root,
37
- {
38
- label: label ?? "Selecione uma op\xE7\xE3o",
39
- value: inputValue,
40
- onChange: handleChange,
41
- disabled,
42
- placeholder,
43
- ref: triggerRef
44
- }
45
- ) });
46
- };
47
-
48
- exports.AutocompleteTrigger = AutocompleteTrigger;
@@ -1,9 +0,0 @@
1
- 'use strict';
2
-
3
- var React = require('react');
4
-
5
- const AutocompleteContext = React.createContext(
6
- void 0
7
- );
8
-
9
- exports.AutocompleteContext = AutocompleteContext;
@@ -1,19 +0,0 @@
1
- 'use strict';
2
-
3
- var Root = require('./Root.js');
4
- var Trigger = require('./Trigger.js');
5
- var Popover = require('./Popover.js');
6
- var Options = require('./Options.js');
7
- var Option = require('./Option.js');
8
- var GroupedOptions = require('./GroupedOptions.js');
9
-
10
- const Autocomplete = {
11
- Root: Root.AutocompleteRoot,
12
- Trigger: Trigger.AutocompleteTrigger,
13
- Popover: Popover.AutocompletePopover,
14
- Options: Options.AutocompleteOptions,
15
- Option: Option.AutocompleteOption,
16
- GroupedOptions: GroupedOptions.AutocompleteGroupedOptions
17
- };
18
-
19
- exports.Autocomplete = Autocomplete;
@@ -1,35 +0,0 @@
1
- 'use strict';
2
-
3
- var React = require('react');
4
-
5
- const useAutocompleteGroupedOptions = ({
6
- options: _options
7
- }) => {
8
- const [options, setOptions] = React.useState();
9
- const [isLoading, setIsLoading] = React.useState();
10
- const [error, setError] = React.useState();
11
- const initData = async (fetch) => {
12
- setIsLoading(true);
13
- try {
14
- const result = await fetch();
15
- if (result) {
16
- setOptions(result ?? []);
17
- }
18
- } catch (e) {
19
- setError(String(e));
20
- } finally {
21
- setIsLoading(false);
22
- }
23
- };
24
- React.useEffect(() => {
25
- if (typeof _options === "function") initData(_options);
26
- else setOptions(_options);
27
- }, [_options]);
28
- return {
29
- isLoading,
30
- options,
31
- error
32
- };
33
- };
34
-
35
- exports.useAutocompleteGroupedOptions = useAutocompleteGroupedOptions;
@@ -1,35 +0,0 @@
1
- 'use strict';
2
-
3
- var React = require('react');
4
-
5
- const useAutocompleteOptions = ({
6
- options: _options
7
- }) => {
8
- const [options, setOptions] = React.useState();
9
- const [isLoading, setIsLoading] = React.useState();
10
- const [error, setError] = React.useState();
11
- const initData = React.useCallback(async (fetch) => {
12
- setIsLoading(true);
13
- try {
14
- const result = await fetch();
15
- if (result) {
16
- setOptions(result ?? []);
17
- }
18
- } catch (e) {
19
- setError(String(e));
20
- } finally {
21
- setIsLoading(false);
22
- }
23
- }, []);
24
- React.useEffect(() => {
25
- if (typeof _options === "function") initData(_options);
26
- else setOptions(_options);
27
- }, [_options]);
28
- return {
29
- isLoading,
30
- options,
31
- error
32
- };
33
- };
34
-
35
- exports.useAutocompleteOptions = useAutocompleteOptions;
@@ -1,30 +0,0 @@
1
- import { jsx, jsxs } from 'react/jsx-runtime';
2
- import { selectVariants } from '@tecsinapse/cortex-core';
3
- import { AutocompleteOption } from './Option.js';
4
- import { useAutocompleteGroupedOptions } from '../../hooks/useAutocompleteGroupedOptions.js';
5
- import { SkeletonOptions } from '../Select/SkeletonOptions.js';
6
-
7
- const { groupedTitle, list } = selectVariants();
8
- const AutocompleteGroupedOptions = ({
9
- onSelect,
10
- groupedLabelExtractor,
11
- options
12
- }) => {
13
- const { options: _options, isLoading } = useAutocompleteGroupedOptions({
14
- options
15
- });
16
- return isLoading ? /* @__PURE__ */ jsx(SkeletonOptions, {}) : /* @__PURE__ */ jsx("ul", { role: "listbox", className: list(), children: [..._options ?? []].map(([key, value]) => /* @__PURE__ */ jsxs("div", { children: [
17
- /* @__PURE__ */ jsx("span", { className: groupedTitle(), children: groupedLabelExtractor?.(key) }),
18
- value.map((option) => /* @__PURE__ */ jsx(
19
- AutocompleteOption,
20
- {
21
- grouped: true,
22
- option,
23
- onSelect
24
- },
25
- option.value
26
- ))
27
- ] }, key)) });
28
- };
29
-
30
- export { AutocompleteGroupedOptions };
@@ -1,36 +0,0 @@
1
- import { jsx } from 'react/jsx-runtime';
2
- import { option } from '@tecsinapse/cortex-core';
3
- import { useContext, useCallback } from 'react';
4
- import { AutocompleteContext } from './context.js';
5
-
6
- const AutocompleteOption = ({
7
- option: option$1,
8
- onSelect,
9
- grouped = false
10
- }) => {
11
- const context = useContext(AutocompleteContext);
12
- if (!context)
13
- throw new Error("AutocompleteOptions must be used within AutocompleteRoot");
14
- const { setOpen } = context;
15
- const handleSelect = useCallback(
16
- (option2) => {
17
- setOpen(false);
18
- onSelect?.(option2);
19
- },
20
- [onSelect, setOpen]
21
- );
22
- return /* @__PURE__ */ jsx(
23
- "li",
24
- {
25
- onClick: () => handleSelect(option$1),
26
- className: option({
27
- selected: false,
28
- grouped
29
- }),
30
- role: "option",
31
- children: /* @__PURE__ */ jsx("span", { className: "truncate flex-1", children: option$1.label })
32
- }
33
- );
34
- };
35
-
36
- export { AutocompleteOption };
@@ -1,29 +0,0 @@
1
- import { jsx } from 'react/jsx-runtime';
2
- import { selectVariants } from '@tecsinapse/cortex-core';
3
- import { useMemo } from 'react';
4
- import { AutocompleteOption } from './Option.js';
5
- import { useAutocompleteOptions } from '../../hooks/useAutocompleteOptions.js';
6
- import { SkeletonOptions } from '../Select/SkeletonOptions.js';
7
-
8
- const { list } = selectVariants();
9
- const AutocompleteOptions = ({
10
- options,
11
- onSelect,
12
- children
13
- }) => {
14
- const { options: _options, isLoading } = useAutocompleteOptions({ options });
15
- const defaultOptions = useMemo(
16
- () => _options?.map((option) => /* @__PURE__ */ jsx(
17
- AutocompleteOption,
18
- {
19
- option,
20
- onSelect
21
- },
22
- option.value
23
- )) ?? [],
24
- [_options, onSelect]
25
- );
26
- return isLoading ? /* @__PURE__ */ jsx(SkeletonOptions, {}) : /* @__PURE__ */ jsx("ul", { role: "listbox", className: list(), children: children ?? defaultOptions });
27
- };
28
-
29
- export { AutocompleteOptions };
@@ -1,32 +0,0 @@
1
- import { jsx } from 'react/jsx-runtime';
2
- import { useContext } from 'react';
3
- import { FloatingPortal } from '@floating-ui/react';
4
- import { Popover } from '../Popover/index.js';
5
- import { AutocompleteContext } from './context.js';
6
- import clsx from 'clsx';
7
-
8
- const AutocompletePopover = ({
9
- children,
10
- className
11
- }) => {
12
- const context = useContext(AutocompleteContext);
13
- if (!context)
14
- throw new Error("AutocompletePopover must be used within AutocompleteRoot");
15
- const { triggerWidth } = context;
16
- return /* @__PURE__ */ jsx(FloatingPortal, { children: /* @__PURE__ */ jsx(
17
- Popover.Content,
18
- {
19
- className: clsx(
20
- "bg-white shadow-md rounded-md overflow-y-auto max-h-[30vh] outline-none z-9999",
21
- className
22
- ),
23
- style: {
24
- width: triggerWidth ? `${triggerWidth}px` : "auto"
25
- },
26
- initialFocus: -1,
27
- children
28
- }
29
- ) });
30
- };
31
-
32
- export { AutocompletePopover };
@@ -1,32 +0,0 @@
1
- import { jsx } from 'react/jsx-runtime';
2
- import { useState } from 'react';
3
- import { Popover } from '../Popover/index.js';
4
- import { AutocompleteContext } from './context.js';
5
-
6
- const AutocompleteRoot = ({ children }) => {
7
- const [triggerWidth, setTriggerWidth] = useState();
8
- const [open, setOpen] = useState(false);
9
- return /* @__PURE__ */ jsx(
10
- AutocompleteContext.Provider,
11
- {
12
- value: {
13
- open,
14
- setOpen,
15
- triggerWidth,
16
- setTriggerWidth
17
- },
18
- children: /* @__PURE__ */ jsx(
19
- Popover.Root,
20
- {
21
- placement: "bottom-start",
22
- controlled: true,
23
- isOpen: open,
24
- setIsOpen: setOpen,
25
- children: /* @__PURE__ */ jsx("div", { className: "relative w-full h-full", children })
26
- }
27
- )
28
- }
29
- );
30
- };
31
-
32
- export { AutocompleteRoot };
@@ -1,46 +0,0 @@
1
- import { jsx } from 'react/jsx-runtime';
2
- import { useContext, useRef, useEffect } from 'react';
3
- import { Popover } from '../Popover/index.js';
4
- import { Input } from '../Input/index.js';
5
- import { AutocompleteContext } from './context.js';
6
-
7
- const AutocompleteTrigger = ({
8
- inputValue,
9
- onChange,
10
- label,
11
- disabled,
12
- placeholder
13
- }) => {
14
- const context = useContext(AutocompleteContext);
15
- if (!context)
16
- throw new Error("AutocompleteTrigger must be used within AutocompleteRoot");
17
- const { setTriggerWidth, setOpen } = context;
18
- const triggerRef = useRef(null);
19
- useEffect(() => {
20
- if (triggerRef.current && setTriggerWidth) {
21
- const width = triggerRef.current.getBoundingClientRect().width;
22
- setTriggerWidth(width);
23
- }
24
- }, [triggerRef.current, setTriggerWidth]);
25
- const handleChange = (event) => {
26
- onChange(event);
27
- if (event.target.value.length > 0) {
28
- setOpen(true);
29
- } else {
30
- setOpen(false);
31
- }
32
- };
33
- return /* @__PURE__ */ jsx(Popover.Trigger, { children: /* @__PURE__ */ jsx(
34
- Input.Root,
35
- {
36
- label: label ?? "Selecione uma op\xE7\xE3o",
37
- value: inputValue,
38
- onChange: handleChange,
39
- disabled,
40
- placeholder,
41
- ref: triggerRef
42
- }
43
- ) });
44
- };
45
-
46
- export { AutocompleteTrigger };
@@ -1,7 +0,0 @@
1
- import { createContext } from 'react';
2
-
3
- const AutocompleteContext = createContext(
4
- void 0
5
- );
6
-
7
- export { AutocompleteContext };
@@ -1,17 +0,0 @@
1
- import { AutocompleteRoot } from './Root.js';
2
- import { AutocompleteTrigger } from './Trigger.js';
3
- import { AutocompletePopover } from './Popover.js';
4
- import { AutocompleteOptions } from './Options.js';
5
- import { AutocompleteOption } from './Option.js';
6
- import { AutocompleteGroupedOptions } from './GroupedOptions.js';
7
-
8
- const Autocomplete = {
9
- Root: AutocompleteRoot,
10
- Trigger: AutocompleteTrigger,
11
- Popover: AutocompletePopover,
12
- Options: AutocompleteOptions,
13
- Option: AutocompleteOption,
14
- GroupedOptions: AutocompleteGroupedOptions
15
- };
16
-
17
- export { Autocomplete };
@@ -1,33 +0,0 @@
1
- import { useState, useEffect } from 'react';
2
-
3
- const useAutocompleteGroupedOptions = ({
4
- options: _options
5
- }) => {
6
- const [options, setOptions] = useState();
7
- const [isLoading, setIsLoading] = useState();
8
- const [error, setError] = useState();
9
- const initData = async (fetch) => {
10
- setIsLoading(true);
11
- try {
12
- const result = await fetch();
13
- if (result) {
14
- setOptions(result ?? []);
15
- }
16
- } catch (e) {
17
- setError(String(e));
18
- } finally {
19
- setIsLoading(false);
20
- }
21
- };
22
- useEffect(() => {
23
- if (typeof _options === "function") initData(_options);
24
- else setOptions(_options);
25
- }, [_options]);
26
- return {
27
- isLoading,
28
- options,
29
- error
30
- };
31
- };
32
-
33
- export { useAutocompleteGroupedOptions };
@@ -1,33 +0,0 @@
1
- import { useState, useCallback, useEffect } from 'react';
2
-
3
- const useAutocompleteOptions = ({
4
- options: _options
5
- }) => {
6
- const [options, setOptions] = useState();
7
- const [isLoading, setIsLoading] = useState();
8
- const [error, setError] = useState();
9
- const initData = useCallback(async (fetch) => {
10
- setIsLoading(true);
11
- try {
12
- const result = await fetch();
13
- if (result) {
14
- setOptions(result ?? []);
15
- }
16
- } catch (e) {
17
- setError(String(e));
18
- } finally {
19
- setIsLoading(false);
20
- }
21
- }, []);
22
- useEffect(() => {
23
- if (typeof _options === "function") initData(_options);
24
- else setOptions(_options);
25
- }, [_options]);
26
- return {
27
- isLoading,
28
- options,
29
- error
30
- };
31
- };
32
-
33
- export { useAutocompleteOptions };
@@ -1,2 +0,0 @@
1
- import { AutocompleteGroupedOptionsProps } from './types';
2
- export declare const AutocompleteGroupedOptions: ({ onSelect, groupedLabelExtractor, options, }: AutocompleteGroupedOptionsProps) => import("react/jsx-runtime").JSX.Element;
@@ -1,2 +0,0 @@
1
- import { AutocompleteOptionProps } from './types';
2
- export declare const AutocompleteOption: ({ option, onSelect, grouped, }: AutocompleteOptionProps) => import("react/jsx-runtime").JSX.Element;
@@ -1,2 +0,0 @@
1
- import { AutocompleteOptionsProps } from './types';
2
- export declare const AutocompleteOptions: ({ options, onSelect, children, }: AutocompleteOptionsProps) => import("react/jsx-runtime").JSX.Element;