0.2.0 • Published 8 months ago

@dgreasi/react-native-time-slot-picker v0.2.0

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

react-native-time-slot-picker

NPM version npm npm npm runs with expo

Features

  • No dependencies.
  • A time slot picker for react native.
  • Pass the availableDates you want to show.
  • Pick a day and the timeslot you wish.
  • Simple UX.
  • Use colors of your preference by using the params.
  • Use day shortnames and month names of your preference by using the params.
  • Change the title of the timeslots section by using the params.
  • Change the width of timeslot element by using the params.

Table of contents

Screenshots

You can test the library by opening the following snack here.

Run example locally

git clone https://github.com/dgreasi/react-native-time-slot-picker.git
cd react-native-time-slot-picker
npm i # or `yarn`
npm run example ios # or `yarn example ios`

Installation

npm i @dgreasi/react-native-time-slot-picker
# OR
yarn add @dgreasi/react-native-time-slot-picker

Usage

import * as React from 'react';
import { SafeAreaView, StatusBar } from 'react-native';
import {
  IAppointment,
  IAvailableDates,
  TimeSlotPicker,
} from '@dgreasi/react-native-time-slot-picker';
import { useEffect, useState } from 'react';

const availableDates: IAvailableDates[] = [
  {
    date: '2023-08-17T21:00:00.000Z', // new Date().toISOString()
    slotTimes: ['08:00-09:00', '09:00-10:00'], // Array<string> of time slots
  },
  {
    date: '2023-08-18T21:00:00.000Z',
    slotTimes: [], // No availability
  },
  {
    date: '2023-08-19T21:00:00.000Z',
    slotTimes: ['08:00-09:00', '09:00-10:00'],
  },
];

export default function App() {
  const [dateOfAppointment, setDateOfAppointment] =
    useState<IAppointment | null>(null);

  useEffect(() => {
    // Contains the selected date, time slot in the following format
    // {"appointmentDate": "2023-08-17T21:00:00.000Z", "appointmentTime": "18:00-19:00"}
    console.log('Date of appointment updated: ', dateOfAppointment);
  }, [dateOfAppointment]);

  return (
    <SafeAreaView>
      <StatusBar backgroundColor="transparent" barStyle="dark-content" />
      <TimeSlotPicker
        availableDates={availableDates}
        setDateOfAppointment={setDateOfAppointment}
      />
    </SafeAreaView>
  );
}

You can find a detailed example here.

Props

Prop nameDescriptionTypeDefault
setDateOfAppointmentA component to use on top of header image. It can also be used without header image to render a custom component as header.(data: IAppointment \| null) => voidREQUIRED
availableDatesThe array of the available slot times per date.IAvailableDates[]fixedAvailableDates
scheduledAppointmentAn already existed appointment, which is going to mark the specific date as with appointment.IAppointmentundefined
marginTopMargin top for the whole component.number0
datePickerBackgroundColorBackground color of the section with the horizontal scroll, which contains the days.hex string'#FFFFFF'
timeSlotsBackgroundColorBackground color of the section that contains the time slots.hex string'#FFFFFF'
timeSlotsTitleTitle of section that contains thestring'Select time'
mainColorMain color of the time slot pickerhex string'#04060A'
timeSlotWidthTime slot pill widthnumber96
dayNamesOverrideDay string array to override letters for each Calendar day. First day is Sunday.string[]['S', 'M', 'T', 'W', 'T', 'F', 'S']
monthNamesOverrideMonth string array to override default month names that are used as title.string[]['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']

Interfaces

NameDescription
IAvailableDates{ date: string, slotTimes: string[] }
IAppointment{ appointmentDate: string, appointmentTime: string }

Roadmap

  • Update scheduledAppointment arg to accept multiple appointments.
  • Update logic of getAppointmentDay() to show dot in dates.
  • Merge providers for performance improvement.

License

MIT