Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/npm_and_yarn/url-parse-1.5.1
Browse files Browse the repository at this point in the history
  • Loading branch information
hartzis committed May 13, 2021
2 parents e2072dc + 29d03df commit b397712
Show file tree
Hide file tree
Showing 20 changed files with 4,710 additions and 65 deletions.
48 changes: 44 additions & 4 deletions CONTRIBUTING.md
Expand Up @@ -25,7 +25,14 @@ Make changes/updates to the `src/index.ts` file.
### Verify updates with the examples

Build, run, and test examples locally:
`yarn run start:examples`
```sh
# Go into examples folder
react-swipeable$ cd examples
# Yarn install
react-swipeable/examples$ yarn
# Run the start:dev:local command
react-swipeable/examples$ yarn start:dev:local
```

Then open a browser tab to `http://localhost:8080/`.

Expand Down Expand Up @@ -72,10 +79,12 @@ $ yarn run prettier
$ yarn run format
```

## Releasing a new version to NPM

_Only for project administrators_
## Project Maintainers
### Releasing a new version
1. Publish to npm
2. Update version in `examples`

#### 1. Publish to npm
```sh
# (1) Runs tests, lint, build published dir, updates package.json
$ npm version [patch|minor|major|<version>]
Expand All @@ -86,3 +95,34 @@ $ npm publish
# (3) Then, update github and push new associated tag
$ git push --follow-tags
```

#### 2. Update version in the examples

After publishing a new version to npm we need to make sure the `examples` get updated.
1. Bump the `react-swipeable` version in `examples/package.json` to the new just released version
2. Run `yarn` to install and update the lock file
3. Push changes to `main` branch so the codesandbox examples get updated
4. Build and deploy updated examples to github pages

### Building and deploying examples to github pages

The examples build using the most recent version of `react-swipeable`.

Make sure you've already completed the above steps for `Update version in the examples` so the `examples` have the most recent version installed.

(Optional) Validate examples build locally
```sh
# From root run build:examples
$ yarn build:examples

# cd into examples and start simple http server(python v3)
# validate everything works locally: http://localhost:8080/
$ cd examples
examples$ python -m http.server 8080
```

```sh
# From the root run build:publish:examples
# This will build and publish the examples app to github pages
$ yarn build:publish:examples
```
7 changes: 5 additions & 2 deletions README.md
Expand Up @@ -4,9 +4,9 @@ React swipe event handler hook

[![build status](https://img.shields.io/travis/FormidableLabs/react-swipeable/master.svg?style=flat-square)](https://travis-ci.org/FormidableLabs/react-swipeable) [![Coverage Status](https://img.shields.io/coveralls/FormidableLabs/react-swipeable/master.svg?style=flat-square)](https://coveralls.io/github/FormidableLabs/react-swipeable?branch=master) [![npm version](https://img.shields.io/npm/v/react-swipeable.svg?style=flat-square)](https://www.npmjs.com/package/react-swipeable) [![npm downloads](https://img.shields.io/npm/dm/react-swipeable.svg?style=flat-square)](https://www.npmjs.com/package/react-swipeable) [![gzip size](https://flat.badgen.net/bundlephobia/minzip/react-swipeable)](https://bundlephobia.com/result?p=react-swipeable)

[![Edit react-swipeable image carousel](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/react-swipeable-image-carousel-hben8?file=/src/Carousel.js)
[![Edit react-swipeable image carousel](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/github/FormidableLabs/react-swipeable/tree/main/examples?file=/app/SimpleCarousel/Carousel.tsx)

[Github Pages Demo](http://formidablelabs.github.io/react-swipeable/)
### [Github Pages Demo](http://formidablelabs.github.io/react-swipeable/)

### Api

Expand Down Expand Up @@ -183,6 +183,9 @@ This explanation and example borrowed from `use-gesture`'s [wonderful docs](http
Please see our [contributions guide](./CONTRIBUTING.md).
### Maintainers
[Project Maintenance](./CONTRIBUTING.md#project-maintainers)
## Maintenance Status
**Active:** Formidable is actively working on this project, and we expect to continue for work for the foreseeable future. Bug reports, feature requests and pull requests are welcome.
4 changes: 3 additions & 1 deletion examples/README.md
Expand Up @@ -3,4 +3,6 @@ react-swipeable examples

This is the code that generates the example app - http://stack.formidable.com/react-swipeable/.

Please look at the steps in the [main readme](https://github.com/FormidableLabs/react-swipeable#development), up one directory.
You can play with the examples on [codesandbox](https://codesandbox.io/s/github/FormidableLabs/react-swipeable/tree/main/examples).

Or you can run `yarn && yarn start` inside of this folder to run the examples locally.
54 changes: 29 additions & 25 deletions examples/app/App.tsx
@@ -1,42 +1,46 @@
import * as React from 'react';
// @ts-ignore
import ScrollUp from 'react-scroll-up';
import FeatureTestConsole from './FeatureTestConsole';

const scrollUpArrowStyles = { fontSize: '20px', border: '2px solid black', borderRadius: '50%', padding: '10px', background: 'white' };
import SimpleCarousel from './SimpleCarousel';
import SimplePattern from './SimplePattern';
import { Paper } from './components';

export default function App({version}: {version: any}) {
return (
<div className="row">
<ScrollUp showUnder={20}
easing={'easeOutCubic'}
duration={500}>
<span style={scrollUpArrowStyles}></span>
</ScrollUp>
<div className="medium-6 column" style={{width: "95%"}}>
<h1>react-swipeable&nbsp;<a href="https://github.com/FormidableLabs/react-swipeable" style={{fontSize: "0.75rem"}}>v{version}</a></h1>
<h1>
react-swipeable&nbsp;
<a
href="https://github.com/FormidableLabs/react-swipeable"
style={{fontSize: "0.75rem"}}
>
v{version}
</a>
</h1>

<dl>
<dt>Examples:</dt>
<dd><a href="#FeatureTestConsole">Feature testing with console log output</a></dd>
<dd><a href="#SimpleCarousel">Image Carousel using react-swipeable</a></dd>
<dd><a href="#SimplePattern">Swipe pattern using react-swipeable</a></dd>
<dd><a href="#FeatureTestConsole">💻 Feature testing with console log ⇨</a></dd>
<dd><a href="#SimpleCarousel">🖼 Image Carousel ⇨</a></dd>
<dd><a href="#SimplePattern">👉 Swipe pattern ⇨</a></dd>
</dl>
<hr />
<FeatureTestConsole />

<Paper id="FeatureTestConsole">
<FeatureTestConsole />
</Paper>
<hr />
<h2>Codesandbox Examples:</h2>
<div className="row" id="SimpleCarousel">
<iframe src="https://codesandbox.io/embed/react-swipeable-image-carousel-hben8?autoresize=1&fontsize=14&hidenavigation=1&module=%2Fsrc%2FCarousel.js&theme=light&view=preview" style={{width: '100%', height: '500px', border: '0', borderRadius: '4px', overflow: 'hidden'}} title="react-swipeable image carousel" allow="accelerometer; ambient-light-sensor; camera; encrypted-media; geolocation; gyroscope; hid; microphone; midi; payment; usb; vr; xr-spatial-tracking" sandbox="allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts" />
</div>

<Paper id="SimpleCarousel">
<SimpleCarousel />
</Paper>
<hr />
<div className="row" id="SimplePattern">
<iframe src="https://codesandbox.io/embed/react-swipeable-direction-pattern-example-jkt4z?autoresize=1&fontsize=14&hidenavigation=1&module=%2Fsrc%2Fpattern.js&theme=light&view=preview"
style={{width: '100%', height: '500px', border: '0', borderRadius: '4px', overflow: 'hidden'}}
title="react-swipeable direction pattern example"
allow="accelerometer; ambient-light-sensor; camera; encrypted-media; geolocation; gyroscope; hid; microphone; midi; payment; usb; vr; xr-spatial-tracking"
sandbox="allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts" />
</div>

<Paper id="SimplePattern">
<SimplePattern />
</Paper>
<hr />

<p style={{"marginBottom": "2rem"}}>
Thanks for checking out the examples! Let us know if you discover anything or have thoughts on improvements, and&nbsp;
<a href="https://github.com/FormidableLabs/react-swipeable/issues">submit an issue or PR!</a>
Expand Down
@@ -1,5 +1,5 @@
import React from 'react';
import { useSwipeable } from '../../src/index';
import { useSwipeable } from 'react-swipeable';

function SwipeableHook(props: any) {
const { children, className, style, ...rest } = props;
Expand Down
File renamed without changes.
Expand Up @@ -161,9 +161,9 @@ export default class Main extends Component<any, IState> {
}

return (
<div className="row" id="FeatureTestConsole">
<div className="row">
<div className="small-12 column">
<h5><strong>Test react-swipeable features.</strong></h5>
<h5><strong>💻 Test react-swipeable features.</strong></h5>
<SwipeableHook
{...boundSwipes}
{...swipeableDirProps}
Expand All @@ -175,7 +175,7 @@ export default class Main extends Component<any, IState> {
className="callout hookComponent"
style={swipeableStyle}>
<div onTouchStart={()=>this.resetState()}>
<h5>Hook - Swipe inside here to test</h5>
<h5>Swipe inside here to test</h5>
<p>See output below and check the console for 'onSwiping' and 'onSwiped' callback output(open dev tools)</p>
<span>You can also 'toggle' the swiped props being applied to this container below.</span>
</div>
Expand Down
100 changes: 100 additions & 0 deletions examples/app/SimpleCarousel/Carousel.tsx
@@ -0,0 +1,100 @@
import React, { FunctionComponent } from 'react';
import { useSwipeable } from 'react-swipeable';
import {
Wrapper,
CarouselContainer,
CarouselSlot,
SlideButtonContainer,
SlideButton,
PREV,
NEXT
} from '../components';

type Direction = typeof PREV | typeof NEXT;

interface CarouselState {
pos: number;
sliding: boolean;
dir: Direction;
}

type CarouselAction =
| { type: Direction, numItems: number }
| { type: 'stopSliding' | 'reset' };

const getOrder = (index: number, pos: number, numItems: number) => {
return index - pos < 0 ? numItems - Math.abs(index - pos) : index - pos;
};

const initialState: CarouselState = { pos: 0, sliding: false, dir: NEXT };

const Carousel: FunctionComponent = (props) => {
const [state, dispatch] = React.useReducer(reducer, initialState);
const numItems = React.Children.count(props.children);

const slide = (dir: Direction) => {
dispatch({ type: dir, numItems });
setTimeout(() => {
dispatch({ type: 'stopSliding' });
}, 50);
};

const handlers = useSwipeable({
onSwipedLeft: () => slide(NEXT),
onSwipedRight: () => slide(PREV),
preventDefaultTouchmoveEvent: true,
trackMouse: true
});

return (
<div {...handlers}>
<Wrapper>
<CarouselContainer dir={state.dir} sliding={state.sliding}>
{React.Children.map(props.children, (child, index) => (
<CarouselSlot
key={index}
order={getOrder(index, state.pos, numItems)}
>
{child}
</CarouselSlot>
))}
</CarouselContainer>
</Wrapper>
<SlideButtonContainer>
<SlideButton onClick={() => slide(PREV)} float="left">
Prev
</SlideButton>
<SlideButton onClick={() => slide(NEXT)} float="right">
Next
</SlideButton>
</SlideButtonContainer>
</div>
);
};

function reducer(state: CarouselState, action: CarouselAction): CarouselState {
switch (action.type) {
case 'reset':
return initialState;
case PREV:
return {
...state,
dir: PREV,
sliding: true,
pos: state.pos === 0 ? action.numItems - 1 : state.pos - 1
};
case NEXT:
return {
...state,
dir: NEXT,
sliding: true,
pos: state.pos === action.numItems - 1 ? 0 : state.pos + 1
};
case 'stopSliding':
return { ...state, sliding: false };
default:
return state;
}
}

export default Carousel;
25 changes: 25 additions & 0 deletions examples/app/SimpleCarousel/index.tsx
@@ -0,0 +1,25 @@
import React from 'react';
import { Item } from '../components';
import Carousel from './Carousel';
// Carousel originally copied from:
// https://medium.com/@incubation.ff/build-your-own-css-carousel-in-react-part-one-86f71f6670ca

function SimpleCarousel() {
return (
<div>
<h5 style={{ marginBottom: '20px' }}>
<strong>🖼 Image Carousel</strong>
</h5>

<Carousel>
<Item img="https://unsplash.it/475/205" />
<Item img="https://unsplash.it/476/205" />
<Item img="https://unsplash.it/477/205" />
<Item img="https://unsplash.it/478/205" />
<Item img="https://unsplash.it/479/205" />
</Carousel>
</div>
);
}

export default SimpleCarousel;
24 changes: 24 additions & 0 deletions examples/app/SimplePattern/index.tsx
@@ -0,0 +1,24 @@
import React from 'react';
import { Item } from '../components';
import Carousel from './pattern';
// Carousel originally copied from:
// https://medium.com/@incubation.ff/build-your-own-css-carousel-in-react-part-one-86f71f6670ca

function SimplePattern() {
return (
<div>
<h5 style={{ marginBottom: '20px' }}>
<strong>👉 Swipe pattern</strong>
</h5>
<Carousel>
<Item img="https://unsplash.it/475/205" />
<Item img="https://unsplash.it/476/205" />
<Item img="https://unsplash.it/477/205" />
<Item img="https://unsplash.it/478/205" />
<Item img="https://unsplash.it/479/205" />
</Carousel>
</div>
);
}

export default SimplePattern;

0 comments on commit b397712

Please sign in to comment.