Title: CSS Variable Namespacing by mattrbeck · Pull Request #68846 · angular/angular · GitHub
Open Graph Title: CSS Variable Namespacing by mattrbeck · Pull Request #68846 · angular/angular
X Title: CSS Variable Namespacing by mattrbeck · Pull Request #68846 · angular/angular
Description: Superseds #67362. Primary differences are: Opt-out syntax is now a --global prefix, e.g. --global--foo: blue Added support for style properties, e.g. [style.--foo]="'blue'" Added errors for prefix missing trailing double-hyphen, e.g. --global-foo This adds CSS variable namespacing support to Angular. This allows multiple apps to coexist on the same page with isolated CSS variables, meaning one can use color: var(--primary-color); without worrying about accidentally inheriting the primary color of a different app which happens to set it on an ancestor element. To enable this feature, call provideCssVarNamespacing in your app.config.ts. Typically you want to configure this with the same value as APP_ID, but with an additional separator at the end (a - or _): import {ApplicationConfig, APP_ID} from '@angular/core'; import {provideCssVarNamespacing} from '@angular/platform-browser'; export const appConfig: ApplicationConfig = { providers: [ { provide: APP_ID, useValue: 'my-app', }, provideCssVarNamespacing('my-app_'), ], }; This only namespaces styles in Angular components (the styles or styleUrls properties in @Component). It does not namespace global styles, which are out of scope for this effort. Namespacing does naturally break any JavaScript references to CSS variables, therefore this PR also introduces CssVarNamespacer which allows you to automatically namespace variables based on what is configured in the application. import {CssVarNamespacer} from '@angular/platform-browser'; const namespacer = inject(CssVarNamespacer); const color = namespacer.namespace('--primary-color'); getComputedStyle(someElement).getPropertyValue(color); Libraries should consider always using the namespacer when referring to CSS variables, as they may be consumed by applications which enable namespacing. Namespacing works by having the compiler unconditionally prepend %NS% to CSS variables (--foo -> --%NS%foo) and then at runtime replaces %NS% with a namespace specified by provideCssVarNamespacing('my-app_') (--%NS%foo -> --my-app_foo). Internal bug: b/485672083 Closes #67362 via supersession.
Open Graph Description: Superseds #67362. Primary differences are: Opt-out syntax is now a --global prefix, e.g. --global--foo: blue Added support for style properties, e.g. [style.--foo]="'blue'" Added...
X Description: Superseds #67362. Primary differences are: Opt-out syntax is now a --global prefix, e.g. --global--foo: blue Added support for style properties, e.g. [style.--foo]="'blue'...
Opengraph URL: https://github.com/angular/angular/pull/68846
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:d1b0673a-b241-03a6-32f4-40758010d411 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | 942E:2E4579:8FD162:C88C2A:6A6249D5 |
| html-safe-nonce | f2a2b6d721c7e356eec90d41b3a4b712062467d05c64affd0be074daf20436bb |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5NDJFOjJFNDU3OTo4RkQxNjI6Qzg4QzJBOjZBNjI0OUQ1IiwidmlzaXRvcl9pZCI6IjQ3MjE5OTYyODA5MTA0NjU0OTMiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | c6e92832ba202ff03ec270b32f11759705f010a716434bb21736cfc8a675a88d |
| hovercard-subject-tag | pull_request:3720112558 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/angular/angular/pull/68846/files |
| twitter:image | https://avatars.githubusercontent.com/u/22065329?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/22065329?s=400&v=4 |
| og:image:alt | Superseds #67362. Primary differences are: Opt-out syntax is now a --global prefix, e.g. --global--foo: blue Added support for style properties, e.g. [style.--foo]="'blue'" Added... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 5d6ba65d73ecc4e3394fe318d2b2f98e6f8eed4878b5421b938e20d30bde267b |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/angular/angular git https://github.com/angular/angular.git |
| octolytics-dimension-user_id | 139426 |
| octolytics-dimension-user_login | angular |
| octolytics-dimension-repository_id | 24195339 |
| octolytics-dimension-repository_nwo | angular/angular |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 24195339 |
| octolytics-dimension-repository_network_root_nwo | angular/angular |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 2dadc56fd5989b76a8ae7304e3aa56d0b485e5dc |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width