-
Notifications
You must be signed in to change notification settings - Fork 380
Support attribute selectors in stylex.when and conditional styles #1449
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
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
workflow: benchmarks/sizeComparison of minified (terser) and compressed (brotli) size results, measured in bytes. Smaller is better.
|
workflow: benchmarks/perfComparison of performance test results, measured in operations per second. Larger is better.
|
...s/@stylexjs/babel-plugin/src/shared/preprocess-rules/__tests__/flatten-raw-style-obj-test.js
Show resolved
Hide resolved
"Styling-agnostic" react component systems, such as base-ui, expose state based styling hooks through the use of dom element attributes. Actually listening to these in StyleX, while possible through usage of the `:is()` psedudoselector, is overly verbose and uncessary. This diff addresses this by adding support for attribute selectors in stylex.when calls and conditional styles. ### Motivation - Allow `stylex.when` and conditional style objects to accept attribute selectors (including value-matching forms) rather than only attribute-existence markers. - Treat attribute selectors like pseudo-classes in the preprocessing and validation pipeline so downstream CSS generation remains correct. - Surface attribute-selector usage in types and docs so consumers get proper editor/compile-time guidance. ### Description - Accept keys starting with `[` in validation and preprocessing by updating `basic-validation.js`, `flatten-raw-style-obj.js`, and `PreRule.pseudos` to treat attribute selectors like pseudos. - Extend `when` helpers to accept attribute selectors by adding a `WhenSelector` union, updating `validatePseudoSelector` to allow `[`...`]`, and applying the selector when building `:where` / `:has` clauses in `when.js`. - Update Flow/TypeScript definitions in `StyleXTypes.js` and `StyleXTypes.d.ts` to permit attribute selectors for `stylex.when.*` signatures. - Add/update tests and documentation to use value-based attribute selectors (tests and snapshots in `transform-stylex-when-test.js` and `flatten-raw-style-obj-test.js`, and docs in `when.mdx`). ### Testing - Ran `yarn workspace @stylexjs/babel-plugin test -- transform-stylex-when-test --updateSnapshot`, where the test suite passed and snapshots were updated but the overall command returned non-zero due to global coverage thresholds being unmet. - The changed test file `transform-stylex-when-test.js` passed (all tests green) and snapshots were updated successfully. - Ran `npm run lint`, which completed successfully. - Pre-commit formatting/lint hooks ran as part of the commit and completed successfully.
"Styling-agnostic" react component systems, such as base-ui, expose state based styling hooks through the use of dom element attributes. Actually listening to these in StyleX, while possible through usage of the
:is()psedudoselector, is overly verbose and uncessary. This diff addresses this by adding support for attribute selectors in stylex.when calls and conditional styles.Motivation
stylex.whenand conditional style objects to accept attribute selectors (including value-matching forms) rather than only attribute-existence markers.Description
[in validation and preprocessing by updatingbasic-validation.js,flatten-raw-style-obj.js, andPreRule.pseudosto treat attribute selectors like pseudos.whenhelpers to accept attribute selectors by adding aWhenSelectorunion, updatingvalidatePseudoSelectorto allow[...], and applying the selector when building:where/:hasclauses inwhen.js.StyleXTypes.jsandStyleXTypes.d.tsto permit attribute selectors forstylex.when.*signatures.transform-stylex-when-test.jsandflatten-raw-style-obj-test.js, and docs inwhen.mdx).Testing
yarn workspace @stylexjs/babel-plugin test -- transform-stylex-when-test --updateSnapshot, where the test suite passed and snapshots were updated but the overall command returned non-zero due to global coverage thresholds being unmet.transform-stylex-when-test.jspassed (all tests green) and snapshots were updated successfully.npm run lint, which completed successfully.