Skip to content
Permalink
Browse files

testing npm, base transformer

  • Loading branch information...
piotrzdziarski committed Feb 15, 2019
1 parent 523614a commit 8037485df5b4d2ce97bdc927f6217464329fba04
@@ -6,4 +6,7 @@
/dist
/.babelrc
/webpack-prod.config.js
/webpack.config.js
/webpack.config.js
/src
/index.html
/setupTests.js
21 LICENSE
@@ -0,0 +1,21 @@
## The MIT License (MIT) ##

Copyright (c) 2019 Piotr Zdziarski

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
@@ -1,5 +1,5 @@
# React Fullscreen Lightbox Basic
## Version - 0.0.4 - In Development
## Version - 0.0.7 - In Development
## Description
In developmet - React version of Fullscreen Lightbox.

@@ -1,7 +1,7 @@
import React, { Component } from 'react';
import FsLightbox from "../src/FsLightbox.js";
import "./css/demo.css";
import { testImageURL, testVideoURL, testYoutubeURL } from "../tests/schemas/testVariables";
import FsLightbox from "../src";

class DemoComponent extends Component {

@@ -11,6 +11,7 @@ class DemoComponent extends Component {
this.state = {
isOpen: true,
};
this.slide = 1;
this.videosPosters = [];
this.videosPosters[0] = '../demo/images/1.jpeg';
this.toggleLightbox = this.toggleLightbox.bind(this);
@@ -22,7 +23,6 @@ class DemoComponent extends Component {
})
}


render() {
return (
<>
@@ -35,9 +35,11 @@ class DemoComponent extends Component {
<FsLightbox
isOpen={ this.state.isOpen }
urls={ [
testImageURL,
testVideoURL,
testImageURL
] }
slide={ 1 }
slide={ this.slide }
videosPosters={[
testImageURL
]}
@@ -1 +1,9 @@
<!doctype html> <html lang=en> <head> <meta charset=utf-8> <title>React Fullscreen Lightbox Basic</title></head> <body> <div id=app></div> <script type="text/javascript" src="./main.js"></script></body> </html>
<!doctype html>
<html lang=en>
<head>
<meta charset=utf-8>
<title>React Fullscreen Lightbox Basic</title></head>
<body>
<div id=app></div>
</body>
</html>
2,046 main.js

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more.

@@ -1,6 +1,6 @@
{
"name": "fslightbox-react",
"version": "0.0.4",
"version": "0.0.7",
"description": "React version of Fullscreen Lightbox",
"main": "main.js",
"scripts": {
@@ -64,6 +64,8 @@
"isomorphic-fetch": "^2.2.1",
"jest": "^24.1.0",
"style-loader": "^0.23.1",
"terser-webpack-plugin": "^1.2.2",
"uglifyjs-webpack-plugin": "^2.1.1",
"webpack": "^4.29.1",
"webpack-cli": "^3.2.3",
"webpack-dev-server": "^3.1.14"
@@ -2,7 +2,7 @@ import React, { Component } from 'react';
import PropTypes from 'prop-types';
import Nav from "./components/nav/Nav.jsx";
import "./css/fslightboxBasic.css";
import CloseOpenLightbox from "./core/CloseOpenLightbox";
import CloseOpenLightbox from "./core/CloseOpenLightbox";
import SlideButtonLeft from "./components/slideButtons/SlideButtonLeft.jsx";
import SlideButtonRight from "./components/slideButtons/SlideButtonRight.jsx";
import MediaHolder from "./components/holders/MediaHolder.jsx";
@@ -43,14 +43,11 @@ class FsLightbox extends Component {
this.maxSourceWidth = 0;
this.maxSourceHeight = 0;
this.sourceDimensions = [];


}

setStates() {
this.state = {
isOpen: this.props.isOpen,
slide: (this.props.slide) ? this.props.slide : 1,
};
}

@@ -103,7 +100,10 @@ class FsLightbox extends Component {
if (!this.state.isOpen) return null;
return (
<div ref={ this.elements.container } className="fslightbox-container">
<Nav closeLightbox={ this.closeOpenLightbox.closeLightbox }/>
<Nav
slide={ this.slide }
totalSlides={ this.totalSlides }
closeLightbox={ this.closeOpenLightbox.closeLightbox }/>
<SlideButtonLeft/>
<SlideButtonRight/>
<MediaHolder _={ this }/>
@@ -8,13 +8,18 @@ class Nav extends Component {
return (
<div className="fslightbox-nav">
<Toolbar closeLightbox={ this.props.closeLightbox }/>
<SlideNumber/>
<SlideNumber
slide={ this.props.slide }
totalSlides={ this.props.totalSlides }
/>
</div>
);
}
}

Nav.propTypes = {
slide: PropTypes.number,
totalSlides: PropTypes.number,
closeLightbox: PropTypes.func
};
export default Nav;
@@ -1,15 +1,20 @@
import React, { Component } from 'react';
import PropTypes from 'prop-types';

class SlideNumber extends Component {
render() {
return (
<div className="fslightbox-slide-number-container">
<div className="fslightbox-slide-number">1</div>
<div className="fslightbox-slide-number">{ this.props.slide }</div>
<div className="fslightbox-slide-number fslightbox-slash">/</div>
<div className="fslightbox-slide-number">4</div>
<div className="fslightbox-slide-number">{ this.props.totalSlides }</div>
</div>
);
}
}

SlideNumber.propTypes = {
slide: PropTypes.number,
totalSlides: PropTypes.number,
};
export default SlideNumber;
@@ -28,7 +28,7 @@ class Source extends Component {
}

sourceWasCreated() {
// after that refresh source stored in sourcesJSXComponents is attached
// after that refresh source stored in sourcesJSXComponents is attached so we can access refs
this.forceUpdate();
this.props._.sourceComponentsCreators[this.props.i].createSourceTransformer();
}
@@ -53,8 +53,8 @@ class Source extends Component {

onSourceLoad() {
this.props._.elements.sources[this.props.i].current.classList.add('fslightbox-fade-in-class');
this.props._.sourceSizeAdjusters[this.props.i].updateSource();
this.props._.sourceSizeAdjusters[this.props.i].adjustSourceSize();
this.props._.sourceTransformers[this.props.i].transform();
}


@@ -1,5 +1,13 @@
export const CONTAINER_FADE_OUT_TIME = 250;

//sources types
export const IMAGE_TYPE = 'image';
export const VIDEO_TYPE = 'video';
export const YOUTUBE_TYPE = 'youtube';
export const INVALID_TYPE = 'invalid';

// stage sources order types
export const PREVIOUS_POSITION = -1;
export const CURRENT_POSITION = 0;
export const NEXT_POSITION = 1;
export const NOT_IN_STAGE = null;
@@ -4,7 +4,6 @@ export class SourceSizeAdjuster {
*/
constructor(_) {
this._ = _;
this.element = null;
this.i = null;
this.sourceWidth = 0;
this.sourceHeight = 0;
@@ -19,10 +18,6 @@ export class SourceSizeAdjuster {
this.ratio = this.sourceWidth / this.sourceHeight;
}

updateSource() {
this.element = this._.elements.sources[this.i].current;
}

adjustSourceSize() {
this.newHeight = this._.maxSourceWidth / this.ratio;

@@ -46,7 +41,7 @@ export class SourceSizeAdjuster {
}

setDimensions() {
this.element.style.height = this.newHeight + "px";
this.element.style.width = (this.newHeight * this.ratio) + "px";
this._.elements.sources[this.i].current.style.height = this.newHeight + "px";
this._.elements.sources[this.i].current.style.width = (this.newHeight * this.ratio) + "px";
}
}
@@ -1,10 +1,53 @@
import { CURRENT_POSITION, NEXT_POSITION, PREVIOUS_POSITION } from "../../constants/CoreConstants";

export class SourceTransformer {
/**
* @param _ {FsLightbox}
*/
constructor(_) {
this._ = _;
this.i = null;
this.source = null;
}

setIndex(index) {
this.i = index;
}

transform() {
this.getSourceStagePosition();
}

getSourceStagePosition() {
switch (this.i - this._.slide) {
case PREVIOUS_POSITION:
this.transformNegative();
break;
case CURRENT_POSITION:
this.transformZero();
break;
case NEXT_POSITION:
this.transformPositive();
break;
default:
this.notInStage();
}
}

notInStage() {

}


transformNegative() {
this._.elements.sources[this.i].current.style.transform = 'translate(' + -this._.slideDistance * window.innerWidth + 'px,0)';
}

transformZero() {
this._.elements.sources[this.i].current.style.transform = 'translate(0,0)';
}

transformPositive() {
this._.elements.sources[this.i].current.style.transform = 'translate(' + this._.slideDistance * window.innerWidth + 'px,0)';
}
}
@@ -1,3 +1,3 @@
import FsLightbox from "./FsLightbox";
import FsLightbox from './FsLightbox';

export default FsLightbox;
@@ -0,0 +1,3 @@
export const getStagePosition = () => {

};

This file was deleted.

0 comments on commit 8037485

Please sign in to comment.
You can’t perform that action at this time.