@tecsinapse/cortex-react 2.2.0-beta.6 → 2.2.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 (57) hide show
  1. package/dist/cjs/components/Autocomplete/GroupedOptions.js +11 -1
  2. package/dist/cjs/components/Autocomplete/Option.js +5 -3
  3. package/dist/cjs/components/Autocomplete/Options.js +17 -12
  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/index.js +2 -0
  16. package/dist/cjs/provider/ManagerContext.js +5 -0
  17. package/dist/cjs/service/SnackbarSonner.js +32 -0
  18. package/dist/esm/components/Autocomplete/GroupedOptions.js +11 -1
  19. package/dist/esm/components/Autocomplete/Option.js +5 -3
  20. package/dist/esm/components/Autocomplete/Options.js +18 -13
  21. package/dist/esm/components/Autocomplete/Root.js +8 -2
  22. package/dist/esm/components/Autocomplete/Trigger.js +3 -4
  23. package/dist/esm/components/Autocomplete/context.js +1 -3
  24. package/dist/esm/components/PhoneInput/FlagIcon.js +25 -0
  25. package/dist/esm/components/PhoneInput/Option.js +27 -0
  26. package/dist/esm/components/PhoneInput/Options.js +119 -0
  27. package/dist/esm/components/PhoneInput/Popover.js +20 -0
  28. package/dist/esm/components/PhoneInput/Root.js +59 -0
  29. package/dist/esm/components/PhoneInput/Trigger.js +113 -0
  30. package/dist/esm/components/PhoneInput/context.js +16 -0
  31. package/dist/esm/components/PhoneInput/index.js +15 -0
  32. package/dist/esm/index.js +1 -0
  33. package/dist/esm/provider/ManagerContext.js +5 -0
  34. package/dist/esm/service/SnackbarSonner.js +32 -0
  35. package/dist/types/components/Autocomplete/GroupedOptions.d.ts +1 -1
  36. package/dist/types/components/Autocomplete/Option.d.ts +1 -1
  37. package/dist/types/components/Autocomplete/Options.d.ts +1 -1
  38. package/dist/types/components/Autocomplete/Root.d.ts +1 -1
  39. package/dist/types/components/Autocomplete/context.d.ts +4 -3
  40. package/dist/types/components/Autocomplete/index.d.ts +4 -4
  41. package/dist/types/components/Autocomplete/types.d.ts +17 -13
  42. package/dist/types/components/PhoneInput/FlagIcon.d.ts +8 -0
  43. package/dist/types/components/PhoneInput/Option.d.ts +6 -0
  44. package/dist/types/components/PhoneInput/Options.d.ts +3 -0
  45. package/dist/types/components/PhoneInput/Popover.d.ts +4 -0
  46. package/dist/types/components/PhoneInput/Root.d.ts +2 -0
  47. package/dist/types/components/PhoneInput/Trigger.d.ts +2 -0
  48. package/dist/types/components/PhoneInput/context.d.ts +15 -0
  49. package/dist/types/components/PhoneInput/index.d.ts +16 -0
  50. package/dist/types/components/PhoneInput/types.d.ts +13 -0
  51. package/dist/types/components/index.d.ts +1 -0
  52. package/dist/types/hooks/useAutocompleteGroupedOptions.d.ts +4 -5
  53. package/dist/types/hooks/useAutocompleteOptions.d.ts +4 -5
  54. package/dist/types/hooks/useFileUpload.d.ts +4 -4
  55. package/dist/types/provider/ManagerContext.d.ts +1 -1
  56. package/dist/types/service/SnackbarSonner.d.ts +19 -0
  57. package/package.json +5 -3
@@ -1,8 +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';
4
5
  import { useAutocompleteGroupedOptions } from '../../hooks/useAutocompleteGroupedOptions.js';
5
6
  import { SkeletonOptions } from '../Select/SkeletonOptions.js';
7
+ import { AutocompleteContext } from './context.js';
6
8
 
7
9
  const { groupedTitle, list } = selectVariants();
8
10
  const AutocompleteGroupedOptions = ({
@@ -13,6 +15,14 @@ const AutocompleteGroupedOptions = ({
13
15
  const { options: _options, isLoading } = useAutocompleteGroupedOptions({
14
16
  options
15
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;
16
26
  return isLoading ? /* @__PURE__ */ jsx(SkeletonOptions, {}) : /* @__PURE__ */ jsx("ul", { role: "listbox", className: list(), children: [..._options ?? []].map(([key, value]) => /* @__PURE__ */ jsxs("div", { children: [
17
27
  /* @__PURE__ */ jsx("span", { className: groupedTitle(), children: groupedLabelExtractor?.(key) }),
18
28
  value.map((option) => /* @__PURE__ */ jsx(
@@ -22,7 +32,7 @@ const AutocompleteGroupedOptions = ({
22
32
  option,
23
33
  onSelect
24
34
  },
25
- option.value
35
+ keyExtractor(option)
26
36
  ))
27
37
  ] }, key)) });
28
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,9 +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
5
  import { useAutocompleteOptions } from '../../hooks/useAutocompleteOptions.js';
6
6
  import { SkeletonOptions } from '../Select/SkeletonOptions.js';
7
+ import { AutocompleteContext } from './context.js';
7
8
 
8
9
  const { list } = selectVariants();
9
10
  const AutocompleteOptions = ({
@@ -11,19 +12,23 @@ const AutocompleteOptions = ({
11
12
  onSelect,
12
13
  children
13
14
  }) => {
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]
15
+ const context = useContext(
16
+ AutocompleteContext
25
17
  );
26
- return isLoading ? /* @__PURE__ */ jsx(SkeletonOptions, {}) : /* @__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
+ )) });
27
32
  };
28
33
 
29
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 };
package/dist/esm/index.js CHANGED
@@ -43,6 +43,7 @@ export { Toggle } from './components/Toggle.js';
43
43
  export { Tooltip } from './components/Tooltip.js';
44
44
  export { Uploader } from './components/Uploader/index.js';
45
45
  export { Autocomplete } from './components/Autocomplete/index.js';
46
+ export { PhoneInput } from './components/PhoneInput/index.js';
46
47
  export { useCalendar } from './hooks/useCalendar.js';
47
48
  export { useCalendarCell } from './hooks/useCalendarCell.js';
48
49
  export { useCalendarGrid } from './hooks/useCalendarGrid.js';
@@ -67,6 +67,11 @@ import 'react-dom';
67
67
  import '../components/Autocomplete/context.js';
68
68
  import '../components/Autocomplete/Options.js';
69
69
  import '../components/Autocomplete/GroupedOptions.js';
70
+ import '../components/PhoneInput/Options.js';
71
+ import '../components/PhoneInput/context.js';
72
+ import 'react-international-phone';
73
+ import 'react-icons/io5';
74
+ import 'country-flag-icons/react/3x2';
70
75
 
71
76
  const ManagerContext = createContext(null);
72
77
  const ManagerProvider = ({ children }) => {
@@ -33,6 +33,38 @@ 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
+ }
36
68
  }
37
69
 
38
70
  export { SnackbarSonner };
@@ -1,2 +1,2 @@
1
1
  import { AutocompleteGroupedOptionsProps } from './types';
2
- export declare const AutocompleteGroupedOptions: ({ onSelect, groupedLabelExtractor, options, }: AutocompleteGroupedOptionsProps) => import("react/jsx-runtime").JSX.Element;
2
+ export declare const AutocompleteGroupedOptions: <T>({ onSelect, groupedLabelExtractor, options, }: AutocompleteGroupedOptionsProps<T>) => import("react/jsx-runtime").JSX.Element;
@@ -1,2 +1,2 @@
1
1
  import { AutocompleteOptionProps } from './types';
2
- export declare const AutocompleteOption: ({ option, onSelect, grouped, }: AutocompleteOptionProps) => import("react/jsx-runtime").JSX.Element;
2
+ export declare const AutocompleteOption: <T>({ option, onSelect, grouped, }: AutocompleteOptionProps<T>) => import("react/jsx-runtime").JSX.Element;
@@ -1,2 +1,2 @@
1
1
  import { AutocompleteOptionsProps } from './types';
2
- export declare const AutocompleteOptions: ({ options, onSelect, children, }: AutocompleteOptionsProps) => import("react/jsx-runtime").JSX.Element;
2
+ export declare const AutocompleteOptions: <T>({ options, onSelect, children, }: AutocompleteOptionsProps<T>) => import("react/jsx-runtime").JSX.Element;
@@ -1,2 +1,2 @@
1
1
  import { AutocompleteRootProps } from './types';
2
- export declare const AutocompleteRoot: ({ children }: AutocompleteRootProps) => import("react/jsx-runtime").JSX.Element;
2
+ export declare const AutocompleteRoot: <T>({ keyExtractor, labelExtractor, children, }: AutocompleteRootProps<T>) => import("react/jsx-runtime").JSX.Element;
@@ -1,9 +1,10 @@
1
1
  import { Dispatch, SetStateAction } from 'react';
2
- interface AutocompleteContextType {
2
+ export interface AutocompleteContextType<T> {
3
3
  open: boolean;
4
4
  setOpen: (open: boolean) => void;
5
5
  triggerWidth: number | undefined;
6
6
  setTriggerWidth: Dispatch<SetStateAction<number | undefined>>;
7
+ keyExtractor: (option: T) => string;
8
+ labelExtractor: (option: T) => string;
7
9
  }
8
- export declare const AutocompleteContext: import("react").Context<AutocompleteContextType | undefined>;
9
- export {};
10
+ export declare const AutocompleteContext: import("react").Context<AutocompleteContextType<any> | undefined>;