Skip to content

Commit f26ebf6

Browse files
author
Sean Bethel
committed
add a navigation component
1 parent 1ffa99c commit f26ebf6

File tree

5 files changed

+26
-7
lines changed

5 files changed

+26
-7
lines changed

src/assets/src/components/PageNav.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import React, { Component } from 'react';
2+
import ReactSync from '../ReactSync';
3+
import { collect } from 'collect.js';
4+
5+
6+
class PageNav extends Component{
7+
render(){
8+
// nav
9+
const links = collect(ReactSync.pages).map(p => (new p).renderNavLink()).values();
10+
11+
return links;
12+
}
13+
}
14+
15+
export default PageNav;

src/assets/src/components/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ import Notification from './Notification';
77
import Page from './Page';
88
import Pagination from './Pagination';
99
import Shell from './Shell';
10+
import PageNav from './PageNav';
1011

11-
export { Alert, Field, Form, LegacyModel, Model, Notification, Page, Pagination, Shell };
12+
export { Alert, Field, Form, LegacyModel, Model, Notification, Page, Pagination, Shell, PageNav };

src/assets/src/main.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Pagination, Page, Model, Field, Form, Notification } from './components';
1+
import { Pagination, Page, Model, Field, Form, Notification, PageNav } from './components';
22

33
import * as helpers from './helpers';
44

@@ -22,6 +22,7 @@ const LaravelReactSync = {
2222
Field,
2323
Form,
2424
Notification,
25+
PageNav,
2526
ReactSync,
2627
Reducer,
2728
};
@@ -36,6 +37,7 @@ export {
3637
Field,
3738
Form,
3839
Notification,
40+
PageNav,
3941
ReactSync,
4042
Reducer,
4143
};

src/react-sync-stubs/components/App.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import ReactDOM from 'react-dom';
55

66
import * as _models from 'models';
77

8-
import LaravelReactSync, { Model, helpers as react_sync_helpers } from 'laravel_react_sync';
8+
import LaravelReactSync, { Model, PageNav, helpers as react_sync_helpers } from 'laravel_react_sync';
99

1010
const { app_current } = react_sync_helpers;
1111

@@ -21,7 +21,7 @@ class App extends Component {
2121
super(props);
2222
this.state = this.props.page_props;
2323

24-
window.app = window.app || function(){
24+
typeof window.app !== "function" && window.app = function(){
2525
return this;
2626
}.bind(this);
2727
}
@@ -35,7 +35,7 @@ class App extends Component {
3535

3636
components(){
3737
const { App, ...rest } = require('./');
38-
return rest;
38+
return { PageNav, ...rest };
3939
}
4040

4141
pages(){
@@ -61,8 +61,9 @@ class App extends Component {
6161
throw new Error(`\n\nYou are trying to render a component called: '${renderable.dataset.reactRender}' that doesn't exist, or isn't exported from './Components'\n\nAvailable components are: ${Object.keys(renderables).join(', ')}\n\n`);
6262
}
6363
const { defaultProps = {} } = Renderable;
64+
const defaultPageProps = this.CurrentPage ? this.CurrentPage.defaultProps : {};
6465
return ReactDOM.createPortal(
65-
<Renderable attributes={{...renderable.dataset}} {...defaultProps} {...this.CurrentPage.defaultProps} {...this.state} />,
66+
<Renderable attributes={{...renderable.dataset}} {...defaultProps} {...defaultPageProps} {...this.state} />,
6667
renderable
6768
);
6869
});

src/views/layout.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232

3333
<div class="collapse navbar-collapse" id="navbarSupportedContent">
3434
<!-- Left Side Of Navbar -->
35-
<ul class="navbar-nav mr-auto" id="navbarPageList">
35+
<ul class="navbar-nav mr-auto" id="navbarPageList" data-react-render="PageNav">
3636

3737
</ul>
3838

0 commit comments

Comments
 (0)