svelte icon indicating copy to clipboard operation
svelte copied to clipboard

[feat] Support css units in fly & blur transitions

Open bfanger opened this issue 2 years ago • 1 comments

For the fly transition, the x & y are passed as numbers and are used are pixel values (px) This limits the range of what fly can do.

This PR adds support for passing the x & y as strings that can contain CSS units:

You can create an animation that are relative:

<div class="box" in:fly={{x: '100%'}} />

'100%' is based on the width of the box.

Or based on the viewport:

<div class="modal" in:fly={{y: '50vh'}} />

Other units are also supported, we use rem a lot, currently we are calculating the px value or accept that the animation doesn't scale. With this PR we would be able to write:

<h1 class="title" in:fly={{y: '3rem'}} />

As a guideline for the regex I looked at css notation.
'100%' ✅
'100 %' ❌

If no unit is provided it falls back to using px. '50' is interpreted as '50px'

Closes #6050

Before submitting the PR, please make sure you do the following

  • [X] It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • [X] Prefix your PR title with [feat], [fix], [chore], or [docs].
  • [X] This message body should clearly illustrate what problems it solves.
  • [X] Ideally, include a test that fails without this PR but passes with it.

Tests

  • [X] Run the tests with npm test and lint the project with npm run lint

bfanger avatar Jun 21 '22 13:06 bfanger

Please add this feature to blur too, it also expects a number of pixels.

Edit: once CSSUnitValue is available on all major browsers we should support it too. Maybe you could implement it already?

GauBen avatar Jul 14 '22 12:07 GauBen

Would you mind fixing the small merge conflict in this PR? We'll be attempting to go through all the outstanding PRs in the coming weeks

benmccann avatar Feb 22 '23 05:02 benmccann

Someone is attempting to deploy a commit to the Svelte Team on Vercel.

A member of the Team first needs to authorize it.

vercel[bot] avatar Feb 22 '23 07:02 vercel[bot]

split_css_unit does add additional runtime code, but only when importing a transition that might use it.

bfanger avatar Mar 14 '23 17:03 bfanger

@Conduitry I think this is missing from the 3.57.0 changelog

techniq avatar Mar 16 '23 18:03 techniq