Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@rsuite/document-nav

Package Overview
Dependencies
Maintainers
5
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@rsuite/document-nav

Document navigation is automatically generated based on the HTML title (h1-h6) tag

  • 1.0.10
  • Source
  • npm
  • Socket score

Version published
Maintainers
5
Created
Source

Document Nav

Document navigation is automatically generated based on the HTML title (h1-h6) tag.

Install

npm i @rsuite/document-nav --save

Examples

import { NavProvider, Content, Nav } from '@rsuite/document-nav';
import '@rsuite/document-nav/lib/less/index.less';

function render() {
  return (
    <NavProvider>
      <div className="row">
        <div className="col col-md-4">
          <Nav />
        </div>
        <div className="col col-md-20">
          <Content>{require('redeme.md')}</Content>
        </div>
      </div>
    </NavProvider>
  );
}

Style

@import '@rsuite/document-nav/lib/less/index.less';
@doc-nav-active-color: #34c3ff;

使用方法

自动解析手动设置两种使用方式:

自动解析

只需按照如下结构组合代码,document-nav 会自动从 Content 中解析出所有的 h 标签,并生成导航菜单。

NavProvider 负责 ContentNav 的协作,需放在外层,中间可以任意布局。

<NavProvider>
  <Nav />
  <Content>
    ...content
  </Content>
</NavProvider>

可以使用 minLevelmaxLevel 来限制导航的标题级别,如 minLevel = 2maxLevel = 4 时,只有 h2, h3, h4 会被导航。

注意

该方法使用标题作为锚点 ID,请尽量避免标题名称重复。

import { NavProvider, Content, Nav } from '@rsuite/document-nav';
import '@rsuite/document-nav/lib/less/index.less';

function render() {
  return (
    <NavProvider>
      <div className="row">
        <div className="col col-md-4">
          <Nav />
        </div>
        <div className="col col-md-20">
          <Content>{require('redeme.md')}</Content>
        </div>
      </div>
    </NavProvider>
  );
}

手动设置

在 Nav 组件中通过 NavItem 组件设置导航。

import { NavProvider, Content, Nav } from '@rsuite/document-nav';
import '@rsuite/document-nav/lib/less/index.less';

function render() {
  return (
    <NavProvider>
      <div className="row">
        <div className="col col-md-4">
          <Nav>
            <Nav.Item anchor="h-3" title="二级标题---2">
                <Nav.Item anchor="h-3-1" title="三级标题">
              </Nav.Item>
              <Nav.Item anchor="h-4" title="二级标题---3" />
          </Nav>
        </div>
        <div className="col col-md-20">
          <Content>{require('redeme.md')}</Content>
        </div>
      </div>
    </NavProvider>
  );
}

Props

<Nav>

NameType (Default)Description
fixedboolean (true)是否固定在屏幕的某一个位置?仅当为 true 时,offset 属性才会生效,为 false 时,导航菜单跟随文档流
offsetobject ({left: 'auto', top: 60})定位,属性为 top, right, bottom, left
widthnumber (250)导航部分的宽。当 fixedtrue 时,默认为 250, 为 false 时默认为 100%
scrollBarstring ('right')导航栏边上的滚动条位置,leftright
minLevelnumber (2)最小导航级别,默认为 2h2
maxLevelnumber (4)最大导航级别,默认为 4h4
showOrderNumberboolean (true)是否显示标题前的序号
onceboolean (true)只解析一次文档?设为true则只会解析一次,文档发生变化时不会重新解析,性能较好。
rtlboolean (false)文档从右侧开始阅读
deepnumber (10)解析的 DOM 深度,避免和标题无关的 DOM 层级过深导致的性能损耗

<Nav.Item>

NameType (Default)Description
anchorstring对应的锚点 id
titlestring显示的标题
childrennode可选,子导航菜单

License

MIT licensed

Keywords

FAQs

Package last updated on 17 Jan 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc