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

@teokamali/react-time-table

v1.1.1

Published

A headless time slot table component for React. This library provides a flexible, headless TimeTable component that allows you to manage and display time slots in a customizable manner without enforcing any specific UI. It uses context and compound compon

Downloads

162

Readme

@teokamali/react-time-table

A headless time slot table component for React. This library provides a flexible, headless TimeTable component that allows you to manage and display time slots in a customizable manner without enforcing any specific UI. It uses context and compound components to enable rich interactions with time slots.

Installation

To install the library, use npm or yarn:

bash
npm install @teokamali/react-time-table
# or
yarn add @teokamali/react-time-table

Usage

Basic Usage

import TimeTable from "@teokamali/react-time-table";
import "./styles/timeTable.css";

function App() {
   return (
      <div>
         <TimeTable
            availableTimeRange={["1", "24"]}
            cellDuration={60}
            disabledSlots={["2024-09-07T08:00"]}
            onChange={(data) => console.log(data)}
            maxSlots={20}
            startDate={0}
         >
            {({ timeSlots, days }) => (
               <div className={"container"}>
                  <TimeTable.Column>
                     <span className={"whiteBox"}>Time/Day</span>
                     {timeSlots.map((time) => (
                        <TimeTable.Day key={time}>
                           <div className={"timeSlot"}>
                              <span className={"timeSlotText"}>{time}</span>
                           </div>
                        </TimeTable.Day>
                     ))}
                  </TimeTable.Column>
                  {days.map((day) => (
                     <TimeTable.Column key={day.fullDate}>
                        <div>
                           <div className={"dayBox"}>
                              <span className="dayText dayTextVisibleSm">
                                 {day.dayName}
                              </span>
                              <br />
                              <span className="dayText dayTextHiddenSm">
                                 {day.dayDate}
                              </span>
                           </div>
                           {timeSlots.map((slot) => {
                              const timestamp = `${day.fullDate}T${slot}`;
                              return (
                                 <TimeTable.Slot
                                    key={timestamp}
                                    timestamp={timestamp}
                                    day={day}
                                    time={slot}
                                 >
                                    {({ isDisabled, isSelected }) => (
                                       <div
                                          className={`slot ${
                                             isDisabled
                                                ? "slotDisabled"
                                                : isSelected
                                                  ? "slotSelected"
                                                  : ""
                                          }`}
                                       >
                                          {slot}
                                       </div>
                                    )}
                                 </TimeTable.Slot>
                              );
                           })}
                        </div>
                     </TimeTable.Column>
                  ))}
               </div>
            )}
         </TimeTable>
      </div>
   );
}

export default App;

Components

  • TimeTable: The main component that provides context and manages state for time slots. Accepts the following props:

    • maxSlots (number): Maximum number of slots that can be selected.
    • disabledSlots (array of strings): List of timestamps that are disabled.
    • availableTimeRange (array of strings): The range of hours available (e.g., ["1", "24"]).
    • cellDuration (number): Duration of each time slot in minutes.
    • onChange (function): Callback function that is called whenever the selected slots change.
    • startDate (number or Moment): The starting date for the week.
    • children (function or ReactNode): A function or ReactNode that receives the timeSlots and days as arguments.
  • TimeTable.Column: A container for columns in the timetable.

  • TimeTable.Day: A container for days in the timetable.

  • TimeTable.Slot: Represents a single time slot. Accepts the following props:

    • timestamp (string): The timestamp for the slot.
    • day (IWeekDay): The day associated with the slot.
    • time (string): The time of the slot.
    • children (function or ReactNode): A function or ReactNode that receives the isDisabled and isSelected state.

Props API

TimeTable Props

  • maxSlots (optional): number — The maximum number of time slots that can be selected. Default is 9999.

  • disabledSlots (optional): Array<string> — An array of timestamps representing disabled time slots.

  • availableTimeRange (optional): [IHour, IHour] — An array with start and end hours for the available time range (e.g., ["1", "24"]).

  • cellDuration (optional): number — The duration of each time slot in minutes. Default is 60.

  • onChange (optional): (selectedSlots: IDate[]) => void — A callback function called when the selected slots change.

  • startDate (optional): Moment | number — The start date for the week. Can be a Moment object or a number representing the offset from now.

  • children (optional): ((context: { timeSlots: string[]; days: IWeekDay[] }) => ReactNode) | ReactNode — A function or ReactNode to render the table. Receives timeSlots and days as arguments.

TimeTable.Slot Props

  • timestamp: string — The timestamp of the slot.

  • day: IWeekDay — The day associated with the slot.

  • time: string — The time of the slot.

  • children (optional): ((context: { isDisabled: boolean; isSelected: boolean }) => ReactNode) | ReactNode — A function or ReactNode that receives isDisabled and isSelected state.

Types

  • IDate: Represents a selected slot with day, time, and timestamp.
  • IWeekDay: Represents a day of the week with dayName, dayDate, and fullDate.
  • ITimeTable: The props interface for TimeTable.
  • SlotType: The type for the Slot component.
  • TimeTableType: The type for the TimeTable component, including compound components.

License

MIT License

Author

Teo Kamalipour

Repository

Find the source code and additional information at GitHub - @teokamali/react-time-table