@vygruppen/spor-react 2.4.2 → 2.4.3

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.
@@ -1,5 +1,5 @@
1
1
 
2
- > @vygruppen/spor-react@2.4.2 build
2
+ > @vygruppen/spor-react@2.4.3 build
3
3
  > tsup src/index.tsx --dts --treeshake --format cjs,esm
4
4
 
5
5
  CLI Building entry: src/index.tsx
@@ -10,12 +10,12 @@
10
10
  ESM Build start
11
11
  DTS Build start
12
12
  "toTime" is imported from external module "@internationalized/date" but never used in "dist/index.js".
13
- "toTime" is imported from external module "@internationalized/date" but never used in "dist/chunk-C3DS6BFF.mjs".
14
- CJS dist/index.js 895.96 KB
15
- CJS ⚡️ Build success in 4923ms
13
+ "toTime" is imported from external module "@internationalized/date" but never used in "dist/chunk-Z3I6W6PC.mjs".
14
+ CJS dist/index.js 896.27 KB
15
+ CJS ⚡️ Build success in 5484ms
16
16
  ESM dist/index.mjs 2.08 KB
17
- ESM dist/CountryCodeSelect-FDAGWNSZ.mjs 351.67 KB
18
- ESM dist/chunk-C3DS6BFF.mjs 416.15 KB
19
- ESM ⚡️ Build success in 4924ms
20
- DTS ⚡️ Build success in 18562ms
21
- DTS dist/index.d.ts 261.82 KB
17
+ ESM dist/CountryCodeSelect-GFQIGSFV.mjs 351.67 KB
18
+ ESM dist/chunk-Z3I6W6PC.mjs 416.47 KB
19
+ ESM ⚡️ Build success in 5484ms
20
+ DTS ⚡️ Build success in 22623ms
21
+ DTS dist/index.d.ts 262.86 KB
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @vygruppen/spor-react
2
2
 
3
+ ## 2.4.3
4
+
5
+ ### Patch Changes
6
+
7
+ - 5640417f: Autosuggest: Fix a bug where the onSelectionChanged was called with no item on nested lists
8
+
3
9
  ## 2.4.2
4
10
 
5
11
  ### Patch Changes
@@ -1,4 +1,4 @@
1
- import { createTexts, useTranslation, InfoSelect, SelectItem } from './chunk-C3DS6BFF.mjs';
1
+ import { createTexts, useTranslation, InfoSelect, SelectItem } from './chunk-Z3I6W6PC.mjs';
2
2
  import React from 'react';
3
3
 
4
4
  // ../../node_modules/awesome-phonenumber/index-esm.mjs
@@ -4022,7 +4022,6 @@ var AttachedInputs = ({
4022
4022
  function Autosuggest({
4023
4023
  label,
4024
4024
  fetcher,
4025
- children,
4026
4025
  onSelectionChange,
4027
4026
  ...props
4028
4027
  }) {
@@ -4037,7 +4036,15 @@ function Autosuggest({
4037
4036
  if (!onSelectionChange) {
4038
4037
  return;
4039
4038
  }
4040
- return onSelectionChange(list2.getItem(key));
4039
+ let selectedItem = list2.getItem(key);
4040
+ if (!selectedItem) {
4041
+ selectedItem = list2.items.flatMap(
4042
+ (item) => "children" in item && Array.isArray(item.children) ? item.children : []
4043
+ ).find((child) => child.key === key);
4044
+ }
4045
+ if (selectedItem) {
4046
+ onSelectionChange(selectedItem);
4047
+ }
4041
4048
  };
4042
4049
  return /* @__PURE__ */ React49__default.createElement(
4043
4050
  Combobox,
@@ -4049,8 +4056,7 @@ function Autosuggest({
4049
4056
  onSelectionChange: handleSelectionChange,
4050
4057
  isLoading: list2.isLoading,
4051
4058
  ...props
4052
- },
4053
- children
4059
+ }
4054
4060
  );
4055
4061
  }
4056
4062
  var Dialog = ({ title, children, ...props }) => {
@@ -4238,6 +4244,8 @@ function Combobox({
4238
4244
  marginTop,
4239
4245
  marginX,
4240
4246
  marginY,
4247
+ marginRight,
4248
+ marginLeft,
4241
4249
  paddingBottom,
4242
4250
  paddingRight,
4243
4251
  paddingTop,
@@ -4267,7 +4275,7 @@ function Combobox({
4267
4275
  },
4268
4276
  state2
4269
4277
  );
4270
- return /* @__PURE__ */ React49__default.createElement(FormControl, null, /* @__PURE__ */ React49__default.createElement(
4278
+ return /* @__PURE__ */ React49__default.createElement(React49__default.Fragment, null, /* @__PURE__ */ React49__default.createElement(
4271
4279
  Input,
4272
4280
  {
4273
4281
  ...inputProps,
@@ -4280,6 +4288,8 @@ function Combobox({
4280
4288
  borderTopRightRadius,
4281
4289
  marginBottom,
4282
4290
  marginTop,
4291
+ marginRight,
4292
+ marginLeft,
4283
4293
  marginX,
4284
4294
  marginY,
4285
4295
  paddingBottom,
@@ -4929,7 +4939,7 @@ var texts13 = createTexts({
4929
4939
  sv: "Telefonnummer"
4930
4940
  }
4931
4941
  });
4932
- var LazyCountryCodeSelect = React49__default.lazy(() => import('./CountryCodeSelect-FDAGWNSZ.mjs'));
4942
+ var LazyCountryCodeSelect = React49__default.lazy(() => import('./CountryCodeSelect-GFQIGSFV.mjs'));
4933
4943
  var Radio = forwardRef((props, ref) => {
4934
4944
  return /* @__PURE__ */ React49__default.createElement(Radio$1, { ...props, ref });
4935
4945
  });
package/dist/index.d.ts CHANGED
@@ -654,7 +654,7 @@ type AutosuggestProps<T> = {
654
654
  * Defaults to "input"
655
655
  */
656
656
  menuTrigger?: ComboboxProps<T>["menuTrigger"];
657
- } & Pick<InputProps, "marginTop" | "marginBottom" | "marginY" | "marginX" | "paddingTop" | "paddingBottom" | "paddingLeft" | "paddingRight" | "paddingY" | "paddingX" | "leftIcon" | "rightIcon" | "borderTopRightRadius" | "borderTopLeftRadius" | "borderBottomRightRadius" | "borderBottomLeftRadius" | "onFocus">;
657
+ } & Pick<InputProps, "marginTop" | "marginBottom" | "marginRight" | "marginLeft" | "marginY" | "marginX" | "paddingTop" | "paddingBottom" | "paddingLeft" | "paddingRight" | "paddingY" | "paddingX" | "leftIcon" | "rightIcon" | "borderTopRightRadius" | "borderTopLeftRadius" | "borderBottomRightRadius" | "borderBottomLeftRadius" | "onFocus">;
658
658
  /**
659
659
  * A component that provides an autocomplete search field with suggestions.
660
660
  *
@@ -685,8 +685,30 @@ type AutosuggestProps<T> = {
685
685
  * );
686
686
  * };
687
687
  * ```
688
+ *
689
+ * The `fetcher` function can be any function that returns an iterable of items. This means that you can use any API library you want, as long as it returns an iterable of items.
690
+ *
691
+ * The items need to have a `key` property, which is used to identify the item. The `key` property can be any type, but it needs to be unique for each item.
692
+ *
693
+ * ```tsx
694
+ * [{ key: 'some-key', ...}, { key: 'some-other-key', ... }]
695
+ * ```
696
+ *
697
+ * You can also return a set of nested items, which will be rendered as a sub-list (or section). This is useful if you want to group your items. These items need to have a title prop (for labelling the section), as well as a `children` prop, which in turn will contain an iterable of items:
698
+ *
699
+ * ```tsx
700
+ * [
701
+ * {
702
+ * title: 'The title of the section',
703
+ * children: [{ key: 'some-key', ... }]
704
+ * },
705
+ * {...}
706
+ * ]
707
+ * ```
708
+ *
709
+ * The `onSelectionChanged` will return the correct `item` (the one with the matching `key`), even if the item is in a sub-list.
688
710
  */
689
- declare function Autosuggest<T extends object>({ label, fetcher, children, onSelectionChange, ...props }: AutosuggestProps<T>): React__default.JSX.Element;
711
+ declare function Autosuggest<T extends object>({ label, fetcher, onSelectionChange, ...props }: AutosuggestProps<T>): React__default.JSX.Element;
690
712
 
691
713
  type CardSelectProps = BoxProps & {
692
714
  /** The design of the trigger button.
@@ -823,7 +845,7 @@ type ComboboxProps<T> = AriaComboBoxProps<T> & {
823
845
  label: string;
824
846
  /** Whether or not the combobox is waiting for new suggestions */
825
847
  isLoading?: boolean;
826
- } & Pick<InputProps, "marginTop" | "marginBottom" | "marginY" | "marginX" | "paddingTop" | "paddingBottom" | "paddingLeft" | "paddingRight" | "paddingY" | "paddingX" | "leftIcon" | "rightIcon" | "borderTopRightRadius" | "borderTopLeftRadius" | "borderBottomRightRadius" | "borderBottomLeftRadius" | "onFocus">;
848
+ } & Pick<InputProps, "marginTop" | "marginBottom" | "marginRight" | "marginLeft" | "marginY" | "marginX" | "paddingTop" | "paddingBottom" | "paddingLeft" | "paddingRight" | "paddingY" | "paddingX" | "leftIcon" | "rightIcon" | "borderTopRightRadius" | "borderTopLeftRadius" | "borderBottomRightRadius" | "borderBottomLeftRadius" | "onFocus">;
827
849
  /**
828
850
  * A combobox is a combination of an input and a list of suggestions.
829
851
  *
@@ -847,7 +869,7 @@ type ComboboxProps<T> = AriaComboBoxProps<T> & {
847
869
  * </Combobox>
848
870
  * ```
849
871
  */
850
- declare function Combobox<T extends object>({ label, isLoading, leftIcon, rightIcon, borderBottomLeftRadius, borderBottomRightRadius, borderTopLeftRadius, borderTopRightRadius, marginBottom, marginTop, marginX, marginY, paddingBottom, paddingRight, paddingTop, paddingLeft, paddingX, paddingY, onFocus, ...rest }: ComboboxProps<T>): React__default.JSX.Element;
872
+ declare function Combobox<T extends object>({ label, isLoading, leftIcon, rightIcon, borderBottomLeftRadius, borderBottomRightRadius, borderTopLeftRadius, borderTopRightRadius, marginBottom, marginTop, marginX, marginY, marginRight, marginLeft, paddingBottom, paddingRight, paddingTop, paddingLeft, paddingX, paddingY, onFocus, ...rest }: ComboboxProps<T>): React__default.JSX.Element;
851
873
 
852
874
  type FormControlProps = FormControlProps$1;
853
875
  declare const FormControl: _chakra_ui_system_dist_system_types.ComponentWithAs<"div", FormControlProps$1>;
package/dist/index.js CHANGED
@@ -3753,7 +3753,6 @@ var init_AttachedInputs = __esm({
3753
3753
  function Autosuggest({
3754
3754
  label,
3755
3755
  fetcher,
3756
- children,
3757
3756
  onSelectionChange,
3758
3757
  ...props
3759
3758
  }) {
@@ -3768,7 +3767,15 @@ function Autosuggest({
3768
3767
  if (!onSelectionChange) {
3769
3768
  return;
3770
3769
  }
3771
- return onSelectionChange(list2.getItem(key));
3770
+ let selectedItem = list2.getItem(key);
3771
+ if (!selectedItem) {
3772
+ selectedItem = list2.items.flatMap(
3773
+ (item) => "children" in item && Array.isArray(item.children) ? item.children : []
3774
+ ).find((child) => child.key === key);
3775
+ }
3776
+ if (selectedItem) {
3777
+ onSelectionChange(selectedItem);
3778
+ }
3772
3779
  };
3773
3780
  return /* @__PURE__ */ React49__namespace.default.createElement(
3774
3781
  Combobox,
@@ -3780,8 +3787,7 @@ function Autosuggest({
3780
3787
  onSelectionChange: handleSelectionChange,
3781
3788
  isLoading: list2.isLoading,
3782
3789
  ...props
3783
- },
3784
- children
3790
+ }
3785
3791
  );
3786
3792
  }
3787
3793
  var init_Autosuggest = __esm({
@@ -4753,6 +4759,8 @@ function Combobox({
4753
4759
  marginTop,
4754
4760
  marginX,
4755
4761
  marginY,
4762
+ marginRight,
4763
+ marginLeft,
4756
4764
  paddingBottom,
4757
4765
  paddingRight,
4758
4766
  paddingTop,
@@ -4782,7 +4790,7 @@ function Combobox({
4782
4790
  },
4783
4791
  state2
4784
4792
  );
4785
- return /* @__PURE__ */ React49__namespace.default.createElement(exports.FormControl, null, /* @__PURE__ */ React49__namespace.default.createElement(
4793
+ return /* @__PURE__ */ React49__namespace.default.createElement(React49__namespace.default.Fragment, null, /* @__PURE__ */ React49__namespace.default.createElement(
4786
4794
  exports.Input,
4787
4795
  {
4788
4796
  ...inputProps,
@@ -4795,6 +4803,8 @@ function Combobox({
4795
4803
  borderTopRightRadius,
4796
4804
  marginBottom,
4797
4805
  marginTop,
4806
+ marginRight,
4807
+ marginLeft,
4798
4808
  marginX,
4799
4809
  marginY,
4800
4810
  paddingBottom,
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- export { Accordion, AccordionButton, AccordionIcon, AccordionItem, AccordionPanel, AttachedInputs, Autosuggest, Badge, Box, Button, ButtonGroup, Card, CardSelect, Center, Checkbox, CheckboxGroup, ChoiceChip, ClosableAlert, CloseButton, Code, Collapse, ColorInlineLoader, ColorSpinner, Combobox, Container, ContentLoader, DarkFullScreenLoader, DarkInlineLoader, DarkMode, DarkSpinner, DatePicker, DateRangePicker, Divider, Drawer, DrawerBody, DrawerCloseButton, DrawerContent, DrawerFooter, ModalHeader as DrawerHeader, DrawerOverlay, Expandable, ExpandableAlert, ExpandableItem, Fade, Flex, FloatingActionButton, FormControl, FormErrorMessage, FormHelperText, FormLabel, Grid, GridItem, HStack, Heading, IconButton, Image, Img, InfoSelect, InfoTag, Input, InputGroup, InputLeftElement, InputRightElement, Item, ItemDescription, ItemLabel, JumpButton, Language, LanguageProvider, LightFullScreenLoader, LightInlineLoader, LightMode, LightSpinner, LineIcon, ListBox, Modal, ModalBody, ModalCloseButton, ModalContent, ModalFooter, ModalHeader, ModalOverlay, NativeSelect, NumericStepper, PasswordInput, PhoneNumberInput, PlayPauseButton, Popover, PopoverAnchor, PopoverArrow, PopoverBody, PopoverCloseButton, PopoverContent, PopoverFooter, PopoverHeader, PopoverTrigger, PopoverWizardBody, ProgressBar, ProgressLoader, Radio, RadioGroup, ScaleFade, SearchInput, Section, SelectItem, SelectItemDescription, SelectItemLabel, SimpleDrawer, SimpleGrid, SimplePopover, Skeleton, SkeletonCircle, SkeletonText, SkipButton, Slide, SlideFade, Spacer, SporProvider, Stack, StaticAlert, Stepper, StepperStep, Switch, Tab, TabList, TabPanel, TabPanels, Table, TableCaption, Tabs, Tbody, Td, Text, TextLink, Textarea, Tfoot, Th, Thead, Time, TimePicker, Tr, TravelTag, VStack, VyLogo, WizardPopover, Wrap, WrapItem, createTexts, extendTheme, fontFaces, theme, tokens, useBreakpointValue, useClipboard, useColorMode, useColorModePreference, useColorModeValue, useControllableProp, useDisclosure, useMediaQuery, useMergeRefs, useOutsideClick, usePrefersReducedMotion, useTheme, useToast, useToken, useTranslation } from './chunk-C3DS6BFF.mjs';
1
+ export { Accordion, AccordionButton, AccordionIcon, AccordionItem, AccordionPanel, AttachedInputs, Autosuggest, Badge, Box, Button, ButtonGroup, Card, CardSelect, Center, Checkbox, CheckboxGroup, ChoiceChip, ClosableAlert, CloseButton, Code, Collapse, ColorInlineLoader, ColorSpinner, Combobox, Container, ContentLoader, DarkFullScreenLoader, DarkInlineLoader, DarkMode, DarkSpinner, DatePicker, DateRangePicker, Divider, Drawer, DrawerBody, DrawerCloseButton, DrawerContent, DrawerFooter, ModalHeader as DrawerHeader, DrawerOverlay, Expandable, ExpandableAlert, ExpandableItem, Fade, Flex, FloatingActionButton, FormControl, FormErrorMessage, FormHelperText, FormLabel, Grid, GridItem, HStack, Heading, IconButton, Image, Img, InfoSelect, InfoTag, Input, InputGroup, InputLeftElement, InputRightElement, Item, ItemDescription, ItemLabel, JumpButton, Language, LanguageProvider, LightFullScreenLoader, LightInlineLoader, LightMode, LightSpinner, LineIcon, ListBox, Modal, ModalBody, ModalCloseButton, ModalContent, ModalFooter, ModalHeader, ModalOverlay, NativeSelect, NumericStepper, PasswordInput, PhoneNumberInput, PlayPauseButton, Popover, PopoverAnchor, PopoverArrow, PopoverBody, PopoverCloseButton, PopoverContent, PopoverFooter, PopoverHeader, PopoverTrigger, PopoverWizardBody, ProgressBar, ProgressLoader, Radio, RadioGroup, ScaleFade, SearchInput, Section, SelectItem, SelectItemDescription, SelectItemLabel, SimpleDrawer, SimpleGrid, SimplePopover, Skeleton, SkeletonCircle, SkeletonText, SkipButton, Slide, SlideFade, Spacer, SporProvider, Stack, StaticAlert, Stepper, StepperStep, Switch, Tab, TabList, TabPanel, TabPanels, Table, TableCaption, Tabs, Tbody, Td, Text, TextLink, Textarea, Tfoot, Th, Thead, Time, TimePicker, Tr, TravelTag, VStack, VyLogo, WizardPopover, Wrap, WrapItem, createTexts, extendTheme, fontFaces, theme, tokens, useBreakpointValue, useClipboard, useColorMode, useColorModePreference, useColorModeValue, useControllableProp, useDisclosure, useMediaQuery, useMergeRefs, useOutsideClick, usePrefersReducedMotion, useTheme, useToast, useToken, useTranslation } from './chunk-Z3I6W6PC.mjs';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vygruppen/spor-react",
3
- "version": "2.4.2",
3
+ "version": "2.4.3",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.mjs",
6
6
  "types": "./dist/index.d.ts",
@@ -53,6 +53,8 @@ type AutosuggestProps<T> = {
53
53
  InputProps,
54
54
  | "marginTop"
55
55
  | "marginBottom"
56
+ | "marginRight"
57
+ | "marginLeft"
56
58
  | "marginY"
57
59
  | "marginX"
58
60
  | "paddingTop"
@@ -99,11 +101,32 @@ type AutosuggestProps<T> = {
99
101
  * );
100
102
  * };
101
103
  * ```
104
+ *
105
+ * The `fetcher` function can be any function that returns an iterable of items. This means that you can use any API library you want, as long as it returns an iterable of items.
106
+ *
107
+ * The items need to have a `key` property, which is used to identify the item. The `key` property can be any type, but it needs to be unique for each item.
108
+ *
109
+ * ```tsx
110
+ * [{ key: 'some-key', ...}, { key: 'some-other-key', ... }]
111
+ * ```
112
+ *
113
+ * You can also return a set of nested items, which will be rendered as a sub-list (or section). This is useful if you want to group your items. These items need to have a title prop (for labelling the section), as well as a `children` prop, which in turn will contain an iterable of items:
114
+ *
115
+ * ```tsx
116
+ * [
117
+ * {
118
+ * title: 'The title of the section',
119
+ * children: [{ key: 'some-key', ... }]
120
+ * },
121
+ * {...}
122
+ * ]
123
+ * ```
124
+ *
125
+ * The `onSelectionChanged` will return the correct `item` (the one with the matching `key`), even if the item is in a sub-list.
102
126
  */
103
127
  export function Autosuggest<T extends object>({
104
128
  label,
105
129
  fetcher,
106
- children,
107
130
  onSelectionChange,
108
131
  ...props
109
132
  }: AutosuggestProps<T>) {
@@ -114,11 +137,26 @@ export function Autosuggest<T extends object>({
114
137
  };
115
138
  },
116
139
  });
140
+
117
141
  const handleSelectionChange = (key: React.Key) => {
118
142
  if (!onSelectionChange) {
119
143
  return;
120
144
  }
121
- return onSelectionChange(list.getItem(key));
145
+
146
+ let selectedItem = list.getItem(key);
147
+ if (!selectedItem) {
148
+ // If the item is not in the list, it might be in a sub-list
149
+ selectedItem = list.items
150
+ .flatMap((item) =>
151
+ "children" in item && Array.isArray(item.children)
152
+ ? item.children
153
+ : []
154
+ )
155
+ .find((child) => child.key === key);
156
+ }
157
+ if (selectedItem) {
158
+ onSelectionChange(selectedItem);
159
+ }
122
160
  };
123
161
  return (
124
162
  <Combobox
@@ -129,8 +167,6 @@ export function Autosuggest<T extends object>({
129
167
  onSelectionChange={handleSelectionChange}
130
168
  isLoading={list.isLoading}
131
169
  {...props}
132
- >
133
- {children}
134
- </Combobox>
170
+ />
135
171
  );
136
172
  }
@@ -1,7 +1,7 @@
1
1
  import React, { useRef } from "react";
2
2
  import { AriaComboBoxProps, useComboBox, useFilter } from "react-aria";
3
3
  import { useComboBoxState } from "react-stately";
4
- import { ColorSpinner, FormControl, Input, InputProps, ListBox } from "..";
4
+ import { ColorSpinner, Input, InputProps, ListBox } from "..";
5
5
  import { Popover } from "./Popover";
6
6
 
7
7
  export type ComboboxProps<T> = AriaComboBoxProps<T> & {
@@ -13,6 +13,8 @@ export type ComboboxProps<T> = AriaComboBoxProps<T> & {
13
13
  InputProps,
14
14
  | "marginTop"
15
15
  | "marginBottom"
16
+ | "marginRight"
17
+ | "marginLeft"
16
18
  | "marginY"
17
19
  | "marginX"
18
20
  | "paddingTop"
@@ -65,6 +67,8 @@ export function Combobox<T extends object>({
65
67
  marginTop,
66
68
  marginX,
67
69
  marginY,
70
+ marginRight,
71
+ marginLeft,
68
72
  paddingBottom,
69
73
  paddingRight,
70
74
  paddingTop,
@@ -98,7 +102,7 @@ export function Combobox<T extends object>({
98
102
  );
99
103
 
100
104
  return (
101
- <FormControl>
105
+ <>
102
106
  <Input
103
107
  {...inputProps}
104
108
  ref={inputRef}
@@ -110,6 +114,8 @@ export function Combobox<T extends object>({
110
114
  borderTopRightRadius={borderTopRightRadius}
111
115
  marginBottom={marginBottom}
112
116
  marginTop={marginTop}
117
+ marginRight={marginRight}
118
+ marginLeft={marginLeft}
113
119
  marginX={marginX}
114
120
  marginY={marginY}
115
121
  paddingBottom={paddingBottom}
@@ -153,6 +159,6 @@ export function Combobox<T extends object>({
153
159
  </ListBox>
154
160
  </Popover>
155
161
  )}
156
- </FormControl>
162
+ </>
157
163
  );
158
164
  }