Skip to content

Commit 2a12366

Browse files
committed
add DirectionalButton component
1 parent 87ab2fb commit 2a12366

File tree

3 files changed

+76
-46
lines changed

3 files changed

+76
-46
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@kunai-consulting/fork-react-image-lightbox",
3-
"version": "6.0.4",
3+
"version": "6.0.5-alpha.1",
44
"description": "A lightbox component for React.js",
55
"scripts": {
66
"build": "rollup -c",

src/__tests__/__snapshots__/react-image-lightbox.spec.js.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ exports[`Snapshot Testing Lightbox renders properly" 1`] = `
1010
closeButtonComponentProps={Object {}}
1111
closeButtonImage={null}
1212
closeLabel="Close lightbox"
13+
directionalButtonComponent={null}
14+
directionalButtonComponentProps={Object {}}
1315
discourageDownloads={false}
1416
enableZoom={true}
1517
imageCaption={null}
@@ -202,7 +204,6 @@ exports[`Snapshot Testing Lightbox renders properly" 1`] = `
202204
type="button"
203205
/>
204206
</div>
205-
206207
</div>
207208
208209
<div
@@ -452,7 +453,6 @@ exports[`Snapshot Testing Lightbox renders properly" 1`] = `
452453
type="button"
453454
/>
454455
</div>
455-
456456
</div>
457457
458458
<div

src/react-image-lightbox.js

Lines changed: 73 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1549,7 +1549,7 @@ class ReactImageLightbox extends Component {
15491549
}
15501550
/>
15511551
)}
1552-
</div>{' '}
1552+
</div>
15531553
</div>
15541554
{prevSrc && !isMobile ? (
15551555
<button // Move to previous image button
@@ -1600,27 +1600,39 @@ class ReactImageLightbox extends Component {
16001600
<div className="ril__thumbNailsContainer">
16011601
<div className="ril__thumbNails">
16021602
{/* TODO previous and Next thumbnail images should show more thumbs if available */}
1603-
{prevSrc && (
1604-
<button // Move to previous image button
1605-
type="button"
1606-
className={`ril__thumbNails ril__navButtonsThumbs${
1607-
this.props.thumbnailArrowLeft ? '' : 'ril__navButtonPrev'
1608-
}`}
1609-
key="prev"
1610-
aria-label={this.props.prevLabel}
1611-
title={this.props.prevLabel}
1612-
onClick={
1613-
!this.isAnimating() ? this.requestMovePrev : undefined
1614-
} // Ignore clicks during animation
1615-
style={
1616-
this.props.thumbnailArrowLeft
1617-
? {
1618-
background: `url('${this.props.thumbnailArrowLeft}') no-repeat center`,
1619-
}
1620-
: {}
1621-
}
1622-
/>
1623-
)}
1603+
{prevSrc &&
1604+
(this.props.directionalButtonComponent ? (
1605+
<this.props.directionalButtonComponent
1606+
onClickHandler={
1607+
!this.isAnimating() ? this.requestMovePrev : undefined
1608+
}
1609+
direction="left"
1610+
ariaLabel={this.props.prevLabel}
1611+
{...this.props.directionalButtonComponentProps}
1612+
/>
1613+
) : (
1614+
<button // Move to previous image button
1615+
type="button"
1616+
className={`ril__thumbNails ril__navButtonsThumbs${
1617+
this.props.thumbnailArrowLeft
1618+
? ''
1619+
: 'ril__navButtonPrev'
1620+
}`}
1621+
key="prev"
1622+
aria-label={this.props.prevLabel}
1623+
title={this.props.prevLabel}
1624+
onClick={
1625+
!this.isAnimating() ? this.requestMovePrev : undefined
1626+
} // Ignore clicks during animation
1627+
style={
1628+
this.props.thumbnailArrowLeft
1629+
? {
1630+
background: `url('${this.props.thumbnailArrowLeft}') no-repeat center`,
1631+
}
1632+
: {}
1633+
}
1634+
/>
1635+
))}
16241636
{this.props.thumbnailImages.map((img, index) => (
16251637
<img
16261638
className={`thumbNails${
@@ -1642,27 +1654,39 @@ class ReactImageLightbox extends Component {
16421654
/>
16431655
))}
16441656

1645-
{nextSrc && (
1646-
<button // Move to next image button
1647-
type="button"
1648-
className={`ril__thumbNails ril__navButtonsThumbs${
1649-
this.props.thumbnailArrowRight ? '' : 'ril__navButtonNext'
1650-
}`}
1651-
key="next"
1652-
aria-label={this.props.nextLabel}
1653-
title={this.props.nextLabel}
1654-
onClick={
1655-
!this.isAnimating() ? this.requestMoveNext : undefined
1656-
} // Ignore clicks during animation
1657-
style={
1658-
this.props.thumbnailArrowRight
1659-
? {
1660-
background: `url('${this.props.thumbnailArrowRight}') no-repeat center`,
1661-
}
1662-
: {}
1663-
}
1664-
/>
1665-
)}
1657+
{nextSrc &&
1658+
(this.props.directionalButtonComponent ? (
1659+
<this.props.directionalButtonComponent
1660+
onClickHandler={
1661+
!this.isAnimating() ? this.requestMoveNext : undefined
1662+
}
1663+
direction="right"
1664+
ariaLabel={this.props.nextLabel}
1665+
{...this.props.directionalButtonComponentProps}
1666+
/>
1667+
) : (
1668+
<button // Move to next image button
1669+
type="button"
1670+
className={`ril__thumbNails ril__navButtonsThumbs${
1671+
this.props.thumbnailArrowRight
1672+
? ''
1673+
: 'ril__navButtonNext'
1674+
}`}
1675+
key="next"
1676+
aria-label={this.props.nextLabel}
1677+
title={this.props.nextLabel}
1678+
onClick={
1679+
!this.isAnimating() ? this.requestMoveNext : undefined
1680+
} // Ignore clicks during animation
1681+
style={
1682+
this.props.thumbnailArrowRight
1683+
? {
1684+
background: `url('${this.props.thumbnailArrowRight}') no-repeat center`,
1685+
}
1686+
: {}
1687+
}
1688+
/>
1689+
))}
16661690
</div>
16671691
</div>
16681692
)}
@@ -1825,6 +1849,10 @@ ReactImageLightbox.propTypes = {
18251849
closeButtonComponent: PropTypes.element,
18261850
closeButtonComponentProps: PropTypes.shape({}),
18271851

1852+
// custom directional button component
1853+
directionalButtonComponent: PropTypes.element,
1854+
directionalButtonComponentProps: PropTypes.shape({}),
1855+
18281856
// image header component
18291857
imageHeaderComponent: PropTypes.element,
18301858

@@ -1877,6 +1905,8 @@ ReactImageLightbox.defaultProps = {
18771905
thumbnailImages: [],
18781906
closeButtonComponent: null,
18791907
closeButtonComponentProps: {},
1908+
directionalButtonComponent: null,
1909+
directionalButtonComponentProps: {},
18801910
imageHeaderComponent: null,
18811911
maxHeightOffset: 0,
18821912
maxWidthOffset: 0,

0 commit comments

Comments
 (0)