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: css units in fly & blur transitions #7623

Merged
merged 4 commits into from
Mar 15, 2023

Conversation

bfanger
Copy link
Contributor

@bfanger bfanger commented Jun 21, 2022

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

  • 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
  • Prefix your PR title with [feat], [fix], [chore], or [docs].
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.

Tests

  • Run the tests with npm test and lint the project with npm run lint

@GauBen
Copy link
Contributor

GauBen commented Jul 14, 2022

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?

@bfanger bfanger changed the title [feat] Support css units in fly transition [feat] Support css units in fly & blur transitions Jul 16, 2022
@benmccann
Copy link
Member

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

@vercel
Copy link

vercel bot commented Feb 22, 2023

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

A member of the Team first needs to authorize it.

Copy link
Member

@dummdidumm dummdidumm left a comment

Choose a reason for hiding this comment

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

#6050 is the alternative to this - and I'm split on which one is better. Usability wise this PR feels better as you can input the number as you would in regular styles. The downside is the slightly increased runtime code because we need that split_css_unit function.

test/utils/index.ts Outdated Show resolved Hide resolved
site/content/docs/04-run-time.md Outdated Show resolved Hide resolved
site/content/docs/04-run-time.md Outdated Show resolved Hide resolved
test/utils/index.ts Outdated Show resolved Hide resolved
src/runtime/internal/utils.ts Outdated Show resolved Hide resolved
@bfanger
Copy link
Contributor Author

bfanger commented Mar 14, 2023

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

@benmccann benmccann changed the title [feat] Support css units in fly & blur transitions feat: css units in fly & blur transitions Mar 14, 2023
Co-authored-by: Ben McCann <322311+benmccann@users.noreply.github.com>
Copy link
Member

@dummdidumm dummdidumm left a comment

Choose a reason for hiding this comment

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

Thank you!

@dummdidumm dummdidumm merged commit 6aee49b into sveltejs:master Mar 15, 2023
@techniq
Copy link

techniq commented Mar 16, 2023

@Conduitry I think this is missing from the 3.57.0 changelog

@geoffrich geoffrich mentioned this pull request Mar 17, 2023
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants