Last active
October 4, 2021 19:13
-
-
Save DZuz14/d75100bb7dba0d6f88628d7ca0f7ad26 to your computer and use it in GitHub Desktop.
Slider With React Hooks 7
This file contains hidden or 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
/** @jsx jsx */ | |
import React, { useState, useEffect, useRef } from 'react' | |
import { css, jsx } from '@emotion/core' | |
import SliderContent from './SliderContent' | |
import Slide from './Slide' | |
/** | |
* @function Slider | |
*/ | |
const Slider = props => { | |
const getWidth = () => window.innerWidth | |
const [state, setState] = useState({ | |
translate: 0, | |
transition: 0.45 | |
}) | |
const { translate, transition } = state | |
return ( | |
<div css={SliderCSS}> | |
<SliderContent | |
translate={translate} | |
transition={transition} | |
width={getWidth() * props.slides.length} | |
> | |
{props.slides.map((slide, i) => ( | |
<Slide key={slide + i} content={slide} /> | |
))} | |
</SliderContent> | |
</div> | |
) | |
} | |
const SliderCSS = css` | |
position: relative; | |
height: 100vh; | |
width: 100vw; | |
margin: 0 auto; | |
overflow: hidden; | |
` | |
export default Slider |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment