Skip to content

Commit

Permalink
Changes:
Browse files Browse the repository at this point in the history
        - New component Burger Menu added into bodiless-organisms
        - header uses new design API
        - Added Burger Menu to the site header (visible only on mobile screens)
        - Added new page /burger-menu/ with burger-menu example
        - Basic Documentation for the Burger Menu
        - updated package* files with new dependency - negomi/react-burger-menu
        - Submenus in Burger Menu implemented as accordions
        - If menu item with submenu is a link, than "Overview" link added to accordion body. "Overview" text is configurable by site-builder
        - Updates for Main Menu: new HOC's: asMainMenu, asEditableMainMenu

         Technical Details:

        - Extended the site tailwind.config
        - Burger Menu API matches Main Menu API
        - new HOC - asStatic sets the component and its children to read-only mode
        - fix for List, preventing unwanted properties to appear into static mode
        - Standardized API for applying responsive classes between
        - withEditableTitle HOC: Allow injection of asEditable to support different kinds of editors

        References:

        - https://www.npmjs.com/package/react-burger-menu

        How To Test:

        - Add to site's Main Menu next items:

          - Item with link and with submenu
          - Item without link and with submenu
          - Item with link and without submenu
          - Item without link and without submenu

        - Resize the browser screen to small size
        - Check that burger menu button is visible
        - Open the burger menu
        - Check that close button works as expected
        - Check that items with submenu rendered as accordionns
        - Check that item with link and with submenu has an "Overview" link in the accordion body
  • Loading branch information
Dmitry committed Jan 21, 2020
1 parent a137a84 commit b0b22d2
Show file tree
Hide file tree
Showing 31 changed files with 908 additions and 72 deletions.
6 changes: 6 additions & 0 deletions examples/test-site/src/components/Elements.token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ const asYMargin = addClasses('my-2');
const asNegXMargin = addClasses('-mx-1');
const asNegYMargin = addClasses('-my-1');

/* Responsive design */
const asMobileOnly = addClasses('md:hidden xs:block');
const asExceptMobile = addClasses('xs:hidden md:block');

/* Primary coloring */
const asPrimaryColorBackground = addClasses('bg-gray-200');
const asTextColorPrimary = addClasses('text-black');
Expand Down Expand Up @@ -84,6 +88,7 @@ export {
asAlignRight,
asAlignCenter,
asAlignJustify,
asExceptMobile,
asHeader1,
asHeader2,
asHeader3,
Expand All @@ -96,6 +101,7 @@ export {
asEditableLink,
asEditable,
asImageRounded,
asMobileOnly,
asSuperScript,
asTextColorPrimary,
asXMargin,
Expand Down
48 changes: 34 additions & 14 deletions examples/test-site/src/components/Layout/header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,36 +12,52 @@
* limitations under the License.
*/

import React, { FC } from 'react';
import React, { FC, ComponentType, HTMLProps } from 'react';
import { Link } from 'gatsby';
import { flow } from 'lodash';
import {
applyDesign,
addClasses,
withDesign,
designable,
DesignableComponentsProps,
DesignableProps,
Div,
} from '@bodiless/fclasses';
import MainMenu from '../Menus/MainMenu';
import BurgerMenu from '../Menus/BurgerMenu';
import {
asPageContainer,
asHeader1,
asPrimaryColorBackground,
} from '../Elements.token';

const getHeaderComponents = applyDesign({
type HeaderComponents = {
Wrapper: ComponentType<any>,
Container: ComponentType<any>,
MobileContainer: ComponentType<any>,
SiteReturn: ComponentType<any>,
DesktopMenu: ComponentType<any>,
MobileMenu: ComponentType<any>,
};
export type Props = {
siteLogo: string,
} & DesignableComponentsProps<HeaderComponents> & HTMLProps<HTMLElement>;

const headerComponents:HeaderComponents = {
Wrapper: Div,
Container: Div,
SiteReturn: Div,
Menu: MainMenu,
});
const Header: FC<DesignableProps & { siteLogo: string }> = ({ design, siteLogo }) => {
DesktopMenu: MainMenu,
MobileMenu: BurgerMenu,
};
const Header: FC<DesignableProps & { siteLogo: string }> = ({ siteLogo, components }) => {
const {
Wrapper,
Container,
SiteReturn,
Menu,
} = getHeaderComponents(design);
DesktopMenu,
MobileMenu,
} = components;

return (
<Wrapper>
Expand All @@ -53,14 +69,18 @@ const Header: FC<DesignableProps & { siteLogo: string }> = ({ design, siteLogo }
</SiteReturn>
</Container>
<div className="container mx-auto">
<Menu nodeKey="MainMenu" nodeCollection="site" />
<DesktopMenu nodeKey="MainMenu" nodeCollection="site" />
<MobileMenu nodeKey="MainMenu" nodeCollection="site" />
</div>
</Wrapper>
);
};
const asSiteHeader = withDesign({
Wrapper: flow(asPrimaryColorBackground, addClasses('')),
Container: flow(asPageContainer, addClasses('flex min-h-16 items-end')),
SiteReturn: flow(asHeader1, addClasses('flex-shrink')),
});
const asSiteHeader = flow(
designable(headerComponents),
withDesign({
Wrapper: flow(asPrimaryColorBackground, addClasses('')),
Container: flow(asPageContainer, addClasses('flex min-h-16 items-end')),
SiteReturn: flow(asHeader1, addClasses('flex-shrink')),
}),
);
export default asSiteHeader(Header);
52 changes: 52 additions & 0 deletions examples/test-site/src/components/Menus/BurgerMenu/burger-menu.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/**
* Copyright © 2019 Johnson & Johnson
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/* Position and sizing of burger button */
.bm-burger-button {
position: relative;
width: 30px;
height: 24px;
margin-left: calc(100% - 30px - 1rem);
margin-top: 0.25rem;
margin-bottom: 0.25rem;
}

/* Color/shape of burger icon bars */
.bm-burger-bars {
background: white;
}
.bm-burger-bars-hover {
background: black;
}

/* Position and sizing of clickable cross button */
.bm-cross-button {
height: 36px;
width: 36px;
}

/* Color/shape of close button cross */
.bm-cross {
background: white;
}

/*
Sidebar wrapper styles
Note: Beware of modifying this element as it can break the animations - you should not need to touch it in most cases
*/
.bm-menu-wrap {
position: fixed;
height: 100%;
top: 0;
}
94 changes: 94 additions & 0 deletions examples/test-site/src/components/Menus/BurgerMenu/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/**
* Copyright © 2019 Johnson & Johnson
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import React, { FunctionComponent } from 'react';
import { flow } from 'lodash';
import {
A,
addProps,
withDesign,
addClasses,
Li,
replaceWith,
} from '@bodiless/fclasses';
import { withChild, asStatic } from '@bodiless/core';
import {
asEditableMenu,
asEditableBurgerSubMenu,
BurgerMenuClean,
SingleAccordionClean,
withSubmenu,
} from '@bodiless/organisms';
import { asEditable, List } from '@bodiless/components';
import { asMobileOnly } from '../../Elements.token';
import './burger-menu.css';

const defaultTopMenuLinksStyles = flow(
addClasses('text-black'),
);

const EditableLinkList = flow(
asEditableMenu(asEditable),
defaultTopMenuLinksStyles,
)(List);

const BurgerSubMenu = flow(
asEditableBurgerSubMenu('Overview', asEditable),
withDesign({
Wrapper: replaceWith(Li),
TitleWrapper: addClasses('font-bold text-black'),
Body: withDesign({
Wrapper: addClasses('pl-1'),
}),
}),
)(SingleAccordionClean);

const Body = withSubmenu(BurgerSubMenu)(EditableLinkList);

const HeaderContents: FunctionComponent = () => (
<A href="/">
<img src="/images/bodiless_logo.png" className="h-16" alt="Return To Home" />
</A>
);

const asBurgerMenuDefaultStyles = flow(
withDesign({
Wrapper: flow(
asMobileOnly,
addClasses('bg-teal-600'),
),
Slide: flow(
addClasses('bg-burger-menu'),
addProps({
noOverlay: true,
width: '100%',
right: true,
}),
),
Header: flow(
withChild(HeaderContents),
addClasses('bg-teal-600 pt-3 pb-4'),
),
Body: flow(
replaceWith(Body),
addClasses('p-3'),
),
}),
);

const BurgerMenu = flow(
asStatic,
asBurgerMenuDefaultStyles,
)(BurgerMenuClean);

export default BurgerMenu;
11 changes: 7 additions & 4 deletions examples/test-site/src/components/Menus/MainMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,17 @@ import {
withDesign,
} from '@bodiless/fclasses';
import {
asEditable,
List,
} from '@bodiless/components';
import {
asHorizontalMenu,
asHorizontalSubMenu,
asEditableMenu,
asEditableSubMenu,
asEditableMainMenu,
asEditableMainSubMenu,
withSubmenu,
} from '@bodiless/organisms';
import { asExceptMobile } from '../Elements.token';

const asWhiteColoredLink = flow(
removeClasses('bl-text-primary hover:bl-underline'),
Expand All @@ -44,7 +46,7 @@ const withTealBackground = addClasses('bg-teal-600');
const withLimitedHeightStyles = addClasses('overflow-y-hidden max-h-menu-row');
const withSubmenuStyles = addClasses('-ml-2');
const MenuSubList = flow(
asEditableSubMenu,
asEditableMainSubMenu(asEditable),
asHorizontalSubMenu,
withDesign({
Title: withLinkStyles,
Expand All @@ -61,7 +63,7 @@ const MenuSubList = flow(
)(List);

const MenuList = flow(
asEditableMenu,
asEditableMainMenu(asEditable),
asHorizontalMenu,
withDesign({
Title: withLinkStyles,
Expand All @@ -75,6 +77,7 @@ const MenuList = flow(
withMenuStyles,
),
}),
asExceptMobile,
)(List);

export default withSubmenu(MenuSubList)(MenuList);
44 changes: 44 additions & 0 deletions examples/test-site/src/data/pages/burger-menu/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**
* Copyright © 2019 Johnson & Johnson
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import React from 'react';
import { graphql } from 'gatsby';
import { Page } from '@bodiless/gatsby-theme-bodiless';

import Layout from '../../../components/Layout';
import MainMenu from '../../../components/Menus/MainMenu';
import BurgerMenu from '../../../components/Menus/BurgerMenu';

export default (props: any) => (
<Page {...props}>
<Layout>
<h1 className="text-3xl font-bold">Burger Menu Demo</h1>
<div className="ml-10">
<p className="py-3">
The following is an burger menu shares the same data as MainMenu
</p>
</div>
<div className="ml-10">
<BurgerMenu nodeKey="my-menu" />
<MainMenu nodeKey="my-menu" />
</div>
</Layout>
</Page>
);

export const query = graphql`
query($slug: String!) {
...PageQuery
...SiteQuery
}
`;
13 changes: 11 additions & 2 deletions examples/test-site/tailwind.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,13 @@ module.exports = {
|
*/

// screens: {},
screens: {
xs: '300px',
sm: '640px',
md: '768px',
lg: '1024px',
xl: '1280px',
},

/*
|---------------------------------------------------------------------------
Expand Down Expand Up @@ -172,7 +178,10 @@ module.exports = {
|
*/

// backgroundColor: theme => theme('colors'),
backgroundColor: theme => ({
...theme('colors'),
'burger-menu': '#D7D7D7',
}),

/*
|---------------------------------------------------------------------------
Expand Down

0 comments on commit b0b22d2

Please sign in to comment.