Skip to content

Commit

Permalink
Adding more documentation for CustomNav, following public request
Browse files Browse the repository at this point in the history
  • Loading branch information
mavarazy committed Feb 4, 2018
1 parent c60ef08 commit 44d1419
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 1 deletion.
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,37 @@ CustomNavs will receive 3 properties

Look at pagination for more details.

For example, if we want to use NavBar to navigate in paginated form, we can define `CustomNav` like this

```js
import React from "react";
import { GENERIC_NAV } from "react-jsonschema-form-pagination/lib/utils";

function CustomNavs({ navs: { links }, onNavChange }) {
let relLinks = links.filter(({ nav }) => nav !== GENERIC_NAV);
return (
<nav className="navbar navbar-default">
<div className="container-fluid">
<div className="collapse navbar-collapse">
<ul className="nav navbar-nav">
{relLinks.map(({ nav, name, icon, isActive }, i) => (
<li key={i} onClick={() => onNavChange(nav)} className={isActive ? "active" : null}>
<a>
{icon && <span className={icon} aria-hidden="true"/>}
&nbsp;{name || nav}
</a>
</li>
))}
</ul>
</div>
</div>
</nav>
);
}

export default CustomNavs;
```

## Nav ordering

By default all tabs rendered in order they appear in uiSchema, since it's a primary source of layer reference,
Expand Down
3 changes: 2 additions & 1 deletion playground/app/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import React, { Component } from "react";
import applyNav from "../../src";
import Form from "react-jsonschema-form";
import conf from "./conf";
import CustomNav from "./CustomNavs";

let FormWithNav = applyNav(Form);
let FormWithNav = applyNav(Form, CustomNav);

export class App extends Component {
constructor(props) {
Expand Down
29 changes: 29 additions & 0 deletions playground/app/CustomNavs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import React from "react";
import { GENERIC_NAV } from "../../src/utils";

function Navs({ navs: { links }, onNavChange }) {
let relLinks = links.filter(({ nav }) => nav !== GENERIC_NAV);
return (
<nav className="navbar navbar-default">
<div className="container-fluid">
<div className="collapse navbar-collapse">
<ul className="nav navbar-nav">
{relLinks.map(({ nav, name, icon, isActive }, i) => (
<li
key={i}
onClick={() => onNavChange(nav)}
className={isActive ? "active" : null}>
<a>
{icon && <span className={icon} aria-hidden="true" />}
&nbsp;{name || nav}
</a>
</li>
))}
</ul>
</div>
</div>
</nav>
);
}

export default Navs;

0 comments on commit 44d1419

Please sign in to comment.