@tecsinapse/cortex-react 2.2.0-beta.5 → 2.2.0-beta.7

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 (61) hide show
  1. package/dist/cjs/components/Autocomplete/GroupedOptions.js +17 -2
  2. package/dist/cjs/components/Autocomplete/Option.js +5 -3
  3. package/dist/cjs/components/Autocomplete/Options.js +19 -11
  4. package/dist/cjs/components/Autocomplete/Root.js +8 -2
  5. package/dist/cjs/components/Autocomplete/Trigger.js +3 -4
  6. package/dist/cjs/components/Autocomplete/context.js +1 -3
  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 +121 -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 +115 -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/hooks/useAutocompleteGroupedOptions.js +35 -0
  16. package/dist/cjs/hooks/useAutocompleteOptions.js +35 -0
  17. package/dist/cjs/index.js +2 -0
  18. package/dist/cjs/provider/ManagerContext.js +5 -0
  19. package/dist/cjs/service/SnackbarSonner.js +32 -0
  20. package/dist/esm/components/Autocomplete/GroupedOptions.js +17 -2
  21. package/dist/esm/components/Autocomplete/Option.js +5 -3
  22. package/dist/esm/components/Autocomplete/Options.js +20 -12
  23. package/dist/esm/components/Autocomplete/Root.js +8 -2
  24. package/dist/esm/components/Autocomplete/Trigger.js +3 -4
  25. package/dist/esm/components/Autocomplete/context.js +1 -3
  26. package/dist/esm/components/PhoneInput/FlagIcon.js +25 -0
  27. package/dist/esm/components/PhoneInput/Option.js +27 -0
  28. package/dist/esm/components/PhoneInput/Options.js +119 -0
  29. package/dist/esm/components/PhoneInput/Popover.js +20 -0
  30. package/dist/esm/components/PhoneInput/Root.js +59 -0
  31. package/dist/esm/components/PhoneInput/Trigger.js +113 -0
  32. package/dist/esm/components/PhoneInput/context.js +16 -0
  33. package/dist/esm/components/PhoneInput/index.js +15 -0
  34. package/dist/esm/hooks/useAutocompleteGroupedOptions.js +33 -0
  35. package/dist/esm/hooks/useAutocompleteOptions.js +33 -0
  36. package/dist/esm/index.js +1 -0
  37. package/dist/esm/provider/ManagerContext.js +5 -0
  38. package/dist/esm/service/SnackbarSonner.js +32 -0
  39. package/dist/types/components/Autocomplete/GroupedOptions.d.ts +1 -1
  40. package/dist/types/components/Autocomplete/Option.d.ts +1 -1
  41. package/dist/types/components/Autocomplete/Options.d.ts +1 -1
  42. package/dist/types/components/Autocomplete/Root.d.ts +1 -1
  43. package/dist/types/components/Autocomplete/context.d.ts +4 -3
  44. package/dist/types/components/Autocomplete/index.d.ts +4 -4
  45. package/dist/types/components/Autocomplete/types.d.ts +16 -12
  46. package/dist/types/components/PhoneInput/FlagIcon.d.ts +8 -0
  47. package/dist/types/components/PhoneInput/Option.d.ts +6 -0
  48. package/dist/types/components/PhoneInput/Options.d.ts +3 -0
  49. package/dist/types/components/PhoneInput/Popover.d.ts +4 -0
  50. package/dist/types/components/PhoneInput/Root.d.ts +2 -0
  51. package/dist/types/components/PhoneInput/Trigger.d.ts +2 -0
  52. package/dist/types/components/PhoneInput/context.d.ts +15 -0
  53. package/dist/types/components/PhoneInput/index.d.ts +16 -0
  54. package/dist/types/components/PhoneInput/types.d.ts +13 -0
  55. package/dist/types/components/index.d.ts +1 -0
  56. package/dist/types/hooks/useAutocompleteGroupedOptions.d.ts +9 -0
  57. package/dist/types/hooks/useAutocompleteOptions.d.ts +9 -0
  58. package/dist/types/hooks/useFileUpload.d.ts +4 -4
  59. package/dist/types/provider/ManagerContext.d.ts +1 -1
  60. package/dist/types/service/SnackbarSonner.d.ts +19 -0
  61. package/package.json +5 -3
package/dist/cjs/index.js CHANGED
@@ -45,6 +45,7 @@ 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
47
  var index$8 = require('./components/Autocomplete/index.js');
48
+ var index$9 = require('./components/PhoneInput/index.js');
48
49
  var useCalendar = require('./hooks/useCalendar.js');
49
50
  var useCalendarCell = require('./hooks/useCalendarCell.js');
50
51
  var useCalendarGrid = require('./hooks/useCalendarGrid.js');
@@ -129,6 +130,7 @@ exports.Toggle = Toggle.Toggle;
129
130
  exports.Tooltip = Tooltip.Tooltip;
130
131
  exports.Uploader = index$7.Uploader;
131
132
  exports.Autocomplete = index$8.Autocomplete;
133
+ exports.PhoneInput = index$9.PhoneInput;
132
134
  exports.useCalendar = useCalendar.useCalendar;
133
135
  exports.useCalendarCell = useCalendarCell.useCalendarCell;
134
136
  exports.useCalendarGrid = useCalendarGrid.useCalendarGrid;
@@ -69,6 +69,11 @@ require('react-dom');
69
69
  require('../components/Autocomplete/context.js');
70
70
  require('../components/Autocomplete/Options.js');
71
71
  require('../components/Autocomplete/GroupedOptions.js');
72
+ require('../components/PhoneInput/Options.js');
73
+ require('../components/PhoneInput/context.js');
74
+ require('react-international-phone');
75
+ require('react-icons/io5');
76
+ require('country-flag-icons/react/3x2');
72
77
 
73
78
  const ManagerContext = React.createContext(null);
74
79
  const ManagerProvider = ({ children }) => {
@@ -35,6 +35,38 @@ 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
+ }
38
70
  }
39
71
 
40
72
  exports.SnackbarSonner = SnackbarSonner;
@@ -1,6 +1,10 @@
1
1
  import { jsx, jsxs } from 'react/jsx-runtime';
2
2
  import { selectVariants } from '@tecsinapse/cortex-core';
3
+ import { useContext } from 'react';
3
4
  import { AutocompleteOption } from './Option.js';
5
+ import { useAutocompleteGroupedOptions } from '../../hooks/useAutocompleteGroupedOptions.js';
6
+ import { SkeletonOptions } from '../Select/SkeletonOptions.js';
7
+ import { AutocompleteContext } from './context.js';
4
8
 
5
9
  const { groupedTitle, list } = selectVariants();
6
10
  const AutocompleteGroupedOptions = ({
@@ -8,7 +12,18 @@ const AutocompleteGroupedOptions = ({
8
12
  groupedLabelExtractor,
9
13
  options
10
14
  }) => {
11
- return /* @__PURE__ */ jsx("ul", { role: "listbox", className: list(), children: [...options ?? []].map(([key, value]) => /* @__PURE__ */ jsxs("div", { children: [
15
+ const { options: _options, isLoading } = useAutocompleteGroupedOptions({
16
+ options
17
+ });
18
+ const context = useContext(
19
+ AutocompleteContext
20
+ );
21
+ if (!context)
22
+ throw new Error(
23
+ "AutocompleteGroupedOptions must be used within AutocompleteRoot"
24
+ );
25
+ const { keyExtractor } = context;
26
+ return isLoading ? /* @__PURE__ */ jsx(SkeletonOptions, {}) : /* @__PURE__ */ jsx("ul", { role: "listbox", className: list(), children: [..._options ?? []].map(([key, value]) => /* @__PURE__ */ jsxs("div", { children: [
12
27
  /* @__PURE__ */ jsx("span", { className: groupedTitle(), children: groupedLabelExtractor?.(key) }),
13
28
  value.map((option) => /* @__PURE__ */ jsx(
14
29
  AutocompleteOption,
@@ -17,7 +32,7 @@ const AutocompleteGroupedOptions = ({
17
32
  option,
18
33
  onSelect
19
34
  },
20
- option.value
35
+ keyExtractor(option)
21
36
  ))
22
37
  ] }, key)) });
23
38
  };
@@ -8,10 +8,12 @@ const AutocompleteOption = ({
8
8
  onSelect,
9
9
  grouped = false
10
10
  }) => {
11
- const context = useContext(AutocompleteContext);
11
+ const context = useContext(
12
+ AutocompleteContext
13
+ );
12
14
  if (!context)
13
15
  throw new Error("AutocompleteOptions must be used within AutocompleteRoot");
14
- const { setOpen } = context;
16
+ const { setOpen, labelExtractor } = context;
15
17
  const handleSelect = useCallback(
16
18
  (option2) => {
17
19
  setOpen(false);
@@ -28,7 +30,7 @@ const AutocompleteOption = ({
28
30
  grouped
29
31
  }),
30
32
  role: "option",
31
- children: /* @__PURE__ */ jsx("span", { className: "truncate flex-1", children: option$1.label })
33
+ children: /* @__PURE__ */ jsx("span", { className: "truncate flex-1", children: labelExtractor(option$1) })
32
34
  }
33
35
  );
34
36
  };
@@ -1,7 +1,10 @@
1
1
  import { jsx } from 'react/jsx-runtime';
2
2
  import { selectVariants } from '@tecsinapse/cortex-core';
3
- import { useMemo } from 'react';
3
+ import { useContext } from 'react';
4
4
  import { AutocompleteOption } from './Option.js';
5
+ import { useAutocompleteOptions } from '../../hooks/useAutocompleteOptions.js';
6
+ import { SkeletonOptions } from '../Select/SkeletonOptions.js';
7
+ import { AutocompleteContext } from './context.js';
5
8
 
6
9
  const { list } = selectVariants();
7
10
  const AutocompleteOptions = ({
@@ -9,18 +12,23 @@ const AutocompleteOptions = ({
9
12
  onSelect,
10
13
  children
11
14
  }) => {
12
- const defaultOptions = useMemo(
13
- () => options?.map((option) => /* @__PURE__ */ jsx(
14
- AutocompleteOption,
15
- {
16
- option,
17
- onSelect
18
- },
19
- option.value
20
- )) ?? [],
21
- [options, onSelect]
15
+ const context = useContext(
16
+ AutocompleteContext
22
17
  );
23
- return /* @__PURE__ */ jsx("ul", { role: "listbox", className: list(), children: children ?? defaultOptions });
18
+ if (!context)
19
+ throw new Error("AutocompleteOptions must be used within AutocompleteRoot");
20
+ const { keyExtractor } = context;
21
+ const { options: _options, isLoading } = useAutocompleteOptions({
22
+ options
23
+ });
24
+ return isLoading ? /* @__PURE__ */ jsx(SkeletonOptions, {}) : /* @__PURE__ */ jsx("ul", { role: "listbox", className: list(), children: children ?? _options?.map((option) => /* @__PURE__ */ jsx(
25
+ AutocompleteOption,
26
+ {
27
+ option,
28
+ onSelect
29
+ },
30
+ keyExtractor(option)
31
+ )) });
24
32
  };
25
33
 
26
34
  export { AutocompleteOptions };
@@ -3,7 +3,11 @@ import { useState } from 'react';
3
3
  import { Popover } from '../Popover/index.js';
4
4
  import { AutocompleteContext } from './context.js';
5
5
 
6
- const AutocompleteRoot = ({ children }) => {
6
+ const AutocompleteRoot = ({
7
+ keyExtractor,
8
+ labelExtractor,
9
+ children
10
+ }) => {
7
11
  const [triggerWidth, setTriggerWidth] = useState();
8
12
  const [open, setOpen] = useState(false);
9
13
  return /* @__PURE__ */ jsx(
@@ -13,7 +17,9 @@ const AutocompleteRoot = ({ children }) => {
13
17
  open,
14
18
  setOpen,
15
19
  triggerWidth,
16
- setTriggerWidth
20
+ setTriggerWidth,
21
+ keyExtractor,
22
+ labelExtractor
17
23
  },
18
24
  children: /* @__PURE__ */ jsx(
19
25
  Popover.Root,
@@ -30,17 +30,16 @@ const AutocompleteTrigger = ({
30
30
  setOpen(false);
31
31
  }
32
32
  };
33
- return /* @__PURE__ */ jsx(Popover.Trigger, { children: /* @__PURE__ */ jsx(
33
+ return /* @__PURE__ */ jsx(Popover.Trigger, { children: /* @__PURE__ */ jsx("div", { ref: triggerRef, children: /* @__PURE__ */ jsx(
34
34
  Input.Root,
35
35
  {
36
36
  label: label ?? "Selecione uma op\xE7\xE3o",
37
37
  value: inputValue,
38
38
  onChange: handleChange,
39
39
  disabled,
40
- placeholder,
41
- ref: triggerRef
40
+ placeholder
42
41
  }
43
- ) });
42
+ ) }) });
44
43
  };
45
44
 
46
45
  export { AutocompleteTrigger };
@@ -1,7 +1,5 @@
1
1
  import { createContext } from 'react';
2
2
 
3
- const AutocompleteContext = createContext(
4
- void 0
5
- );
3
+ const AutocompleteContext = createContext(void 0);
6
4
 
7
5
  export { AutocompleteContext };
@@ -0,0 +1,25 @@
1
+ import { jsx } from 'react/jsx-runtime';
2
+ import * as Flags from 'country-flag-icons/react/3x2';
3
+
4
+ const FlagIcon = ({
5
+ countryCode,
6
+ className = "w-[25px]",
7
+ title
8
+ }) => {
9
+ if (!countryCode) return null;
10
+ const upperCode = countryCode.toUpperCase();
11
+ const FlagComponent = Flags[upperCode];
12
+ if (!FlagComponent) {
13
+ return null;
14
+ }
15
+ return /* @__PURE__ */ jsx(
16
+ FlagComponent,
17
+ {
18
+ className,
19
+ title: title || upperCode,
20
+ "aria-label": `Flag of ${upperCode}`
21
+ }
22
+ );
23
+ };
24
+
25
+ export { FlagIcon };
@@ -0,0 +1,27 @@
1
+ import { jsxs, jsx } from 'react/jsx-runtime';
2
+
3
+ const PhoneInputOption = ({
4
+ country,
5
+ handleSelectCountry,
6
+ disableClick = false
7
+ }) => {
8
+ return /* @__PURE__ */ jsxs(
9
+ "button",
10
+ {
11
+ className: "flex w-full h-[2rem] items-center justify-between p-centi cursor-pointer hover:bg-secondary-xlight bg-inherit",
12
+ onClick: () => {
13
+ handleSelectCountry(country);
14
+ },
15
+ disabled: disableClick,
16
+ children: [
17
+ /* @__PURE__ */ jsx("span", { children: country?.name }),
18
+ /* @__PURE__ */ jsxs("span", { className: "text-secondary-light text-sm", children: [
19
+ "+",
20
+ country?.dialCode
21
+ ] })
22
+ ]
23
+ }
24
+ );
25
+ };
26
+
27
+ export { PhoneInputOption };
@@ -0,0 +1,119 @@
1
+ import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
2
+ import { useState, useMemo } from 'react';
3
+ import { Divider } from '../Divider.js';
4
+ import { usePhoneContext } from './context.js';
5
+ import { PhoneInputOption } from './Option.js';
6
+ import 'clsx';
7
+ import '../Accordion/context.js';
8
+ import 'react-icons/lia';
9
+ import '@internationalized/date';
10
+ import '../Badge.js';
11
+ import 'react-icons/md';
12
+ import '@tecsinapse/cortex-core';
13
+ import 'react-aria';
14
+ import 'react-stately';
15
+ import '../../provider/MenubarContext.js';
16
+ import '../../provider/SnackbarProvider.js';
17
+ import '../../provider/CalendarProvider.js';
18
+ import '../../provider/ManagerContext.js';
19
+ import '../Popover/Context.js';
20
+ import 'react-dropzone';
21
+ import 'uuid';
22
+ import '@floating-ui/react';
23
+ import 'currency.js';
24
+ import '../Calendar/CalendarCell.js';
25
+ import 'react-icons/fa';
26
+ import 'react-icons/io';
27
+ import 'embla-carousel-react';
28
+ import 'embla-carousel-autoplay';
29
+ import '../ColorPicker.js';
30
+ import '../DatePicker/DateSegment.js';
31
+ import '../DatePicker/DatePickerInputBase.js';
32
+ import '../GroupButton.js';
33
+ import { Input } from '../Input/index.js';
34
+ import '../Menubar/Left.js';
35
+ import '../../styles/menubar.js';
36
+ import '../Menubar/Right.js';
37
+ import '../Menubar/Dropdown.js';
38
+ import '../Menubar/MostUsed.js';
39
+ import '../Menubar/MostUsedItem.js';
40
+ import '../Menubar/Header.js';
41
+ import '../Menubar/Item.js';
42
+ import '../../provider/CategoriesContext.js';
43
+ import '../Menubar/SubItem.js';
44
+ import '../ProgressBar/Progress.js';
45
+ import '../RadioButton.js';
46
+ import '../Select/GroupedOptions.js';
47
+ import '../Select/context.js';
48
+ import '../Select/MultiGroupedOptions.js';
49
+ import '../Select/MultiOptions.js';
50
+ import '../Select/Options.js';
51
+ import '../Select/Trigger.js';
52
+ import '../../styles/stepNodeVariants.js';
53
+ import '../TextArea/Box.js';
54
+ import '../TextArea/Face.js';
55
+ import '../TextArea/Left.js';
56
+ import '../TextArea/Right.js';
57
+ import '../TextArea/Root.js';
58
+ import '../TimePicker/TimeFieldInput.js';
59
+ import '../Tooltip.js';
60
+ import 'react-icons/hi2';
61
+ import 'react-icons/fa6';
62
+ import 'react-dom';
63
+ import 'react-icons/io5';
64
+ import '../Autocomplete/context.js';
65
+ import '../Autocomplete/Options.js';
66
+ import '../Autocomplete/GroupedOptions.js';
67
+ import { defaultCountries, parseCountry } from 'react-international-phone';
68
+ import 'country-flag-icons/react/3x2';
69
+
70
+ const countries = defaultCountries.map((c) => {
71
+ return parseCountry(c);
72
+ });
73
+ const PhoneInputOptions = ({
74
+ hasSearch = true
75
+ }) => {
76
+ const { country, setCountry, setIsOpen } = usePhoneContext();
77
+ const [searchText, setSearchText] = useState("");
78
+ const filteredCountries = useMemo(() => {
79
+ return countries.filter(
80
+ (c) => c.iso2 !== country?.iso2 && (c.name.toLowerCase().includes(searchText.toLowerCase()) || c.dialCode.includes(searchText))
81
+ );
82
+ }, [country, searchText]);
83
+ const handleSelect = (country2) => {
84
+ setCountry?.(country2.iso2);
85
+ setIsOpen?.(false);
86
+ };
87
+ return /* @__PURE__ */ jsxs("div", { className: "w-full h-full flex flex-col overflow-y-auto", children: [
88
+ hasSearch ? /* @__PURE__ */ jsx(
89
+ Input.Search,
90
+ {
91
+ onChange: (e) => setSearchText(e.target.value),
92
+ variants: { className: "mx-deca my-centi outline-none" }
93
+ }
94
+ ) : null,
95
+ country ? /* @__PURE__ */ jsxs(Fragment, { children: [
96
+ /* @__PURE__ */ jsx(
97
+ PhoneInputOption,
98
+ {
99
+ country,
100
+ handleSelectCountry: handleSelect,
101
+ disableClick: true
102
+ }
103
+ ),
104
+ /* @__PURE__ */ jsx(Divider, {})
105
+ ] }) : null,
106
+ filteredCountries.map((country2) => {
107
+ return /* @__PURE__ */ jsx(
108
+ PhoneInputOption,
109
+ {
110
+ country: country2,
111
+ handleSelectCountry: handleSelect
112
+ },
113
+ `${country2.dialCode} ${country2.iso2}`
114
+ );
115
+ })
116
+ ] });
117
+ };
118
+
119
+ export { PhoneInputOptions };
@@ -0,0 +1,20 @@
1
+ import { jsx } from 'react/jsx-runtime';
2
+ import { FloatingPortal } from '@floating-ui/react';
3
+ import { Popover } from '../Popover/index.js';
4
+ import { usePhoneContext } from './context.js';
5
+
6
+ const PhoneInputPopover = ({ children }) => {
7
+ const { triggerWidth } = usePhoneContext();
8
+ return /* @__PURE__ */ jsx(FloatingPortal, { children: /* @__PURE__ */ jsx(
9
+ Popover.Content,
10
+ {
11
+ className: "bg-white shadow-md rounded-md overflow-hidden h-full max-h-[30vh] outline-none z-9999",
12
+ style: {
13
+ width: triggerWidth ? `${triggerWidth}px` : "auto"
14
+ },
15
+ children
16
+ }
17
+ ) });
18
+ };
19
+
20
+ export { PhoneInputPopover };
@@ -0,0 +1,59 @@
1
+ import { jsx } from 'react/jsx-runtime';
2
+ import { useState } from 'react';
3
+ import { Popover } from '../Popover/index.js';
4
+ import clsx from 'clsx';
5
+ import { usePhoneInput, defaultCountries } from 'react-international-phone';
6
+ import { PhoneInputContext } from './context.js';
7
+
8
+ const PhoneInputRoot = ({
9
+ children,
10
+ className,
11
+ onChange,
12
+ ...rest
13
+ }) => {
14
+ const [triggerWidth, setTriggerWidth] = useState();
15
+ const [isOpen, setIsOpen] = useState(false);
16
+ const {
17
+ country,
18
+ handlePhoneValueChange,
19
+ inputRef,
20
+ inputValue,
21
+ phone,
22
+ setCountry
23
+ } = usePhoneInput({
24
+ countries: defaultCountries,
25
+ onChange: ({ phone: phone2, ...rest2 }) => {
26
+ onChange?.(phone2, { ...rest2 });
27
+ },
28
+ ...rest
29
+ });
30
+ return /* @__PURE__ */ jsx(
31
+ Popover.Root,
32
+ {
33
+ placement: "bottom-start",
34
+ controlled: true,
35
+ isOpen,
36
+ setIsOpen,
37
+ children: /* @__PURE__ */ jsx(
38
+ PhoneInputContext.Provider,
39
+ {
40
+ value: {
41
+ triggerWidth,
42
+ setTriggerWidth,
43
+ isOpen,
44
+ setIsOpen,
45
+ country,
46
+ setCountry,
47
+ handlePhoneValueChange,
48
+ inputValue,
49
+ phone,
50
+ inputRef
51
+ },
52
+ children: /* @__PURE__ */ jsx("div", { className: clsx("relative w-full h-full", className), children })
53
+ }
54
+ )
55
+ }
56
+ );
57
+ };
58
+
59
+ export { PhoneInputRoot };
@@ -0,0 +1,113 @@
1
+ import { jsx, jsxs } from 'react/jsx-runtime';
2
+ import { IoChevronDown } from 'react-icons/io5';
3
+ import 'clsx';
4
+ import { useRef, useEffect } from 'react';
5
+ import '../Accordion/context.js';
6
+ import 'react-icons/lia';
7
+ import '@internationalized/date';
8
+ import '../Badge.js';
9
+ import 'react-icons/md';
10
+ import '@tecsinapse/cortex-core';
11
+ import 'react-aria';
12
+ import 'react-stately';
13
+ import '../../provider/MenubarContext.js';
14
+ import '../../provider/SnackbarProvider.js';
15
+ import '../../provider/CalendarProvider.js';
16
+ import '../../provider/ManagerContext.js';
17
+ import '../Popover/Context.js';
18
+ import 'react-dropzone';
19
+ import 'uuid';
20
+ import '@floating-ui/react';
21
+ import 'currency.js';
22
+ import '../Calendar/CalendarCell.js';
23
+ import 'react-icons/fa';
24
+ import 'react-icons/io';
25
+ import 'embla-carousel-react';
26
+ import 'embla-carousel-autoplay';
27
+ import '../ColorPicker.js';
28
+ import '../DatePicker/DateSegment.js';
29
+ import { Popover } from '../Popover/index.js';
30
+ import '../DatePicker/DatePickerInputBase.js';
31
+ import '../GroupButton.js';
32
+ import { Input } from '../Input/index.js';
33
+ import '../Menubar/Left.js';
34
+ import '../../styles/menubar.js';
35
+ import '../Menubar/Right.js';
36
+ import '../Menubar/Dropdown.js';
37
+ import '../Menubar/MostUsed.js';
38
+ import '../Menubar/MostUsedItem.js';
39
+ import '../Menubar/Header.js';
40
+ import '../Menubar/Item.js';
41
+ import '../../provider/CategoriesContext.js';
42
+ import '../Menubar/SubItem.js';
43
+ import '../ProgressBar/Progress.js';
44
+ import '../RadioButton.js';
45
+ import '../Select/GroupedOptions.js';
46
+ import '../Select/context.js';
47
+ import '../Select/MultiGroupedOptions.js';
48
+ import '../Select/MultiOptions.js';
49
+ import '../Select/Options.js';
50
+ import '../Select/Trigger.js';
51
+ import '../../styles/stepNodeVariants.js';
52
+ import '../TextArea/Box.js';
53
+ import '../TextArea/Face.js';
54
+ import '../TextArea/Left.js';
55
+ import '../TextArea/Right.js';
56
+ import '../TextArea/Root.js';
57
+ import '../TimePicker/TimeFieldInput.js';
58
+ import '../Tooltip.js';
59
+ import 'react-icons/hi2';
60
+ import 'react-icons/fa6';
61
+ import 'react-dom';
62
+ import '../Autocomplete/context.js';
63
+ import '../Autocomplete/Options.js';
64
+ import '../Autocomplete/GroupedOptions.js';
65
+ import './Options.js';
66
+ import { usePhoneContext } from './context.js';
67
+ import 'react-international-phone';
68
+ import { FlagIcon } from './FlagIcon.js';
69
+
70
+ const PhoneInputTrigger = ({
71
+ disabled = false,
72
+ label,
73
+ ...rest
74
+ }) => {
75
+ const {
76
+ setIsOpen,
77
+ setTriggerWidth,
78
+ country,
79
+ handlePhoneValueChange,
80
+ inputValue
81
+ } = usePhoneContext();
82
+ const triggerRef = useRef(null);
83
+ useEffect(() => {
84
+ if (triggerRef.current && setTriggerWidth) {
85
+ const width = triggerRef.current.getBoundingClientRect().width;
86
+ setTriggerWidth(width);
87
+ }
88
+ }, [triggerRef.current, setTriggerWidth]);
89
+ return /* @__PURE__ */ jsx(Popover.Trigger, { disabled, children: /* @__PURE__ */ jsxs(Input.Face, { ref: triggerRef, children: [
90
+ /* @__PURE__ */ jsx(
91
+ Input.Box,
92
+ {
93
+ value: inputValue,
94
+ onChange: handlePhoneValueChange,
95
+ label: label ?? "Insert a phone number",
96
+ ...rest
97
+ }
98
+ ),
99
+ /* @__PURE__ */ jsx(Input.Right, { children: /* @__PURE__ */ jsxs(
100
+ "div",
101
+ {
102
+ className: "flex items-center gap-1 cursor-pointer w-full",
103
+ onClick: () => setIsOpen?.(true),
104
+ children: [
105
+ country ? /* @__PURE__ */ jsx(FlagIcon, { countryCode: country.iso2, className: "w-[25px]" }) : null,
106
+ /* @__PURE__ */ jsx(IoChevronDown, { className: "h-full text-md" })
107
+ ]
108
+ }
109
+ ) })
110
+ ] }) });
111
+ };
112
+
113
+ export { PhoneInputTrigger };
@@ -0,0 +1,16 @@
1
+ import { createContext, useContext } from 'react';
2
+
3
+ const PhoneInputContext = createContext(
4
+ null
5
+ );
6
+ const usePhoneContext = () => {
7
+ const context = useContext(PhoneInputContext);
8
+ if (!context) {
9
+ throw new Error(
10
+ "usePhoneInputContext must be used within a usePhoneInputProvider"
11
+ );
12
+ }
13
+ return context;
14
+ };
15
+
16
+ export { PhoneInputContext, usePhoneContext };
@@ -0,0 +1,15 @@
1
+ import { PhoneInputOption } from './Option.js';
2
+ import { PhoneInputOptions } from './Options.js';
3
+ import { PhoneInputPopover } from './Popover.js';
4
+ import { PhoneInputRoot } from './Root.js';
5
+ import { PhoneInputTrigger } from './Trigger.js';
6
+
7
+ const PhoneInput = {
8
+ Root: PhoneInputRoot,
9
+ Popover: PhoneInputPopover,
10
+ Trigger: PhoneInputTrigger,
11
+ Option: PhoneInputOption,
12
+ Options: PhoneInputOptions
13
+ };
14
+
15
+ export { PhoneInput };
@@ -0,0 +1,33 @@
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 };