-
Notifications
You must be signed in to change notification settings - Fork 45
Feature/popover #13
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
Feature/popover #13
Conversation
…y-fix Fixed Atom name hardcoding from story on component basis
@@ -0,0 +1,74 @@ | |||
// @flow |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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 = { |
There was a problem hiding this comment.
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 : '')}; |
There was a problem hiding this comment.
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"> |
There was a problem hiding this comment.
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> |
There was a problem hiding this comment.
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 && ( |
There was a problem hiding this comment.
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 />', () => { |
There was a problem hiding this comment.
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 }; |
There was a problem hiding this comment.
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<*>, |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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`, |
There was a problem hiding this comment.
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', |
There was a problem hiding this comment.
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', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By Default Close Variation
There was a problem hiding this 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', |
There was a problem hiding this comment.
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> |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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` |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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', () => { |
There was a problem hiding this comment.
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!
There was a problem hiding this 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.
… trigger as element
There was a problem hiding this 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 :)
EDIT 02 -
@vinodloha Please find new changes as requested -
const element = trigger && React.cloneElement(trigger, { onClick: this.handleClick });
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.
List
component to show in the popover body component.New Screenshot -
Initial commit for Atom | Popover.