diff --git a/dist/NavEntry.d.ts b/dist/NavEntry.d.ts index d2d3815..7a37870 100644 --- a/dist/NavEntry.d.ts +++ b/dist/NavEntry.d.ts @@ -1,10 +1,10 @@ /// export type NavEntryInfo = { label: string; - link: string; + path: string; children?: NavEntryInfo[]; }; -export declare function NavEntry({ entry: { label, link, children }, dir, here, children: childrenJSX, }: { +export declare function NavEntry({ entry: { label, path, children }, dir, here, children: childrenJSX, }: { entry: NavEntryInfo; dir: string; here: string; diff --git a/dist/index.esm.js b/dist/index.esm.js index be7d751..d289c7e 100644 --- a/dist/index.esm.js +++ b/dist/index.esm.js @@ -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)); } diff --git a/dist/index.js b/dist/index.js index 0244d9c..0b5f19d 100644 --- a/dist/index.js +++ b/dist/index.js @@ -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)); } diff --git a/package.json b/package.json index 84cc1bf..226363e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@sup39/mdx-nav", - "version": "0.1.0", + "version": "0.2.0", "author": "sup39 ", "repository": "github.com:sup39/supMDX-nav", "description": "Nav component for supMDX", diff --git a/src/NavBase.tsx b/src/NavBase.tsx index fc0da7e..3021fcb 100644 --- a/src/NavBase.tsx +++ b/src/NavBase.tsx @@ -24,7 +24,7 @@ export function NavBase({ return ; diff --git a/src/NavEntry.tsx b/src/NavEntry.tsx index 961d5f4..a84bca2 100644 --- a/src/NavEntry.tsx +++ b/src/NavEntry.tsx @@ -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({ - 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({ {isHere ? childrenJSX : <>}
{ - children.map(entry => {childrenJSX}) + children.map(entry => {childrenJSX}) }
:
{label}