|
| 1 | +# Pattern Wrapper Plugin for Pattern Lab Node |
| 2 | + |
| 3 | +This plugin allows users to add a wrapper div with css class(es) around a pattern when shown in the |
| 4 | +single preview. |
| 5 | +If it gets included in another pattern, the wrapper is not added. |
| 6 | + |
| 7 | +This comes in handy if you, for example, use theming classes to visualize different backgrounds, colors etc. |
| 8 | + |
| 9 | +## Configuration |
| 10 | + |
| 11 | +After the installation, you will see the config in your `patternlab-config.json`: |
| 12 | + |
| 13 | +``` |
| 14 | +"plugins": { |
| 15 | + "patternlab-plugin-pattern-wrap": { |
| 16 | + "enabled": true, |
| 17 | + "initialized": false, |
| 18 | + "options": { |
| 19 | + "wrapClassKey": [""] |
| 20 | + } |
| 21 | + } |
| 22 | +} |
| 23 | +``` |
| 24 | + |
| 25 | +If you don't see this config object, add the plugin via the command: |
| 26 | + |
| 27 | +``` |
| 28 | +patternlab install --plugins patternlab-plugin-pattern-wrap |
| 29 | +``` |
| 30 | + |
| 31 | +In the `wrapClassKey` array you can add the data keys which should be used to get the class names. |
| 32 | + |
| 33 | +## How does it work? |
| 34 | + |
| 35 | +The plugin will look for any "data key" added to the `wrapClassKey` array and then will add that |
| 36 | +entry to the wrapper element. |
| 37 | + |
| 38 | +Data key can be set inside the Markdown or JSON file of any pattern. |
| 39 | + |
| 40 | +**Example Config** |
| 41 | + |
| 42 | +``` |
| 43 | +"wrapClassKey": ["theme-class"] |
| 44 | +``` |
| 45 | + |
| 46 | +### Markdown |
| 47 | + |
| 48 | +Usage https://patternlab.io/docs/documenting-patterns/ |
| 49 | + |
| 50 | +_my-pattern.md_ |
| 51 | + |
| 52 | +``` |
| 53 | +--- |
| 54 | +theme-class: my-theme-class |
| 55 | +--- |
| 56 | +``` |
| 57 | + |
| 58 | +Will create `<div class="pl-pattern-wrapper-element my-theme-class"></div>` around the rendered |
| 59 | +pattern. |
| 60 | + |
| 61 | +### JSON |
| 62 | + |
| 63 | +Usage https://patternlab.io/docs/creating-pattern-specific-values/ |
| 64 | + |
| 65 | +_my-pattern.json_ |
| 66 | + |
| 67 | +``` |
| 68 | +{ |
| 69 | + "theme-class": "my-other-theme-class" |
| 70 | +} |
| 71 | +``` |
| 72 | + |
| 73 | +Will create `<div class="pl-pattern-wrapper-element my-other-theme-class"></div>` around the |
| 74 | +rendered pattern. |
| 75 | + |
| 76 | +#### Pseudo-Patterns |
| 77 | + |
| 78 | +This will work with pseudo-patterns too (Usage https://patternlab.io/docs/using-pseudo-patterns/) |
| 79 | + |
| 80 | +_my-pattern~variant.json_ |
| 81 | + |
| 82 | +``` |
| 83 | +{ |
| 84 | + "theme-class": "my-variant-theme-class" |
| 85 | +} |
| 86 | +``` |
| 87 | + |
| 88 | +Will create `<div class="pl-pattern-wrapper-element my-variant-theme-class"></div>` around the |
| 89 | +rendered pattern. |
| 90 | + |
| 91 | +### Multiple entries in "wrapClassKey" |
| 92 | + |
| 93 | +Will result in multiple classes in the wrapper div. |
| 94 | + |
| 95 | +**Example Config** |
| 96 | + |
| 97 | +``` |
| 98 | +"wrapClassKey": ["theme-class", "other-class"] |
| 99 | +``` |
| 100 | + |
| 101 | +_my-pattern.json_ |
| 102 | + |
| 103 | +``` |
| 104 | +{ |
| 105 | + "theme-class": "theme-class", |
| 106 | + "other-class": "some-other-class" |
| 107 | +} |
| 108 | +``` |
| 109 | + |
| 110 | +_Result_ |
| 111 | + |
| 112 | +``` |
| 113 | +<div class="pl-pattern-wrapper-element theme-class some-other-class"></div> |
| 114 | +``` |
0 commit comments