A toggler is an interaction that coordinates two components — a button, and a set of contents.
When you click the button, the states of both the button and the contents are toggled.
data-ur-set="toggler"
data-ur-toggler-component="button"
data-ur-toggler-component="content"
data-ur-toggler-component="button"
data-ur-toggler-component="content"
data-ur-toggler-component="drawer"
You can also directly initialize the widget in JavaScript (components can be passed in as strings/elements/arrays):
Uranium.lib.toggler({ button: "#a", content: "#b" });
<div data-ur-set="toggler"> <div data-ur-toggler-component="button">Click on the button</div> <div data-ur-toggler-component="content">And content appears</div> </div>
/* Recommended SCSS Styling */ [data-ur-toggler-component="content"] { display: none; &[data-ur-state="enabled"] { display: block; } }
/* Recommended CSS Styling */ [data-ur-toggler-component="content"] { display: none; } [data-ur-toggler-component="content"][data-ur-state="enabled"] { display: block; }
If we want something to start out visible, and then disappear when we click on the button, we can just add the data-ur-state="enabled"
attribute to the button and its content.
<div data-ur-set="toggler"> <div data-ur-toggler-component="button" data-ur-state="enabled"> Toggle This Picture! </div> <div data-ur-toggler-component="content" data-ur-state="enabled"> <img src="/images/popup.jpeg"> </div> </div>
It's super-easy to nest togglers as well. Click on the button, and then click on the text that shows up below. (Notice how the sub-togglers even remember what state they were in when you toggle the main button.)
Foods
<div data-ur-set="toggler"> <p data-ur-toggler-component="button">Foods</p> <ul data-ur-toggler-component="content"> <li data-ur-set="toggler"> <div data-ur-toggler-component="button">Veggies</div> <ul data-ur-toggler-component="content"> <li>Beets</li> <li>Carrots</li> </ul> </li> <li data-ur-set="toggler"> <div data-ur-toggler-component="button">Meats</div> <ul data-ur-toggler-component='content'> <li>Beef</li> <li>Fish</li> </ul> </li> </ul> </div>
Note: This example uses flexbox CSS to activate the visual drawer behavior, but the Uranium behavior is the same across all browsers, and you may implement the visual effects any way you prefer.