defaultPosition now allows strings - #361
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 |
| } | ||
|
|
||
| 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.
You create a DefaultControlPosition type above but then don't use it here.
| 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.
This comment no longer makes sense with the changes above.
|
|
||
| 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.
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.
Reworked this to hopefully be more clear
| 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.
Why no template string here?
There was a problem hiding this comment.
Added template strings everywhere I could
| 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.
This is wrong, svg transforms shouldn't have px.
There was a problem hiding this comment.
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