1.3.0 • Published 12 months ago

appointment-calendar-carousal v1.3.0

Weekly downloads
-
License
MIT
Repository
github
Last release
12 months ago

appointment-calendar-carousal

React components for creating carousel based calendar appointments.

NPM version Bundle size Downloads

Quickstart

Install the library with peer dependencies:

# With yarn
yarn add appointment-calendar-carousal antd dayjs

# or with npm
npm i appointment-calendar-carousal antd dayjs

Note: antd and dayjs are required for this package to work. It is recommended to use antd@^5.0.0 and dayjs@1.11.0

Then, import the AppointmentCalenderProvider and wrap your app with it

import { AppointmentCalenderProvider } from 'appointment-calendar-carousal'

function App() {
    return (
        <AppointmentCalenderProvider>
         {...}
        </AppointmentCalenderProvider>
    )
}

Lastly, import CalendarAppointment and useAppointmentCalender hook

import CalendarAppointment, { useAppointmentCalender } from 'appointment-calendar-carousal'

function SomeComponent() {
    const { selectedDates } = useAppointment()

    return (
        {...}
         <CalendarAppointment />
        {...}
    )
}

Docs

You can use appointment-calendar-carousal as is by just wrapping the app with AppointmentCalenderProvider and placing the CalendarAppointment component where needed. Then You can get values from the provided useAppointment hook.

Or you can use useAppointment hook with your own custom components and even mix some of the provided components like CalenderCard.

Components

AppointmentCalenderProvider

This is a Wrapper for the appointment state management and pre-configurations.

PropTypeDescriptionDefault
datesIDate[]Provide custom dates list (you can use provided helper functions to create dates list)-
formatsObjectProvide the custom format for Date and Time-
durationStepnumberNumber by which duration should increase or decrease30
minDurationnumberMinimum that the duration can be30
maxDurationnumberMaximum that the duration can be120
tokennumberStyle Tokens for the calender components-
interface IDate = {
  dates: Dayjs;
  closed: boolean;
}
interface Formats = {
  date: string; /** @default "DD, MMMM YYYY" */
  time: string; /** @default "h:mm a" */
}

CalendarAppointment

This is the main component and can be used as is with useAppointment, or can be used as a controlled component.

PropTypeDescriptionDefault
datesIDate[]Provide custom dates list if not using Provider-
durationStepnumberAmount by which duration should increase or decrease30
minDurationnumberMinimum time the duration can be30
maxDurationnumberMaximum time the duration can be120
formatsObjectProvide the custom format for Date and Time-
timeComponentReactElementCustom component for time panel-
calenderComponentReactElementCustom component for calender panel-
durationComponentReactElementCustom component for duration panel-
containerStyleCSSPropertiesComponent container styles object-
collapseContainerStyleCSSPropertiesCollapse container styles object-
durationContainerStylesCSSPropertiesDuration panel container styles object-
cardStyles{head?: CSSProperties, body: CSSProperties}CalenderCard component styles object-
onChange({dateTime, duration}) => voidcallback each time any value is changed-

CalendarCarousel

This is the default calender component used in CalendarAppointment.

PropTypeDescriptionDefault
datesIDate[]Provide custom dates list if not using Provider-
containerWidthnumberCustom width of the container (recommended to leave default)calculated
cardStyles{head?: CSSProperties, body: CSSProperties}CalenderCard component styles object-
onSelectDate(date: Dayjs) => voidCallback when date is selected-

CalenderCard

This is the default calender card component used in CalendarCarousel component.

PropTypeDescriptionDefault
dateDayjsDate to be displayed on the card-
closedbooleanIf true, card will be grayed and un-selectablefalse
onClick(e: MouseEvent) => voidCallback on click-
headStyleCSSPropertiesStyles object for head part of the card-
bodyStyleCSSPropertiesStyles object for body part of the card-

Hooks

useAppointmentCalender()

This contains all the configs and state of the appointment calender.

ValuesTypeDescription
datesIDate[]List of dates to be shown in carousel
formatsObjectProvided formats for date and time
valuesSelectedValuesObject containing currently selected values
durationStepnumberAmount by which duration should increase or decrease
minDurationnumberMinimum time the duration can be
maxDurationnumberMaximum time the duration can be
setDate(Dayjs): voidManually set the current selected date
setDuration(number): voidManually set the current selected duration
setDatesList(IDate): voidManually set the list of dates
addTime(value: number, type: string): DayjsAdds time into current selected date object and returns it
subtractTime(value: number, type: string): DayjsSubtract time from current selected date object and returns it
increaseDuration(number): numberAdds time into duration and returns updated duration
decreaseDuration(number): numberSubtract time from duration and returns updated duration
canAddTime(by: 'hours' or 'minutes'): booleanreturns true if time can be added without changing day
canSubtractTime(by: 'hours' or 'minutes'): booleanreturns true if time can be subtracted without changing day
interface SelectedValues {
  datetime: Dayjs
  duration: number
}

Helper Functions

These helper functions can be used to generate a list of dates.

getDateList()

ArgsTypeDescription
startnumberStart date of the list
endDayjsLast date of the list
closedDaysClosedDaysSets closed to true for selected days of the week
type ClosedDays = Array<'Monday' | 'Tuesday' | 'Wednesday' | 'Thursday' | 'Friday' | 'Saturday' | 'Sunday'>

getDatesByNumber()

ArgsTypeDescription
numbernumberNumber by which list items are added based on the type
typeManipulateTypeType by which number of items to be added are decided. for example, "day" or "month
closedDaysClosedDaysSets closed to true for selected days of the week

getDates()

:no_entry: DEPRECATED

ArgsTypeDescription
radiusnumberif no from and to are provided you can provide radius to let generate dates list with in the radius of Now
fromDayjsDate from which the date list should start
toDayjsDate at which the date list should end
closedDaysClosedDaysSets closed to true for selected days of the week

Design Token

Design token can be provided to AppointmentCalenderProvider for customization.

List of available tokens:

TokenDescriptionTypeDefault
calenderColorColor of the header of CalenderCard when activestring'#ff4d4f',
calenderDisabledColorColor of the header of CalenderCard when disabledstring'#8c8c8c',
calenderTextColorColor of date and day fonts in CalenderCardstring'#8c8c8c',
fontSizeSMSmall font sizenumber12,
fontSizeStandard font sizenumber14,
fontSizeLGLarge font sizenumber16,
fontSizeXLSuper large font sizenumber20,
fontSizeXXLExtra super large font sizenumber24,
fontSizeXXXLExtra super duper large font sizenumber30,
calenderDateFontSizefont size of date in CalenderCardnumber40,
calenderCardSizeSize of the CalenderCardnumber170,
calenderCardGapGap between CalenderCard componentsnumber10,
calenderCardsPerViewNumber of CalenderCard shown per viewnumber or Breakpoint3,
interface BreakPoint {
  xs?: number
  sm?: number
  md?: number
  lg?: number
  xl?: number
  xxl?: number
}

License

MIT Licensed Copyright (c) 2023 Muqarrab Hussain

1.3.0

12 months ago

1.2.1

12 months ago

1.2.0

12 months ago

1.1.3

12 months ago

1.1.2

12 months ago

1.1.1

12 months ago

1.1.0

12 months ago

1.0.3

12 months ago

1.0.2

12 months ago

1.0.1

12 months ago

1.0.0

12 months ago