Skip to content

Conversation

swapnesh
Copy link
Contributor

@swapnesh swapnesh commented Apr 2, 2019

EDIT 02 -

@vinodloha Please find new changes as requested -

  1. Added BEM naming convention in writing classnames.
  2. Used prop based styling as suggested rather than creation of new nodes.
  3. Changed code structure to use the component body to set the Popover content and defined prop for supplying heading and trigger element/content as suggested.
  4. Did bare minimum css.
  5. Keeping trigger as "React$Element<*>" instead on Node as Node type is incompatible with the elements if cloned
    const element = trigger && React.cloneElement(trigger, { onClick: this.handleClick });
  6. Removed unnecessary dummy title Helloooooo from story.js file.

Let me know on case of any further query.

EDIT 01 -

@vinodloha Please find changes made after changing Atom to Molecule Popover. Please let me know in case of further query.

  1. Changed Atom to molecule.
  2. Added isVisible property to have more controlled component.
  3. Added List component to show in the popover body component.
  4. Done with bare minimum CSS part by adding border/colour etc.
  5. Changed header to h3 tag than div to be more semantically correct.
  6. Added close button in Popover.
  7. Changed data types as requested.

New Screenshot -

Popover-molecule


Initial commit for Atom | Popover.

storybook

vinodloha and others added 2 commits April 2, 2019 10:09
@@ -0,0 +1,74 @@
// @flow
Copy link
Collaborator

Choose a reason for hiding this comment

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

@swapnesh Popover should be a molecule, Since it usually holds and displays other components. Please restructure 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.

@vinodloha I made the changes as mentioned. Kindly review

};

state: State = {
showPopover: false,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Use isVisible property instead.

@@ -0,0 +1,7 @@
const defaultConfig = {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you also make a sample where we are putting another component like LIst inside popover?

import { css } from 'styled-components';

export default css`
${props => (props.inheritedStyles ? props.inheritedStyles : '')};
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please do right bare minimum CSS like: Border Box, Small padding to all 4 side of the content.

<div role="presentation" onClick={this.handleClick} ref={this.wrapperRef}>
{children}
{showPopover && (
<div role="dialog">
Copy link
Collaborator

Choose a reason for hiding this comment

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

Pop overs usually have a pointer too can we include that conditionally? Example: https://codepen.io/esaramago/pen/jbXZaz and https://getbootstrap.com/docs/4.1/components/popovers/

Also Placing a class on popOverHeader and popOverBody divs would give better styling control to people using it.

{children}
{showPopover && (
<div role="dialog">
<div>{popOverHeader}</div>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Semantically DIV doesn't seem right tag for it. May be a H3 will help??

return (
<div role="presentation" onClick={this.handleClick} ref={this.wrapperRef}>
{children}
{showPopover && (
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we also have an optional Close button with-in the popover?


import Popover from '../index';

describe('<Popover />', () => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

The test could be a bit better, at least test the code you wrote, like close and open functionality. Or any other new feature you add. Just snapshot is not enough.

// @flow
import type { Node } from 'react';

export type Props = { popOverBody: String, popOverHeader: String, children: Node };
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is not how we define type String --> string
I would recommend you change
popOverHeader --> heading (It should be both string and Node type)
popOverBody --> trigger (This should be a Node or String that will trigger popover)
children --> it should be the content or body of the popover

export type Props = {
popOverBody: Node | string,
popOverHeader: Node | string,
children: React$Element<*>,
Copy link
Collaborator

Choose a reason for hiding this comment

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

For Children correct type is Node

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Initially I defined children as node (in new use case - its trigger prop) but getting Linting error. On github flow
issue thread I found that if an element is cloned then it should be mentioned as React$Element<*>

storiesOf('Molecules', module).addWithChapters('Popover', {
chapters: [
{
title: `Helloooooo`,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please Put formal Title

title: 'Popover Variations',
sections: [
{
title: '[isVisible=true] variation',
Copy link
Collaborator

Choose a reason for hiding this comment

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

Title Should be contextual and description: Please name this as "By Default Open Variation"

),
},
{
title: '[isVisible=false] variation',
Copy link
Collaborator

Choose a reason for hiding this comment

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

By Default Close Variation

Copy link

@amrit07 amrit07 left a comment

Choose a reason for hiding this comment

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

popover should be accessible via keyboard as well. Ref: https://reactjs.org/docs/accessibility.html
Also they should also breakout from a parent with overflow hidden; for e.g carousel. Ref: https://reactjs.org/docs/portals.html

),
},
{
title: 'List(Component) variation',
Copy link
Collaborator

Choose a reason for hiding this comment

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

List Content Variation

title: 'Optional close button variation',
sectionFn: () => (
<Popover {...noCloseBtnPopover}>
<button>Click to Open</button>
Copy link
Collaborator

Choose a reason for hiding this comment

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

See this is not really right, the content which is less is placed in the body of component (being picked as children) and the content which really is body gets set as prop. This is a wrong design pattern and would always confuse react developers. Can you please change it, i had given this comment earlier too.

So use the component body to set the Popover content and defined prop for supplying heading and trigger element/content.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@vinodloha Changed the structuring as requested. Now the inner part of component represents the body of popover and trigger prop will represent the node for triggering the body content.

@@ -0,0 +1,18 @@
import styled from 'styled-components';

const PopoverContentWrapper = styled.div`
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is not the right way, just encapsulate all CSS in a class and apply that to whole component. Its easier that way to make variations.

popOverHeader: Node | string,
children: React$Element<*>,
isVisible: boolean,
wrapperBackground: string,
Copy link
Collaborator

Choose a reason for hiding this comment

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

wrapperBackground is useless, if someone wants to overwrite this component's style its not going to be background only. We should make way for enabling them to overwrite all CSS. Set class names in BEM terminology.

We are using this technique ${props => (props.inheritedStyles ? props.inheritedStyles : '')}; in all components. Please follow the same.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed the unnecessary class and prop for css and aligned class naming with BEM.

PopoverComponent = shallow(<Popover>Test</Popover>);
});

test('should render correctly', () => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Test cases needs to improve, you have a open/close functionality too. Test it here!

Copy link
Collaborator

@vinodloha vinodloha left a comment

Choose a reason for hiding this comment

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

Please fix these review comments, there are some fundamental problems so can't accept it in current form.

Copy link
Collaborator

@vinodloha vinodloha left a comment

Choose a reason for hiding this comment

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

Looking good now! I have added few extra tests.

But @swapnesh Thanks for this effort, must appreciated :)

@vinodloha vinodloha merged commit 9c7c749 into develop Apr 8, 2019
@vinodloha vinodloha deleted the feature/popover branch April 8, 2019 19:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants