You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Start by telling react-lightbox to render the elements you want when the document is loaded.
32
+
Just put them inside the LightboxTrigger element and LightboxModal element:
33
+
34
+
```html
35
+
<body>
36
+
<divid='react-canvas'></div>
37
+
<scripttype="text/jsx">
38
+
/** @jsx React.DOM */
39
+
40
+
React.renderComponent(
41
+
<Lightbox>
42
+
<LightboxTrigger>
43
+
<a href='#'>Click me to open!</a>
44
+
</LightboxTrigger>
45
+
<LightboxModal>
46
+
<div>
47
+
<h1>This is the basic usage!</h1>
48
+
<p>Good luck :D</p>
49
+
</div>
50
+
</LightboxModal>
51
+
</Lightbox>,
52
+
document.getElementById('react-canvas')
53
+
);
54
+
</script>
55
+
</body>
56
+
```
57
+
We done! That’s all you need to do!
58
+
Click on the text and you’ll see the beautiful lightbox popup on your browser!
59
+
See the [Basic usage](http://howtomakeaturn.github.io/react-lightbox/basic.html).
60
+
61
+
*NOTE! react-lightbox will auto-bind openLightbox function to the onClick event of the element inside the LightboxTrigger. You don’t need to set the onClick event yourself.*
62
+
63
+
If you think simply use ‘a’ tag as trigger and ‘p’ tag as the content of lightbox is too simple, you can create custom elements for both LightboxTrigger and LightboxModal:
Your custom elements inside LightboxTrigger and LightboxModal will receive ‘openLightbox’ and ‘closeLightbox’ functions automatically. Use them in whatever way you want.
108
+
109
+
The live example for above code is here: [Custom elements](http://howtomakeaturn.github.io/react-lightbox/custom-element.html).
110
+
111
+
112
+
113
+
*NOTE! If you use custom element as trigger, react-lightbox will NOT auto-bind openLightbox for you. Remember to bind it as the example shows.*
114
+
115
+
# Advanced
116
+
117
+
Sometimes you need to share variables between elements inside the lightbox. For instance, you want the change the text in the trigger according to the text user type into the textarea in modal. How can we deal with that?
118
+
119
+
React-lightbox provide ‘setLightboxState’ function to solve this.
120
+
First, pass the values you want to share between elements to the Lightbox element ‘data’ props:
To change the shared value, use the ‘setLightboxState’ function which all children elements will receive automatically.
132
+
133
+
What happened behind it is easy. Lightbox set the ‘data’ object as state. And then pass every value inside the state to all children as props! So every time you ‘setLightboxState’, all the elements will update automatically!
134
+
135
+
Here’s a more concrete example:
136
+
137
+
```
138
+
<body>
139
+
<div id='react-canvas'></div>
140
+
<script type="text/jsx">
141
+
/** @jsx React.DOM */
142
+
var ToggleText = React.createClass({
143
+
render: function() {
144
+
var text = this.props.content.trim() ? 'View Notes' : 'Add Notes';
0 commit comments