Skip to content

feat(header-navigation): add implementation#525

Merged
blackswanny merged 4 commits intomasterfrom
feature/header
Nov 30, 2018
Merged

feat(header-navigation): add implementation#525
blackswanny merged 4 commits intomasterfrom
feature/header

Conversation

@blackswanny
Copy link
Contributor

@blackswanny blackswanny commented Nov 20, 2018

add header navigation implementation

Header navigation is highly customizable component. All examples provide different ways customers can address their design and concerns. They mainly show flexibility of Base UI rather than component itself.

@gergelyke gergelyke changed the title add header navigation implementation feat(header-navigation): add implementation Nov 20, 2018
@gergelyke
Copy link
Contributor

screen shot 2018-11-20 at 9 45 55 am

it seems like the hamburger icon is not in the middle

Copy link
Contributor

@gergelyke gergelyke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are you planning to add tests in a separate PR?

/* eslint-env node */
/* eslint-disable flowtype/require-valid-file-annotation */
module.exports = {
WITH_MENU_ELEMENT: 'With Dropdown Menu',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you please add Header navigation (or something similar) to the names, so for the visual regression tests it is simpler to include in screener.config.js?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

})
}
>
<svg
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we move the svg to a file and import it, just to make this example more readable?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

// Styled elements
export {
Root as StyledRoot,
NavigationItem,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add Styled to the NavigationItem and NavigationList components for consistency?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As per @schnerd original proposal current names look more semantically right. I can rename it if needed

#514 (comment)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with @Austin94 comment, we should be consistent. So far we export any styled component with Styled prefix. We should be consistent.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@gergelyke
Copy link
Contributor

also, for the menu should we use point cursor instead of the text?

@blackswanny
Copy link
Contributor Author

blackswanny commented Nov 20, 2018

it seems like the hamburger icon is not in the middle

@gergelyke
fixed

@blackswanny blackswanny force-pushed the feature/header branch 2 times, most recently from d2cffe0 to b365be5 Compare November 20, 2018 21:50
@blackswanny
Copy link
Contributor Author

blackswanny commented Nov 20, 2018

also, for the menu should we use point cursor instead of the text?

@gergelyke
Menu is used with it's own default styles, however I added cursor for better customization

@blackswanny
Copy link
Contributor Author

are you planning to add tests in a separate PR?

yes, next commit

@nadiia
Copy link
Contributor

nadiia commented Nov 20, 2018

Tab links in the example are not keyboard navigatable. Could you fix it please?


import * as React from 'react';
import {Button} from '../button';
import {StatefulMenu as Menu, KEY_STRINGS} from '../menu';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We use menu component in the examples but the menu doesn't seem to work - never shows up in the current build.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

<div
tabIndex="0"
aria-label="Navigation menu"
style={{lineHeight: 'initial'}}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's only single style but may still not be a good example to show how we do styling since it created an inline styles. Let's use styled for adding styles.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

</NavigationItem>
<NavigationItem>Uber</NavigationItem>
</NavigationList>
<NavigationList $align={ALIGN.center} />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this empty centered navigation list for?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So in my flexbox styles if all element are left or right docked flexbox still docks them together. I had to add this center to avoid it. I checked flexbox implementation and didn't find other solution. So there has to be at least one element, that is able to flexGrow.
image

image

image

export {
Root as StyledRoot,
NavigationItem,
NavigationList,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should create container components for both NavigationItem and NavigationList that will take overrides and render StyledNavigationItem and StyledNavigationList accordingly. Since this falls outside the pattern we used in other components so far. Same as we do for the HeaderNavigation.
@schnerd what do you think about it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we want to export it as a container we should add a container component to it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@blackswanny
Copy link
Contributor Author

Tab links in the example are not keyboard navigatable. Could you fix it please?

@nadiia fixed

@blackswanny blackswanny force-pushed the feature/header branch 3 times, most recently from b6a4037 to 8690d87 Compare November 21, 2018 21:28
@gergelyke
Copy link
Contributor

Can you update the cursor to use the pointer style instead of text?

@blackswanny blackswanny force-pushed the feature/header branch 4 times, most recently from 2ed4ca7 to 010c33f Compare November 27, 2018 07:08
@gergelyke
Copy link
Contributor

also, can you please add the warning that says that this component is in a beta state, and may change without notice in the near future?

@blackswanny
Copy link
Contributor Author

Can you update the cursor to use the pointer style instead of text?

updated for the whole header navigation

@blackswanny blackswanny force-pushed the feature/header branch 2 times, most recently from 0286047 to 96ade26 Compare November 28, 2018 19:30
Copy link
Contributor

@nadiia nadiia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you address the styled components vs container components comment please?

// Styled elements
export {
Root as StyledRoot,
NavigationItem,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with @Austin94 comment, we should be consistent. So far we export any styled component with Styled prefix. We should be consistent.

export {
Root as StyledRoot,
NavigationItem,
NavigationList,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we want to export it as a container we should add a container component to it

@blackswanny blackswanny force-pushed the feature/header branch 2 times, most recently from 90e1e54 to 98f4ff9 Compare November 28, 2018 21:24
@blackswanny
Copy link
Contributor Author

Could you address the styled components vs container components comment please?

@nadiia renamed those to be styled components

};
componentDidMount() {
// eslint-disable-next-line no-console
console.warn(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it should only warn in a DEV env

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

<React.Fragment>
<div style={{marginTop: '50px'}} />
<HeaderNavigation>
<NavigationList $align={ALIGN.left}>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I must've missed this one on a previous look through. Why is this prop $ prefixed? It seems like there should be a container that would do the $ mapping

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a styled component. If we add container, it would add complexity to maintain things.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pretty torn on this. It could be confusing to users if some of the primary exports for a component require $ prefixes. On the other hand I agree creating wrappers every time we use this pattern could be annoying.

A couple ideas:

  1. Write an HOC that wraps styled components and maps the $ props:
import {asPrimaryExport} from '../styled/as-primary-export-hoc';

export const StyledNavigationList = styled('div', {...});

export const NavigationList = asPrimaryExport(StyledNavigationList, ['align', 'prop2', 'prop3']);

This would be far less tedious than maintaining a wrapper component for every time we use this pattern.

  1. Add logic to our styled implementation that supports similar prop mapping
export const StyledNavigationList = styled('div', {...}, {
  mapProps: ['align', 'prop2', 'prop3']
});

Internally I think this could use styletron's withWrapper? Still not 100% sure. Also adds more complexity to our styled implementation.

--

Obviously those are outside the scope of this specific PR, just trying to think of the best long term solution. Maybe short term we bite the bullet and build a container manually?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@schnerd Thanks for the proposals! I'd +1 the #1 HOC. Also should be easy to switch to this approach if meanwile we create containers manually.
@blackswanny what do you think?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

apparently, my last comment wasn't submitted when I replied

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I applied 1) approach. Currently need to fix the test using it

@blackswanny blackswanny force-pushed the feature/header branch 2 times, most recently from af7260c to 459fc93 Compare November 29, 2018 17:41
@gergelyke
Copy link
Contributor

can you please use the theme variables for the hamburger icon too?

screen shot 2018-11-29 at 9 41 46 am

render() {
const {overrides = {}} = this.props;
const [Root, rootProps] = getOverrides(overrides.Root, StyledRoot);
return <Root {...this.props} {...rootProps} />;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we use ...rest here so overrides isn't passed down to Root without a $ prefix?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think, current code fixed it
image

<React.Fragment>
<div style={{marginTop: '50px'}} />
<HeaderNavigation>
<NavigationList $align={ALIGN.left}>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pretty torn on this. It could be confusing to users if some of the primary exports for a component require $ prefixes. On the other hand I agree creating wrappers every time we use this pattern could be annoying.

A couple ideas:

  1. Write an HOC that wraps styled components and maps the $ props:
import {asPrimaryExport} from '../styled/as-primary-export-hoc';

export const StyledNavigationList = styled('div', {...});

export const NavigationList = asPrimaryExport(StyledNavigationList, ['align', 'prop2', 'prop3']);

This would be far less tedious than maintaining a wrapper component for every time we use this pattern.

  1. Add logic to our styled implementation that supports similar prop mapping
export const StyledNavigationList = styled('div', {...}, {
  mapProps: ['align', 'prop2', 'prop3']
});

Internally I think this could use styletron's withWrapper? Still not 100% sure. Also adds more complexity to our styled implementation.

--

Obviously those are outside the scope of this specific PR, just trying to think of the best long term solution. Maybe short term we bite the bullet and build a container manually?

@blackswanny
Copy link
Contributor Author

can you please use the theme variables for the hamburger icon too?

fixed. @gergelyke

Copy link
Contributor

@gergelyke gergelyke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am an A on this once David's feedback is resolved

@chasestarr
Copy link
Collaborator

chasestarr commented Nov 29, 2018

Deploy preview for baseui ready!

Built with commit 178c457

https://deploy-preview-525--baseui.netlify.com

}, {});
return <StyledComponent {...styledProps} />;
};
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is awesome.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool

};
}),
['align'],
);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be nice to also flowtype this component since it's a primary export.

Flow, might complain that this is incompatible with return type of asPrimaryExport, but you could always cast through any to fix that.

export const NavigationList: React.ComponentType<
  {align: string, children: React.Node}
> = (asPrimaryExport( ... ): any);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed. I wonder why flow didn't complain about it

@blackswanny blackswanny force-pushed the feature/header branch 2 times, most recently from 6d7f501 to b7c4069 Compare November 30, 2018 01:05
Copy link
Contributor

@nadiia nadiia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before merging please make sure that the Styled component wrapped in HOC behaves as a styled component in cases of restyling

@blackswanny
Copy link
Contributor Author

Before merging please make sure that the Styled component wrapped in HOC behaves as a styled component in cases of restyling

added example for that

@blackswanny blackswanny merged commit d729075 into master Nov 30, 2018
@baseui-probot-app-workflow baseui-probot-app-workflow bot deleted the feature/header branch November 30, 2018 21:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants