|
| 1 | +import { Meta, Story } from "@storybook/addon-docs"; |
| 2 | +import { ToggleItself, ToggleTarget, ToggleTargetScope } from "./toggle.stories.js"; |
| 3 | + |
| 4 | +<Meta title="Patterns/Toggle" /> |
| 5 | + |
| 6 | +# Toggle Pattern |
| 7 | + |
| 8 | +A pattern to toggle classes on HTML elements. |
| 9 | + |
| 10 | +# Migration note (Plone 6) |
| 11 | + |
| 12 | +This mockup pattern will probably replaced by patternslib/toggle. Some features are |
| 13 | +already broken like "Toggle an element by hover event". |
| 14 | +We decided to not migrate all examples and no tests. |
| 15 | + |
| 16 | +# Configuration |
| 17 | + |
| 18 | +```md |
| 19 | +| **Option** | **Type** | **Default** | **Description** | |
| 20 | +| ------------- | -------- | ----------- | -------------------------------------------------------- | |
| 21 | +| `target` | `string` | `null` | Selector of the target elements to toggle (`undefined`). | |
| 22 | +| `targetScope` | `null` | `global` | Selector of a target scope element in ancestors. | |
| 23 | +| `attribute` | `string` | `null` | Element attribute which will be toggled (`class`). | |
| 24 | +| `event` | `string` | `null` | Event that will trigger toggling (`click`). | |
| 25 | +``` |
| 26 | + |
| 27 | +# Examples |
| 28 | + |
| 29 | +## Toggle itself |
| 30 | + |
| 31 | +<br /> |
| 32 | +<Story name="Toggle Itself" of={ToggleItself} /> |
| 33 | + |
| 34 | +```html |
| 35 | +<button |
| 36 | + type="button" |
| 37 | + class="btn btn-primary pat-toggle mb-2" |
| 38 | + data-pat-toggle="value:btn-lg;" |
| 39 | +> |
| 40 | + This button goes bigger/smaller! |
| 41 | +</button> |
| 42 | +``` |
| 43 | + |
| 44 | +## Toggle all targets (global scope) |
| 45 | + |
| 46 | +<br /> |
| 47 | +<Story name="Toggle Taget" of={ToggleTarget} /> |
| 48 | + |
| 49 | +```html |
| 50 | +<div class="wrapper"> |
| 51 | + <button |
| 52 | + type="button" |
| 53 | + class="btn btn-primary pat-toggle mb-2" |
| 54 | + data-pat-toggle="value:badge-success;target:.targetElement" |
| 55 | + > |
| 56 | + This button is toggling the background of a element.</button |
| 57 | + ><br /> |
| 58 | + <span class="targetElement badge bg-secondary">Hello World</span> |
| 59 | +</div> |
| 60 | +``` |
| 61 | + |
| 62 | +## Toggle specific target inside a target scope |
| 63 | + |
| 64 | +<br /> |
| 65 | +<Story name="Toggle Taget Scope" of={ToggleTargetScope} /> |
| 66 | + |
| 67 | +```html |
| 68 | +<div class="wrapper"> |
| 69 | + <div class="myScope"> |
| 70 | + <button |
| 71 | + type="button" |
| 72 | + class="btn btn-primary pat-toggle mb-2" |
| 73 | + data-pat-toggle="value:bg-success;target:.targetElement;targetScope:.myScope;" |
| 74 | + > |
| 75 | + toggle</button |
| 76 | + ><br /> |
| 77 | + <span class="targetElement badge bg-secondary mb-4">Hello World</span> |
| 78 | + </div> |
| 79 | + <div class="myScope"> |
| 80 | + <button |
| 81 | + type="button" |
| 82 | + class="btn btn-primary pat-toggle mb-2" |
| 83 | + data-pat-toggle="value:bg-success;target:.targetElement;targetScope:.myScope;" |
| 84 | + > |
| 85 | + toggle</button |
| 86 | + ><br /> |
| 87 | + <span class="targetElement badge bg-secondary">Hello World</span> |
| 88 | + </div> |
| 89 | +</div> |
| 90 | +``` |
| 91 | + |
| 92 | +## Toggle more than one target inside a specific target scope |
| 93 | + |
| 94 | +<br /> |
| 95 | +<Story name="Toggle Taget Scope" of={ToggleTargetScope} /> |
| 96 | + |
| 97 | +```html |
| 98 | +<div class="wrapper"> |
| 99 | + <div class="myScope"> |
| 100 | + <button |
| 101 | + type="button" |
| 102 | + class="btn btn-primary pat-toggle mb-2" |
| 103 | + data-pat-toggle="value:bg-success;target:.targetElement;targetScope:.myScope;" |
| 104 | + > |
| 105 | + toggle</button |
| 106 | + ><br /> |
| 107 | + <span class="targetElement badge bg-secondary">Hello World</span> |
| 108 | + <span class="targetElement badge bg-secondary mb-4">Hello again</span> |
| 109 | + </div> |
| 110 | + <div class="myScope"> |
| 111 | + <button |
| 112 | + type="button" |
| 113 | + class="btn btn-primary pat-toggle mb-2" |
| 114 | + data-pat-toggle="value:bg-success;target:.targetElement;targetScope:.myScope;" |
| 115 | + > |
| 116 | + toggle</button |
| 117 | + ><br /> |
| 118 | + <span class="targetElement badge bg-secondary">Hello World</span> |
| 119 | + </div> |
| 120 | +</div> |
| 121 | +``` |
0 commit comments