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-hovering-cards-carousel

v0.9.71

Published

React Carousel which renders cards with hover effects.

Downloads

40

Readme

React Hovering Cards Carousel

React Carousel which renders cards with hover effects.

Find on GitHub
Find on NPM

  • How to use?
    • Setup
      • Import styling
    • <Carousel/> component
      • Properties
        • cards
        • scale
        • reloadOnResize
        • upcomingEventLabel
        • buttonColor
        • buttonSpacing
    • Types of cards
      • type Custom
        • How to create a JSX Element (card overlay)
        • Example with type Custom
      • type Event (@AUBGTheHUB)
      • type Article (@AUBGTheHUB)
    • Component initialization
      • Initialization of hardcoded arrays
      • Fetching from an endpoint and mapping response to specific card type
    • Quirks:

How to use:

In order for the component's styling to work, you need to import style.css:

import `../node_modules/react-hovering-cards-carousel/dist/style.css`

<Carousel/>:

<Carousel cards={events} scale={1.25} buttonsBackground={"red"} reloadOnResize={false}/>
  • cards props is an array of type Custom, Article or Event where the items are the ones getting rendered.
  • scale (default: 1) prop accepts a number which signifies the times the component sizes up or down depending on your needs.
  • reloadOnResize (default: true) prop accepts a boolean value which would either enable or disable the window reloading behavior triggered by the component when resolution is being changed.
  • upcomingEventLabel (optional) prop accepts an object defining a specific label which is shown when an event is upcoming. More about this in the Quirks section.
  • buttonColor (default: black) set color of arrow buttons.
  • buttonSpacing (default: 40) control the space between the buttons and the main container. Value is in pixels and multiplied by -1. Hence values lower than > 40 bring the buttons closer to the container.

type Custom:

image: string; // <img src={prop.image}>
children: JSX.Element; // this is what gets rendered when you hover over the card

How to create a JSX Element:

type CustomChildProp = {
  title: string;
  description: string;
  // add additional
};

let CustomChild = (prop: CustomChildProp) => {
  return (
    <div>
      <h1>{prop.title}</h1>
      <p>{prop.description}</p>
      {/* add additional */}
    </div>
  );
};

Additionally you may (preferably) add specific styling to your JSX Element:

import './style.css' // either in a parent component or in the same place
// where you define the CustomChild Element


let CustomChild = (prop: CustomChildProp) => {
  return (
    <div className="container">
      <h1 className="title-header">{prop.title}</h1>
      <p className="description">{prop.description}</p>
      {/* add additional */}
    </div>
  );
};

Create a <Carousel/> using type Custom (see example code here):


import {Custom} from 'react-hovering-cards-carousel'

.
.
.

// declare array
const arr = [
  new Custom("https://example.com", <CustomChild title="Example", description="This is an example"/>),

  new Custom("https://secondexample.uk", <CustomChild title="Example Two", description="This is the second example">)
]

.
.
.

<Carousel cards={arr}/>

The types below were developed for internal use within the @AUBGTheHub organization, but you can make use of them as you wish!

type Event:

title: string;
image: string; // <img src={prop.image}/>
description: string;
location: string; // url (e.g. Google Maps)
startingTime: string; // ISO String
link: string; // url (e.g. Facebook)

type Article:

title: string;
link: string; // url (e.g. Medium)
author: string;
image: string; // <img src={prop.image}/>

Initialize the component:

Create a list and populate it with objects of type Custom | Event | Article and then pass it to <Carousel/>

  • hardcoded items
import "../node_modules/react-hovering-cards-carousel/dist/style.css"
import { Carousel, Custom } from "react-hovering-cards-carousel";

.
.
.

let customArr: Array<Custom> = [
    new Custom("first item", ...),
    new Custom("second item", ...),
    ...
]

return (
    <div className="container">
        <Carousel cards={customArr}/>
    </div>
)
 const [events, setEvents] = useState<Event[]>([]);

  useEffect(() => {
    axios({
      method: "get",
      url: "https://dev.thehub-aubg.com/api/event",
    }).then((res) => {
      let resData: Array<unknown> = res.data.data.events;
      let temp: Array<Event> = [];

      if (resData) {
        resdata.forEach((element: any) => {
          temp.push(
            new Event(
              element.title,
              element.banner,
              element.description,
              element.locationlink,
              element.startdate,
              element.facebooklink
            )
          );
        });

      setEvents(temp);
      }
    });
  }, []);


    return (
    <div className="App">
      <Carousel cards={events} />
    </div>
  );

<Carousel/> styling:

You may use hex, rgb() and rgba() values everywhere color is mentioned.

<Carousel cards={cards} buttonColor={"red"}>
// you can define colors the same way you do in css (hex, rgb(), rgba())

Quirks:

Events - You may add labels for upcoming events:

upcomingEventLabel is an object which requires text, backgroundColor and color.

  • text is what's getting rendered in the div
  • backgroundColor is the color of the box
  • color is the color of the text
<Carousel
  cards={events}
  upcomingEventLabel={{
    text: "Upcoming",
    backgroundColor: "rgba(255, 255, 255, 0.7)",
    color: "black",
  }}
/>

Box won't get rendered if prop.startingTime cannot be parse as a Date() object.