Menu component layout updated

This commit is contained in:
tmshv committed 2019-10-15 05:47:01 +03:00
1 parent 9ca50e87c2
commit 792be94a79
2 files changed
+65 -35

No files matched your search

+33
View File
@@ -0,0 +1,33 @@
import * as React from 'react'
export interface IMenuItemProps {
active: boolean
text: string
url: string
}
export const MenuItem: React.FC<IMenuItemProps> = ({ active, text, url }) => (
<>
<style jsx>{`
a {
color: var(--dark-color);
}
a:visited {
color: var(--dark-color);
}
a:hover {
border-color: var(--dark-color);
}
`}</style>
{active
? (
<span>{text}</span>
) : (
<a href={url}>{text}</a>
)
}
</>
)
+32 -35
View File
@@ -3,24 +3,10 @@ import cx from 'classnames'
import { getPathWithNoTrailingSlash } from '../../lib/url' import { getPathWithNoTrailingSlash } from '../../lib/url'
import { MenuToggle } from './MenuToggle' import { MenuToggle } from './MenuToggle'
import { useScreenType } from '../../hooks/useScreenType' import { useScreenType } from '../../hooks/useScreenType'
import { MenuItem } from './MenuItem'
const itemUrl = (url: string) => getPathWithNoTrailingSlash(url) const itemUrl = (url: string) => getPathWithNoTrailingSlash(url)
const selectedClassName = (flag: boolean) => flag
? 'selected'
: ''
const hmenuCurClassName = (flag: boolean) => flag
? 'HMenu__item--cur'
: ''
const MenuItem = ({ active, text, url }) => active
? (
<span>{text}</span>
) : (
<a href={itemUrl(url)}>{text}</a>
)
export interface IMenuProps { export interface IMenuProps {
items: any[] items: any[]
} }
@@ -40,50 +26,58 @@ export const Menu: React.FC<IMenuProps> = props => {
}, [isMobile]) }, [isMobile])
return ( return (
<menu className="main-menu HMenu"> <menu>
<style jsx>{` <style jsx>{`
.main-menu { menu {
display: flex;
align-items: flex-start;
font-size: var(--normal-font-size); font-size: var(--normal-font-size);
list-style: none;
} }
.main-menu li { li {
display: inline-block;
padding: 0.3em 0.2em 0; padding: 0.3em 0.2em 0;
margin: 0 0.5em; margin-right: 1.0em;
position: relative; position: relative;
border-top: var(--menu-colored-mark-thickness) solid rgba(0, 0, 0, 0);
} }
.main-menu li:first-child { li:first-child {
margin-left: 1em; margin-left: 1em;
} }
.selected { li:last-child {
font-weight: bold; margin-right: 0;
border-top: var(--menu-colored-mark-thickness) solid var(--light-color);
} }
.selected.blue { li.selected {
font-weight: bold;
//border-top: var(--menu-colored-mark-thickness) solid var(--light-color);
}
li.selected.blue {
border-top-color: var(--blue-color); border-top-color: var(--blue-color);
} }
.selected.orange { li.selected.orange {
border-top-color: var(--orange-color); border-top-color: var(--orange-color);
} }
.selected.green { li.selected.green {
border-top-color: var(--green-color); border-top-color: var(--green-color);
} }
.selected.yellow { li.selected.yellow {
border-top-color: var(--yellow-color); border-top-color: var(--yellow-color);
} }
.selected.pink { li.selected.pink {
border-top-color: var(--pink-color); border-top-color: var(--pink-color);
} }
.selected.red { li.selected.red {
border-top-color: var(--red-color); border-top-color: var(--red-color);
} }
`}</style> `}</style>
@@ -99,13 +93,16 @@ export const Menu: React.FC<IMenuProps> = props => {
{props.items.map((item, index) => ( {props.items.map((item, index) => (
<li key={index} <li key={index}
className={cx( className={cx(
'HMenu__item', item.color, {
hmenuCurClassName(item.highlighted), selected: item.highlighted,
selectedClassName(item.highlighted), }
item.color,
)} )}
> >
<MenuItem {...item} /> <MenuItem
url={itemUrl(item.url)}
text={item.text}
active={item.active}
/>
</li> </li>
))} ))}
</menu> </menu>