Skip to content
This repository was archived by the owner on Jan 19, 2023. It is now read-only.

Commit c9905c7

Browse files
committed
Merge branch 'image-caption' of git://github.com/c00kiemon5ter/react-image-lightbox into captions
2 parents bdb409a + e0448c5 commit c9905c7

File tree

5 files changed

+77
-4
lines changed

5 files changed

+77
-4
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ animationOnKeyInput | bool | `false` | | Disable animation on
9898
animationDuration | number | `300` | | Animation duration (ms)
9999
keyRepeatLimit | number | `180` | | Required interval of time (ms) between key actions (prevents excessively fast navigation of images)
100100
keyRepeatKeyupBonus | number | `40` | | Amount of time (ms) restored after each keyup (makes rapid key presses slightly faster than holding down the key to navigate images)
101-
imageTitle | string | | | Image title
101+
imageTitle | node | | | Image title
102+
imageCaption | node | | | Image caption - a small piece of text that describes the image
102103
toolbarButtons | node[] | | | Array of custom toolbar buttons
103104
reactModalStyle | Object | `{}` | | Set z-index style, etc., for the parent react-modal (format: https://github.com/reactjs/react-modal#styles )
104105
imagePadding | number | `10` | | Padding (px) between the edge of the window and the lightbox

src/examples/cats/app.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,33 @@ const titles = [
6161
</span>),
6262
];
6363

64+
const captions = [
65+
'',
66+
'Sad kitten wants a hug',
67+
(<p>
68+
.. not in the&nbsp;
69+
<em>
70+
mood
71+
</em>
72+
&nbsp;for games right now
73+
</p>),
74+
(<p>
75+
Meow!? What do you mean by «Earth is&nbsp;
76+
<strong>
77+
round
78+
</strong>
79+
»? Are you&nbsp;
80+
<em>
81+
absolutely
82+
</em>
83+
&nbsp;
84+
<strong>
85+
sure
86+
</strong>
87+
&nbsp;you know what you&#39;re talking about?
88+
</p>),
89+
];
90+
6491
const App = React.createClass({
6592
getInitialState() {
6693
return {
@@ -98,6 +125,7 @@ const App = React.createClass({
98125
onMoveNextRequest={this.moveNext}
99126

100127
imageTitle={titles[this.state.index]}
128+
imageCaption={captions[this.state.index]}
101129
/>
102130
);
103131
}

src/react-image-lightbox.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@ if (_ieVersion < 10) {
3636
};
3737
}
3838

39+
function handleCaptionMousewheel(event) {
40+
event.stopPropagation();
41+
}
42+
43+
function handleCaptionMouseDown(event) {
44+
event.stopPropagation();
45+
}
46+
3947
class ReactImageLightbox extends Component {
4048
constructor(props) {
4149
super(props);
@@ -84,6 +92,8 @@ class ReactImageLightbox extends Component {
8492
this.requestClose = this.requestClose.bind(this);
8593
this.requestMoveNext = this.requestMoveNext.bind(this);
8694
this.requestMovePrev = this.requestMovePrev.bind(this);
95+
this.handleCaptionMousewheel = handleCaptionMousewheel;
96+
this.handleCaptionMouseDown = handleCaptionMouseDown;
8797
}
8898

8999
componentWillMount() {
@@ -1149,6 +1159,21 @@ class ReactImageLightbox extends Component {
11491159
</li>
11501160
</ul>
11511161
</div>
1162+
1163+
{!this.props.imageCaption ? '' :
1164+
<div // Image caption
1165+
onWheel={this.handleCaptionMousewheel}
1166+
onMouseDown={this.handleCaptionMouseDown}
1167+
className={`ril-caption ${styles.caption}`}
1168+
>
1169+
<div
1170+
className={`ril-caption-content ${styles.captionContent}`}
1171+
>
1172+
{this.props.imageCaption}
1173+
</div>
1174+
</div>
1175+
}
1176+
11521177
</div>
11531178
</Modal>
11541179
);
@@ -1241,6 +1266,9 @@ ReactImageLightbox.propTypes = {
12411266
// Image title
12421267
imageTitle: PropTypes.node,
12431268

1269+
// Image caption
1270+
imageCaption: PropTypes.node,
1271+
12441272
//-----------------------------
12451273
// Lightbox style
12461274
//-----------------------------

src/style.scss

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
$toolbarHeight: 50px;
2+
$maxCaptionHeight: 150px;
23

34
@keyframes closeWindow {
45
0% { opacity: 1; }
@@ -94,17 +95,32 @@ $toolbarHeight: 50px;
9495
background-size: cover;
9596
}
9697

98+
.caption,
9799
.toolbar {
98100
background-color: rgba(0, 0, 0, 0.5);
99101
position: absolute;
100102
left: 0;
101-
top: 0;
102103
right: 0;
103-
height: $toolbarHeight;
104104
display: flex;
105105
justify-content: space-between;
106106
}
107107

108+
.caption {
109+
bottom: 0;
110+
max-height: $maxCaptionHeight;
111+
overflow: auto;
112+
113+
.captionContent {
114+
padding: 10px 20px;
115+
color: #FFF;
116+
}
117+
}
118+
119+
.toolbar {
120+
top: 0;
121+
height: $toolbarHeight;
122+
}
123+
108124
.toolbarSide {
109125
height: $toolbarHeight;
110126
margin: 0;

src/util.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export function translate(str, replaceStrings = null) {
1818

1919
let translated = str;
2020
if (replaceStrings) {
21-
Object.keys(replaceStrings).forEach(placeholder => {
21+
Object.keys(replaceStrings).forEach((placeholder) => {
2222
translated = translated.replace(placeholder, replaceStrings[placeholder]);
2323
});
2424
}

0 commit comments

Comments
 (0)