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

Open
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

wuz
Copy link

@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

⚠️ No Changeset found

Latest commit: e8117c9

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

@wuz wuz marked this pull request as ready for review July 19, 2024 15:15
@wuz
Copy link
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
Copy link
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
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.

Comment on lines +42 to +48
createViewTransition: {
maxParams: 2,
hasDebugId: ({ arguments: args }) => {
const previousArg = args[args.length - 1];
return t.isStringLiteral(previousArg) || t.isTemplateLiteral(previousArg);
},
},
Copy link
Contributor

@askoufis askoufis Sep 17, 2024

Choose a reason for hiding this comment

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

This should be almost identical to createContainer.

Suggested change
createViewTransition: {
maxParams: 2,
hasDebugId: ({ arguments: args }) => {
const previousArg = args[args.length - 1];
return t.isStringLiteral(previousArg) || t.isTemplateLiteral(previousArg);
},
},
createViewTransition: {
maxParams: 1,
},

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