npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-carousel-cards-npm

v1.1.5

Published

Carousel with falling on the sides cards

Downloads

235

Readme

react-carousel-npm

React component Carousel

NPM version Build npm-typescript License

Installation:

npm install react-carousel-cards-npm --save-dev

or

yarn add -D react-carousel-cards-npm

With SIde Cards Carousel

Usage:

First Create Card component which will be inside Carousel:

const Card = (props: any) => {
  /** In props will be all values which are in cards array **/
  console.log('Card props', props);
    
  return (
     <div
       style={{
          display: 'flex',
          flexDirection: 'column',
          boxShadow: '0px 10px 15px 0px rgba(0,0,0,0.1)',
          borderRadius: '8px',
          /** Add wrapper to card and path to styles={props.style} for correct displaying **/
          ...props.style,
        }}
      >
        <img
          src={props.imageSrc}
          height={'240px'}
          width={'100%'}
          /** Also add width and maxWidth for image if it's large **/
          style={{ borderRadius: '8px 8px 0 0', objectFit: 'cover', width: props.width, maxWidth: props.maxWidth }}
        />
        <div style={{ padding: '16px', fontSize: '18px', fontWeight: 700, borderRadius: '0 0 8px 8px' }}>
          {props.name}
        </div>
     </div>
  );
};

Add Carousel to your component variant With Side Cards:

import React from 'react'
import ReactDOM from 'react-dom/client'
import { Carousel } from 'react-carousel-cards-npm'

const root = ReactDOM.createRoot(document.getElementById('root') as HTMLElement);

const cards = [
  {
    id: 'da57db-4ea7-4258-8f34-74425bbc444422', 
    name: 'Amsterdam is the capital and most populous city of the Netherlands.', 
    imageSrc: 'https://i.ytimg.com/vi/DHGNQUfcgEE/maxresdefault.jpg',},
  {
    id: '789zxda57db-4ea7-4258-8f34-74425bbc444411',
    name: 'Tokyo is the capital and most populous city of Japan.',
    imageSrc: 'https://i.pinimg.com/originals/94/43/57/944357cc0e0fdcbdfd9e266c4422a1a3.jpg',
  },
  {
    id: '712389zxda57db-4ea7-4258-8f34-74425bbc444411',
    name: 'Seoul, officially the Seoul Special Metropolitan City, is the capital of the Republic of Korea.',
    imageSrc: 'https://c4.wallpaperflare.com/wallpaper/798/291/709/autumn-lake-park-building-wallpaper-preview.jpg',
  },
];

root.render(
  <React.StrictMode>
    <div
      style={{
        background: '#1000015d',
        /** Add position relative for wrapper and overflowX hidden for hidding side cards **/
        position: 'relative',
        overflowX: 'hidden',
        padding: '0 30px 20px',
        }}
      >
        <Carousel
          i18n='cards'
          header={<h1>With Side Cards Carousel</h1>}
          /** Set your card width **/
          cardWidth={445}
          marginCard={16}
          variant='withSideCards'
          /** Add key for each card ID **/
          cards={cards.map(item => ({...item, key: item.id}))}
          noCardsText='No cards selected'
        >
          <Card />
        </Carousel>
    </div>
  </React.StrictMode>,
);

Regular Carousel

Regular Carousel component:

<Carousel
  i18n='cards'
  header={<h1>Regular Carousel</h1>}
  /** Set your card width **/
  cardWidth={445}
  marginCard={16}
  /** Add key for each card ID **/
  cards={cards.map(item => ({ ...item, key: item.id }))}
  noCardsText='No cards selected'
>
  <Card />
</Carousel>

Custom Arrows and Pagination

Custom CustomArrowBtn if you want to add your own arrows:

Create custom button:

const CustomArrowBtn = (props: any) => {
  const { isLeftArrow, ...rest } = props;
  /** In props will be which arrow left/right = isLeftArrow **/
  console.log('Arrow props', props);

  return <button {...rest}>{isLeftArrow ? '<' : '>'}</button>;
};

Create CustomPaginationBtn pagination:

const CustomPaginationBtn = (props: any) => {
  const { isActivePage, ...rest } = props;
  /** In props will be which pagination btn is active = isActivePage **/
  console.log('Pagination btn props', props);

  return (
    <button {...rest} style={{ backgroundColor: isActivePage ? 'orange' : 'grey' }}>
      click
    </button>
  );
};

Add CustomArrowBtn or to yourCarousel`:

<Carousel
  i18n='cards'
  header={<h1>With Custom Arrows Carousel</h1>}
  paginationButtonStyles={{ cursor: 'pointer', marginBottom: '10px' }}
  cardWidth={445}
  marginCard={16}
  variant='withSideCards'
  cards={cards.map(card => ({ ...card, key: card.id }))}
  noCardsText='No cards selected'
  CustomArrowBtn={<CustomArrowBtn />}
  CustomPaginationBtn={<CustomPaginationBtn />}
>
  <Card />
</Carousel>

No Cards Block

No cards Block of Carousel:

<Carousel
  i18n='cards'
  header={<h1>No Cards Carousel</h1>}
  paginationButtonStyles={{ cursor: 'pointer', marginBottom: '10px' }}
  cardWidth={445}
  marginCard={16}
  variant='withSideCards'
  cards={[]}
  noCardsText='No cards selected'
>
  <Card />
</Carousel>

Custom No Cards Block

CustomNoCardsBlock of Carousel:

const CustomNoCardsBlock = (props: any) => {
  /** In props will be noCardsText **/
  console.log('No cards props', props);

  return (
    <div
      style={{
        width: '100%',
        height: '100px',
        display: 'flex',
        alignItems: 'center',
        justifyContent: 'center',
        border: '1px solid gray',
        borderRadius: '8px',
        backgroundColor: 'lightcyan',
      }}
    >
      {props.noCardsText}
    </div>
  );
};

Several variants example of Carousel:

<Carousel
  i18n='cards'
  header={<h1>Carousel</h1>}
  cardWidth={445}
  marginCard={16}
  variant={['withSideCards', 'withoutArrows']}
  cards={[]}
>
  <Card />
</Carousel>

UseCarouselContext Usage

Custom Arrows using useCarouselContext:

Create custom arrows and get handles from useCarouselContext:

const CustomArrowsPreview = () => {
  const { handlePrevPage, currentPage, handleNextPage, totalPageCount } = useCarouselContext();

  const btnStyles: CSSProperties = {
    position: 'absolute',
    top: '50%',
    border: 'none',
    background: 'cornflowerblue',
    padding: '14px',
    cursor: 'pointer',
  };

  console.log('currentPage', currentPage);

  return (
    <>
      <button style={{ ...btnStyles, left: 0 }} onClick={handlePrevPage} disabled={currentPage === 1}>
        prev
      </button>
      <button style={{ ...btnStyles, right: 0 }} onClick={handleNextPage} disabled={currentPage === totalPageCount}>
        next
      </button>
    </>
  );
};

Necessary to cover Carousel and CustomArrowsPreview inside provider for correct work if you want to use useCarouselContext:

<CarouselContextProvider>
  <Carousel
    i18n='cards'
    header={<h1>Use Carousel Context</h1>}
    paginationButtonStyles={{ cursor: 'pointer', marginBottom: '10px' }}
    cardWidth={445}
    marginCard={16}
    defaultActivePage={2}
    variant={['regular', 'withoutArrows']}
    cards={cards.map(card => ({ ...card, key: card.id }))}
    noCardsText='No cards selected'
    CustomNoCardsBlock={<CustomNoCardsBlock />}
  >
    <Card />
  </Carousel>
  <CustomArrowsPreview />
</CarouselContextProvider>

Custom Animation

withAnimation prop of Carousel:

Several variants example of Carousel:

<Carousel 
  i18n='cards'
  header={<h1>Use Carousel Context</h1>}
  paginationButtonStyles={{ cursor: 'pointer', marginBottom: '10px' }}
  cardWidth={445}
  marginCard={16}
  variant={['regular', 'withoutArrows']}
  cards={cards.map(card => ({ ...card, key: card.id }))}
  noCardsText='No cards selected'
  withAnimation={{
	animateIn: { opacity: '1', transition: 'opacity 0.5s ease-in-out' },
    animateOut: { opacity: '0', transition: 'opacity 0.5s ease-in-out' },
    animationInterval: 500,
  }}
  CustomNoCardsBlock={<CustomNoCardsBlock />}
>
  <Card />
</Carousel>

Example swipes of Carousel in mobile:

Mobile Swipes

Props Carousel:

| Name | Type | Description | |:-------------------------|---------------------------------------------------------------------------------------------------|:--------------------------------------------------| | header | React.ReactNode | Header of Carosel where you can | | cards | any[] | Cards array which will be shown inside Carousel | | disabled | boolean | To disable arrows | | variant | regular withSideCards withoutArrows withoutPagination Variant[] | Variants for shoing Carousel. | | cardWidth | number | Each card max width Default = 300 px | | marginCard | number | Margin between 2 cards | | noCardsText | string | No cards text inside block. | | CustomArrowBtn | React.ReactNode | Custom arrows for Carousel | | CustomPaginationBtn | React.ReactNode | Custom Pagination for Carousel | | children | React.ReactNode | Cards inside Carousel | | defaultCardsCount | number | How many cards will be shown on page by default | | defaultActivePage | number | Which page will be active by default | | cardContainerStyles | React.CSSProperties | Styles for cards container | | carouselContainerStyles | React.CSSProperties | Styles for carousel container | | paginationButtonStyles | React.CSSProperties | Styles for pagination button | | CustomNoCardsBlock | React.ReactNode | Custom No cards Block | | withAnimation | { animateIn: CSSProperties; animateOut: CSSProperties; animationInterval: number } or boolean | For adding custom animation or setting default |

Props useCarouselContext:

| Name | Type | Description | |:-------------------------|---------------------------|:-------------------------------| | currentPage | number | Active selected page | | totalPageCount | number | Total pages count | | handleNextPage | () => void | Handle to switch to next page | | handlePrevPage | () => void | Handle to switch to prev page | | onCurrentPage | (page: number) => void | Set state to exact page | | onTotalPageCountChange | (count: number) => void | Set state to exact total count |

If you want to support

Give a ⭐️ to project if you like it!