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-calendar-carousel

v1.2.0

Published

Calendar carousal is a mobile friendly component which give emphasis on selected date and time, you might have seen similar examples in booking related websites where selected dates must remain visible at all times for good UX.

Downloads

24

Readme

react-calendar-carousel

Calendar carousal is a mobile friendly component which give emphasis on selected date and time, you might have seen similar examples in booking related websites where selected dates must remain visible at all times for good UX.

Table of contents

Installation

You can install react-calendar-carousel using npm.

npm i react-calendar-carousel --save

Usage

import Calendar, { CalendarConfigProvider } from 'react-calendar-carousel'

const MyCalendarComponent = () => {
  return (
    <CalendarConfigProvider>
      <Calendar />
    </CalendarConfigProvider>
  )
}

export default MyCalendarComponent

API

The Calendar component can be used by wrapping it in the CalendarConfigProvider, both imported from react-calendar-carousel. All of the calendar’s state management and date logic are bundled in useCalendar custom hook.

Components 

CalendarConfigProvider

| Prop | Description | Type | Default | | :----------- | :----------------------------------------------------------- | :---------------------------------------------- | :------- | | dates | The dates displayed in the Carousel | DateRange | One week | | durationStep | The minutes by which duration should increase or decrease by | number | 15 | | formats | The display format for date, time, and clock | Formats | - | | minDuration | Lower threshold for the duration (in minutes) | number | 60 | | maxDuration | Upper threshold for the duration (in minutes) | number | 180 | | cards | Amount of cards per screen to be displayed | CardBreakpoint | - | | closedDate | Function that specifies the dates that cannot be selected | (date: Dayjs) => boolean | false | | closedHours | Hours that should be closed | ClosedHoursRange | - | | theme | Theme for the calendar and the components within | CalendarTheme | - |

Calendar

| Prop | Description | Type | Default | | :---------------- | :-------------------------------------------------- | :------------------------------ | :--------- | | panelsToShow | Panels that will be filtered out or not shown | PanelsToShow | - | | activePanels | What panels should initially be opened | string | string[] | ['1', '2'] | | dateComponent | Component that will replace the card carousel | ReactNode | - | | timeComponent | Component that will replace the time picker | ReactNode | - | | durationComponent | Component that will replace the duration setter | ReactNode | - |

Hooks 

useCalendar

This custom hook provides access to all the state values of the package, along with the functions to update the state.

| Name | Description | Type | | :--------------- | :----------------------------------------------------------- | :---------------------------------------------- | | selected | Selected date, time, and duration | Selected | | setDate | Function to update the selected date | (date: Dayjs) => void | | setTime | Function to update the selected time | (time: Dayjs) => void | | increaseDuration | Function to increase the selected duration | (offset: number) => number | | decreaseDuration | Function to decrease the selected duration | (offset: number) => number | | dates | The dates displayed in the carousel | IDate[] | | durationStep | The minutes by which duration should increase or decrease by | number | | formats | The display format for date, time, and clock | Formats | | minDuration | Lower threshold for the duration (in minutes) | number | | maxDuration | Upper threshold for the duration (in minutes) | number | | cards | Amount of cards per screen to be displayed | CardBreakpoint | | closedDate | Function that specifies the dates that cannot be selected | (date: Dayjs) => boolean | | closedHours | Hours that should be closed | ClosedHoursRange |

Custom Types

DateRange

Range of dates given by start and end.

type DateRange = {
  start: Dayjs
  end: Dayjs
}

IDate

Date entry with its associated information.

type IDate = {
  date: Dayjs
  closed?: boolean
}

Formats

Display format for the date, time and allow the selection of 12 or 24 hour format.

type Formats = {
  date: string /** @default "DD MMMM YYYY"*/
  time: string /** @default "hh:mm a" */
  clock: '12h' | '24h' /** @default "12h" */
}

CardBreakpoint

Number of cards to display per slide based on the different screen sizes.

export type CardBreakpoint = {
  xs: number /** @default 1 */
  sm: number /** @default 4 */
  md: number /** @default 6 */
  lg: number /** @default 8 */
  xl: number /** @default 10 */
  xxl: number /** @default 14 */
}

ClosedHoursRange

Range of closed hours, including start and end.

type ClosedHoursRange = {
  start: number
  end: number
}

Selected

export type Selected = {
  date: Dayjs | null
  time: Dayjs | null
  duration: number /** @default average(minDuration, maxDuration)*/
}

CalendarTheme

type CalendarTheme = {
  isDark: boolean /**@default false */
  general?: Partial<AliasToken>
  custom?: Partial<CustomStyles>
}

AliasToken

general styles are applied using Ant Design tokens. More info here. The general styles are inherited if a custom property is not provided.

CustomStyles

custom styles allow for component-specific customization. Below are the styles that can be applied. | Name | Description | Type | | :--- | :--- | :--- | | colorCardHeader | Header color for open date cards | string | colorCardHeaderDisabled | Header color for closed date cards | string | colorCardHeaderText | Text color for date card header | string | colorCardBodyText | Text color for date card body | string | colorButton | Color for the buttons that update duration | string | colorTimePicker | Color for the TimePicker component | string | cardGap | Gap between the date cards in the carousel | number | buttonBorderRadius | Border radius of buttons that update duration | number | carouselWidth | Width of the entire Calendar component | number

PanelsToShow

export type PanelsToShow = {
  date?: boolean /** @default true */
  time?: boolean /** @default true */
  duration?: boolean /** @default true */
}

Utils

getDatesFromRange

returns: IDate[] Get a list of dates by providing a range of dates. | Param | Description | Type | | :--- | :--- | :--- | | range | Range of dates | DateRange | | closedDate | Function that specifies the dates that cannot be selected | (date: Dayjs) => boolean |

getDurationInHours

returns: string Convert minutes into hour representation. | Param | Description | Type | | :--- | :--- | :--- | | minutes | The duration in minutes | number

getFormattedDate

returns: string Convert date to a formatted string. | Param | Description | Type | | :--- | :--- | :--- | | date | The date to format | Dayjs | null | format | The format to return | string

getFormattedTime

returns: string Convert time to a formatted string. | Param | Description | Type | | :--- | :--- | :--- | | time | The time to format | Dayjs | null | format | The format to return | string

Built With

License

Copyright © 2023 Hassam Ud Din. This project is MIT licensed.