@ostack.tech/ui 0.3.4 → 0.4.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.
@@ -1,5 +1,5 @@
1
- import { IconProp } from '@fortawesome/fontawesome-svg-core';
2
1
  import { ComponentPropsWithoutRef, ComponentPropsWithRef, ReactNode } from 'react';
2
+ import { IconProp } from '../Icon';
3
3
  import { IconButton, IconButtonSize } from '../IconButton';
4
4
  import { PopoverContent } from '../Popover';
5
5
  /** Properties of the feedback popover component. */
@@ -71,9 +71,9 @@ export * from './utils/control.ts';
71
71
  export * from './utils/cx.ts';
72
72
  export * from './utils/filtering.ts';
73
73
  export * from './utils/keyboardShortcut.ts';
74
- export * from './utils/locationUtils.ts';
75
74
  export * from './utils/mergeAriaIds.ts';
76
75
  export * from './utils/nativeControls.ts';
76
+ export * from './utils/navigate.ts';
77
77
  export * from './utils/numericStringUtils.ts';
78
78
  export * from './utils/parseDateStrict.ts';
79
79
  export * from './utils/sorting.ts';
@@ -86,12 +86,15 @@ export * from './utils/useDateTransformer.tsx';
86
86
  export * from './utils/useIntersectionObserver.ts';
87
87
  export * from './utils/useLatestValues.ts';
88
88
  export * from './utils/useLayoutEffect.ts';
89
+ export * from './utils/useLocation.ts';
89
90
  export * from './utils/useMeasure.ts';
90
91
  export * from './utils/useMediaQuery.ts';
91
92
  export * from './utils/useNumericTransformer.tsx';
92
93
  export * from './utils/useResponsiveValues.ts';
93
94
  export * from './utils/useScrollbarSize.ts';
94
95
  export * from './utils/useScrollPosition.ts';
96
+ export * from './utils/useSearchParam.ts';
97
+ export * from './utils/useSearchParams.ts';
95
98
  export * from './utils/useSpacing.ts';
96
99
  export * from './utils/warnOnce.ts';
97
100
  export * from './utils/zustandUtils.ts';
@@ -0,0 +1,16 @@
1
+ /** Options used to navigate to a new location. */
2
+ export interface NavigationOptions {
3
+ /** Optional state to push. */
4
+ state?: unknown;
5
+ /**
6
+ * Whether to replace the current history entry.
7
+ *
8
+ * @default false
9
+ */
10
+ replace?: boolean;
11
+ }
12
+ /**
13
+ * Function used to navigate to a new URL (small utility function around
14
+ * `history.pushState` and `history.replaceState`).
15
+ */
16
+ export declare function navigate(url: string | URL, options?: NavigationOptions): void;
@@ -0,0 +1,30 @@
1
+ /** Representation of the URL's location path (`pathname`, `search`, and `hash`). */
2
+ interface LocationPath {
3
+ /**
4
+ * String containing the pathname of the URL.
5
+ *
6
+ * _E.g._, `/foo/bar` in `https://example.org:8080/foo/bar?q=baz#bang`.
7
+ */
8
+ readonly pathname: string;
9
+ /**
10
+ * Search string (also known as _query string_): `"?"` followed by the
11
+ * parameters of the URL or an empty string if there are no such parameters.
12
+ *
13
+ * _E.g._, `?q=baz` in `https://example.org:8080/foo/bar?q=baz#bang`.
14
+ */
15
+ readonly search: string;
16
+ /**
17
+ * `"#"` followed by the fragment identifier of the URL or an empty string if
18
+ * there is no fragment identifier.
19
+ *
20
+ * _E.g._, `#bang` in `https://example.org:8080/foo/bar?q=baz#bang`.
21
+ */
22
+ readonly hash: string;
23
+ }
24
+ /**
25
+ * Hook exposing the current location and a function to navigate to a new
26
+ * location.
27
+ */
28
+ export declare function useLocation(): LocationPath;
29
+ export declare function useLocation<T>(selector: (location: LocationPath) => T): T;
30
+ export {};
@@ -0,0 +1,26 @@
1
+ import { SetSearchParamsOptions } from './useSearchParams.ts';
2
+ /** Options used to navigate to the new search parameter. */
3
+ export interface SetSearchParamOptions extends SetSearchParamsOptions {
4
+ /**
5
+ * Whether the search parameter should be cleared when its value equals the
6
+ * default value.
7
+ *
8
+ * @default false
9
+ */
10
+ clearDefaultValue?: boolean;
11
+ }
12
+ /** Result of the {@link useSearchParam} hook. */
13
+ export type UseSearchParamResult<TValue extends string | undefined = string | undefined> = [
14
+ searchParamValue: TValue,
15
+ setSearchParamValue: (nextSearchParamValue: {
16
+ toString(): string;
17
+ } | null | undefined | ((prevSearchParamValue: TValue) => {
18
+ toString(): string;
19
+ } | null | undefined), options?: SetSearchParamOptions) => void
20
+ ];
21
+ /**
22
+ * Hook exposing the value of a single URL search parameter and a function to
23
+ * update it.
24
+ */
25
+ export declare function useSearchParam(searchParam: string): UseSearchParamResult;
26
+ export declare function useSearchParam(searchParam: string, defaultValue: string): UseSearchParamResult<string>;
@@ -0,0 +1,20 @@
1
+ import { NavigationOptions } from './navigate.ts';
2
+ /** Options used to navigate to the new search parameters. */
3
+ export interface SetSearchParamsOptions extends NavigationOptions {
4
+ /**
5
+ * Whether to clear the URL's hash when navigating.
6
+ *
7
+ * @default false
8
+ */
9
+ clearHash?: boolean;
10
+ }
11
+ /** Result of the {@link useSearchParams} hook. */
12
+ export type UseSearchParamsResult = [
13
+ searchParams: URLSearchParams,
14
+ setSearchParams: (nextSearchParams: (string[][] | Record<string, string> | string | URLSearchParams) | ((prevSearchParams: URLSearchParams) => string[][] | Record<string, string> | string | URLSearchParams), options?: SetSearchParamsOptions) => void
15
+ ];
16
+ /**
17
+ * Hook exposing the current URL search parameters and a function to update
18
+ * them.
19
+ */
20
+ export declare function useSearchParams(): UseSearchParamsResult;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ostack.tech/ui",
3
3
  "description": "ostack/UI component library.",
4
- "version": "0.3.4",
4
+ "version": "0.4.0",
5
5
  "homepage": "https://ui.ostack.tech/",
6
6
  "author": {
7
7
  "name": "Opensoft",
@@ -1,85 +0,0 @@
1
- /** Representation of the URL's location path (`pathname`, `search`, and `hash`). */
2
- interface LocationPath {
3
- /**
4
- * String containing the pathname of the URL.
5
- *
6
- * _E.g._, `/foo/bar` in `https://example.org:8080/foo/bar?q=baz#bang`.
7
- */
8
- readonly pathname: string;
9
- /**
10
- * Search string (also known as _query string_): `"?"` followed by the
11
- * parameters of the URL or an empty string if there are no such parameters.
12
- *
13
- * _E.g._, `?q=baz` in `https://example.org:8080/foo/bar?q=baz#bang`.
14
- */
15
- readonly search: string;
16
- /**
17
- * `"#"` followed by the fragment identifier of the URL or an empty string if
18
- * there is no fragment identifier.
19
- *
20
- * _E.g._, `#bang` in `https://example.org:8080/foo/bar?q=baz#bang`.
21
- */
22
- readonly hash: string;
23
- }
24
- /** Options used to navigate to a new location. */
25
- export interface NavigationOptions {
26
- /** Optional state to push. */
27
- state?: unknown;
28
- /**
29
- * Whether to replace the current history entry.
30
- *
31
- * @default false
32
- */
33
- replace?: boolean;
34
- }
35
- /** Result of the {@link useLocation} hook. */
36
- export type UseLocationResult = [
37
- location: LocationPath,
38
- navigate: (url: string | URL, options?: NavigationOptions) => void
39
- ];
40
- /**
41
- * Hook exposing the current location and a function to navigate to a new
42
- * location.
43
- */
44
- export declare function useLocation(): UseLocationResult;
45
- /** Options used to navigate to the new search parameters. */
46
- export interface SetSearchParamsOptions extends NavigationOptions {
47
- /**
48
- * Whether to clear the URL's hash when navigating.
49
- *
50
- * @default false
51
- */
52
- clearHash?: boolean;
53
- }
54
- /** Result of the {@link useSearchParams} hook. */
55
- export type UseSearchParamsResult = [
56
- searchParams: URLSearchParams,
57
- setSearchParams: (nextSearchParams: (string[][] | Record<string, string> | string | URLSearchParams) | ((prevSearchParams: URLSearchParams) => string[][] | Record<string, string> | string | URLSearchParams), options?: SetSearchParamsOptions) => void
58
- ];
59
- /**
60
- * Hook exposing the current URL search parameters and a function to update
61
- * them.
62
- */
63
- export declare function useSearchParams(): UseSearchParamsResult;
64
- /** Options used to navigate to the new search parameter. */
65
- export interface SetSearchParamOptions extends SetSearchParamsOptions {
66
- /**
67
- * Whether the search parameter should be cleared when its value equals the
68
- * default value.
69
- *
70
- * @default false
71
- */
72
- clearDefaultValue?: boolean;
73
- }
74
- /** Result of the {@link useSearchParam} hook. */
75
- export type UseSearchParamResult<TValue extends string | undefined = string | undefined> = [
76
- searchParamValue: TValue,
77
- setSearchParamValue: (nextSearchParamValue: string | number | bigint | boolean | null | undefined | ((prevSearchParamValue: TValue) => string | number | bigint | boolean | null | undefined), options?: SetSearchParamOptions) => void
78
- ];
79
- /**
80
- * Hook exposing the value of a single URL search parameter and a function to
81
- * update it.
82
- */
83
- export declare function useSearchParam(searchParam: string): UseSearchParamResult;
84
- export declare function useSearchParam(searchParam: string, defaultValue: string): UseSearchParamResult<string>;
85
- export {};