@vygruppen/spor-react 2.3.4 → 2.4.1

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.
package/dist/index.d.ts CHANGED
@@ -8,10 +8,11 @@ import * as React from 'react';
8
8
  import React__default, { ChangeEvent } from 'react';
9
9
  import { DateValue } from '@internationalized/date';
10
10
  export { Time } from '@internationalized/date';
11
- import { AriaDatePickerProps, AriaDateRangePickerProps, AriaPositionProps, AriaListBoxOptions } from 'react-aria';
11
+ import { AriaDatePickerProps, AriaDateRangePickerProps, AriaPositionProps, AriaComboBoxProps, AriaListBoxProps } from 'react-aria';
12
12
  import { TimeValue } from '@react-types/datepicker';
13
- import { SelectState, ListState } from 'react-stately';
14
- export { Item as SelectItem } from 'react-stately';
13
+ import * as react_stately from 'react-stately';
14
+ import { ListState, SelectState } from 'react-stately';
15
+ export { Item, Section } from 'react-stately';
15
16
  import * as _chakra_ui_theme_tools_dist_component from '@chakra-ui/theme-tools/dist/component';
16
17
  import * as _chakra_ui_styled_system from '@chakra-ui/styled-system';
17
18
 
@@ -606,6 +607,80 @@ type AttachedInputsProps = FlexProps;
606
607
  */
607
608
  declare const AttachedInputs: ({ flexDirection, ...rest }: AttachedInputsProps) => React__default.JSX.Element;
608
609
 
610
+ type AutosuggestProps<T> = {
611
+ /** The label of the search field */
612
+ label: string;
613
+ /**
614
+ * The function responsible for fetching new suggestion items, based on the query.
615
+ *
616
+ * This will typically be an API call to a backend service.
617
+ *
618
+ * @example
619
+ * ```tsx
620
+ * const fetcher = async (query?: string) => {
621
+ * const response = await fetch(`https://some.api.com/filter=${query}`);
622
+ * const json = await response.json();
623
+ * return json;
624
+ * };
625
+ * ```
626
+ * */
627
+ fetcher: (query?: string) => Promise<Iterable<T>>;
628
+ /**
629
+ * A render function that receives each item, and returns the UI for each item in the list.
630
+ *
631
+ * @example
632
+ * ```tsx
633
+ * <Autosuggest {...otherProps}>
634
+ * {(user) => (
635
+ * <Item key={user.id} textValue={user.fullName}>
636
+ * <ItemLabel>{user.fullName}</ItemLabel>
637
+ * <ItemDescription>{user.asl}</ItemDescription>
638
+ * </Item>
639
+ * )}
640
+ * </Autosuggest>
641
+ * ```
642
+ *
643
+ * You technically don't need to use the `<SelectItemLabel />` and `<SelectItemDescription />` components, but they are recommended to improve the accessibility of the search results. You can style them however you want, so there should never be a reason not to include at least the `<SelectItemLabel />` component. But who's judging?
644
+ * */
645
+ children: ComboboxProps<T>["children"];
646
+ /**
647
+ * Callback for when the selection changes.
648
+ */
649
+ onSelectionChange?: ComboboxProps<T>["onSelectionChange"];
650
+ } & Pick<InputProps, "marginTop" | "marginBottom" | "marginY" | "marginX" | "paddingTop" | "paddingBottom" | "paddingLeft" | "paddingRight" | "paddingY" | "paddingX" | "leftIcon" | "rightIcon" | "borderTopRightRadius" | "borderTopLeftRadius" | "borderBottomRightRadius" | "borderBottomLeftRadius" | "onFocus">;
651
+ /**
652
+ * A component that provides an autocomplete search field with suggestions.
653
+ *
654
+ * This component requires a `fetcher` prop, which is a function that receives a query string, and returns a list of items that match the query.
655
+ *
656
+ * @example
657
+ * ```tsx
658
+ * const fetcher = async (query?: string) => {
659
+ * const response = await fetch(`https://some.api.vy.no/filter=${query}`);
660
+ * const json = await response.json();
661
+ * return json;
662
+ * };
663
+ *
664
+ * const Example = () => {
665
+ * return (
666
+ * <Autosuggest
667
+ * label="Search for users"
668
+ * fetcher={fetcher}
669
+ * onSelectionChange={(item) => console.log(item)}
670
+ * >
671
+ * {(user) => (
672
+ * <Item key={user.id} textValue={user.fullName}>
673
+ * <ItemLabel>{user.fullName}</ItemLabel>
674
+ * <ItemDescription>{user.asl}</ItemDescription>
675
+ * </Item>
676
+ * )}
677
+ * </Autosuggest>
678
+ * );
679
+ * };
680
+ * ```
681
+ */
682
+ declare function Autosuggest<T extends object>({ label, fetcher, children, onSelectionChange, ...boxProps }: AutosuggestProps<T>): React__default.JSX.Element;
683
+
609
684
  type CardSelectProps = BoxProps & {
610
685
  /** The design of the trigger button.
611
686
  *
@@ -736,47 +811,36 @@ type ChoiceChipProps = {
736
811
  */
737
812
  declare const ChoiceChip: _chakra_ui_system_dist_system_types.ComponentWithAs<_chakra_ui_system_dist_system_types.As, ChoiceChipProps>;
738
813
 
739
- type NumericStepperProps = {
740
- /** The name of the input field */
741
- name?: string;
742
- /** The current value */
743
- value?: number;
744
- /** A default value, if uncontrolled */
745
- defaultValue?: number;
746
- /** Callback for when the value changes */
747
- onChange?: (value: number) => void;
748
- /** Optional minimum value. Defaults to 0 */
749
- minValue?: number;
750
- /** Optional maximum value. Defaults to 99 */
751
- maxValue?: number;
752
- /** Whether the stepper is disabled or not */
753
- isDisabled?: boolean;
754
- } & Omit<BoxProps, "onChange">;
755
- /** A simple stepper component for integer values
756
- *
757
- * Allows you to choose a given integer value, like for example the number of
758
- * adults on your journey.
759
- *
760
- * ```tsx
761
- * <NumericStepper value={value} onChange={setValue} />
762
- * ```
763
- *
764
- * You can also set a minimum and/or maximum value:
765
- *
766
- * ```tsx
767
- * <NumericStepper value={value} onChange={setValue} minValue={1} maxValue={10} />
768
- * ```
814
+ type ComboboxProps<T> = AriaComboBoxProps<T> & {
815
+ /** The label of the combobox */
816
+ label: string;
817
+ /** Whether or not the combobox is waiting for new suggestions */
818
+ isLoading?: boolean;
819
+ } & Pick<InputProps, "marginTop" | "marginBottom" | "marginY" | "marginX" | "paddingTop" | "paddingBottom" | "paddingLeft" | "paddingRight" | "paddingY" | "paddingX" | "leftIcon" | "rightIcon" | "borderTopRightRadius" | "borderTopLeftRadius" | "borderBottomRightRadius" | "borderBottomLeftRadius" | "onFocus">;
820
+ /**
821
+ * A combobox is a combination of an input and a list of suggestions.
769
822
  *
770
- * You can use the NumericStepper inside of a FormControl component to get IDs etc linked up automatically:
823
+ * It is used to select a single item from a list of suggestions.
771
824
  *
825
+ * @example
772
826
  * ```tsx
773
- * <FormControl>
774
- * <FormLabel>Number of adults</FormLabel>
775
- * <NumericStepper />
776
- * </FormControl>
827
+ * <Combobox
828
+ * label="Choose a color"
829
+ * items={[
830
+ * { label: "Green", value: "green" },
831
+ * { label: "Blue", value: "blue" },
832
+ * { label: "Yellow", value: "yellow" },
833
+ * ]}
834
+ * >
835
+ * {(item) => (
836
+ * <Item key={item.value} value={item.value}>
837
+ * {item.label}
838
+ * </Item>
839
+ * )}
840
+ * </Combobox>
777
841
  * ```
778
842
  */
779
- declare function NumericStepper({ name: nameProp, id: idProp, value: valueProp, defaultValue, onChange: onChangeProp, minValue, maxValue, isDisabled, ...boxProps }: NumericStepperProps): React__default.JSX.Element;
843
+ 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;
780
844
 
781
845
  type FormControlProps = FormControlProps$1;
782
846
  declare const FormControl: _chakra_ui_system_dist_system_types.ComponentWithAs<"div", FormControlProps$1>;
@@ -817,7 +881,7 @@ declare const FormErrorMessage: ({ children, ...boxProps }: FormErrorMessageProp
817
881
  type FormLabelProps = FormLabelProps$1;
818
882
  declare const FormLabel: _chakra_ui_system_dist_system_types.ComponentWithAs<"label", FormLabelProps$1>;
819
883
 
820
- type InfoSelectProps<T> = {
884
+ type InfoSelectProps<T extends object> = {
821
885
  /**
822
886
  * Either a render function accepting an item, and returning a <SelectItem />,
823
887
  * or a list of <SelectItem />s.
@@ -845,7 +909,7 @@ type InfoSelectProps<T> = {
845
909
  * </Select>
846
910
  * ```
847
911
  **/
848
- children: React__default.ReactNode | ((item: T) => React__default.ReactNode);
912
+ children: React__default.ReactElement | ((item: T) => React__default.ReactElement);
849
913
  /**
850
914
  * The items to render
851
915
  *
@@ -941,18 +1005,16 @@ type InfoSelectProps<T> = {
941
1005
  * ]}
942
1006
  * >
943
1007
  * {(item) => (
944
- * <SelectItem key={item.key}>
1008
+ * <Item key={item.key}>
945
1009
  * {item.label}
946
- * </SelectItem>
1010
+ * </Item>
947
1011
  * )}
948
1012
  * </InfoSelect>
949
1013
  * ```
950
1014
  *
951
1015
  * @see https://spor.vy.no/komponenter/info-select
952
1016
  */
953
- declare function InfoSelect<T extends {
954
- key: string;
955
- }>({ placeholder, width, height, onChange, value, isLabelSrOnly, defaultValue, ...props }: InfoSelectProps<T>): React__default.JSX.Element;
1017
+ declare function InfoSelect<T extends object>({ placeholder, width, height, onChange, value, isLabelSrOnly, defaultValue, ...props }: InfoSelectProps<T>): React__default.JSX.Element;
956
1018
 
957
1019
  type InputProps = Exclude<InputProps$1, "variant" | "size"> & {
958
1020
  /** The input's label */
@@ -1011,33 +1073,72 @@ declare const InputLeftElement: _chakra_ui_system_dist_system_types.ComponentWit
1011
1073
  */
1012
1074
  declare const InputRightElement: _chakra_ui_system_dist_system_types.ComponentWithAs<"div", InputElementProps$1>;
1013
1075
 
1014
- type ListBoxProps = {
1015
- listBoxRef?: React__default.RefObject<HTMLUListElement>;
1016
- listBoxOptions: AriaListBoxOptions<unknown>;
1017
- state: SelectState<unknown> | ListState<unknown>;
1018
- } & BoxProps;
1076
+ /** @deprecated use Item instead */
1077
+ declare const SelectItem: <T>(props: react_stately.ItemProps<T>) => JSX.Element;
1078
+
1079
+ type ListBoxProps<T> = AriaListBoxProps<T> & Omit<BoxProps, "filter" | "autoFocus" | "children"> & {
1080
+ /** External reference to the ListBox itself */
1081
+ listBoxRef: React__default.RefObject<HTMLUListElement>;
1082
+ /** Whether or not the listbox is waiting on new data, i.e. through a autosuggest search */
1083
+ isLoading?: boolean;
1084
+ /** The state of the listbox, provided externally somehow. */
1085
+ state: ListState<T> | SelectState<T>;
1086
+ };
1019
1087
  /**
1020
- * A listbox component.
1088
+ * A component that renders a list box with selectable options.
1021
1089
  *
1022
- * This component is currently only thought to be used with the `InfoSelect` component. Usage outside of that is not documented, nor intended.
1090
+ * @example
1091
+ * ```jsx
1092
+ * const options = [
1093
+ * { id: 1, name: "Option 1" },
1094
+ * { id: 2, name: "Option 2" },
1095
+ * { id: 3, name: "Option 3" },
1096
+ * ];
1097
+ *
1098
+ * const state = useListState({ items: options });
1099
+ * const ref = useRef(null);
1100
+ *
1101
+ * return (
1102
+ * <ListBox state={state} listBoxRef={ref}>
1103
+ * {(option) => <div key={option.id}>{option.name}</div>}
1104
+ * </ListBox>
1105
+ * );
1106
+ * ```
1107
+ *
1108
+ * @example
1109
+ * ```jsx
1110
+ * const { data, isLoading } = useSWR('/api/options')
1111
+ * const state = useListState({ items: data });
1112
+ * const ref = useRef(null);
1113
+ *
1114
+ * return (
1115
+ * <ListBox state={state} isLoading={isLoading} ref={ref}>
1116
+ * {(option) => <div key={option.id}>{option.name}</div>}
1117
+ * </ListBox>
1118
+ * );
1119
+ * ```
1023
1120
  */
1024
- declare const ListBox: _chakra_ui_system_dist_system_types.ComponentWithAs<"ul", ListBoxProps>;
1121
+ declare function ListBox<T extends object>({ isLoading, listBoxRef, state, ...props }: ListBoxProps<T>): React__default.JSX.Element;
1025
1122
  /**
1026
- * Renders a label for a SelectItem.
1123
+ * Renders a label for a listbox item.
1027
1124
  *
1028
- * Useful if you want to render a custom SelectItem - especially if it has a description.
1125
+ * Useful if you want to render a custom Item - especially if it has a description.
1029
1126
  */
1030
- declare function SelectItemLabel({ children }: {
1127
+ declare function ItemLabel({ children }: {
1031
1128
  children: React__default.ReactNode;
1032
1129
  }): React__default.JSX.Element;
1130
+ /** @deprecated use ItemLabel instead */
1131
+ declare const SelectItemLabel: typeof ItemLabel;
1033
1132
  /**
1034
- * Renders a description for a SelectItem.
1133
+ * Renders a description for an Item.
1035
1134
  *
1036
- * Useful if you want to render a custom SelectItem with more than just a label.
1135
+ * Useful if you want to render a custom Item with more than just a label.
1037
1136
  */
1038
- declare function SelectItemDescription({ children, }: {
1137
+ declare function ItemDescription({ children }: {
1039
1138
  children: React__default.ReactNode;
1040
1139
  }): React__default.JSX.Element;
1140
+ /** @deprecated Use ItemDescription instead */
1141
+ declare const SelectItemDescription: typeof ItemDescription;
1041
1142
 
1042
1143
  type NativeSelectProps = Exclude<SelectProps, "colorScheme" | "variant" | "size"> & {
1043
1144
  label?: string;
@@ -1058,6 +1159,48 @@ type NativeSelectProps = Exclude<SelectProps, "colorScheme" | "variant" | "size"
1058
1159
  */
1059
1160
  declare const NativeSelect: _chakra_ui_system_dist_system_types.ComponentWithAs<"select", NativeSelectProps>;
1060
1161
 
1162
+ type NumericStepperProps = {
1163
+ /** The name of the input field */
1164
+ name?: string;
1165
+ /** The current value */
1166
+ value?: number;
1167
+ /** A default value, if uncontrolled */
1168
+ defaultValue?: number;
1169
+ /** Callback for when the value changes */
1170
+ onChange?: (value: number) => void;
1171
+ /** Optional minimum value. Defaults to 0 */
1172
+ minValue?: number;
1173
+ /** Optional maximum value. Defaults to 99 */
1174
+ maxValue?: number;
1175
+ /** Whether the stepper is disabled or not */
1176
+ isDisabled?: boolean;
1177
+ } & Omit<BoxProps, "onChange">;
1178
+ /** A simple stepper component for integer values
1179
+ *
1180
+ * Allows you to choose a given integer value, like for example the number of
1181
+ * adults on your journey.
1182
+ *
1183
+ * ```tsx
1184
+ * <NumericStepper value={value} onChange={setValue} />
1185
+ * ```
1186
+ *
1187
+ * You can also set a minimum and/or maximum value:
1188
+ *
1189
+ * ```tsx
1190
+ * <NumericStepper value={value} onChange={setValue} minValue={1} maxValue={10} />
1191
+ * ```
1192
+ *
1193
+ * You can use the NumericStepper inside of a FormControl component to get IDs etc linked up automatically:
1194
+ *
1195
+ * ```tsx
1196
+ * <FormControl>
1197
+ * <FormLabel>Number of adults</FormLabel>
1198
+ * <NumericStepper />
1199
+ * </FormControl>
1200
+ * ```
1201
+ */
1202
+ declare function NumericStepper({ name: nameProp, id: idProp, value: valueProp, defaultValue, onChange: onChangeProp, minValue, maxValue, isDisabled, ...boxProps }: NumericStepperProps): React__default.JSX.Element;
1203
+
1061
1204
  type PasswordInputProps = InputProps;
1062
1205
  declare const PasswordInput: _chakra_ui_system_dist_system_types.ComponentWithAs<"input", InputProps>;
1063
1206
 
@@ -3589,10 +3732,10 @@ declare const theme: {
3589
3732
  };
3590
3733
  _focus: {
3591
3734
  outline: string;
3592
- background: string;
3735
+ backgroundColor: string;
3593
3736
  };
3594
3737
  _selected: {
3595
- background: string;
3738
+ backgroundColor: string;
3596
3739
  color: string;
3597
3740
  };
3598
3741
  };
@@ -6927,4 +7070,4 @@ type TextProps = Omit<TextProps$1, "textStyle"> & {
6927
7070
  */
6928
7071
  declare const Text: _chakra_ui_system_dist_system_types.ComponentWithAs<"p", TextProps>;
6929
7072
 
6930
- export { Accordion, AccordionProps, AttachedInputs, Badge, BadgeProps, Button, ButtonGroup, ButtonGroupProps, ButtonProps, Card, CardProps, CardSelect, Checkbox, CheckboxGroup, CheckboxGroupProps, CheckboxProps, ChoiceChip, ChoiceChipProps, ClosableAlert, CloseButton, CloseButtonProps, Code, CodeProps, ColorInlineLoader, ColorInlineLoaderProps, ColorSpinner, ColorSpinnerProps, ContentLoader, ContentLoaderProps, DarkFullScreenLoader, DarkInlineLoader, DarkInlineLoaderProps, DarkSpinner, DarkSpinnerProps, DatePicker, DateRangePicker, Divider, DividerProps, Drawer, DrawerContent, ModalHeader as DrawerHeader, Expandable, ExpandableAlert, ExpandableItem, ExpandableItemProps, FloatingActionButton, FormControl, FormControlProps, FormErrorMessage, FormErrorMessageProps, FormLabel, FormLabelProps, Heading, HeadingProps, IconButton, IconButtonProps, InfoSelect, InfoTag, InfoTagProps, Input, InputElementProps, InputLeftElement, InputProps, InputRightElement, JumpButton, Language, LanguageProvider, LightFullScreenLoader, LightInlineLoader, LightInlineLoaderProps, LightSpinner, LightSpinnerProps, LineIcon, LineIconProps, ListBox, ModalHeader, ModalHeaderProps, NativeSelect, NativeSelectProps, NumericStepper, PasswordInput, PasswordInputProps, PhoneNumberInput, PlayPauseButton, PopoverWizardBody, PopoverWizardProps, ProgressBar, ProgressLoader, Radio, RadioGroup, RadioGroupProps, RadioProps, SearchInput, SearchInputProps, SelectItemDescription, SelectItemLabel, SimpleDrawer, SimpleDrawerProps, SimplePopover, Skeleton, SkeletonCircle, SkeletonCircleProps, SkeletonProps, SkeletonText, SkeletonTextProps, SkipButton, SpinnerProps, SporProvider, Stack, StackProps, StaticAlert, Stepper, StepperStep, Switch, SwitchProps, Table, TableProps, Tabs, TabsProps, Text, TextLink, TextProps, Textarea, TextareaProps, TimePicker, ToastOptions, Translations, TravelTag, TravelTagProps, VyLogo, VyLogoProps, WizardPopover, WizardPopoverProps, createTexts, fontFaces, theme, useToast, useTranslation };
7073
+ export { Accordion, AccordionProps, AttachedInputs, Autosuggest, Badge, BadgeProps, Button, ButtonGroup, ButtonGroupProps, ButtonProps, Card, CardProps, CardSelect, Checkbox, CheckboxGroup, CheckboxGroupProps, CheckboxProps, ChoiceChip, ChoiceChipProps, ClosableAlert, CloseButton, CloseButtonProps, Code, CodeProps, ColorInlineLoader, ColorInlineLoaderProps, ColorSpinner, ColorSpinnerProps, Combobox, ComboboxProps, ContentLoader, ContentLoaderProps, DarkFullScreenLoader, DarkInlineLoader, DarkInlineLoaderProps, DarkSpinner, DarkSpinnerProps, DatePicker, DateRangePicker, Divider, DividerProps, Drawer, DrawerContent, ModalHeader as DrawerHeader, Expandable, ExpandableAlert, ExpandableItem, ExpandableItemProps, FloatingActionButton, FormControl, FormControlProps, FormErrorMessage, FormErrorMessageProps, FormLabel, FormLabelProps, Heading, HeadingProps, IconButton, IconButtonProps, InfoSelect, InfoTag, InfoTagProps, Input, InputElementProps, InputLeftElement, InputProps, InputRightElement, ItemDescription, ItemLabel, JumpButton, Language, LanguageProvider, LightFullScreenLoader, LightInlineLoader, LightInlineLoaderProps, LightSpinner, LightSpinnerProps, LineIcon, LineIconProps, ListBox, ModalHeader, ModalHeaderProps, NativeSelect, NativeSelectProps, NumericStepper, PasswordInput, PasswordInputProps, PhoneNumberInput, PlayPauseButton, PopoverWizardBody, PopoverWizardProps, ProgressBar, ProgressLoader, Radio, RadioGroup, RadioGroupProps, RadioProps, SearchInput, SearchInputProps, SelectItem, SelectItemDescription, SelectItemLabel, SimpleDrawer, SimpleDrawerProps, SimplePopover, Skeleton, SkeletonCircle, SkeletonCircleProps, SkeletonProps, SkeletonText, SkeletonTextProps, SkipButton, SpinnerProps, SporProvider, Stack, StackProps, StaticAlert, Stepper, StepperStep, Switch, SwitchProps, Table, TableProps, Tabs, TabsProps, Text, TextLink, TextProps, Textarea, TextareaProps, TimePicker, ToastOptions, Translations, TravelTag, TravelTagProps, VyLogo, VyLogoProps, WizardPopover, WizardPopoverProps, createTexts, fontFaces, theme, useToast, useTranslation };