Skip to content

Commit

Permalink
Merge pull request #112 from branislavblazek/canSwipe_attr
Browse files Browse the repository at this point in the history
canSwipe attr support + docs
  • Loading branch information
femioladeji authored Nov 23, 2020
2 parents 167482b + 83db5d0 commit 0843123
Show file tree
Hide file tree
Showing 7 changed files with 257 additions and 109 deletions.
46 changes: 24 additions & 22 deletions docs/App.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
import React, { useState } from "react";
import { BrowserRouter, Route, Switch } from "react-router-dom";
import Navbar from "./views/components/NavBar";
import Sidebar from "./views/components/SideBar";
import ExamplesPage from "./views/pages/ExamplesPage";
import LandingPage from "./views/pages/LandingPage";
import ApiPage from "./views/pages/ApiPage";
import ForTypescript from "./views/pages/ForTypescript";
import SlideExample from "./views/pages//Examples/Slide";
import FadeExample from "./views/pages//Examples/Fade";
import ZoomExample from "./views/pages//Examples/Zoom";
import ZoomOutExample from "./views/pages//Examples/ZoomOut";
import CustomArrow from "./views/pages//Examples/CustomArrow";
import CustomIndicator from "./views/pages//Examples/CustomIndicator";
import PauseHover from "./views/pages//Examples/PauseHover";
import Autoplay from "./views/pages//Examples/Autoplay";
import Methods from "./views/pages//Examples/Methods";
import Callback from "./views/pages//Examples/Callback";
import Next from "./views/pages/Next";
import "./views/styles.css";
import "./app.css";
import React, { useState } from 'react';
import { BrowserRouter, Route, Switch } from 'react-router-dom';
import Navbar from './views/components/NavBar';
import Sidebar from './views/components/SideBar';
import ExamplesPage from './views/pages/ExamplesPage';
import LandingPage from './views/pages/LandingPage';
import ApiPage from './views/pages/ApiPage';
import ForTypescript from './views/pages/ForTypescript';
import SlideExample from './views/pages//Examples/Slide';
import FadeExample from './views/pages//Examples/Fade';
import ZoomExample from './views/pages//Examples/Zoom';
import ZoomOutExample from './views/pages//Examples/ZoomOut';
import CustomArrow from './views/pages//Examples/CustomArrow';
import CustomIndicator from './views/pages//Examples/CustomIndicator';
import PauseHover from './views/pages//Examples/PauseHover';
import CanSwipe from './views/pages//Examples/CanSwipe';
import Autoplay from './views/pages//Examples/Autoplay';
import Methods from './views/pages//Examples/Methods';
import Callback from './views/pages//Examples/Callback';
import Next from './views/pages/Next';
import './views/styles.css';
import './app.css';

// package css
import "../src/css/styles.css";
import '../src/css/styles.css';

const App = () => {
const [sidebar, setSidebar] = useState(true);
Expand Down Expand Up @@ -53,6 +54,7 @@ const App = () => {
<Route exact path="/custom-arrows" component={CustomArrow} />
<Route exact path="/custom-indicators" component={CustomIndicator} />
<Route exact path="/pause-hover" component={PauseHover} />
<Route exact path="/can-swipe" component={CanSwipe} />
<Route exact path="/autoplay" component={Autoplay} />
<Route exact path="/methods" component={Methods} />
<Route exact path="/callback" component={Callback} />
Expand Down
56 changes: 52 additions & 4 deletions docs/views/codeStrings.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ const Slideshow = () => {
'images/slide_3.jpg',
'images/slide_4.jpg'
];
const zoomInProperties = {
indicators: true,
scale: 1.4
Expand Down Expand Up @@ -207,7 +207,7 @@ const Slideshow = () => {
'images/slide_3.jpg',
'images/slide_4.jpg'
];
const zoomOutProperties = {
indicators: true,
scale: 0.4
Expand Down Expand Up @@ -355,7 +355,7 @@ const Slideshow = () => {
'images/slide_3.jpg',
'images/slide_4.jpg'
];
const zoomOutProperties = {
indicators: true,
scale: 0.4,
Expand Down Expand Up @@ -396,7 +396,7 @@ const PauseHoverExample = () => {
"assets/images/slide_6.jpg",
"assets/images/slide_7.jpg"
];
const fadeProperties = {
duration: 3000,
pauseOnHover: true
Expand Down Expand Up @@ -434,6 +434,54 @@ const PauseHoverExample = () => {
export default PauseHoverExample;
`;

export const canSwipe = `
import React from 'react';
import { Slide } from 'react-slideshow-image';
const canSwipeExample = () => {
const images = [
"assets/images/slide_5.jpg",
"assets/images/slide_6.jpg",
"assets/images/slide_7.jpg"
];
const fadeProperties = {
duration: 3000,
canSwipe: false,
};
return (
<div>
<h2>Fade Effect</h2>
<div className="slide-container">
<Slide {...fadeProperties}>
<div className="each-fade">
<div>
<img src={fadeImages[0]} />
</div>
<p>First Slide</p>
</div>
<div className="each-fade">
<p>Second Slide</p>
<div>
<img src={fadeImages[1]} />
</div>
</div>
<div className="each-fade">
<div>
<img src={fadeImages[2]} />
</div>
<p>Third Slide</p>
</div>
</Slide>
</div>
</div>
);
};
export default CanSwipeExample;
`;

export const autoplayCode = `
import React, { useState } from "react";
import { Slide } from "react-slideshow-image";
Expand Down
11 changes: 7 additions & 4 deletions docs/views/components/SideBar.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React, { useState } from "react";
import { NavLink } from "react-router-dom";
import React, { useState } from 'react';
import { NavLink } from 'react-router-dom';

const Sidebar = ({ isOpen }) => {
const [dropDowns, setDropDowns] = useState(false);

const setMargin = isOpen ? "0" : "-60%";
const setMargin = isOpen ? '0' : '-60%';

return (
<div className="sidebar" style={{ marginLeft: setMargin }}>
Expand Down Expand Up @@ -35,6 +35,9 @@ const Sidebar = ({ isOpen }) => {
<NavLink activeClassName="is-active" to="/pause-hover">
Pause on hover
</NavLink>
<NavLink activeClassName="is-active" to="/can-swipe">
Can swipe
</NavLink>
<NavLink activeClassName="is-active" to="/autoplay">
Autoplay toggle
</NavLink>
Expand All @@ -46,7 +49,7 @@ const Sidebar = ({ isOpen }) => {
</NavLink>
</div>
) : (
""
''
)}
<NavLink activeClassName="is-active" to="/api">
Props &amp; Methods
Expand Down
13 changes: 11 additions & 2 deletions docs/views/pages/ApiPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,15 @@ const Api = () => {
hovers the slider
</td>
</tr>
<tr>
<td>canSwipe</td>
<td>boolean</td>
<td>true</td>
<td>
Determines whether the user can go to next or previous slide by
the mouse or by touching
</td>
</tr>
<tr>
<td>onChange</td>
<td>function</td>
Expand All @@ -114,8 +123,8 @@ const Api = () => {
<td>string</td>
<td>linear</td>
<td>
The timing transition function to use. You can use one of linear,
ease, ease-in, ease-out, cubic, cubic-in, cubic-out
The timing transition function to use. You can use one of
linear, ease, ease-in, ease-out, cubic, cubic-in, cubic-out
</td>
</tr>
</tbody>
Expand Down
61 changes: 61 additions & 0 deletions docs/views/pages/Examples/CanSwipe.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import React from 'react';
import SyntaxHighlighter from 'react-syntax-highlighter';
import { dark } from 'react-syntax-highlighter/dist/esm/styles/hljs';
import { Slide } from '../../../../src';
import { canSwipe, fadeEffectCSS } from '../../codeStrings';

const CanSwipeExample = () => {
const fadeImages = [
'assets/images/slide_5.jpg',
'assets/images/slide_6.jpg',
'assets/images/slide_7.jpg'
];

const fadeProperties = {
duration: 3000,
canSwipe: false
};

return (
<div>
<h2>Can swipe or not</h2>
<p>
User can't swipe manually slides by mouse or by touching when this is
set to false
</p>
<SyntaxHighlighter language="react" style={dark}>
{canSwipe}
</SyntaxHighlighter>
<br />
<div>
<Slide {...fadeProperties}>
<div className="each-fade">
<div>
<img src={fadeImages[0]} />
</div>
<p>First slide</p>
</div>
<div className="each-fade">
<p>Second Slide</p>
<div>
<img src={fadeImages[1]} />
</div>
</div>
<div className="each-fade">
<div>
<img src={fadeImages[2]} />
</div>
<p>Third Slide</p>
</div>
</Slide>
</div>
<br />
Here is the css used to accomplish this layout.
<SyntaxHighlighter language="react" style={dark}>
{fadeEffectCSS}
</SyntaxHighlighter>
</div>
);
};

export default CanSwipeExample;
104 changes: 53 additions & 51 deletions src/props.js
Original file line number Diff line number Diff line change
@@ -1,54 +1,56 @@
const defaultProps = {
duration: 5000,
transitionDuration: 1000,
defaultIndex: 0,
infinite: true,
autoplay: true,
indicators: false,
arrows: true,
pauseOnHover: true,
scale: 1,
easing: 'linear'
};

export const getProps = componentProps => ({
...defaultProps,
...componentProps
});

export const propTypes = {
duration: 'number',
transitionDuration: 'number',
defaultIndex: 'number',
infinite: 'boolean',
indicators: ['boolean', 'function'],
autoplay: 'boolean',
arrows: 'boolean',
onChange: 'function',
pauseOnHover: 'boolean',
prevArrow: ['object', 'function'],
nextArrow: ['object', 'function'],
scale: 'number',
easing: 'string'
};

export const validatePropTypes = props => {
for (const key in props) {
const propValueType = typeof props[key];
if (propTypes[key]) {
if (
Array.isArray(propTypes[key]) &&
!propTypes[key].includes(propValueType)
) {
console.warn(
`${key} must be of one of type ${propTypes[key].join(', ')}`
);
} else if (
!Array.isArray(propTypes[key]) &&
propValueType !== propTypes[key]
) {
console.warn(`${key} must be of type ${propTypes[key]}`);
}
duration: 5000,
transitionDuration: 1000,
defaultIndex: 0,
infinite: true,
autoplay: true,
indicators: false,
arrows: true,
pauseOnHover: true,
scale: 1,
easing: 'linear',
canSwipe: true
};

export const getProps = componentProps => ({
...defaultProps,
...componentProps
});

export const propTypes = {
duration: 'number',
transitionDuration: 'number',
defaultIndex: 'number',
infinite: 'boolean',
indicators: ['boolean', 'function'],
autoplay: 'boolean',
arrows: 'boolean',
onChange: 'function',
pauseOnHover: 'boolean',
prevArrow: ['object', 'function'],
nextArrow: ['object', 'function'],
scale: 'number',
easing: 'string',
canSwipe: 'boolean'
};

export const validatePropTypes = props => {
for (const key in props) {
const propValueType = typeof props[key];
if (propTypes[key]) {
if (
Array.isArray(propTypes[key]) &&
!propTypes[key].includes(propValueType)
) {
console.warn(
`${key} must be of one of type ${propTypes[key].join(', ')}`
);
} else if (
!Array.isArray(propTypes[key]) &&
propValueType !== propTypes[key]
) {
console.warn(`${key} must be of type ${propTypes[key]}`);
}
}
};
}
};
Loading

0 comments on commit 0843123

Please sign in to comment.