0.5.0 • Published 2 years ago

chakra-framer-carousel v0.5.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

chakra-framer-carousel

Note: this package is still under active development. However, the API should remain stable from this point onwards.

npm npm NPM

Demo

Show me right now

Features

  • Hooks for creating a carousel
  • Composition pattern allowing for extensibility
  • No external dependencies

Todo

  • Some sort of testing.
  • JSDoc comments for functions.
  • Add more custom examples.

Installation

yarn add chakra-framer-carousel

Size

  • Bundling strategy is based on vite-dts. If paypal ever accept my application, the team are getting a ☕️. Bundlephobia does not accept esnext so this is from the Vite build.

    FileSize
    dist/chakra-framer-carousel.es.d.ts0.03 KiB
    dist/chakra-framer-carousel.es.js7.17 KiB / gzip: 1.81 KiB
    dist/chakra-framer-carousel.es.js.map8.52 KiB
    dist/chakra-framer-carousel.cjs.d.ts0.03 KiB
    dist/chakra-framer-carousel.cjs.js8.43 KiB / gzip: 2.17 KiB
    dist/chakra-framer-carousel.cjs.js.map8.65 KiB

Usage

Note: Carousels are not always an ideal design choice.

Basic Example

Edit chakra-framer-carousel-demo

import {
  Carousel,
  CarouselItem,
  CarouselItems,
} from "chakra-framer-carousel";

function CarouselDemo() {
  return (
    <Carousel>
      <CarouselItems>
        {images.map((image, index) => {
          return (
            <CarouselItem index={index} key={image}>
              <Card index={index} image={image} />
            </CarouselItem>
          );
        })}
      </CarouselItems>
      <Toolbar />
    </Carousel>
  );
}

Testimonials Example

Edit chakra-framer-carousel-testimonial-demo


Props

ComponentDescription
CarouselThe wrapper that provides context for its children. Children have access to the useCarousel hook. Accepts getMotionStyles props for customizing the animation.
CarouselItemsThe wrapper that converts children into individual carousel items. Accepts FlexProps too.
CarouselItemThe wrapper around a carousel item allowing for use of the useCarouselItem hook.
MotionFlexChakra-UI flex with framer-motion props.

Hooks

useCarousel

Can be used by any component wrapped within a Carousel provider. A common use case is a toolbar to navigate between carouel items.

PropertyDescriptionTypeReturns
onNextMove carousel forwardsFunctionnull
onPreviousMove carousel backwardsFunctionnull
findPositionFind a carousel item's current positionFunction"left" | "center" | "right" | "hidden"
numberOfSlidesCount of carousel itemsNumberNumber
stateReact state for the carousel elementsArray | Nullnull | React.ReactElement<any, string | React.JSXElementConstructor>[]
_onInitializeInternal hook to create initial starting stateFunctionvoid

useCarouselItem

Can be used by any component wrapped within a CarouselItem provider. A common use case is the actual individual carousel item such as an image.

PropertyDescriptionTypeReturns
onNextMove carousel forwardsFunctionnull
onPreviousMove carousel backwardsFunctionnull
positionA carousel item's current positionString"left" | "center" | "right" | "hidden"
numberOfSlidesCount of carousel itemsNumberNumber
onClickHandlerAction when left or right card is clickedFunctionvoid | null

Explaining and Customizing the animation

  • TODO

Known Issues

  • Background Opacity Bug: if no background is set in the global theme or direct parent divs, you can see a hidden card.
  • onInitialize function should be prefixed with an underscore to mark it as internal.

Chakra Specific Alternatives

Other Alternatives

  • Radix have an upcoming carousel component 😁
0.5.0

2 years ago

0.4.2

2 years ago

0.4.1

2 years ago

0.3.0

2 years ago

0.2.0

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago

0.0.9

2 years ago

0.0.8

2 years ago

0.0.7

2 years ago

0.0.6

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago

0.0.0

2 years ago