clear-react-router 2.5.6 → 2.5.7
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/README.md +1 -0
- package/dist/components/Link.d.ts +3 -3
- package/dist/index.js +11 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -314,6 +314,7 @@ Active matching: `'/'` matches only exactly `'/'`; any other target is active on
|
|
|
314
314
|
| `exact` | `boolean` | `false` | When `false`, the link is also considered active if the current URL starts with `to` (useful for nested routes) |
|
|
315
315
|
| `prefetch` | `'hover' \| 'render' \| 'viewport' \| 'none'` | `Router` config | Override the global prefetch strategy |
|
|
316
316
|
| `hoverPrefetchDelay` | `number` | `Router` config | Override the global hover delay |
|
|
317
|
+
| `onMouseEnter` / `onMouseLeave` | Mouse event handlers | `undefined` | Called on hover (e.g. to animate icons). Your handlers run first — the built-in `hover` prefetch still fires afterwards: the handlers are merged, not overridden |
|
|
317
318
|
| `children` | `ReactNode` | required | Content to render inside the link |
|
|
318
319
|
| `className` | `string \| ({ isActive, isPending }) => string` | `undefined` | CSS class name(s). Can be a function for dynamic styling |
|
|
319
320
|
| `style` | `CSSProperties \| ({ isActive, isPending }) => CSSProperties` | `undefined` | Inline styles. Can be a function for dynamic styling |
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type CSSProperties, ReactNode, MouseEvent, ReactElement, Ref } from 'react';
|
|
1
|
+
import { type CSSProperties, ReactNode, MouseEvent, ReactElement, Ref, AnchorHTMLAttributes } from 'react';
|
|
2
2
|
import { LinkDestination, RouterProps, SearchObject } from '../types';
|
|
3
3
|
type ElementState = {
|
|
4
4
|
isActive: boolean;
|
|
@@ -16,7 +16,7 @@ export type ElementProps<T extends HTMLElement = HTMLElement> = {
|
|
|
16
16
|
'aria-current'?: 'page';
|
|
17
17
|
'aria-busy'?: boolean;
|
|
18
18
|
} & Record<`data-${string}` | `aria-${string}`, unknown>;
|
|
19
|
-
export type LinkProps<T extends HTMLElement = HTMLAnchorElement, TPath extends string = string> = {
|
|
19
|
+
export type LinkProps<T extends HTMLElement = HTMLAnchorElement, TPath extends string = string> = Omit<AnchorHTMLAttributes<HTMLAnchorElement>, 'href' | 'onClick' | 'style' | 'className'> & {
|
|
20
20
|
search?: string | SearchObject;
|
|
21
21
|
state?: unknown;
|
|
22
22
|
children?: ReactNode;
|
|
@@ -30,5 +30,5 @@ export type LinkProps<T extends HTMLElement = HTMLAnchorElement, TPath extends s
|
|
|
30
30
|
style?: CSSProperties | ((arg: ElementState) => CSSProperties);
|
|
31
31
|
exact?: boolean;
|
|
32
32
|
} & LinkDestination<TPath> & Record<`data-${string}` | `aria-${string}`, unknown>;
|
|
33
|
-
export declare const Link: <T extends HTMLElement = HTMLAnchorElement, const TPath extends string = string>({ children, to, path, params, search, state, as, prefetch: linkPrefetch, hoverPrefetchDelay, className, style, beforeNavigate, exact, activeClassName, pendingClassName, ...rest }: LinkProps<T, TPath>) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
33
|
+
export declare const Link: <T extends HTMLElement = HTMLAnchorElement, const TPath extends string = string>({ children, to, path, params, search, state, as, prefetch: linkPrefetch, hoverPrefetchDelay, className, style, beforeNavigate, exact, activeClassName, pendingClassName, onMouseEnter: onMouseEnterProp, onMouseLeave: onMouseLeaveProp, ...rest }: LinkProps<T, TPath>) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
34
34
|
export {};
|
package/dist/index.js
CHANGED
|
@@ -1093,7 +1093,7 @@ var useNavigate = router.hooks.useNavigate;
|
|
|
1093
1093
|
var VIEWPORT_DWELL_MS = 250;
|
|
1094
1094
|
var defaultAs = (props) => /* @__PURE__ */ jsx("a", { ...props });
|
|
1095
1095
|
var comparator = (to, pathname, exact) => to === "/" ? pathname === "/" : exact ? pathname === to : pathname === to || pathname?.startsWith(`${to}/`);
|
|
1096
|
-
var Link = ({ children, to, path, params, search, state, as = defaultAs, prefetch: linkPrefetch, hoverPrefetchDelay, className, style, beforeNavigate, exact = false, activeClassName = "active-link", pendingClassName = "pending-link", ...rest }) => {
|
|
1096
|
+
var Link = ({ children, to, path, params, search, state, as = defaultAs, prefetch: linkPrefetch, hoverPrefetchDelay, className, style, beforeNavigate, exact = false, activeClassName = "active-link", pendingClassName = "pending-link", onMouseEnter: onMouseEnterProp, onMouseLeave: onMouseLeaveProp, ...rest }) => {
|
|
1097
1097
|
const [toPathname, toSearch] = splitPathAndSearch(to ?? "");
|
|
1098
1098
|
const pathname = path !== void 0 ? interpolatePath(path, params ?? {}) : toPathname;
|
|
1099
1099
|
const searchString = search === void 0 ? toSearch : typeof search === "object" ? formatSearchObject(search) : search;
|
|
@@ -1114,23 +1114,30 @@ var Link = ({ children, to, path, params, search, state, as = defaultAs, prefetc
|
|
|
1114
1114
|
state,
|
|
1115
1115
|
pathname
|
|
1116
1116
|
]);
|
|
1117
|
-
const onMouseEnter = useCallback(() => {
|
|
1117
|
+
const onMouseEnter = useCallback((event) => {
|
|
1118
|
+
onMouseEnterProp?.(event);
|
|
1118
1119
|
const prefetchDelay = getPrefetchDelay();
|
|
1119
1120
|
if (getPrefetchStrategy() !== "hover" || !prefetchDelay) return;
|
|
1120
1121
|
if (timeout.current) clearTimeout(timeout.current);
|
|
1121
1122
|
timeout.current = window.setTimeout(() => router.runtime.prefetch(location), prefetchDelay);
|
|
1122
1123
|
}, [
|
|
1124
|
+
onMouseEnterProp,
|
|
1123
1125
|
getPrefetchStrategy,
|
|
1124
1126
|
getPrefetchDelay,
|
|
1125
1127
|
location
|
|
1126
1128
|
]);
|
|
1127
|
-
const onMouseLeave = useCallback(() => {
|
|
1129
|
+
const onMouseLeave = useCallback((event) => {
|
|
1130
|
+
onMouseLeaveProp?.(event);
|
|
1128
1131
|
if (getPrefetchStrategy() !== "hover" || !getPrefetchDelay()) return;
|
|
1129
1132
|
if (timeout.current) {
|
|
1130
1133
|
clearTimeout(timeout.current);
|
|
1131
1134
|
timeout.current = 0;
|
|
1132
1135
|
}
|
|
1133
|
-
}, [
|
|
1136
|
+
}, [
|
|
1137
|
+
onMouseLeaveProp,
|
|
1138
|
+
getPrefetchStrategy,
|
|
1139
|
+
getPrefetchDelay
|
|
1140
|
+
]);
|
|
1134
1141
|
useEffect(() => {
|
|
1135
1142
|
if (getPrefetchStrategy() !== "render") return;
|
|
1136
1143
|
const controller = new AbortController();
|