-
Notifications
You must be signed in to change notification settings - Fork 214
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: Allow stencil modifiers-in-selectors #2741
feat: Allow stencil modifiers-in-selectors #2741
Conversation
… feat/allow-stencil-modifiers-in-selectors
Passing run #7299 ↗︎Details:
Review all test suite changes for PR #2741 ↗︎ |
@@ -1,6 +1,6 @@ | |||
{ | |||
"name": "@workday/canvas-kit-css", | |||
"version": "10.3.24", | |||
"version": "10.3.36", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The build process automates the syncing of these version strings.
let vars: TransformerContext['names'] = {}; | ||
let extractedNames: TransformerContext['extractedNames'] = {}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
names
and extractedNames
are used by the static resolution system. The transformation process populates these caches with resolved names.
For example:
const foo = createStencil({
modifiers: {
size: {
small: {},
large: {}
}
}
})
const bar = createStencil({
base: {
// The type of `foo.modifiers.size.small` is `string` which the static
// transform doesn't like. It will now be added to `names` so that
// static resolution uses the actual class name
[`.${foo.modifiers.size.small} :where(&)`]: {
}
}
})
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
names
are a cache of the resolved names for React Kit. It will include hashes. The extractedNames
are the names used in CSS Kit.
for (const key in fallbackVars) { | ||
names[key] = fallbackVars[key]; | ||
} | ||
// vars = {...names, ...fallbackVars}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be removed
… feat/allow-stencil-modifiers-in-selectors
// eslint-disable-next-line guard-for-in | ||
for (const key in fallbackVars) { | ||
names[key] = fallbackVars[key]; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a bug where passing in names
to the transform
did not return the same reference. That's because a new reference was used internally. That means I couldn't properly test changes. This update instead mutates the name cache that was passed in so the cache can be properly tested against.
PR #2741 added the ability to target parent modifier class names to build selectors, but doesn't work in compat mode because compat mode merges all the CSS class names into a single, new class name. I added a `parentModifiers` function that handles this for both React Kit and CSS Kit and updated stencils to add inert class names for the purpose of always matching a selector. I also fixed a bug where passing `undefined` to a Stencil for a modifier key resulted in overriding `defaultModifiers`. [category:Styling]
Summary
Add support for using parent class names in Stencil selectors to support sharing of modifiers to subcomponents. Allows support for #2711
Release Category
Styling
Overall, this change does the following things:
makeEmotionSafe
*-emotion-safe
was being added to the CSS Kit output. CSS Kit doesn't use Emotion and doesn't need to be Emotion safenames
resolution cache from theextractedNames
resolution cache--cnvs-button-label-emotion-safe
--label-button-{hash}
--cnvs-button-label-emotion-safe
--cnvs-button-label
createStyles
andcreateStencils
to thenames
andextractedNames
cache. This allows a reference to class names to be used in selectors.For example, this is not possible before this change:
This was possible at runtime, but the transform did not know how to handle it because the modifier class name wasn't resolved yet. This addition removes the need to share
orientation
with theFormField
's model and have a modifier informFieldLabel
which would require CSS Kit authors to add the orientation modifier to bothFormField
ANDFormField.Label
.Checklist
ready for review
has been added to PRFor the Reviewer