@up42/up-components 8.2.0 → 8.3.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.
- package/dist/cjs/index.js +2 -2
- package/dist/cjs/types/index.d.ts +1 -0
- package/dist/cjs/types/utils/hooks/useUrlParams/index.d.ts +3 -0
- package/dist/cjs/types/utils/hooks/useUrlParams/types.d.ts +22 -0
- package/dist/cjs/types/utils/hooks/useUrlParams/useUrlParams.d.ts +11 -0
- package/dist/cjs/types/utils/hooks/useUrlParams/useUrlParams.test.d.ts +1 -0
- package/dist/cjs/types/utils/hooks/useUrlParams/utils.d.ts +19 -0
- package/dist/cjs/types/utils/hooks/useUrlParams/utils.test.d.ts +1 -0
- package/dist/esm/index.js +2 -2
- package/dist/esm/types/index.d.ts +1 -0
- package/dist/esm/types/utils/hooks/useUrlParams/index.d.ts +3 -0
- package/dist/esm/types/utils/hooks/useUrlParams/types.d.ts +22 -0
- package/dist/esm/types/utils/hooks/useUrlParams/useUrlParams.d.ts +11 -0
- package/dist/esm/types/utils/hooks/useUrlParams/useUrlParams.test.d.ts +1 -0
- package/dist/esm/types/utils/hooks/useUrlParams/utils.d.ts +19 -0
- package/dist/esm/types/utils/hooks/useUrlParams/utils.test.d.ts +1 -0
- package/dist/index.d.ts +55 -2
- package/package.json +3 -3
|
@@ -77,3 +77,4 @@ export { useCursorPagination, type CursorPaginatedResponse } from './utils/hooks
|
|
|
77
77
|
export { useToggle, type UseToggleResult } from './utils/hooks/useToggle';
|
|
78
78
|
export { useDebounce } from './utils/hooks/useDebounce';
|
|
79
79
|
export { useAlert, type CreateAlertProps, type CreateSnackbarProps, } from './global/providers/AlertProvider/AlertProvider';
|
|
80
|
+
export { useUrlParams, searchParamsToObject, objectToSearchParams, valueToString, type ParamsObject, type RemoveParamRules, type SearchParamObject, } from './utils/hooks/useUrlParams';
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export type SearchParamObject = Record<string, string>;
|
|
2
|
+
export type ParamsObject = Record<string, unknown>;
|
|
3
|
+
export type RemoveParamRules<T extends ParamsObject = ParamsObject> = {
|
|
4
|
+
[K in keyof T]?: (value: T[K]) => boolean;
|
|
5
|
+
};
|
|
6
|
+
export type Options<T extends ParamsObject> = {
|
|
7
|
+
cast: (search: SearchParamObject) => T;
|
|
8
|
+
parse: (searchParam: URLSearchParams) => SearchParamObject;
|
|
9
|
+
stringify: (searchParamsObject: T) => ReturnType<URLSearchParams['toString']>;
|
|
10
|
+
removeParams: RemoveParamRules<T>;
|
|
11
|
+
};
|
|
12
|
+
export type PartialOptions<T extends ParamsObject> = Partial<Options<T>>;
|
|
13
|
+
export type UseUrlParamsReturn<T extends ParamsObject> = {
|
|
14
|
+
/** Search params object literal. */
|
|
15
|
+
params: T;
|
|
16
|
+
/** Navigate using given search params object literal. */
|
|
17
|
+
setParams: (params: ParamsObject) => void;
|
|
18
|
+
/** Stringified search params for use when navigating to other paths. */
|
|
19
|
+
stringParams: string;
|
|
20
|
+
/** Default params obtained by running the cast function with an empty object. Useful for resetting filters to their initial state. */
|
|
21
|
+
defaultParams: T;
|
|
22
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ParamsObject, PartialOptions, UseUrlParamsReturn } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Parses URLSearchParams into an object and supports navigating with updated search params.
|
|
4
|
+
* Supports custom parsing (e.g. arrays, dates) and serialization back to a search string.
|
|
5
|
+
*
|
|
6
|
+
* @param options.cast - How to turn Record<string, string> into the params object (required when using typed params).
|
|
7
|
+
* @param options.parse - How to turn URLSearchParams into Record<string, string>. Default: entries as-is.
|
|
8
|
+
* @param options.stringify - How to stringify the params object. Default: arrays as comma-separated, dates as YYYY-MM-DD.
|
|
9
|
+
* @param options.removeParams - Map of param keys to predicate functions; when setParams runs, params whose predicate returns true are removed from the URL.
|
|
10
|
+
*/
|
|
11
|
+
export declare function useUrlParams<TParams extends ParamsObject>(options?: PartialOptions<TParams>): UseUrlParamsReturn<TParams>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ParamsObject, SearchParamObject } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* There could be many ways to parse URLSearchParams to an object.
|
|
4
|
+
* For example, how should `a` be treated in `a=1&b=2&a=3`?
|
|
5
|
+
* This implementation is a choice.
|
|
6
|
+
*/
|
|
7
|
+
export declare function searchParamsToObject(searchParam: URLSearchParams): SearchParamObject;
|
|
8
|
+
/**
|
|
9
|
+
* Stringify a value to a string.
|
|
10
|
+
* @param value - The value to stringify.
|
|
11
|
+
* @returns The stringified value.
|
|
12
|
+
*/
|
|
13
|
+
export declare function valueToString(value: unknown): string;
|
|
14
|
+
/**
|
|
15
|
+
* There could be many ways to serialize an object to URLSearchParams.
|
|
16
|
+
* For example, how should `d` be treated in `{ d: new Date() }`? How should arrays behave?
|
|
17
|
+
* This implementation is a choice.
|
|
18
|
+
*/
|
|
19
|
+
export declare function objectToSearchParams<T extends ParamsObject = ParamsObject>(object: T): string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/index.d.ts
CHANGED
|
@@ -11761,5 +11761,58 @@ type ContextState = {
|
|
|
11761
11761
|
*/
|
|
11762
11762
|
declare const useAlert: () => ContextState;
|
|
11763
11763
|
|
|
11764
|
-
|
|
11765
|
-
|
|
11764
|
+
type SearchParamObject = Record<string, string>;
|
|
11765
|
+
type ParamsObject = Record<string, unknown>;
|
|
11766
|
+
type RemoveParamRules<T extends ParamsObject = ParamsObject> = {
|
|
11767
|
+
[K in keyof T]?: (value: T[K]) => boolean;
|
|
11768
|
+
};
|
|
11769
|
+
type Options<T extends ParamsObject> = {
|
|
11770
|
+
cast: (search: SearchParamObject) => T;
|
|
11771
|
+
parse: (searchParam: URLSearchParams) => SearchParamObject;
|
|
11772
|
+
stringify: (searchParamsObject: T) => ReturnType<URLSearchParams['toString']>;
|
|
11773
|
+
removeParams: RemoveParamRules<T>;
|
|
11774
|
+
};
|
|
11775
|
+
type PartialOptions<T extends ParamsObject> = Partial<Options<T>>;
|
|
11776
|
+
type UseUrlParamsReturn<T extends ParamsObject> = {
|
|
11777
|
+
/** Search params object literal. */
|
|
11778
|
+
params: T;
|
|
11779
|
+
/** Navigate using given search params object literal. */
|
|
11780
|
+
setParams: (params: ParamsObject) => void;
|
|
11781
|
+
/** Stringified search params for use when navigating to other paths. */
|
|
11782
|
+
stringParams: string;
|
|
11783
|
+
/** Default params obtained by running the cast function with an empty object. Useful for resetting filters to their initial state. */
|
|
11784
|
+
defaultParams: T;
|
|
11785
|
+
};
|
|
11786
|
+
|
|
11787
|
+
/**
|
|
11788
|
+
* Parses URLSearchParams into an object and supports navigating with updated search params.
|
|
11789
|
+
* Supports custom parsing (e.g. arrays, dates) and serialization back to a search string.
|
|
11790
|
+
*
|
|
11791
|
+
* @param options.cast - How to turn Record<string, string> into the params object (required when using typed params).
|
|
11792
|
+
* @param options.parse - How to turn URLSearchParams into Record<string, string>. Default: entries as-is.
|
|
11793
|
+
* @param options.stringify - How to stringify the params object. Default: arrays as comma-separated, dates as YYYY-MM-DD.
|
|
11794
|
+
* @param options.removeParams - Map of param keys to predicate functions; when setParams runs, params whose predicate returns true are removed from the URL.
|
|
11795
|
+
*/
|
|
11796
|
+
declare function useUrlParams<TParams extends ParamsObject>(options?: PartialOptions<TParams>): UseUrlParamsReturn<TParams>;
|
|
11797
|
+
|
|
11798
|
+
/**
|
|
11799
|
+
* There could be many ways to parse URLSearchParams to an object.
|
|
11800
|
+
* For example, how should `a` be treated in `a=1&b=2&a=3`?
|
|
11801
|
+
* This implementation is a choice.
|
|
11802
|
+
*/
|
|
11803
|
+
declare function searchParamsToObject(searchParam: URLSearchParams): SearchParamObject;
|
|
11804
|
+
/**
|
|
11805
|
+
* Stringify a value to a string.
|
|
11806
|
+
* @param value - The value to stringify.
|
|
11807
|
+
* @returns The stringified value.
|
|
11808
|
+
*/
|
|
11809
|
+
declare function valueToString(value: unknown): string;
|
|
11810
|
+
/**
|
|
11811
|
+
* There could be many ways to serialize an object to URLSearchParams.
|
|
11812
|
+
* For example, how should `d` be treated in `{ d: new Date() }`? How should arrays behave?
|
|
11813
|
+
* This implementation is a choice.
|
|
11814
|
+
*/
|
|
11815
|
+
declare function objectToSearchParams<T extends ParamsObject = ParamsObject>(object: T): string;
|
|
11816
|
+
|
|
11817
|
+
export { ActionToolbar, Alert, Avatar, Badge, Banner, Button, Checkbox, CodeBlock, CodeInline, CodeSnippet, ContactBox, ControlButton, CopyButton, DataGrid, DateTime, Divider, DocumentationPopover, EditTagsButton, EmptyState, FeatureCard, FeatureCardHeader, FeatureCardHeaderActions, FeatureFlagCheckbox, FilterPopover, FindUsersButton, FormCheckbox, FormDatePicker, FormDateRangePicker, FormDateRangePickerList, FormDateTimePicker, FormInput, FormRadio, FormSelect, FormSwitch, GridContainer, GridItem, Icon, Illustration, InfoCard, InfoModal, InfoPopover, Input, LearnMoreButton, Link, Loading, Logo, NotFound, PageContainer, PageHeader, PageHeaderV2, Popover, Radio, RoleBanner, Select, Slider, StatusLight, Switch, Tab, TabGroup, Table, TableBody, TableCell, TableContainer, TableFooter, TableHead, TablePagination, TableRow, TableSortLabel, Tabs, Tag, TagsList, ToggleButton, Typography, UpComponentsProvider, analytics, capitalize, copyToClipboard, formatDate, formatFileSize, formatNumber, generateQueryKey, objectToSearchParams, searchParamsToObject, theme, useAlert, useCursorPagination, useDebounce, useQueryParams, useRemotePagination, useToggle, useUrlParams, valueToString };
|
|
11818
|
+
export type { ActionToolbarProps, AlertProps, AnalyticsConfig, AvatarProps, BadgeProps, BannerProps, ButtonProps, CheckboxProps, CodeBlockProps, CodeInlineProps, CodeSnippetItemProps, CodeSnippetProps, ContactBoxProps, ControlButtonProps, CopyButtonProps, CreateAlertProps, CreateSnackbarProps, CursorPaginatedResponse, DateRange, DateTimeProps, DividerProps, DocumentationPopoverProps, EditTagsButtonProps, EmptyStateProps, FeatureCardHeaderActionsProps, FeatureCardHeaderProps, FeatureCardProps, FeatureFlagCheckboxProps, FilterPopoverProps, FindUsersButtonProps, FormCheckboxProps, FormDatePickerDateType, FormDatePickerProps, FormDateRangePickerListProps, FormDateRangePickerProps, FormDateTimePickerProps, FormInputProps, FormRadioProps, FormSelectProps, FormSwitchProps, GridContainerProps, GridItemProps, IconAction, IconProps$1 as IconProps, IllustrationProps, InfoCardProps, InfoModalProps, InfoPopoverProps, InputProps, LearnMoreButtonProps, LinkProps, LoadingProps, LogoProps, MenuAction, NotFoundProps, PageContainerProps, PageHeaderProps, PageHeaderV2Props, PaginatedResponse, ParamsObject, PopoverProps, RadioProps, RemoveParamRules, RoleBannerProps, SearchParamObject, SelectProps, SliderProps, StatusLightProps, SwitchProps, TabGroupProps, TabProps, TableBodyProps, TableCellProps, TableContainerProps, TableFooterProps, TableHeadProps, TablePaginationProps, TableProps, TableRowProps, TableSortLabelProps, TabsProps, TagItem, TagProps, TagsListProps, ToggleButtonProps, TypographyProps, UseToggleResult };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@up42/up-components",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.3.0",
|
|
4
4
|
"description": "UP42 Component Library",
|
|
5
5
|
"author": "Axel Fuhrmann axel.fuhrmann@up42.com",
|
|
6
6
|
"license": "ISC",
|
|
@@ -78,7 +78,6 @@
|
|
|
78
78
|
"lint-staged": "^12.3.1",
|
|
79
79
|
"prettier": "^2.5.1",
|
|
80
80
|
"react": "^18.3.1",
|
|
81
|
-
"react-router": "^7.12.0",
|
|
82
81
|
"rimraf": "^6.1.2",
|
|
83
82
|
"rollup": "^4.59.0",
|
|
84
83
|
"rollup-plugin-dts": "^6.1.0",
|
|
@@ -99,7 +98,8 @@
|
|
|
99
98
|
"@mui/x-data-grid-premium": "^6.8.0",
|
|
100
99
|
"@mui/x-date-pickers-pro": "^6.8.0",
|
|
101
100
|
"react": "^18.3.1",
|
|
102
|
-
"react-dom": "^18.3.1"
|
|
101
|
+
"react-dom": "^18.3.1",
|
|
102
|
+
"react-router": "^7.12.0"
|
|
103
103
|
},
|
|
104
104
|
"lint-staged": {
|
|
105
105
|
"*.{js,tsx,ts}": "eslint --cache --fix",
|