Replies: 1 comment
-
|
ping @mellyeliu @necolas for feedback |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
View Transitions are awesome. However, large parts of how they work depend on global style rules and unique identifiers which makes them a bad fit for an atomic styling system like StyleX.
However, with the addition of
view-transition-class, which is now well supported in both Chrome and Safari (Firefox doesn't have any view transition support at all so far), there is now an opportunity to add a first class API that actually makes sense in StyleX.The proposal
We could introduce a new
stylex.viewTransitionClassAPI that works similarly to howstylex.keyframesworks.Details
stylex.viewTransitionClasswould take an object that can have the following keys:groupas an equivalent to::view-transition-group(*.theGeneratedClass)imagePairas an equivalent to::view-transition-image-pair(*.theGeneratedClass)oldas an equivalent to::view-transition-old(*.theGeneratedClass)newas an equivalent to::view-transition-new(*.theGeneratedClass)All four keys would be optional, however, similar to
stylex.keyframesgenerating a className with no styles would be a no-op.The function would return a string which would be a generated className that can be used as the value of
viewTransitionClass.All of the other rules from
stylex.keyframeswould apply:stylex.viewTransitionClassin the same file a separateconstdeclaration or inline within thestylex.createcall itselfstylex.defineVars(orstylex.defineConsts) call to be able to import it from another file.stylex.keyframesgenerates a single@keyframesrule.What about
view-transition-nameIt is hard offer any special API for
view-transition-nameas it needs to be globally unique by design. It needs be a dynamic style to be usable, so it's probably best used as a dynamic style:(I'm writing another RFC with the idea of offering every CSS property as a pre-defined API for "inline" styles)
However, with the existence of
view-transition-classwe can recommend not using names to apply custom styles to view transitions at all.Names, like IDs, can be used for element identity.
view-transition-classcan be used for applying all custom styles.Should the styles be atomic
Since
view-transition-classsupports multiple space-separated classes, it is possible to generate atomic CSS rules forstylex.viewTransitionClasswhere each style property within would generate an individual class. All of this can be done with no change to the API at all.However, I think it makes more sense to generate a single className for such scenarios. I'm making the assumption that there would only be a handful of "classes" needed in any particular app but that each class could have a large number of styles each, and that atomic styles for this use-case would result in an overall larger CSS file.
In either case, we can try either implementation first and then change our mind later if we want to.
Any other additions?
We should probably start with something minimal and expand later if the need presents itself.
One possibility I could see is adding an additional
bothkey to allow adding styles that would apply to botholdandnewas a way to reduce verbosity. However, I think we should try omitting it at first as we can always use JS object spread to share common styles instead:Fewer, composable APIs are better IMO.
Anything else?
This is all a relatively fresh idea, so I may have missed something important, but so far it feels like a relatively simply and straightforward addition that should make view transitions a lot more convenient in StyleX.
Beta Was this translation helpful? Give feedback.
All reactions