-
Notifications
You must be signed in to change notification settings - Fork 1k
defaultPosition now allows strings #361
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
Conversation
… createSVGTransform to use calc with defaultPosition, adding a test for the new functionality
@STRML @eric-burel I fixed a couple issues in the commit I just made. Linting and tests now pass and I added a test for the new use case. |
@bokuweb when this PR gets merged this issue bokuweb/react-rnd#437 will no longer be relevant. I should just be able to pass "50%" for both x and y defaultPositions |
@STRML any idea why this would be failing only on IE? That's the new spec I added:
|
Hi @tnrich thanks a lot for your work on this. I only used |
…tes instead of a calc function do to IE incompatibility; updating spec to reflect changes
Okay found a solution based on this stackoverflow answer: https://stackoverflow.com/questions/21142923/ie-10-11-css-transitions-with-calc-do-not-work this commit fixes it and tests should now pass :)
|
@STRML bump :) |
@mzabriskie @STRML any thoughts? |
bumping. @STRML is this project still active? |
@STRML bump |
lib/utils/domFns.js
Outdated
@@ -109,13 +109,23 @@ export function offsetXYFromParent(evt: {clientX: number, clientY: number}, offs | |||
return {x, y}; | |||
} | |||
|
|||
export function createCSSTransform({x, y}: {x: number, y: number}): Object { | |||
export function createCSSTransform({x, y}: {x: number, y: number}, defaultPosition: {x: number | string, y: number | string }): Object { |
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.
You create a DefaultControlPosition
type above but then don't use 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.
I now use it here
lib/utils/domFns.js
Outdated
const defaultY = (typeof defaultPosition.y === 'string') ? defaultPosition.y : defaultPosition.y + 'px'; | ||
const translation = (defaultPosition && defaultPosition.x !== 0 && defaultPosition.y !== 0) | ||
? `translate(${defaultX}, ${defaultY}) translate(${x}px,${y}px)` | ||
: 'translate(' + x + 'px,' + y + 'px)'; | ||
// Replace unitless items with px |
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 comment no longer makes sense with the changes above.
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 comment
lib/utils/domFns.js
Outdated
@@ -109,13 +109,23 @@ export function offsetXYFromParent(evt: {clientX: number, clientY: number}, offs | |||
return {x, y}; | |||
} | |||
|
|||
export function createCSSTransform({x, y}: {x: number, y: number}): Object { | |||
export function createCSSTransform({x, y}: {x: number, y: number}, defaultPosition: {x: number | string, y: number | string }): Object { | |||
const defaultX = (typeof defaultPosition.x === 'string') ? defaultPosition.x : defaultPosition.x + 'px'; |
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 really difficult to read. You create these two consts, defaultX
and defaultY
, but they're only actually used if and only if a defaultPosition
is actually present.
You then use that just to prepend what is being returned as a second translate.
This is a lot of logic in what was previously a simple function and should be refactored such that the caller prepends the default translate if needed.
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.
Reworked this to hopefully be more clear
lib/utils/domFns.js
Outdated
const defaultY = (typeof defaultPosition.y === 'string') ? defaultPosition.y : defaultPosition.y + 'px'; | ||
const translation = (defaultPosition && defaultPosition.x !== 0 && defaultPosition.y !== 0) | ||
? `translate(${defaultX}, ${defaultY}) translate(${x}px,${y}px)` | ||
: 'translate(' + x + 'px,' + y + 'px)'; |
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.
Why no template string 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.
Added template strings everywhere I could
lib/utils/domFns.js
Outdated
const defaultX = (typeof defaultPosition.x === 'string') ? defaultPosition.x : defaultPosition.x + 'px'; | ||
const defaultY = (typeof defaultPosition.y === 'string') ? defaultPosition.y : defaultPosition.y + 'px'; | ||
const translation = (defaultPosition && defaultPosition.x !== 0 && defaultPosition.y !== 0) | ||
? `translate(${defaultX}, ${defaultY}) translate(${x}px,${y}px)` |
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 wrong, svg transforms shouldn't have px
.
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 should no longer have px
in it
@STRML let me know if there is anything else I can change to get this PR accepted and merged? Thanks! |
@STRML Thank you very much 👍 |
)" This reverts commit aa0a6b4.
Awesome, thanks all for finishing this PR and merging ! |
@eric-burel @STRML had to revert the changes due to unexpected breakages. I've made a new PR that hopefully solves those issues by introducing a new property |
This is a copy of #271
but with the changes @STRML requested