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

Add createViewTransition function #1450

Merged

Conversation

wuz
Copy link
Contributor

@wuz wuz commented Jul 18, 2024

View transitions are starting to get more support and it would be nice to use the same API style from createContainer to create locally scoped view transition names.

This PR adds a createViewContainer function with a name arg and an optional debugId arg.

Definitely open to suggestions on naming here - similar to CSS container queries, View Transitions have a view-transition-name css property and I thought it would track better with createContainer -> container-name to have createViewTransition -> view-transition-name.

Copy link

changeset-bot bot commented Jul 18, 2024

🦋 Changeset detected

Latest commit: f3deb70

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 28 packages
Name Type
@vanilla-extract/babel-plugin-debug-ids Minor
@vanilla-extract/css Minor
@vanilla-extract/integration Patch
@vanilla-extract/rollup-plugin Patch
@fixtures/features Patch
@fixtures/layers Patch
@fixtures/low-level Patch
@fixtures/next-app-router Patch
@fixtures/next-pages-router Patch
@fixtures/recipes Patch
@fixtures/sprinkles Patch
@fixtures/template-string-paths Patch
@fixtures/themed Patch
@fixtures/thirdparty Patch
@fixtures/unused-modules Patch
@fixtures/thirdparty-dep Patch
@fixtures/thirdparty-dep-dep Patch
vanilla-extract-example-remix Patch
vanilla-extract-example-webpack-react Patch
@vanilla-extract-private/tests Patch
@vanilla-extract/esbuild-plugin-next Patch
@vanilla-extract/esbuild-plugin Patch
@vanilla-extract/jest-transform Patch
@vanilla-extract/parcel-transformer Patch
@vanilla-extract/vite-plugin Patch
@vanilla-extract/webpack-plugin Patch
@vanilla-extract-private/test-helpers Patch
@vanilla-extract/next-plugin Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@wuz wuz marked this pull request as ready for review July 19, 2024 15:15
@wuz
Copy link
Contributor Author

wuz commented Aug 27, 2024

@askoufis not sure if you are the right person to ping here, but I'd love to contribute to this project. This PR was based on some work I've been doing and I'd love to get it merged. If there are other ways I can help out, I'm more than happy to do so as well! We're using vanilla-extract heavily and I'd love to help grow the project.

Thanks!

Copy link
Contributor

@askoufis askoufis left a comment

Choose a reason for hiding this comment

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

Sorry for the delay @wuz. I'm happy to help get this through, though there's no API for actually writing a @view-transition rule just yet.

@view-transition rules are also a bit different to other existing rules in that they can be nested within media queries, but aren't related to any classnames. I might try make a POC for a viewTransition API, and maybe that can be released alongside this API eventually.

packages/css/src/viewTransition.ts Outdated Show resolved Hide resolved
site/docs/api/create-view-transition.md Outdated Show resolved Hide resolved
site/docs/api/create-view-transition.md Outdated Show resolved Hide resolved
packages/babel-plugin-debug-ids/src/index.test.ts Outdated Show resolved Hide resolved
@askoufis
Copy link
Contributor

@wuz I also can't run CI on your fork, you might have some restrictive permissions enabled.

wuz and others added 6 commits September 9, 2024 17:21
…tion-identifier' into wuz/add-view-transition-identifier
Co-authored-by: Adam Skoufis <askoufis@users.noreply.github.com>
Co-authored-by: Adam Skoufis <askoufis@users.noreply.github.com>
@wuz
Copy link
Contributor Author

wuz commented Sep 9, 2024

@askoufis Sorry, was out of office all week last week! Looking at this now! Let me see what's going on with the CI stuff, not sure what the permissions would be.

Edit: Okay, I think I figured out the actions thing - it should work now?

@wuz
Copy link
Contributor Author

wuz commented Sep 9, 2024

Thinking about this a bit, the API could look something like this:

import { globalViewTransition, createViewTransition, createViewTransitionGroup } from '@vanilla-extract/css';

// assuming keyframes called fadeOut and fadeIn defined somewhere

globalViewTransition({
  navigation: 'auto',
});

const fade = createViewTransition({
  old: {
    animationName: fadeOut,
  },
  new: {
    animationName: fadeIn,
  },
});

createViewTransitionGroup(fade, {
  animationDuration: "0.25s",
  animationTimingFunction: "ease",
});

becomes:

  @view-transition {
    navigation: auto;
  }

  ::view-transition-old(viewTransition_fade__jxjrfl) {
    animation-name: fadeOut;
  }

  ::view-transition-new(viewTransition_fade__jxjrfl) {
    animation-name: fadeIn;
  }

  ::view-transition-group(viewTransition_fade__jxjrfl) {
    animation-duration: 0.25s;
    animation-timing-function: ease;
  }
*/

@askoufis
Copy link
Contributor

askoufis commented Sep 17, 2024

I'm unsure if we'd expose APIs like createViewTransition or createViewTransitionGroup as they're quite simple wrappers over some globalStyle calls. I'd leave that to the user to implement unless there's some nuance around view transition selectors that would necessitate VE handling CSS generation (though I don't think is the case).

For defining the @ rule, we could just name the function viewTransition as this aligns with other top-level @ rule APIs like layer and keyframes.

@wuz wuz force-pushed the wuz/add-view-transition-identifier branch from e629e6b to 5a09c55 Compare September 30, 2024 14:28
Copy link
Contributor

@askoufis askoufis left a comment

Choose a reason for hiding this comment

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

Thanks @wuz!

@askoufis askoufis enabled auto-merge (squash) October 1, 2024 03:43
@askoufis askoufis merged commit 7b256d2 into vanilla-extract-css:master Oct 1, 2024
5 checks passed
@askoufis
Copy link
Contributor

askoufis commented Oct 1, 2024

@wuz This has been released in https://github.com/vanilla-extract-css/vanilla-extract/releases/tag/%40vanilla-extract%2Fcss%401.16.0

@wuz wuz deleted the wuz/add-view-transition-identifier branch October 1, 2024 19:40
@wuz
Copy link
Contributor Author

wuz commented Oct 1, 2024

@askoufis Awesome! Thanks so much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants