You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123 lines
2.9 KiB

3 months ago
  1. [![Build Status][ci-img]][ci] [![codecov][codecov-img]][codecov] [![npm][npm-img]][npm]
  2. # CSS Modules: Local by Default
  3. Transformation examples:
  4. Selectors (mode `local`, by default)::
  5. <!-- prettier-ignore-start -->
  6. ```css
  7. .foo { ... } /* => */ :local(.foo) { ... }
  8. .foo .bar { ... } /* => */ :local(.foo) :local(.bar) { ... }
  9. /* Shorthand global selector */
  10. :global .foo .bar { ... } /* => */ .foo .bar { ... }
  11. .foo :global .bar { ... } /* => */ :local(.foo) .bar { ... }
  12. /* Targeted global selector */
  13. :global(.foo) .bar { ... } /* => */ .foo :local(.bar) { ... }
  14. .foo:global(.bar) { ... } /* => */ :local(.foo).bar { ... }
  15. .foo :global(.bar) .baz { ... } /* => */ :local(.foo) .bar :local(.baz) { ... }
  16. .foo:global(.bar) .baz { ... } /* => */ :local(.foo).bar :local(.baz) { ... }
  17. ```
  18. <!-- prettier-ignore-end -->
  19. Declarations (mode `local`, by default):
  20. <!-- prettier-ignore-start -->
  21. ```css
  22. .foo {
  23. animation-name: fadeInOut, global(moveLeft300px), local(bounce);
  24. }
  25. .bar {
  26. animation: rotate 1s, global(spin) 3s, local(fly) 6s;
  27. }
  28. /* => */
  29. :local(.foo) {
  30. animation-name: :local(fadeInOut), moveLeft300px, :local(bounce);
  31. }
  32. :local(.bar) {
  33. animation: :local(rotate) 1s, spin 3s, :local(fly) 6s;
  34. }
  35. ```
  36. <!-- prettier-ignore-end -->
  37. ## Pure Mode
  38. In pure mode, all selectors must contain at least one local class or id
  39. selector
  40. To ignore this rule for a specific selector, add the a `/* cssmodules-pure-ignore */` comment in front
  41. of the selector:
  42. ```css
  43. /* cssmodules-pure-ignore */
  44. :global(#modal-backdrop) {
  45. ...;
  46. }
  47. ```
  48. or by adding a `/* cssmodules-pure-no-check */` comment at the top of a file to disable this check for the whole file:
  49. ```css
  50. /* cssmodules-pure-no-check */
  51. :global(#modal-backdrop) {
  52. ...;
  53. }
  54. :global(#my-id) {
  55. ...;
  56. }
  57. ```
  58. ## Building
  59. ```bash
  60. $ npm install
  61. $ npm test
  62. ```
  63. - Build: [![Build Status][ci-img]][ci]
  64. - Lines: [![coveralls][coveralls-img]][coveralls]
  65. - Statements: [![codecov][codecov-img]][codecov]
  66. ## Development
  67. ```bash
  68. $ yarn test:watch
  69. ```
  70. ## License
  71. MIT
  72. ## With thanks
  73. - [Tobias Koppers](https://github.com/sokra)
  74. - [Glen Maddern](https://github.com/geelen)
  75. ---
  76. Mark Dalgleish, 2015.
  77. [ci-img]: https://github.com/css-modules/postcss-modules-local-by-default/actions/workflows/nodejs.yml/badge.svg
  78. [ci]: https://github.com/css-modules/postcss-modules-local-by-default/actions/workflows/nodejs.yml
  79. [npm-img]: https://img.shields.io/npm/v/postcss-modules-local-by-default.svg?style=flat-square
  80. [npm]: https://www.npmjs.com/package/postcss-modules-local-by-default
  81. [coveralls-img]: https://img.shields.io/coveralls/css-modules/postcss-modules-local-by-default/master.svg?style=flat-square
  82. [coveralls]: https://coveralls.io/r/css-modules/postcss-modules-local-by-default?branch=master
  83. [codecov-img]: https://img.shields.io/codecov/c/github/css-modules/postcss-modules-local-by-default/master.svg?style=flat-square
  84. [codecov]: https://codecov.io/github/css-modules/postcss-modules-local-by-default?branch=master