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

multi-view-calendar

v1.6.0

Published

A React calender component with multiple views(week, month)

Downloads

202

Readme

Multi-View Calendar

A customizable React calendar component that supports week and month views, event scheduling, and internationalization.

Demo

https://codesandbox.io/p/sandbox/cff99y Multi-View Calendar Demo

Table of Contents

Installation

Install the package using npm:

npm install multi-view-calendar

Peer Dependencies

Ensure you have react and react-dom installed in your project:

npm install react react-dom

Features

  • Multiple Views: Switch between week and month views.
  • Event Management: Add and delete events with ease.
  • Internationalization: Supports various languages via the lang prop.
  • Customizable Rendering: Customize event chips with renderEventChip.
  • TypeScript Support: Fully typed for enhanced developer experience.

Usage

Basic Example

import React, { useState } from "react";
import {
  CalendarProvider,
  useCalendar,
  MultiViewCalendar,
} from "multi-view-calendar";

const CalendarControls = () => {
  const { toggleViewMode, goToNext, goToPrevious, viewMode, viewLabel } =
    useCalendar();

  return (
    <div
      style={{
        display: "flex",
        justifyContent: "space-between",
        alignItems: "center",
        margin: "1rem 0",
      }}
    >
      <button
        onClick={toggleViewMode}
        style={{
          background: "#0092D4",
          color: "#FFF",
          padding: "0.5rem",
          border: "none",
          cursor: "pointer",
        }}
      >
        Switch to {viewMode === "week" ? "Month" : "Week"} View
      </button>
      <div style={{ display: "flex", alignItems: "center", marginTop: "1rem" }}>
        <button
          onClick={goToPrevious}
          style={{
            fontSize: "1.5rem",
            fontWeight: "bold",
            background: "none",
            border: "none",
            cursor: "pointer",
            color: "#0092D4",
          }}
        >
          {"<"}
        </button>
        <span
          style={{
            display: "block",
            padding: "0 0.25rem",
            textAlign: "center",
            fontSize: "1.125rem",
            fontWeight: "bold",
          }}
        >
          {viewLabel}
        </span>
        <button
          onClick={goToNext}
          style={{
            fontSize: "1.5rem",
            fontWeight: "bold",
            background: "none",
            border: "none",
            cursor: "pointer",
            color: "#0092D4",
          }}
        >
          {">"}
        </button>
      </div>
    </div>
  );
};

const App = () => {
  const [eventSchedule, setEventSchedule] = useState<{
    [key: string]: { value: string }[];
  }>({
    "2024-09-28": [{ value: "Meeting with John" }],
    "2024-09-29": [{ value: "Project deadline" }],
    "2024-09-30": [{ value: "Team stand-up" }],
  });

  return (
    <CalendarProvider>
      <CalendarControls />
      <MultiViewCalendar
        lang="en"
        eventSchedule={eventSchedule}
        setEventSchedule={setEventSchedule}
      />
    </CalendarProvider>
  );
};

export default App;

Custom Event Handling

import React, { useState } from "react";
import {
  CalendarProvider,
  useCalendar,
  MultiViewCalendar,
} from "multi-view-calendar";

const CalendarControls = () => {
  const { toggleViewMode, goToNext, goToPrevious, viewMode, viewLabel } =
    useCalendar();

  return (
    <div
      style={{
        display: "flex",
        justifyContent: "space-between",
        alignItems: "center",
        margin: "1rem 0",
      }}
    >
      <button
        onClick={toggleViewMode}
        style={{
          background: "#0092D4",
          color: "#FFF",
          padding: "0.5rem",
          border: "none",
          cursor: "pointer",
        }}
      >
        Switch to {viewMode === "week" ? "Month" : "Week"} View
      </button>
      <div style={{ display: "flex", alignItems: "center", marginTop: "1rem" }}>
        <button
          onClick={goToPrevious}
          style={{
            fontSize: "1.5rem",
            fontWeight: "bold",
            background: "none",
            border: "none",
            cursor: "pointer",
            color: "#0092D4",
          }}
        >
          {"<"}
        </button>
        <span
          style={{
            display: "block",
            padding: "0 0.25rem",
            textAlign: "center",
            fontSize: "1.125rem",
            fontWeight: "bold",
          }}
        >
          {viewLabel}
        </span>
        <button
          onClick={goToNext}
          style={{
            fontSize: "1.5rem",
            fontWeight: "bold",
            background: "none",
            border: "none",
            cursor: "pointer",
            color: "#0092D4",
          }}
        >
          {">"}
        </button>
      </div>
    </div>
  );
};

const ExampleUsage = () => {
  const [eventSchedule, setEventSchedule] = useState<{
    [key: string]: { value: string }[];
  }>({
    "2024-09-28": [{ value: "Meeting with John" }],
    "2024-09-29": [{ value: "Project deadline" }],
    "2024-09-30": [{ value: "Team stand-up" }],
  });

  const handleCustomEventDelete = ({
    event,
    eventIndex,
    eventDate,
    dateKey,
  }: {
    dateKey: string;
    event: { value: string };
    eventIndex: number;
    eventDate: Date;
  }) => {
    setEventSchedule((prevSchedule) => {
      const updatedEvents =
        prevSchedule[dateKey]?.filter((_, index) => index !== eventIndex) || [];
      return updatedEvents.length > 0
        ? { ...prevSchedule, [dateKey]: updatedEvents }
        : Object.fromEntries(
            Object.entries(prevSchedule).filter(([key]) => key !== dateKey)
          );
    });

    console.log(`Event deleted on ${eventDate}: ${event.value}`);
  };

  const handleCustomEventAdd = (date: Date, dateKey: string) => {
    const newEvent = {
      value: `Custom event on ${dateKey}`,
    };

    setEventSchedule((prevSchedule) => ({
      ...prevSchedule,
      [dateKey]: prevSchedule[dateKey]
        ? [...prevSchedule[dateKey], newEvent]
        : [newEvent],
    }));

    console.log(`Custom event added on ${date} with key ${dateKey}`);
  };

  return (
    <CalendarProvider>
      <CalendarControls />
      <MultiViewCalendar
        lang="en"
        eventSchedule={eventSchedule} // Pass the state directly to MultiViewCalendar
        setEventSchedule={setEventSchedule} // Pass the setter function for internal state updates
        onEventDelete={handleCustomEventDelete} // Optional
        onEventAdd={handleCustomEventAdd} // Optional
      />
    </CalendarProvider>
  );
};

export default ExampleUsage;

API

Props

| Prop | Type | Default | Description | | -------------------------------------- | -------------------------------------------------------------------------------------------------------------------------- | ------- | --------------------------------------------------------- | | lang (optional) | string | 'en' | Language code for localization. | | eventSchedule | { [key: string]: { value: string }[] } | | The current event schedule. | | setEventSchedule | React.Dispatch<React.SetStateAction<{ [key: string]: { value: string }[] }>> | | Function to update the event schedule. | | onEventAdd (optional) | (date: Date, dateKey: string) => void | | Custom handler for adding events. | | onEventDelete (optional) | (eventData: { event: { value: string }; eventIndex: number; eventDate: Date; dateKey: string }) => void | | Custom handler for deleting events. | | renderEventChip (optional) | ({ event, eventIndex, eventDate }: { event: { value: string }; eventIndex: number; eventDate: Date }) => React.ReactNode | | Custom renderer for event chips. | | containerClasses (optional) | string | | Custom CSS classes for the main container. | | calendarDayNameClasses (optional) | string | | Custom CSS classes for the day name headers. | | calendarDayClasses (optional) | string | | Custom CSS classes for each day cell in the calendar. | | dayNumberContainerClasses (optional) | string | | Custom CSS classes for the day number container. | | dayNumberClasses (optional) | string | | Custom CSS classes for the day number itself. | | ChipsContainerClasses (optional) | string | | Custom CSS classes for the container holding event chips. | | customAddIcon (optional) | React.ReactNode | | Custom icon component for the add event button. |

Author

Mais Aburabie