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

calendar-carousel

v1.0.6

Published

The `calendar-carousel` is a reusable calendar component that gives emphasis on the selected date, time, and duration. Below is a detailed list of how to use it in your project:

Downloads

4

Readme

The calendar-carousel is a reusable calendar component that gives emphasis on the selected date, time, and duration. Below is a detailed list of how to use it in your project:

Table of Contents:

1- Installation.

2- API Reference.

3- Usage Example.

Installation:

Running the following command to install the package:

npm i calendar-carousel

Now import it in the file you want using import Calendar from "calendar-carousel" . Now you can call the container and get the default style and behavior of the calendar. To know how you can change the behavior using props refer to the API section.

API Reference:

The Calendar component provides a flexible and customizable calendar view with carousel functionality. Below is the API reference for the component's props.

| Prop Name | Type | Default Value | Description | | ------------------ | ------------------------------------- | ----------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- | | numCardsToShow | number | 3 | Number of date cards to show in the carousel at a time. | | cardsToScroll | number | 1 | Number of date cards to scroll in one swipe/scroll action. | | dateRange | [dayjs.Dayjs, dayjs.Dayjs] | [dayjs(), dayjs().add(29, "day")] | Date range for the calendar to show. Format should be a valid dayjs date for the start range and end range. If not provided, defaults to today + 29 days. | | offDays | (date: dayjs.Dayjs) | () => false | A user provided custom function to determine if a specific date is a off day and should be disabled. | | holidays | (date: dayjs.Dayjs) => boolean | () => false | A user provided custom function to determine if a specific date is a holiday and should be disabled. | | timeFormat | string | "hh:mm a" | Format for the time picker. Can be "hh:mm a" for 12-hour format or "HH:mm" for 24-hour format. | | durationStep | number | 30 | Step size for duration changes, in seconds by default. | | onDateChange | (date: dayjs.Dayjs) => void | () => {} | Callback function when a date is selected. | | onTimeChange | (time: dayjs.Dayjs \| null) => void | () => {} | Callback function when a time is selected or changed. | | onDurationChange | (duration: number) => void | () => {} | Callback function when the duration is changed. |

Customize Design with Tokens:

The calendar-carousel supports custom design tokens allowing you to tailor the appearance to match your application's theme. Below is a table listing the tokens you can use to customize various aspects of the calendar's UI.

| Token Name | Description | | --------------------- | ------------------------------------------------------------------------------------------ | | colorPrimary | Background color for enabled date cards, arrows, buttons click & focus on time picker etc. | | colorPrimaryText | Text color for enabled date cards. | | colorWarning | Background color for holiday-disabled date cards. | | colorWarningText | Text color for holiday-disabled date cards. | | colorError | Background color for off-day disabled date cards. | | colorErrorText | Text color for off-day disabled date cards. | | borderRadius | Border radius for date cards. | | controlItemBgActive | Background color for active control items (time picker). |

Light and Dark Mode:

Some antd components (mainly the collapse) used don't adhere to the darkAlgorithm properly for that purpose you can modify the ConfigProvider from antd and use the component tokens to customize them for dark/light themes:

<ConfigProvider
  theme={{
    components: {
      Collapse: {
        headerBg: darkTheme ? "black" : "",
      },
      DatePicker: {
        cellHoverBg: token.colorPrimary,
      },
    },
    algorithm: darkMode ? theme.darkAlgorithm : theme.defaultAlgorithm,
    token,
  }}
>
  {children}
</ConfigProvider>

E.g., here I am setting black color from my Collapse Panels in case of darkmode. For more details on how to further customize it refer to the components api's.

Usage Example:

import React from "react";
import Calendar from "calendar-carousel";

const MyComponent = () => {
  // example callback function for offDays
  const customOffDays = (date: dayjs.Dayjs) => {
    return date.day() === 2 || date.day() === 3;
  };

  const holidays = [dayjs("01-01-2023"), dayjs("01-02-2023")];

  // example callback function for holidays
  const checkIfHoliday = (date: dayjs.Dayjs) => {
    return holidays.some((holiday) => holiday.isSame(date, "day"));
  };

  return (
    <Calendar
      numCardsToShow={5}
      cardsToScroll={2}
      dateRange={[dayjs("01-01-2023"), dayjs("01-30-2023")]}
      offDays={customOffDays}
      holidays={checkIfHoliday}
      timeFormat="HH:mm a"
      durationStep={15}
      onDateChange={(date) =>
        console.log("Selected Date:", date.format("MMMM DD, YYYY"))
      }
      onTimeChange={(time) =>
        console.log("Selected Time:", time?.format("HH:mm"))
      }
      onDurationChange={(duration) => console.log("Duration:", duration)}
    />
  );
};

export default MyComponent;