Skip to content

Commit

Permalink
Update examples
Browse files Browse the repository at this point in the history
  • Loading branch information
cheton committed Dec 14, 2017
1 parent a6bd991 commit 23a2801
Show file tree
Hide file tree
Showing 11 changed files with 1,043 additions and 301 deletions.
953 changes: 692 additions & 261 deletions docs/bundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/bundle.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
</head>
<body>
<div id="container"></div>
<script type="text/javascript" src="bundle.js?0cd965825df1576bb078"></script></body>
<script type="text/javascript" src="bundle.js?8aa69aed34de22e44d91"></script></body>
</html>
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,8 @@ export default class extends PureComponent {

pageTitle = {
'home': 'Home',
'charts/barchart': ['Charts', 'Bar Chart'],
'charts/linechart': ['Charts', 'Line Chart'],
'forms/layout': ['Forms', 'Form Layout'],
'forms/validation': ['Forms', 'Form Validation'],
'devices': ['Devices'],
'reports': ['Reports'],
'settings/policy': ['Settings', 'Policy'],
'settings/network': ['Settings', 'Network']
};
Expand Down Expand Up @@ -63,41 +61,21 @@ export default class extends PureComponent {
Home
</NavText>
</NavItem>
<NavItem eventKey="charts">
<NavItem eventKey="devices">
<NavIcon>
<i className="fa fa-fw fa-line-chart" style={{ fontSize: '1.75em' }} />
</NavIcon>
<NavText style={{ paddingRight: 32 }}>
Charts
Devices
</NavText>
<NavItem eventKey="charts/linechart">
<NavText>
Line Chart
</NavText>
</NavItem>
<NavItem eventKey="charts/barchart">
<NavText>
Bar Chart
</NavText>
</NavItem>
</NavItem>
<NavItem eventKey="forms">
<NavItem eventKey="reports">
<NavIcon>
<i className="fa fa-fw fa-list-alt" style={{ fontSize: '1.75em' }} />
</NavIcon>
<NavText style={{ paddingRight: 32 }}>
Forms
Reports
</NavText>
<NavItem eventKey="forms/layout">
<NavText>
Form Layout
</NavText>
</NavItem>
<NavItem eventKey="forms/validation">
<NavText>
Form Validation
</NavText>
</NavItem>
</NavItem>
<NavItem eventKey="settings">
<NavIcon>
Expand Down
3 changes: 2 additions & 1 deletion examples/Navbar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default class extends Component {
};

render() {
const { name, url } = this.props;
const { name, url, children } = this.props;

return (
<nav
Expand Down Expand Up @@ -45,6 +45,7 @@ export default class extends Component {
{ [styles.in]: this.state.collapseIn }
)}
>
{children}
<Button
className={classNames(styles.navbarBtn, styles.navbarRight)}
btnStyle="flat"
Expand Down
2 changes: 1 addition & 1 deletion examples/SideNav.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import SideNav from '../src';

export { NavItem, NavIcon, NavText } from '../src';
export { Toggle, Nav, NavItem, NavIcon, NavText } from '../src';
export default SideNav;
119 changes: 119 additions & 0 deletions examples/Styled/StyledSideNav.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
import styled from 'styled-components';
import SideNav, {
Toggle,
Nav,
NavItem,
NavIcon,
NavText
} from '../SideNav';

// SideNav
const StyledSideNav = styled(SideNav)`
background-color: #fff;
border-right: 1px solid #ddd;
`;
StyledSideNav.defaultProps = SideNav.defaultProps;

// Toggle
const StyledToggle = styled(Toggle)`
background-color: #db3d44;
`;
StyledToggle.defaultProps = Toggle.defaultProps;

// Nav
const StyledNav = styled(Nav)`
background-color: #fff;
&&[class*="expanded--"] {
[class*="sidenav-subnav--"] {
> [class*="sidenav-subnavitem--"],
> [class*="sidenav-subnavitem--"]:hover {
> a {
color: #222;
}
}
> [class*="sidenav-subnavitem--"]:hover {
> a {
background-color: #eee;
}
}
> [class*="sidenav-subnavitem--"][class*="selected--"] {
> a {
color: #db3d44;
}
> a::before {
border-left: 2px solid #db3d44;
}
}
}
}
&& > [class*="sidenav-navitem--"] {
> a {
background-color: inherit;
color: #222;
}
}
&& > [class*="sidenav-navitem--"]:hover {
> a {
background-color: #eee;
}
}
&& > [class*="sidenav-navitem--"],
&& > [class*="sidenav-navitem--"]:hover {
> a {
[class*="sidenav-nav-icon--"] {
&, > * {
color: #666;
}
}
[class*="sidenav-nav-text--"] {
&, > * {
color: #222;
}
}
}
}
&& > [class*="sidenav-navitem--"][class*="selected"],
&& > [class*="sidenav-navitem--"][class*="selected"]:hover {
> a {
[class*="sidenav-nav-icon--"],
[class*="sidenav-nav-text--"] {
&, > * {
color: #db3d44;
}
}
[class*="sidenav-nav-text--"] {
font-weight: 700;
}
}
}
`;
StyledNav.defaultProps = Nav.defaultProps;

// NavItem
const StyledNavItem = styled(NavItem)`
`;
StyledNavItem.defaultProps = NavItem.defaultProps;

// NavIcon
const StyledNavIcon = styled(NavIcon)`
color: #222;
`;
StyledNavIcon.defaultProps = NavIcon.defaultProps;

// NavText
const StyledNavText = styled(NavText)`
color: #222;
`;
StyledNavText.defaultProps = NavText.defaultProps;

export {
StyledToggle as Toggle,
StyledNav as Nav,
StyledNavItem as NavItem,
StyledNavIcon as NavIcon,
StyledNavText as NavText
};
export default StyledSideNav;
187 changes: 187 additions & 0 deletions examples/Styled/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
import Breadcrumbs from '@trendmicro/react-breadcrumbs';
import ensureArray from 'ensure-array';
import React, { PureComponent } from 'react';
import styled from 'styled-components';
import SideNav, { Toggle, Nav, NavItem, NavIcon, NavText } from './StyledSideNav';

const navWidthCollapsed = 64;
const navWidthExpanded = 280;

const NavHeader = styled.div`
display: ${props => (props.expanded ? 'block' : 'none')};
white-space: nowrap;
background-color: #db3d44;
color: #fff;
> * {
color: inherit;
background-color: inherit;
}
`;

// height: 20px + 10px + 10px = 40px
const NavTitle = styled.div`
font-size: 2em;
line-height: 20px;
padding: 10px 0;
`;

// height: 20px + 4px = 24px;
const NavSubTitle = styled.div`
font-size: 1em;
line-height: 20px;
padding-bottom: 4px;
`;

const NavInfoPane = styled.div`
float: left;
width: 100%;
padding: 10px 20px;
background-color: #eee;
`;

const Separator = styled.div`
clear: both;
position: relative;
margin: .8rem 0;
background-color: #ddd;
height: 1px;
`;

const Main = styled.main`
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: ${navWidthCollapsed}px;
overflow: hidden;
transition: all .15s;
padding: 0 20px;
background: ${props => (props.expanded ? 'rgba(0, 0, 0, .6)' : 'inherit')};
transition: background-color .35s cubic-bezier(.4, 0, .2, 1);
`;

export default class extends PureComponent {
state = {
selected: 'home',
expanded: false
};

lastUpdateTime = new Date().toISOString();

onSelect = (selected) => {
this.setState({ selected: selected });
};
onToggle = (expanded) => {
this.setState({ expanded: expanded });
};

pageTitle = {
'home': 'Home',
'devices': ['Devices'],
'reports': ['Reports'],
'settings/policy': ['Settings', 'Policy'],
'settings/network': ['Settings', 'Network']
};

renderBreadcrumbs() {
const { selected } = this.state;
const list = ensureArray(this.pageTitle[selected]);

return (
<Breadcrumbs>
{list.map((item, index) => (
<Breadcrumbs.Item
active={index === list.length - 1}
key={`${selected}_${index}`}
>
{item}
</Breadcrumbs.Item>
))}
</Breadcrumbs>
);
}
render() {
const { expanded, selected } = this.state;

return (
<div>
<SideNav
style={{ minWidth: expanded ? navWidthExpanded : navWidthCollapsed }}
onSelect={this.onSelect}
onToggle={this.onToggle}
>
<Toggle />
<NavHeader expanded={expanded}>
<NavTitle>Side Navigation</NavTitle>
<NavSubTitle>Styled Side Navigation</NavSubTitle>
</NavHeader>
{expanded &&
<NavInfoPane>
<div>Time: {this.lastUpdateTime}</div>
<div>User: admin</div>
</NavInfoPane>
}
<Nav
defaultSelected={selected}
>
<NavItem eventKey="home">
<NavIcon>
<i className="fa fa-fw fa-home" style={{ fontSize: '1.75em' }} />
</NavIcon>
<NavText style={{ paddingRight: 32 }}>
HOME
</NavText>
</NavItem>
<NavItem eventKey="devices">
<NavIcon>
<i className="fa fa-fw fa-line-chart" style={{ fontSize: '1.75em' }} />
</NavIcon>
<NavText style={{ paddingRight: 32 }}>
DEVICES
</NavText>
</NavItem>
<NavItem eventKey="reports">
<NavIcon>
<i className="fa fa-fw fa-list-alt" style={{ fontSize: '1.75em' }} />
</NavIcon>
<NavText style={{ paddingRight: 32 }}>
REPORTS
</NavText>
</NavItem>
<NavItem eventKey="settings">
<NavIcon>
<i className="fa fa-fw fa-cogs" style={{ fontSize: '1.5em' }} />
</NavIcon>
<NavText style={{ paddingRight: 32 }}>
SETTINGS
</NavText>
<NavItem eventKey="settings/policy">
<NavText>
POLICY
</NavText>
</NavItem>
<NavItem eventKey="settings/network">
<NavText>
NETWORK
</NavText>
</NavItem>
</NavItem>
<Separator />
<NavItem eventKey="logout">
<NavIcon>
<i className="fa fa-fw fa-power-off" style={{ fontSize: '1.5em' }} />
</NavIcon>
<NavText style={{ paddingRight: 32 }}>
SIGN OUT
</NavText>
</NavItem>
</Nav>
</SideNav>
<Main expanded={expanded}>
{this.renderBreadcrumbs()}
</Main>
</div>
);
}
}
Loading

0 comments on commit 23a2801

Please sign in to comment.