@sonic-equipment/ui 201.0.0 → 202.0.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/buttons/button/button.js +1 -2
- package/dist/buttons/icon-button/icon-button.js +1 -2
- package/dist/buttons/link/link.js +1 -2
- package/dist/exports.d.ts +2 -0
- package/dist/index.js +3 -1
- package/dist/shared/routing/route-context.d.ts +2 -0
- package/dist/shared/routing/route-context.js +6 -0
- package/dist/shared/routing/route-provider.js +7 -8
- package/dist/shared/routing/types.d.ts +1 -1
- package/dist/shared/routing/use-location.d.ts +3 -3
- package/dist/shared/routing/use-location.js +4 -4
- package/dist/shared/routing/use-navigate.js +4 -7
- package/dist/shared/routing/use-paths.js +4 -5
- package/dist/shared/routing/use-route-link-element.d.ts +1 -1
- package/dist/shared/routing/use-route-link-element.js +5 -6
- package/dist/shared/routing/use-route-link.d.ts +1 -1
- package/dist/shared/routing/use-route-link.js +1 -0
- package/dist/shared/routing/use-router.d.ts +1 -0
- package/dist/shared/routing/use-router.js +13 -0
- package/dist/shared/routing/with-routing.d.ts +1 -0
- package/dist/shared/routing/with-routing.js +2 -1
- package/package.json +1 -1
|
@@ -27,8 +27,7 @@ const Button = forwardRef(({ _pseudo = 'none', 'aria-label': ariaLabel, children
|
|
|
27
27
|
const children = (jsxs(Fragment, { children: [showIconOnLeft && iconElement, jsx("span", { className: buttonStyles.children, children: isLoading ? (isLoading === true ? _children : isLoading) : _children }), withArrow && (jsx(GlyphsArrowBoldCapsRightIcon, { className: buttonStyles['right-arrow-icon'] })), showIconOnRight && iconElement, isLoading && (jsx(ProgressCircle, { className: buttonStyles.spinner, size: "sm", variant: color === 'primary' ? 'white' : 'gray' }))] }));
|
|
28
28
|
if (href) {
|
|
29
29
|
// TODO: only button currently supports ref for now
|
|
30
|
-
|
|
31
|
-
return (jsx(Element, { "aria-label": ariaLabel, className: classNames, "data-disabled": isDisabled ? true : undefined, "data-test-selector": dataTestSelector, onClick: onClick, type: type, ...getRouteLinkProps(href, route), children: children }));
|
|
30
|
+
return (jsx(RouteLinkElement, { "aria-label": ariaLabel, className: classNames, "data-disabled": isDisabled ? true : undefined, "data-test-selector": dataTestSelector, onClick: onClick, type: type, ...getRouteLinkProps(href, route), children: children }));
|
|
32
31
|
}
|
|
33
32
|
return (jsx("button", { ref: ref, "aria-label": ariaLabel, className: classNames, "data-disabled": isDisabled ? true : undefined, "data-test-selector": dataTestSelector, disabled: isDisabled, form: form, formNoValidate: isValidating ? undefined : true, name: name, onClick: handleButtonClick, type: type, value: value, children: children }));
|
|
34
33
|
});
|
|
@@ -13,8 +13,7 @@ function IconButton({ children, className: _className, color = 'primary', 'data-
|
|
|
13
13
|
};
|
|
14
14
|
const className = clsx(styles['icon-button'], styles[size], styles[color], _className);
|
|
15
15
|
if (href) {
|
|
16
|
-
|
|
17
|
-
return (jsx(Element, { className: className, "data-disabled": isDisabled ? true : undefined, "data-test-selector": dataTestSelector, onClick: onClick, target: target, title: title, ...getRouteLinkProps(href, route), ...rest, children: children }));
|
|
16
|
+
return (jsx(RouteLinkElement, { className: className, "data-disabled": isDisabled ? true : undefined, "data-test-selector": dataTestSelector, onClick: onClick, target: target, title: title, ...getRouteLinkProps(href, route), ...rest, children: children }));
|
|
18
17
|
}
|
|
19
18
|
return (jsx("button", { className: className, "data-disabled": isDisabled ? true : undefined, "data-test-selector": dataTestSelector, disabled: isDisabled, onClick: handleButtonClick, title: title, type: type, ...rest, children: children }));
|
|
20
19
|
}
|
|
@@ -12,8 +12,7 @@ const Link = forwardRef(({ children, className: _className, color, hasUnderline,
|
|
|
12
12
|
[styles['has-underline']]: hasUnderline,
|
|
13
13
|
}, styles['link'], color && styles[color], _className);
|
|
14
14
|
if (href) {
|
|
15
|
-
|
|
16
|
-
return (jsx(Element, { ref: ref, className: className, "data-disabled": isDisabled ? true : undefined, id: id, onClick: onClick, onKeyUp: onKeyUp, role: role, tabIndex: isDisabled ? -1 : tabIndex, target: target, title: title, ...getRouteLinkProps(href, route), ...rest, children: children }));
|
|
15
|
+
return (jsx(RouteLinkElement, { ref: ref, className: className, "data-disabled": isDisabled ? true : undefined, id: id, onClick: onClick, onKeyUp: onKeyUp, role: role, tabIndex: isDisabled ? -1 : tabIndex, target: target, title: title, ...getRouteLinkProps(href, route), ...rest, children: children }));
|
|
17
16
|
}
|
|
18
17
|
return (jsx("button", { ref: ref, className: className, "data-disabled": isDisabled ? true : undefined, disabled: isDisabled ? true : undefined, id: id, onClick: onClick, onKeyUp: onKeyUp, role: role, tabIndex: isDisabled ? -1 : tabIndex, title: title, type: "button", ...rest, children: children }));
|
|
19
18
|
});
|
package/dist/exports.d.ts
CHANGED
|
@@ -404,6 +404,7 @@ export * from './shared/providers/cart-provider';
|
|
|
404
404
|
export * from './shared/providers/favorite-provider';
|
|
405
405
|
export * from './shared/providers/global-state-provider';
|
|
406
406
|
export * from './shared/providers/react-query-container';
|
|
407
|
+
export * from './shared/routing/route-context';
|
|
407
408
|
export * from './shared/routing/route-provider';
|
|
408
409
|
export * from './shared/routing/route-utils';
|
|
409
410
|
export * from './shared/routing/types';
|
|
@@ -413,6 +414,7 @@ export * from './shared/routing/use-on-navigate';
|
|
|
413
414
|
export * from './shared/routing/use-paths';
|
|
414
415
|
export * from './shared/routing/use-route-link';
|
|
415
416
|
export * from './shared/routing/use-route-link-element';
|
|
417
|
+
export * from './shared/routing/use-router';
|
|
416
418
|
export * from './shared/routing/with-routing';
|
|
417
419
|
export * from './shared/utils/array';
|
|
418
420
|
export * from './shared/utils/breakpoints';
|
package/dist/index.js
CHANGED
|
@@ -404,6 +404,7 @@ export { CartProvider, useCartEvents } from './shared/providers/cart-provider.js
|
|
|
404
404
|
export { FavoriteProvider, useFavorite, useFavoriteProduct } from './shared/providers/favorite-provider.js';
|
|
405
405
|
export { GlobalStateProvider, GlobalStateProviderContext, useGlobalState } from './shared/providers/global-state-provider.js';
|
|
406
406
|
export { ReactQueryContainer } from './shared/providers/react-query-container.js';
|
|
407
|
+
export { RouteContext } from './shared/routing/route-context.js';
|
|
407
408
|
export { RouteProvider } from './shared/routing/route-provider.js';
|
|
408
409
|
export { buildHref } from './shared/routing/route-utils.js';
|
|
409
410
|
export { useLocation } from './shared/routing/use-location.js';
|
|
@@ -412,7 +413,8 @@ export { useOnNavigate } from './shared/routing/use-on-navigate.js';
|
|
|
412
413
|
export { usePaths } from './shared/routing/use-paths.js';
|
|
413
414
|
export { useRouteLink } from './shared/routing/use-route-link.js';
|
|
414
415
|
export { useRouteLinkElement } from './shared/routing/use-route-link-element.js';
|
|
415
|
-
export {
|
|
416
|
+
export { useRouter } from './shared/routing/use-router.js';
|
|
417
|
+
export { FallbackRouteLink, withRouting } from './shared/routing/with-routing.js';
|
|
416
418
|
export { ensureArray } from './shared/utils/array.js';
|
|
417
419
|
export { breakpoints, getCurrentBreakpoints } from './shared/utils/breakpoints.js';
|
|
418
420
|
export { getCssPropertyValue } from './shared/utils/css.js';
|
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsx
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
2
|
+
import { jsx } from 'react/jsx-runtime';
|
|
3
|
+
import { useMemo } from 'react';
|
|
4
|
+
import { RouteContext } from './route-context.js';
|
|
5
5
|
|
|
6
|
-
function RouteProvider({ children, Link
|
|
7
|
-
|
|
6
|
+
function RouteProvider({ children, Link, navigate, paths, url, }) {
|
|
7
|
+
const value = useMemo(() => ({
|
|
8
8
|
Link,
|
|
9
9
|
navigate,
|
|
10
10
|
paths,
|
|
11
11
|
url,
|
|
12
|
-
});
|
|
13
|
-
return jsx(
|
|
12
|
+
}), [Link, navigate, paths, url]);
|
|
13
|
+
return jsx(RouteContext.Provider, { value: value, children: children });
|
|
14
14
|
}
|
|
15
|
-
const FallbackRouteLink = withRouting('a');
|
|
16
15
|
|
|
17
16
|
export { RouteProvider };
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import qs from 'query-string';
|
|
2
2
|
export declare function useLocation(): {
|
|
3
3
|
basePathname: string | undefined;
|
|
4
|
-
fullPathname: string
|
|
4
|
+
fullPathname: string;
|
|
5
5
|
href: string;
|
|
6
|
-
pathname: string
|
|
6
|
+
pathname: string;
|
|
7
7
|
query: qs.ParsedQuery<string>;
|
|
8
|
-
search: string
|
|
8
|
+
search: string;
|
|
9
9
|
};
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
+
"use client";
|
|
1
2
|
import qs from 'query-string';
|
|
2
|
-
import {
|
|
3
|
+
import { useRouter } from './use-router.js';
|
|
3
4
|
|
|
4
5
|
function useLocation() {
|
|
5
|
-
const
|
|
6
|
-
const { url: { basePathname, pathname, search }, } = routeState || { url: {} };
|
|
6
|
+
const { url: { basePathname, pathname, search }, } = useRouter();
|
|
7
7
|
const query = qs.parse(search || '');
|
|
8
8
|
return {
|
|
9
9
|
basePathname,
|
|
10
10
|
fullPathname: pathname,
|
|
11
11
|
href: `${pathname}${search}`,
|
|
12
|
-
pathname: pathname
|
|
12
|
+
pathname: pathname.replace(new RegExp(`^${basePathname}`), ''),
|
|
13
13
|
query,
|
|
14
14
|
search,
|
|
15
15
|
};
|
|
@@ -1,22 +1,19 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { useRef, useCallback } from 'react';
|
|
3
|
-
import { useGlobalState } from '../providers/global-state-provider.js';
|
|
4
3
|
import { useOnNavigate } from './use-on-navigate.js';
|
|
4
|
+
import { useRouter } from './use-router.js';
|
|
5
5
|
|
|
6
6
|
function useNavigate() {
|
|
7
7
|
const isNavigatingRef = useRef(false);
|
|
8
|
-
const
|
|
8
|
+
const routeState = useRouter();
|
|
9
9
|
const trigger = useOnNavigate(() => {
|
|
10
10
|
isNavigatingRef.current = false;
|
|
11
11
|
});
|
|
12
|
-
if (!state) {
|
|
13
|
-
throw new Error('RouteProvider not found');
|
|
14
|
-
}
|
|
15
12
|
const navigate = useCallback((href, options) => {
|
|
16
13
|
trigger(href, options);
|
|
17
14
|
isNavigatingRef.current = true;
|
|
18
|
-
return
|
|
19
|
-
}, [
|
|
15
|
+
return routeState.navigate(href, options);
|
|
16
|
+
}, [routeState, trigger]);
|
|
20
17
|
return { isNavigating: isNavigatingRef.current, navigate };
|
|
21
18
|
}
|
|
22
19
|
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
"use client";
|
|
2
|
+
import { useRouter } from './use-router.js';
|
|
2
3
|
|
|
3
4
|
function usePaths() {
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
throw new Error('usePaths must be used within a RouteProvider context');
|
|
7
|
-
return routeState.paths;
|
|
5
|
+
const { paths } = useRouter();
|
|
6
|
+
return paths;
|
|
8
7
|
}
|
|
9
8
|
|
|
10
9
|
export { usePaths };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function useRouteLinkElement(): React.ElementType<import("./types").RouteLinkElementProps
|
|
1
|
+
export declare function useRouteLinkElement(): React.ElementType<import("./types").RouteLinkElementProps>;
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
"use client";
|
|
2
|
+
import { useRouter } from './use-router.js';
|
|
3
|
+
import { FallbackRouteLink } from './with-routing.js';
|
|
2
4
|
|
|
3
5
|
function useRouteLinkElement() {
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
throw new Error('RouteProvider not found');
|
|
7
|
-
}
|
|
8
|
-
return state.Link;
|
|
6
|
+
const { Link } = useRouter();
|
|
7
|
+
return Link || FallbackRouteLink;
|
|
9
8
|
}
|
|
10
9
|
|
|
11
10
|
export { useRouteLinkElement };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { NavigateOptions } from './types';
|
|
2
2
|
export declare function useRouteLink(): {
|
|
3
|
-
RouteLinkElement: React.ElementType<import("./types").RouteLinkElementProps
|
|
3
|
+
RouteLinkElement: React.ElementType<import("./types").RouteLinkElementProps>;
|
|
4
4
|
getRouteLinkProps: (href: string, route?: NavigateOptions) => {
|
|
5
5
|
href: string;
|
|
6
6
|
onNavigate: () => void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function useRouter(): import("./types").RouteContextValue;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useContext } from 'react';
|
|
3
|
+
import { RouteContext } from './route-context.js';
|
|
4
|
+
|
|
5
|
+
function useRouter() {
|
|
6
|
+
const context = useContext(RouteContext);
|
|
7
|
+
if (!context) {
|
|
8
|
+
throw new Error('useRouter must be used within a RouteProvider');
|
|
9
|
+
}
|
|
10
|
+
return context;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export { useRouter };
|
|
@@ -5,3 +5,4 @@ export interface WithRoutingProps {
|
|
|
5
5
|
route?: NavigateOptions;
|
|
6
6
|
}
|
|
7
7
|
export declare function withRouting(component: ElementType<RouteLinkElementProps>): React.FunctionComponent<RouteLinkElementProps>;
|
|
8
|
+
export declare const FallbackRouteLink: React.FunctionComponent<RouteLinkElementProps>;
|