Skip to content

Commit

Permalink
Add Lightbox feature to gallery
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Raible committed Jun 25, 2018
1 parent b4e894a commit 47f9cea
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 6 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"react-addons-transition-group": "16.0.0-alpha.3",
"react-dom": "16.3.0",
"react-hot-loader": "3.1.1",
"react-images": "0.5.17",
"react-jhipster": "0.5.2",
"react-photo-gallery": "6.0.28",
"react-redux": "5.0.7",
Expand Down
54 changes: 51 additions & 3 deletions src/main/webapp/app/entities/photo/photo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,30 @@ import { IPhoto } from 'app/shared/model/photo.model';
import { APP_DATE_FORMAT, APP_LOCAL_DATE_FORMAT } from 'app/config/constants';
import { ITEMS_PER_PAGE } from 'app/shared/util/pagination.constants';
import Gallery from 'react-photo-gallery';
import Lightbox from 'react-images';

export interface IPhotoProps extends StateProps, DispatchProps, RouteComponentProps<{ url: string }> {}

export type IPhotoState = IPaginationBaseState;
export interface IPhotoState extends IPaginationBaseState {
currentImage: number;
lightboxIsOpen: boolean;
}

export class Photo extends React.Component<IPhotoProps, IPhotoState> {
state: IPhotoState = {
...getSortState(this.props.location, ITEMS_PER_PAGE)
...getSortState(this.props.location, ITEMS_PER_PAGE),
currentImage: 0,
lightboxIsOpen: false
};

constructor(props) {
super(props);
this.closeLightbox = this.closeLightbox.bind(this);
this.openLightbox = this.openLightbox.bind(this);
this.gotoNext = this.gotoNext.bind(this);
this.gotoPrevious = this.gotoPrevious.bind(this);
}

componentDidMount() {
this.reset();
}
Expand Down Expand Up @@ -52,6 +66,32 @@ export class Photo extends React.Component<IPhotoProps, IPhotoState> {
this.props.getEntities(activePage - 1, itemsPerPage, `${sort},${order}`);
};

openLightbox(event, obj) {
this.setState({
currentImage: obj.index,
lightboxIsOpen: true
});
}

closeLightbox() {
this.setState({
currentImage: 0,
lightboxIsOpen: false
});
}

gotoPrevious() {
this.setState({
currentImage: this.state.currentImage - 1
});
}

gotoNext() {
this.setState({
currentImage: this.state.currentImage + 1
});
}

render() {
const { photoList, match } = this.props;
const photoSet = photoList.map(photo => ({
Expand All @@ -69,7 +109,15 @@ export class Photo extends React.Component<IPhotoProps, IPhotoState> {
<Translate contentKey="galleryApp.photo.home.createLabel">Create new Photo</Translate>
</Link>
</h2>
<Gallery photos={photoSet} />
<Gallery photos={photoSet} onClick={this.openLightbox} />
<Lightbox
images={photoSet}
onClose={this.closeLightbox}
onClickPrev={this.gotoPrevious}
onClickNext={this.gotoNext}
currentImage={this.state.currentImage}
isOpen={this.state.lightboxIsOpen}
/>
<div className="table-responsive">
<InfiniteScroll
pageStart={this.state.activePage}
Expand Down
54 changes: 51 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,13 @@ anymatch@^2.0.0:
micromatch "^3.1.4"
normalize-path "^2.1.1"

aphrodite@^0.5.0:
version "0.5.0"
resolved "https://registry.yarnpkg.com/aphrodite/-/aphrodite-0.5.0.tgz#a4b9a8902662395d2702e70ac7a2b4ca66f25703"
dependencies:
asap "^2.0.3"
inline-style-prefixer "^2.0.0"

app-root-path@^2.0.1:
version "2.1.0"
resolved "https://registry.yarnpkg.com/app-root-path/-/app-root-path-2.1.0.tgz#98bf6599327ecea199309866e8140368fd2e646a"
Expand Down Expand Up @@ -414,7 +421,7 @@ arrify@^1.0.0, arrify@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/arrify/-/arrify-1.0.1.tgz#898508da2226f380df904728456849c1501a4b0d"

asap@~2.0.3:
asap@^2.0.3, asap@~2.0.3:
version "2.0.6"
resolved "https://registry.yarnpkg.com/asap/-/asap-2.0.6.tgz#e50347611d7e690943208bbdafebcbc2fb866d46"

Expand Down Expand Up @@ -1345,7 +1352,7 @@ bootstrap@4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/bootstrap/-/bootstrap-4.0.0.tgz#ceb03842c145fcc1b9b4e15da2a05656ba68469a"

bowser@^1.7.3:
bowser@^1.0.0, bowser@^1.7.3:
version "1.9.3"
resolved "https://registry.yarnpkg.com/bowser/-/bowser-1.9.3.tgz#6643ae4d783f31683f6d23156976b74183862162"

Expand Down Expand Up @@ -3428,6 +3435,10 @@ executable@^1.0.0:
dependencies:
meow "^3.1.0"

exenv@^1.2.2:
version "1.2.2"
resolved "https://registry.yarnpkg.com/exenv/-/exenv-1.2.2.tgz#2ae78e85d9894158670b03d47bec1f03bd91bb9d"

exit-hook@^1.0.0:
version "1.1.1"
resolved "https://registry.yarnpkg.com/exit-hook/-/exit-hook-1.1.1.tgz#f05ca233b48c05d54fff07765df8507e95c02ff8"
Expand Down Expand Up @@ -4713,7 +4724,7 @@ husky@0.14.3:
normalize-path "^1.0.0"
strip-indent "^2.0.0"

hyphenate-style-name@^1.0.2:
hyphenate-style-name@^1.0.1, hyphenate-style-name@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/hyphenate-style-name/-/hyphenate-style-name-1.0.2.tgz#31160a36930adaf1fc04c6074f7eb41465d4ec4b"

Expand Down Expand Up @@ -4887,6 +4898,13 @@ ini@^1.3.4, ini@~1.3.0:
version "1.3.5"
resolved "https://registry.yarnpkg.com/ini/-/ini-1.3.5.tgz#eee25f56db1c9ec6085e0c22778083f596abf927"

inline-style-prefixer@^2.0.0:
version "2.0.5"
resolved "https://registry.yarnpkg.com/inline-style-prefixer/-/inline-style-prefixer-2.0.5.tgz#c153c7e88fd84fef5c602e95a8168b2770671fe7"
dependencies:
bowser "^1.0.0"
hyphenate-style-name "^1.0.1"

inline-style-prefixer@^3.0.6:
version "3.0.8"
resolved "https://registry.yarnpkg.com/inline-style-prefixer/-/inline-style-prefixer-3.0.8.tgz#8551b8e5b4d573244e66a34b04f7d32076a2b534"
Expand Down Expand Up @@ -8224,6 +8242,15 @@ react-hot-loader@3.1.1:
redbox-react "^1.3.6"
source-map "^0.6.1"

react-images@0.5.17:
version "0.5.17"
resolved "https://registry.yarnpkg.com/react-images/-/react-images-0.5.17.tgz#6f76fd03b370176bead7d22cec06afe82fe1cec0"
dependencies:
aphrodite "^0.5.0"
prop-types "^15.6.0"
react-scrolllock "^2.0.1"
react-transition-group "^1.1.3"

react-infinite-scroller@1.1.3:
version "1.1.3"
resolved "https://registry.yarnpkg.com/react-infinite-scroller/-/react-infinite-scroller-1.1.3.tgz#c4230024bc237ce876c76b2e38d77dc1f6aabb26"
Expand Down Expand Up @@ -8263,6 +8290,10 @@ react-popper@^0.8.3:
popper.js "^1.12.9"
prop-types "^15.6.0"

react-prop-toggle@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/react-prop-toggle/-/react-prop-toggle-1.0.2.tgz#8b0b7e74653606b1427cfcf6c4eaa9198330568e"

react-proxy@^3.0.0-alpha.0:
version "3.0.0-alpha.1"
resolved "https://registry.yarnpkg.com/react-proxy/-/react-proxy-3.0.0-alpha.1.tgz#4400426bcfa80caa6724c7755695315209fa4b07"
Expand Down Expand Up @@ -8322,6 +8353,13 @@ react-router@^4.2.0:
prop-types "^15.6.1"
warning "^4.0.1"

react-scrolllock@^2.0.1:
version "2.0.7"
resolved "https://registry.yarnpkg.com/react-scrolllock/-/react-scrolllock-2.0.7.tgz#3b879e1fe308fc900ab76e226e9be594c41226fd"
dependencies:
exenv "^1.2.2"
react-prop-toggle "^1.0.2"

react-test-renderer@^16.0.0-0:
version "16.4.1"
resolved "https://registry.yarnpkg.com/react-test-renderer/-/react-test-renderer-16.4.1.tgz#f2fb30c2c7b517db6e5b10ed20bb6b0a7ccd8d70"
Expand Down Expand Up @@ -8349,6 +8387,16 @@ react-transition-group@2.3.0:
prop-types "^15.5.8"
warning "^3.0.0"

react-transition-group@^1.1.3:
version "1.2.1"
resolved "https://registry.yarnpkg.com/react-transition-group/-/react-transition-group-1.2.1.tgz#e11f72b257f921b213229a774df46612346c7ca6"
dependencies:
chain-function "^1.0.0"
dom-helpers "^3.2.0"
loose-envify "^1.3.1"
prop-types "^15.5.6"
warning "^3.0.0"

react-transition-group@^2.2.1:
version "2.3.1"
resolved "https://registry.yarnpkg.com/react-transition-group/-/react-transition-group-2.3.1.tgz#31d611b33e143a5e0f2d94c348e026a0f3b474b6"
Expand Down

0 comments on commit 47f9cea

Please sign in to comment.