Skip to content

Commit

Permalink
feat: customize nav bar background color style
Browse files Browse the repository at this point in the history
Signed-off-by: krrrr38 <[email protected]>
  • Loading branch information
krrrr38 committed Dec 12, 2021
1 parent 49f2577 commit ece8de5
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/components/layout/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import * as React from 'react';
import { NavBar } from '../nav-bar/nav-bar';
import {NavBar, NavBarStyle} from '../nav-bar/nav-bar';

require('./layout.scss');

export interface LayoutProps {
navItems: Array<{ path: string; iconClassName: string; title: string; }>;
version?: () => React.ReactElement;
navBarStyle?: NavBarStyle;
children?: React.ReactNode;
}

export const Layout = (props: LayoutProps) => (
<div className='layout'>
<NavBar items={props.navItems} version={props.version}/>
<NavBar items={props.navItems} version={props.version} style={props.navBarStyle} />
{props.children}
</div>
);
10 changes: 9 additions & 1 deletion src/components/nav-bar/nav-bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ require('./nav-bar.scss');
export interface NavBarProps {
items: Array<{ path: string; iconClassName: string; title: string; }>;
version?: () => React.ReactElement;
style?: NavBarStyle;
}

export interface NavBarStyle {
backgroundColor?: string;
}

export function isActiveRoute(locationPath: string, path: string) {
Expand All @@ -18,10 +23,13 @@ export function isActiveRoute(locationPath: string, path: string) {

export const NavBar: React.FunctionComponent<NavBarProps> = (props: NavBarProps, context: AppContext) => {
const locationPath = context.router.route.location.pathname;
const navBarStyle = {
...(props.style?.backgroundColor && {background: props.style?.backgroundColor}),
};
return (
<div className={classNames('nav-bar', {
'nav-bar--compact': (props.items || []).length >= 10,
})}>
})} style={navBarStyle}>
<div className='nav-bar__logo'>
<img src='assets/images/logo.png' alt='Argo'/>
<div className='nav-bar__version'>{props.version && props.version()}</div>
Expand Down
14 changes: 14 additions & 0 deletions stories/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,18 @@ storiesOf('Page', module)
</Layout>
</Route>
</Router>
)).add('background color', () => (
<Router history={history}>
<Route path={location.pathname}>
<Layout navItems={navItems} navBarStyle={{backgroundColor: 'red'}}>
<Page title='Hello world!'>
<div style={{padding: '1em'}}>
<div className='white-box'>
Hello world!
</div>
</div>
</Page>
</Layout>
</Route>
</Router>
));

0 comments on commit ece8de5

Please sign in to comment.