Skip to content

Commit 4e24705

Browse files
author
Michael Vurchio
committed
Add more config example to the readme
1 parent 213c8c1 commit 4e24705

File tree

1 file changed

+70
-5
lines changed

1 file changed

+70
-5
lines changed

README.md

Lines changed: 70 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Generate CSS Modules classname on Svelte components
44

55
```bash
6-
npm install --save-dev svelte-preprocess-cssmodules@next
6+
npm install --save-dev svelte-preprocess-cssmodules
77
```
88

99
- [Usage](#usage)
@@ -155,7 +155,7 @@ Toggle a class on an element.
155155

156156
Force a selector to be scoped within a component to prevent style inheritance on child components.
157157

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.
159159

160160
```html
161161
<!-- Parent Component-->
@@ -204,7 +204,7 @@ Force a selector to be scoped within a component to prevent style inheritance on
204204
```html
205205
<!-- Child Component-->
206206

207-
<style module>
207+
<style>
208208
.child-uhRt2j em { color: black; }
209209
</style>
210210

@@ -497,6 +497,71 @@ The list of available keys are:
497497
- `filepath` the path of the component
498498
- `classname` the local className
499499

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+
500565
**`getLocalIdent`**
501566

502567
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
562627
```js
563628
// Preprocess config
564629
...
565-
566630
preprocess: [
567631
cssModules([
568632
mode: 'mixed',
569633
]),
570634
],
635+
...
571636
```
572637
- 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.
574639
```html
575640
<style module>
576641
...

0 commit comments

Comments
 (0)