Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: customize nav bar background color style #167

Merged
merged 1 commit into from
Jan 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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: `linear-gradient(to bottom, ${props.style?.backgroundColor}, #999`}),
};
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>
));