Skip to content
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

feat(Popup): add vertical offset #1146

Closed
wants to merge 3 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/modules/Popup/Popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ export default class Popup extends Component {
/** Horizontal offset in pixels to be applied to the popup */
offset: PropTypes.number,

/** Vertical offset in pixels to be applied to the popup */
verticalOffset: PropTypes.number,
Copy link
Member

Choose a reason for hiding this comment

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

How about allowing an X and Y offset in the current offset prop instead of adding a new prop?

offset={[5, 10]}

// vs

offset={5}
verticalOffset={10} 

We could still allow a single value to apply a horizontal offset only,so it is backwards compatible.

Copy link
Author

Choose a reason for hiding this comment

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

yea, your api is better. will change tomorrow


/** Event triggering the popup */
on: PropTypes.oneOf(_meta.props.on),

Expand Down Expand Up @@ -144,7 +147,7 @@ export default class Popup extends Component {
// Do not access window/document when server side rendering
if (!isBrowser) return style

const { offset } = this.props
const { offset, verticalOffset } = this.props
const { pageYOffset, pageXOffset } = window
const { clientWidth, clientHeight } = document.documentElement

Expand Down Expand Up @@ -187,6 +190,14 @@ export default class Popup extends Component {
}
}

if (verticalOffset) {
if (_.isNumber(style.top)) {
style.top -= verticalOffset
} else {
style.bottom -= verticalOffset
}
}

return style
}

Expand Down