added feature: absolute snap dimensions #337
Merged
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.
Proposed solution
This PR is aiming to allow defining absolute snap dimensions, rather than an infinite grid. It also allows for selective axis definition, so you can absolutely snap only the
x
axis, for example.e.g.
grid={[1,5]}
will land on[1, 5]
,[2, 5]
, as well as[40, 50]
ad infinitum.snap={{ x: [20, 30, 50], y: [10] }}
will only land on[20, 10]
,[30, 10]
,[50, 10]
.Tradeoffs
Drawbacks: This solution puts priority of the absolute snap over the grid. Alternatively, it could snap to the defined grid after the absolute numbers, but I figured that'd be an odd developer experience since they're explicitly defining it to begin with.
There is an additional function added,
findClosestSnap
which does a reduce on the axis array. I've tried to keep this minimal and close to thesnap
function for ease of finding.There is arguably a nomenclature disconnect between
grid
andsnap
props since both are technically "snapping".snap
just seemed less verbose. I can change it if desired.I'm also fairly sure I updated the types correctly, but I'm a typescript user rather than a flowtype user, it may need some tweaking.
Testing Done
I have confirmed this works both in storybook (by adding a new story for it) and in my company's internal application under the npm module name
@therebel/re-resizable
. If this merges I'll update my application to use upstream ^_^EDIT: I also added a new test to
test/index.test.js:427
master
branch: This was forked frommaster
today.