@vygruppen/spor-react 2.5.1 → 2.5.2

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.5.1 build
2
+ > @vygruppen/spor-react@2.5.2 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-QEKFPZKV.mjs".
14
- CJS dist/index.js 895.50 KB
15
- CJS ⚡️ Build success in 4556ms
13
+ "toTime" is imported from external module "@internationalized/date" but never used in "dist/chunk-PFCQ55ZF.mjs".
14
+ CJS dist/index.js 896.29 KB
15
+ CJS ⚡️ Build success in 6499ms
16
16
  ESM dist/index.mjs 2.06 KB
17
- ESM dist/CountryCodeSelect-JL2OVNXX.mjs 351.67 KB
18
- ESM dist/chunk-QEKFPZKV.mjs 415.80 KB
19
- ESM ⚡️ Build success in 4557ms
20
- DTS ⚡️ Build success in 17324ms
21
- DTS dist/index.d.ts 259.33 KB
17
+ ESM dist/CountryCodeSelect-KO3QKE4X.mjs 351.67 KB
18
+ ESM dist/chunk-PFCQ55ZF.mjs 416.47 KB
19
+ ESM ⚡️ Build success in 6500ms
20
+ DTS ⚡️ Build success in 24524ms
21
+ DTS dist/index.d.ts 259.37 KB
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @vygruppen/spor-react
2
2
 
3
+ ## 2.5.2
4
+
5
+ ### Patch Changes
6
+
7
+ - a884fea5: Combobox: Make the width of the attached listbox never outgrow its input field
8
+
3
9
  ## 2.5.1
4
10
 
5
11
  ### Patch Changes
@@ -1,4 +1,4 @@
1
- import { createTexts, useTranslation, InfoSelect, SelectItem } from './chunk-QEKFPZKV.mjs';
1
+ import { createTexts, useTranslation, InfoSelect, SelectItem } from './chunk-PFCQ55ZF.mjs';
2
2
  import React from 'react';
3
3
 
4
4
  // ../../node_modules/awesome-phonenumber/index-esm.mjs
@@ -4219,6 +4219,7 @@ function Combobox({
4219
4219
  const inputRef = useRef(null);
4220
4220
  const listBoxRef = useRef(null);
4221
4221
  const popoverRef = useRef(null);
4222
+ const inputWidth = useInputWidth(inputRef);
4222
4223
  const state2 = useComboBoxState({
4223
4224
  ...rest,
4224
4225
  defaultFilter: contains2,
@@ -4288,12 +4289,36 @@ function Combobox({
4288
4289
  ...listBoxProps,
4289
4290
  state: state2,
4290
4291
  listBoxRef,
4291
- emptyContent
4292
+ emptyContent,
4293
+ maxWidth: inputWidth
4292
4294
  },
4293
4295
  rest.children
4294
4296
  )
4295
4297
  ));
4296
4298
  }
4299
+ var useInputWidth = (inputRef) => {
4300
+ const [inputWidth, setInputWidth] = useState("auto");
4301
+ useEffect(() => {
4302
+ const onResize = debounce(() => {
4303
+ if (inputRef.current) {
4304
+ setInputWidth(`${inputRef.current.offsetWidth}px`);
4305
+ }
4306
+ }, 67);
4307
+ window.addEventListener("resize", onResize);
4308
+ return () => window.removeEventListener("resize", onResize);
4309
+ }, []);
4310
+ return inputWidth;
4311
+ };
4312
+ var debounce = (fn, ms = 100) => {
4313
+ let timer;
4314
+ return () => {
4315
+ clearTimeout(timer);
4316
+ timer = setTimeout(() => {
4317
+ timer = null;
4318
+ fn();
4319
+ }, ms);
4320
+ };
4321
+ };
4297
4322
  var FormControl = forwardRef((props, ref) => {
4298
4323
  return /* @__PURE__ */ React49__default.createElement(FormControl$1, { ...props, ref });
4299
4324
  });
@@ -4363,6 +4388,7 @@ function ListBox({
4363
4388
  isLoading,
4364
4389
  listBoxRef,
4365
4390
  state: state2,
4391
+ maxWidth,
4366
4392
  ...props
4367
4393
  }) {
4368
4394
  const { listBoxProps } = useListBox(props, state2, listBoxRef);
@@ -4373,7 +4399,8 @@ function ListBox({
4373
4399
  ...listBoxProps,
4374
4400
  ref: listBoxRef,
4375
4401
  sx: styles2.container,
4376
- "aria-busy": isLoading
4402
+ "aria-busy": isLoading,
4403
+ maxWidth
4377
4404
  },
4378
4405
  state2.collection.size === 0 && props.emptyContent,
4379
4406
  Array.from(state2.collection).map(
@@ -4901,7 +4928,7 @@ var texts13 = createTexts({
4901
4928
  sv: "Telefonnummer"
4902
4929
  }
4903
4930
  });
4904
- var LazyCountryCodeSelect = React49__default.lazy(() => import('./CountryCodeSelect-JL2OVNXX.mjs'));
4931
+ var LazyCountryCodeSelect = React49__default.lazy(() => import('./CountryCodeSelect-KO3QKE4X.mjs'));
4905
4932
  var Radio = forwardRef((props, ref) => {
4906
4933
  return /* @__PURE__ */ React49__default.createElement(Radio$1, { ...props, ref });
4907
4934
  });
package/dist/index.d.ts CHANGED
@@ -1013,6 +1013,7 @@ type ListBoxProps<T> = AriaListBoxProps<T> & Omit<BoxProps, "filter" | "autoFocu
1013
1013
  state: ListState<T> | SelectState<T>;
1014
1014
  /** UI to render if the collection is empty */
1015
1015
  emptyContent?: React__default.ReactNode;
1016
+ maxWidth?: BoxProps["maxWidth"];
1016
1017
  };
1017
1018
  /**
1018
1019
  * A component that renders a list box with selectable options.
@@ -1048,7 +1049,7 @@ type ListBoxProps<T> = AriaListBoxProps<T> & Omit<BoxProps, "filter" | "autoFocu
1048
1049
  * );
1049
1050
  * ```
1050
1051
  */
1051
- declare function ListBox<T extends object>({ isLoading, listBoxRef, state, ...props }: ListBoxProps<T>): React__default.JSX.Element;
1052
+ declare function ListBox<T extends object>({ isLoading, listBoxRef, state, maxWidth, ...props }: ListBoxProps<T>): React__default.JSX.Element;
1052
1053
  /**
1053
1054
  * Renders a label for a listbox item.
1054
1055
  *
package/dist/index.js CHANGED
@@ -4729,6 +4729,7 @@ function Combobox({
4729
4729
  const inputRef = React49.useRef(null);
4730
4730
  const listBoxRef = React49.useRef(null);
4731
4731
  const popoverRef = React49.useRef(null);
4732
+ const inputWidth = useInputWidth(inputRef);
4732
4733
  const state2 = reactStately.useComboBoxState({
4733
4734
  ...rest,
4734
4735
  defaultFilter: contains2,
@@ -4798,16 +4799,41 @@ function Combobox({
4798
4799
  ...listBoxProps,
4799
4800
  state: state2,
4800
4801
  listBoxRef,
4801
- emptyContent
4802
+ emptyContent,
4803
+ maxWidth: inputWidth
4802
4804
  },
4803
4805
  rest.children
4804
4806
  )
4805
4807
  ));
4806
4808
  }
4809
+ var useInputWidth, debounce;
4807
4810
  var init_Combobox = __esm({
4808
4811
  "src/input/Combobox.tsx"() {
4809
4812
  init_src();
4810
4813
  init_Popover();
4814
+ useInputWidth = (inputRef) => {
4815
+ const [inputWidth, setInputWidth] = React49.useState("auto");
4816
+ React49.useEffect(() => {
4817
+ const onResize = debounce(() => {
4818
+ if (inputRef.current) {
4819
+ setInputWidth(`${inputRef.current.offsetWidth}px`);
4820
+ }
4821
+ }, 67);
4822
+ window.addEventListener("resize", onResize);
4823
+ return () => window.removeEventListener("resize", onResize);
4824
+ }, []);
4825
+ return inputWidth;
4826
+ };
4827
+ debounce = (fn, ms = 100) => {
4828
+ let timer;
4829
+ return () => {
4830
+ clearTimeout(timer);
4831
+ timer = setTimeout(() => {
4832
+ timer = null;
4833
+ fn();
4834
+ }, ms);
4835
+ };
4836
+ };
4811
4837
  }
4812
4838
  });
4813
4839
  exports.FormControl = void 0;
@@ -4893,6 +4919,7 @@ function ListBox({
4893
4919
  isLoading,
4894
4920
  listBoxRef,
4895
4921
  state: state2,
4922
+ maxWidth,
4896
4923
  ...props
4897
4924
  }) {
4898
4925
  const { listBoxProps } = reactAria.useListBox(props, state2, listBoxRef);
@@ -4903,7 +4930,8 @@ function ListBox({
4903
4930
  ...listBoxProps,
4904
4931
  ref: listBoxRef,
4905
4932
  sx: styles2.container,
4906
- "aria-busy": isLoading
4933
+ "aria-busy": isLoading,
4934
+ maxWidth
4907
4935
  },
4908
4936
  state2.collection.size === 0 && props.emptyContent,
4909
4937
  Array.from(state2.collection).map(
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- export { Accordion, AccordionButton, AccordionIcon, AccordionItem, AccordionPanel, AttachedInputs, 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-QEKFPZKV.mjs';
1
+ export { Accordion, AccordionButton, AccordionIcon, AccordionItem, AccordionPanel, AttachedInputs, 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-PFCQ55ZF.mjs';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vygruppen/spor-react",
3
- "version": "2.5.1",
3
+ "version": "2.5.2",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.mjs",
6
6
  "types": "./dist/index.d.ts",
@@ -1,4 +1,4 @@
1
- import React, { useRef } from "react";
1
+ import React, { useEffect, useRef, useState } from "react";
2
2
  import { AriaComboBoxProps, useComboBox, useFilter } from "react-aria";
3
3
  import { useComboBoxState } from "react-stately";
4
4
  import { ColorSpinner, Input, InputProps, ListBox } from "..";
@@ -82,10 +82,12 @@ export function Combobox<T extends object>({
82
82
  }: ComboboxProps<T>) {
83
83
  const { contains } = useFilter({ sensitivity: "base" });
84
84
 
85
- const inputRef = useRef(null);
85
+ const inputRef = useRef<HTMLInputElement>(null);
86
86
  const listBoxRef = useRef(null);
87
87
  const popoverRef = useRef(null);
88
88
 
89
+ const inputWidth = useInputWidth(inputRef);
90
+
89
91
  const state = useComboBoxState({
90
92
  ...rest,
91
93
  defaultFilter: contains,
@@ -153,7 +155,7 @@ export function Combobox<T extends object>({
153
155
  {state.isOpen && !isLoading && (
154
156
  <Popover
155
157
  state={state}
156
- triggerRef={inputRef}
158
+ triggerRef={inputRef as any}
157
159
  ref={popoverRef}
158
160
  placement="bottom start"
159
161
  >
@@ -162,6 +164,7 @@ export function Combobox<T extends object>({
162
164
  state={state}
163
165
  listBoxRef={listBoxRef}
164
166
  emptyContent={emptyContent}
167
+ maxWidth={inputWidth}
165
168
  >
166
169
  {rest.children}
167
170
  </ListBox>
@@ -170,3 +173,28 @@ export function Combobox<T extends object>({
170
173
  </>
171
174
  );
172
175
  }
176
+
177
+ const useInputWidth = (inputRef: React.RefObject<HTMLInputElement>) => {
178
+ const [inputWidth, setInputWidth] = useState("auto");
179
+ useEffect(() => {
180
+ const onResize = debounce(() => {
181
+ if (inputRef.current) {
182
+ setInputWidth(`${inputRef.current.offsetWidth}px`);
183
+ }
184
+ }, 67);
185
+ window.addEventListener("resize", onResize);
186
+ return () => window.removeEventListener("resize", onResize);
187
+ }, []);
188
+ return inputWidth;
189
+ };
190
+
191
+ const debounce = (fn: () => void, ms = 100) => {
192
+ let timer: any;
193
+ return () => {
194
+ clearTimeout(timer);
195
+ timer = setTimeout(() => {
196
+ timer = null;
197
+ fn();
198
+ }, ms);
199
+ };
200
+ };
@@ -30,6 +30,7 @@ type ListBoxProps<T> = AriaListBoxProps<T> &
30
30
  state: ListState<T> | SelectState<T>;
31
31
  /** UI to render if the collection is empty */
32
32
  emptyContent?: React.ReactNode;
33
+ maxWidth?: BoxProps["maxWidth"];
33
34
  };
34
35
 
35
36
  /**
@@ -70,6 +71,7 @@ export function ListBox<T extends object>({
70
71
  isLoading,
71
72
  listBoxRef,
72
73
  state,
74
+ maxWidth,
73
75
  ...props
74
76
  }: ListBoxProps<T>) {
75
77
  const { listBoxProps } = useListBox(props, state, listBoxRef);
@@ -81,6 +83,7 @@ export function ListBox<T extends object>({
81
83
  ref={listBoxRef}
82
84
  sx={styles.container}
83
85
  aria-busy={isLoading}
86
+ maxWidth={maxWidth}
84
87
  >
85
88
  {state.collection.size === 0 && props.emptyContent}
86
89
  {Array.from(state.collection).map((item) =>