rename link
to path
in NavEntry
This commit is contained in:
parent
29b17907c2
commit
1594f6cf2e
6 changed files with 16 additions and 16 deletions
4
dist/NavEntry.d.ts
vendored
4
dist/NavEntry.d.ts
vendored
|
@ -1,10 +1,10 @@
|
|||
/// <reference types="react" />
|
||||
export type NavEntryInfo = {
|
||||
label: string;
|
||||
link: string;
|
||||
path: string;
|
||||
children?: NavEntryInfo[];
|
||||
};
|
||||
export declare function NavEntry<Body>({ entry: { label, link, children }, dir, here, children: childrenJSX, }: {
|
||||
export declare function NavEntry<Body>({ entry: { label, path, children }, dir, here, children: childrenJSX, }: {
|
||||
entry: NavEntryInfo;
|
||||
dir: string;
|
||||
here: string;
|
||||
|
|
8
dist/index.esm.js
vendored
8
dist/index.esm.js
vendored
|
@ -40,8 +40,8 @@ function __rest(s, e) {
|
|||
}
|
||||
|
||||
function NavEntry(_a) {
|
||||
var _b = _a.entry, label = _b.label, link = _b.link, children = _b.children, dir = _a.dir, here = _a.here, childrenJSX = _a.children;
|
||||
var href = dir + link;
|
||||
var _b = _a.entry, label = _b.label, path = _b.path, children = _b.children, dir = _a.dir, here = _a.here, childrenJSX = _a.children;
|
||||
var href = dir + path;
|
||||
var isHere = href.replace(/\/$/, '') === here; // remove trailing slash
|
||||
var isRHere = isHere || here.startsWith(href); // here or is children
|
||||
var _c = useState(isRHere), toggle = _c[0], setToggle = _c[1];
|
||||
|
@ -53,7 +53,7 @@ function NavEntry(_a) {
|
|||
React.createElement("svg", { viewBox: "0 0 8 8", onClick: function () { return setToggle(function (e) { return !e; }); } },
|
||||
React.createElement("polyline", { points: "6 3 4 5 2 3" }))),
|
||||
isHere ? childrenJSX : React.createElement(React.Fragment, null),
|
||||
React.createElement("div", { className: 'nav-dir-child' }, children.map(function (entry) { return React.createElement(NavEntry, { key: entry.link, entry: entry, dir: href, here: here }, childrenJSX); })))) : React.createElement("div", { className: entryCls },
|
||||
React.createElement("div", { className: 'nav-dir-child' }, children.map(function (entry) { return React.createElement(NavEntry, { key: entry.path, entry: entry, dir: href, here: here }, childrenJSX); })))) : React.createElement("div", { className: entryCls },
|
||||
React.createElement(Link, { href: href }, label));
|
||||
}
|
||||
|
||||
|
@ -67,7 +67,7 @@ function NavBase(_a) {
|
|||
return React.createElement("nav", { className: className },
|
||||
children,
|
||||
React.createElement("div", { className: "nav-root" },
|
||||
entries.map(function (entry) { return React.createElement(NavEntry, { key: entry.link, entry: entry, dir: '/', here: pathname }); }),
|
||||
entries.map(function (entry) { return React.createElement(NavEntry, { key: entry.path, entry: entry, dir: '/', here: pathname }); }),
|
||||
headingsJSX));
|
||||
}
|
||||
|
||||
|
|
8
dist/index.js
vendored
8
dist/index.js
vendored
|
@ -42,8 +42,8 @@ function __rest(s, e) {
|
|||
}
|
||||
|
||||
function NavEntry(_a) {
|
||||
var _b = _a.entry, label = _b.label, link = _b.link, children = _b.children, dir = _a.dir, here = _a.here, childrenJSX = _a.children;
|
||||
var href = dir + link;
|
||||
var _b = _a.entry, label = _b.label, path = _b.path, children = _b.children, dir = _a.dir, here = _a.here, childrenJSX = _a.children;
|
||||
var href = dir + path;
|
||||
var isHere = href.replace(/\/$/, '') === here; // remove trailing slash
|
||||
var isRHere = isHere || here.startsWith(href); // here or is children
|
||||
var _c = React.useState(isRHere), toggle = _c[0], setToggle = _c[1];
|
||||
|
@ -55,7 +55,7 @@ function NavEntry(_a) {
|
|||
React.createElement("svg", { viewBox: "0 0 8 8", onClick: function () { return setToggle(function (e) { return !e; }); } },
|
||||
React.createElement("polyline", { points: "6 3 4 5 2 3" }))),
|
||||
isHere ? childrenJSX : React.createElement(React.Fragment, null),
|
||||
React.createElement("div", { className: 'nav-dir-child' }, children.map(function (entry) { return React.createElement(NavEntry, { key: entry.link, entry: entry, dir: href, here: here }, childrenJSX); })))) : React.createElement("div", { className: entryCls },
|
||||
React.createElement("div", { className: 'nav-dir-child' }, children.map(function (entry) { return React.createElement(NavEntry, { key: entry.path, entry: entry, dir: href, here: here }, childrenJSX); })))) : React.createElement("div", { className: entryCls },
|
||||
React.createElement(Link, { href: href }, label));
|
||||
}
|
||||
|
||||
|
@ -69,7 +69,7 @@ function NavBase(_a) {
|
|||
return React.createElement("nav", { className: className },
|
||||
children,
|
||||
React.createElement("div", { className: "nav-root" },
|
||||
entries.map(function (entry) { return React.createElement(NavEntry, { key: entry.link, entry: entry, dir: '/', here: pathname }); }),
|
||||
entries.map(function (entry) { return React.createElement(NavEntry, { key: entry.path, entry: entry, dir: '/', here: pathname }); }),
|
||||
headingsJSX));
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@sup39/mdx-nav",
|
||||
"version": "0.1.0",
|
||||
"version": "0.2.0",
|
||||
"author": "sup39 <dev@sup39.dev>",
|
||||
"repository": "github.com:sup39/supMDX-nav",
|
||||
"description": "Nav component for supMDX",
|
||||
|
|
|
@ -24,7 +24,7 @@ export function NavBase({
|
|||
return <nav className={className}>
|
||||
{children}
|
||||
<div className="nav-root">
|
||||
{entries.map(entry => <NavEntry key={entry.link} entry={entry} dir={'/'} here={pathname} />)}
|
||||
{entries.map(entry => <NavEntry key={entry.path} entry={entry} dir={'/'} here={pathname} />)}
|
||||
{headingsJSX}
|
||||
</div>
|
||||
</nav>;
|
||||
|
|
|
@ -2,14 +2,14 @@ import React, {useState} from 'react';
|
|||
import Link from 'next/link';
|
||||
export type NavEntryInfo = {
|
||||
label: string
|
||||
link: string
|
||||
path: string
|
||||
children?: NavEntryInfo[]
|
||||
};
|
||||
|
||||
export function NavEntry<Body, >({
|
||||
entry: {label, link, children}, dir, here, children: childrenJSX,
|
||||
entry: {label, path, children}, dir, here, children: childrenJSX,
|
||||
}: {entry: NavEntryInfo, dir: string, here: string, children?: Body}) {
|
||||
const href = dir+link;
|
||||
const href = dir+path;
|
||||
const isHere = href.replace(/\/$/, '')===here; // remove trailing slash
|
||||
const isRHere = isHere || here.startsWith(href); // here or is children
|
||||
|
||||
|
@ -22,7 +22,7 @@ export function NavEntry<Body, >({
|
|||
</div>
|
||||
{isHere ? childrenJSX : <></>}
|
||||
<div className='nav-dir-child'>{
|
||||
children.map(entry => <NavEntry key={entry.link} entry={entry} dir={href} here={here}>{childrenJSX}</NavEntry>)
|
||||
children.map(entry => <NavEntry key={entry.path} entry={entry} dir={href} here={here}>{childrenJSX}</NavEntry>)
|
||||
}</div>
|
||||
</></div> : <div className={entryCls}>
|
||||
<Link href={href}>{label}</Link>
|
||||
|
|
Loading…
Reference in a new issue