-
Notifications
You must be signed in to change notification settings - Fork 2
Feature/tech 438 hero component #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 4 commits
5b760a8
368ad83
d22fe2d
a8400b3
fcdc4f0
d9290c7
24d5803
6e99681
351e29c
8fb2bfd
b416bb7
f9f5c9a
e51cc41
94468ab
d3d454b
ed8d805
634ac7d
02f91e1
5259f4e
b642209
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| import React, { useState } from "react"; | ||
| import { AiOutlineLeft, AiOutlineRight } from "react-icons/ai"; | ||
| import Swipe from "react-easy-swipe"; | ||
|
|
||
| const Carousel = ({children}) => { | ||
| const slideLength = children.length; | ||
| const handleNextClick = () => { | ||
| const index = currentIndex === slideLength - 1 ? 0 : currentIndex + 1 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't forget the trailing semicolons! Same comment for most of the lines below |
||
| setCurrentIndex(index) | ||
| } | ||
| const handleOnPrevClick = () => { | ||
| const index = currentIndex === 0 ? slideLength - 1 : currentIndex - 1 | ||
| setCurrentIndex(index) | ||
| }; | ||
|
|
||
| const [currentIndex, setCurrentIndex] = useState(0) | ||
| return ( | ||
| <div className="m-auto"> | ||
| <div className="w-full relative select-none"> | ||
| <AiOutlineLeft | ||
| onClick={handleOnPrevClick} | ||
| className="absolute left-0 text-3xl inset-y-1/2 text-white cursor-pointer" | ||
| /> | ||
| <Swipe> | ||
| { | ||
| children.map((child, index) => | ||
| React.cloneElement(child, { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Quite smart! Well done. |
||
| className: ` | ||
| ${index === currentIndex | ||
| ? "block w-full h-auto object-cover" | ||
| : "hidden"} | ||
| `}) | ||
| ) | ||
| } | ||
| <div> | ||
| </div> | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why the empty |
||
| </Swipe> | ||
| <div className="absolute w-full flex justify-center bottom-0"> | ||
| {children.map((element, index) => { | ||
| return ( | ||
| <div | ||
| className={ | ||
| index === currentIndex | ||
| ? "h-2 w-2 bg-black rounded-full mx-2 mb-2 cursor-pointer" | ||
| : "h-2 w-2 bg-white rounded-full mx-2 mb-2 cursor-pointer" | ||
|
ikhoaA marked this conversation as resolved.
Outdated
|
||
| } | ||
| key={index} | ||
| onClick={() => { | ||
|
ikhoaA marked this conversation as resolved.
Outdated
|
||
| setCurrentIndex(index); | ||
| }} | ||
| /> | ||
| ); | ||
| })} | ||
| </div> | ||
| <AiOutlineRight | ||
| onClick={handleNextClick} | ||
| className="absolute right-0 text-3xl inset-y-1/2 text-white cursor-pointer" | ||
| /> | ||
| </div> | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| export default Carousel; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,28 +3,18 @@ import PropTypes, { element, elementType, node } from 'prop-types'; | |
| import { Button as ButtonComponent } from '../Button'; | ||
| import Content from './Content'; | ||
| const Carousel = lazy(() => | ||
|
loan-laux marked this conversation as resolved.
Outdated
|
||
| import('../vendor/EmblaCarousel/Carousel/Carousel'), | ||
| import('./Carousel'), | ||
| ); | ||
|
|
||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need for an extra line break here |
||
| const Hero = ({ | ||
| classNames = {}, | ||
| title, | ||
| subTitle, | ||
| imageUrl, | ||
| hasOverlay, | ||
| NextImage, | ||
| slides, | ||
| Button = () => ( | ||
| <ButtonComponent | ||
| displayText="Shop Now" | ||
| onClick={() => { | ||
| alert('You clicked me'); | ||
| }} | ||
| /> | ||
| ), | ||
| Button | ||
| }) => { | ||
| const isSlider = slides !== undefined; | ||
|
|
||
| const isSlider = slides.length > 1 | ||
| return ( | ||
| <> | ||
| {isSlider ? ( | ||
|
|
@@ -37,7 +27,7 @@ const Hero = ({ | |
| classNames={classNames} | ||
| subTitle={slide.subTitle} | ||
| Button={Button} | ||
| NextImage={NextImage} | ||
| Image={slide.imageComponent} | ||
| imageUrl={slide.imageUrl} | ||
| hasOverlay={hasOverlay} | ||
| /> | ||
|
|
@@ -47,12 +37,12 @@ const Hero = ({ | |
| </Suspense> | ||
| ) : ( | ||
| <Content | ||
| title={title} | ||
| title={slides[0].title} | ||
| classNames={classNames} | ||
| subTitle={subTitle} | ||
| subTitle={slides[0].subTitle} | ||
| Button={Button} | ||
| NextImage={NextImage} | ||
| imageUrl={imageUrl} | ||
| imageUrl={slides[0].imageUrl} | ||
| Image={slides[0].imageComponent} | ||
| hasOverlay={hasOverlay} | ||
| /> | ||
| )} | ||
|
|
@@ -71,39 +61,19 @@ Hero.propTypes = { | |
| featureTitle: PropTypes.string, | ||
| featureSubtitle: PropTypes.string, | ||
| }), | ||
| /** | ||
| * Title of Hero component | ||
| * e.g. `Hello world` | ||
| */ | ||
| title: PropTypes.string.isRequired, | ||
| /** | ||
| * Subtitle of Hero component | ||
| * e.g. `How to make you feel good` | ||
| */ | ||
| subTitle: PropTypes.string.isRequired, | ||
| /** | ||
| * Hero image URL | ||
| * e.g. `https://images.unsplash.com/photo-1469334031218-e382a71b716b?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=2670&q=80` | ||
| */ | ||
| imageUrl: PropTypes.string.isRequired, | ||
| /** | ||
| * Boolean that toggles the overlay | ||
| * e.g. `true` | ||
| */ | ||
| hasOverlay: PropTypes.bool, | ||
| /** | ||
| * Next.js Image optimizer component | ||
| * e.g. `import Image from 'next/image'` | ||
| */ | ||
| NextImage: PropTypes.elementType, | ||
| /** | ||
| * React Button component | ||
| * e.g. `<ButtonComponent | ||
| * displayText="Shop Now" | ||
| * onClick={() => { | ||
| * alert('You clicked me'); | ||
| * }} | ||
| * />` | ||
| * displayText="Shop Now" | ||
| * onClick={() => { | ||
| * alert('You clicked me'); | ||
| * }} | ||
| * />` | ||
| */ | ||
| Button: PropTypes.elementType.isRequired, | ||
| /** | ||
|
|
@@ -112,9 +82,26 @@ Hero.propTypes = { | |
| */ | ||
| slides: PropTypes.arrayOf( | ||
| PropTypes.shape({ | ||
| title: PropTypes.string, | ||
| subTitle: PropTypes.string, | ||
| imageUrl: PropTypes.string, | ||
| /** | ||
| * Custom Image optimizer component | ||
| * e.g. `import Image from 'next/image'` | ||
| */ | ||
| imageComponent: PropTypes.elementType, | ||
| /** | ||
| * Title of Hero component | ||
| * e.g. `Hello world` | ||
| */ | ||
| title: PropTypes.string.isRequired, | ||
| /** | ||
| * Subtitle of Hero component | ||
| * e.g. `How to make you feel good` | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I appreciate the effort, but I don't think we necessarily need these examples. The names of the props are self-explanatory and the types provide enough info as to what they should be. |
||
| */ | ||
| subTitle: PropTypes.string.isRequired, | ||
| /** | ||
| * Hero image URL | ||
| * e.g. `https://images.unsplash.com/photo-1469334031218-e382a71b716b?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=2670&q=80` | ||
| */ | ||
| imageUrl: PropTypes.string , | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's remove the space before this trailing coma |
||
| }), | ||
| ), | ||
| }; | ||
|
|
||
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Leave spaces in your object destructuring notation:
const Carousel = ({ children }) => {