-
Notifications
You must be signed in to change notification settings - Fork 146
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into dependabot/npm_and_yarn/ssri-6.0.2
- Loading branch information
Showing
20 changed files
with
4,710 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
examples/app/SwipeableHook.tsx → .../app/FeatureTestConsole/SwipeableHook.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |
Oops, something went wrong.