-
Notifications
You must be signed in to change notification settings - Fork 4k
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
style(Popup): fix tests, update typings and propTypes usage #1322
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
import React, { Component, PropTypes } from 'react' | ||
import cx from 'classnames' | ||
import _ from 'lodash' | ||
import React, { Component, PropTypes } from 'react' | ||
|
||
import { | ||
customPropTypes, | ||
getElementType, | ||
getUnhandledProps, | ||
isBrowser, | ||
|
@@ -17,25 +19,16 @@ import PopupHeader from './PopupHeader' | |
|
||
const debug = makeDebugger('popup') | ||
|
||
const _meta = { | ||
name: 'Popup', | ||
type: META.TYPES.MODULE, | ||
props: { | ||
on: ['hover', 'click', 'focus'], | ||
positioning: [ | ||
'top left', | ||
'top right', | ||
'bottom right', | ||
'bottom left', | ||
'right center', | ||
'left center', | ||
'top center', | ||
'bottom center', | ||
], | ||
size: _.without(SUI.SIZES, 'medium', 'big', 'massive'), | ||
wide: [true, false, 'very'], | ||
}, | ||
} | ||
export const POSITIONS = [ | ||
'top left', | ||
'top right', | ||
'bottom right', | ||
'bottom left', | ||
'right center', | ||
'left center', | ||
'top center', | ||
'bottom center', | ||
] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Positions are used in multiple places, so we need it as const. |
||
|
||
/** | ||
* A Popup displays additional information on top of a page. | ||
|
@@ -45,14 +38,14 @@ export default class Popup extends Component { | |
/** Display the popup without the pointing arrow. */ | ||
basic: PropTypes.bool, | ||
|
||
/** You may pass a content as children of the Popup. */ | ||
/** Primary content. */ | ||
children: PropTypes.node, | ||
|
||
/** Classes to add to the Popup className. */ | ||
/** Additional classes. */ | ||
className: PropTypes.string, | ||
|
||
/** Simple text content for the popover */ | ||
content: PropTypes.node, | ||
/** Simple text content for the popover. */ | ||
content: customPropTypes.itemShorthand, | ||
|
||
/** A flowing Popup has no maximum width and continues to flow to fit its content. */ | ||
flowing: PropTypes.bool, | ||
|
@@ -62,22 +55,22 @@ export default class Popup extends Component { | |
// fluid: PropTypes.bool, | ||
|
||
/** Header displayed above the content in bold. */ | ||
header: PropTypes.string, | ||
header: customPropTypes.itemShorthand, | ||
|
||
/** Hide the Popup when scrolling the window. */ | ||
hideOnScroll: PropTypes.bool, | ||
|
||
/** Whether the popup should not close on hover. */ | ||
hoverable: PropTypes.bool, | ||
|
||
/** Invert the colors of the Popup. */ | ||
inverted: PropTypes.bool, | ||
|
||
/** Hide the Popup when scrolling the window. */ | ||
hideOnScroll: PropTypes.bool, | ||
|
||
/** Horizontal offset in pixels to be applied to the Popup. */ | ||
offset: PropTypes.number, | ||
|
||
/** Event triggering the popup */ | ||
on: PropTypes.oneOf(_meta.props.on), | ||
/** Event triggering the popup. */ | ||
on: PropTypes.oneOf(['hover', 'click', 'focus']), | ||
|
||
/** | ||
* Called when a close event happens. | ||
|
@@ -111,11 +104,11 @@ export default class Popup extends Component { | |
*/ | ||
onUnmount: PropTypes.func, | ||
|
||
/** Positioning for the popover */ | ||
positioning: PropTypes.oneOf(_meta.props.positioning), | ||
/** Positioning for the popover. */ | ||
positioning: PropTypes.oneOf(POSITIONS), | ||
|
||
/** Popup size. */ | ||
size: PropTypes.oneOf(_meta.props.size), | ||
size: PropTypes.oneOf(_.without(SUI.SIZES, 'medium', 'big', 'massive')), | ||
|
||
/** Custom Popup style. */ | ||
style: PropTypes.object, | ||
|
@@ -124,15 +117,22 @@ export default class Popup extends Component { | |
trigger: PropTypes.node, | ||
|
||
/** Popup width. */ | ||
wide: PropTypes.oneOf(_meta.props.wide), | ||
wide: PropTypes.oneOfType( | ||
PropTypes.bool, | ||
PropTypes.oneOf(['very']), | ||
), | ||
} | ||
|
||
static defaultProps = { | ||
positioning: 'top left', | ||
on: 'hover', | ||
} | ||
|
||
static _meta = _meta | ||
static _meta = { | ||
name: 'Popup', | ||
type: META.TYPES.MODULE, | ||
} | ||
|
||
static Content = PopupContent | ||
static Header = PopupHeader | ||
|
||
|
@@ -228,7 +228,7 @@ export default class Popup extends Component { | |
|
||
// Lets detect if the popup is out of the viewport and adjust | ||
// the position accordingly | ||
const positions = _.without(_meta.props.positioning, positioning) | ||
const positions = _.without(POSITIONS, positioning) | ||
for (let i = 0; !this.isStyleInViewport(style) && i < positions.length; i++) { | ||
style = this.computePopupStyle(positions[i]) | ||
positioning = positions[i] | ||
|
@@ -349,8 +349,8 @@ export default class Popup extends Component { | |
const popupJSX = ( | ||
<ElementType {...rest} className={classes} style={style} ref={this.popupMounted}> | ||
{children} | ||
{!children && PopupHeader.create(header)} | ||
{!children && PopupContent.create(content)} | ||
{_.isNil(children) && PopupHeader.create(header)} | ||
{_.isNil(children) && PopupContent.create(content)} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Our problem with '0' fixed there 😄 |
||
</ElementType> | ||
) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 type used only by
Popup
.