|
3 | 3 | Generate CSS Modules classname on Svelte components
|
4 | 4 |
|
5 | 5 | ```bash
|
6 |
| -npm install --save-dev svelte-preprocess-cssmodules@next |
| 6 | +npm install --save-dev svelte-preprocess-cssmodules |
7 | 7 | ```
|
8 | 8 |
|
9 | 9 | - [Usage](#usage)
|
@@ -155,7 +155,7 @@ Toggle a class on an element.
|
155 | 155 |
|
156 | 156 | Force a selector to be scoped within a component to prevent style inheritance on child components.
|
157 | 157 |
|
158 |
| -`:local()` is doing the opposite of `:global()` and can only be used with the `native` and `mixed` mode. |
| 158 | +`:local()` is doing the opposite of `:global()` and can only be used with the `native` and `mixed` mode on. |
159 | 159 |
|
160 | 160 | ```html
|
161 | 161 | <!-- Parent Component-->
|
@@ -204,7 +204,7 @@ Force a selector to be scoped within a component to prevent style inheritance on
|
204 | 204 | ```html
|
205 | 205 | <!-- Child Component-->
|
206 | 206 |
|
207 |
| -<style module> |
| 207 | +<style> |
208 | 208 | .child-uhRt2j em { color: black; }
|
209 | 209 | </style>
|
210 | 210 |
|
@@ -497,6 +497,71 @@ The list of available keys are:
|
497 | 497 | - `filepath` the path of the component
|
498 | 498 | - `classname` the local className
|
499 | 499 |
|
| 500 | +*Example of use* |
| 501 | +```js |
| 502 | +// Preprocess config |
| 503 | +... |
| 504 | +preprocess: [ |
| 505 | + cssModules({ |
| 506 | + hashSeeder: ['filepath'], |
| 507 | + }) |
| 508 | +], |
| 509 | +... |
| 510 | +``` |
| 511 | +```html |
| 512 | +<button class="success">Ok</button> |
| 513 | +<button class="cancel">Cancel</button> |
| 514 | +<style module> |
| 515 | + .success { background-color: green; } |
| 516 | + .cancel { background-color: gray; } |
| 517 | +</style> |
| 518 | +``` |
| 519 | + |
| 520 | +*Generating* |
| 521 | + |
| 522 | +```html |
| 523 | +<button class="success-yr6RT">Ok</button> |
| 524 | +<button class="cancel-yr6RT">Cancel</button> |
| 525 | +<style> |
| 526 | + .success-yr6RT { background-color: green; } |
| 527 | + .cancel-yr6RT { background-color: gray; } |
| 528 | +</style> |
| 529 | +``` |
| 530 | + |
| 531 | +**`allowedAttributes`** |
| 532 | + |
| 533 | +Add other attributes than `class` to be parsed by the preprocesser |
| 534 | + |
| 535 | +```js |
| 536 | +// Preprocess config |
| 537 | +... |
| 538 | +preprocess: [ |
| 539 | + cssModules({ |
| 540 | + allowedAttributes: ['data-color', 'classname'], |
| 541 | + }) |
| 542 | +], |
| 543 | +... |
| 544 | +``` |
| 545 | +```html |
| 546 | +<button class="red" data-color="red">Red</button> |
| 547 | +<button class="red" classname="blue">Red or Blue</button> |
| 548 | +<style module> |
| 549 | + .red { background-color: red; } |
| 550 | + .blue { background-color: blue; } |
| 551 | +</style> |
| 552 | +``` |
| 553 | + |
| 554 | +*Generating* |
| 555 | + |
| 556 | +```html |
| 557 | +<button class="red-yr6RT" data-color="red-yr6RT">Red</button> |
| 558 | +<button class="red-yr6RT" classname="blue-aE4qW">Red or Blue</button> |
| 559 | +<style> |
| 560 | + .red-yr6RT { background-color: red; } |
| 561 | + .blue-aE4qW { background-color: blue; } |
| 562 | +</style> |
| 563 | +``` |
| 564 | + |
500 | 565 | **`getLocalIdent`**
|
501 | 566 |
|
502 | 567 | Customize the creation of the classname instead of relying on the built-in function.
|
@@ -562,15 +627,15 @@ If you want to migrate an existing project to `v2` keeping the approach of the 1
|
562 | 627 | ```js
|
563 | 628 | // Preprocess config
|
564 | 629 | ...
|
565 |
| - |
566 | 630 | preprocess: [
|
567 | 631 | cssModules([
|
568 | 632 | mode: 'mixed',
|
569 | 633 | ]),
|
570 | 634 | ],
|
| 635 | + ... |
571 | 636 | ```
|
572 | 637 | - Remove all `$style.` prefix from the html markup
|
573 |
| -- Add the attribute `module` to `<style>` for all your components. |
| 638 | +- Add the attribute `module` to `<style>` within your components. |
574 | 639 | ```html
|
575 | 640 | <style module>
|
576 | 641 | ...
|
|
0 commit comments