2.1.1 • Published 8 months ago

react-draggable-selector v2.1.1

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

🖍 React-Draggable-Selector

Select with a simple drag!

React-Draggable-Selector is a react component that allows users to easily select time ranges by dragging.

This package is for react applications, and uses @emotion for styling and dayjs for date and time management. Its main advantages are its intuitive drag-to-select functionality. You can select a time zone by day of the week or by date. Let's get started!

Live example & Document

Go Live Example

You can learn how to use it directly in the document.

🚀 Quick Start

1. Installation

Use npm package manager to install

$ npm install react-draggable-selector

or install with yarn

$ yarn add react-draggable-selector

2. Usage

Take out the component in your React project.

1. When using Javascript:

import { useState } from 'react';
import { DraggableSelector } from "react-draggable-selector";

function App () {
  const [dates, setDates] = useState([]);  // Should inject sorted, not duplicated Date[]
  const [times, setTimes] = useState([]);

  return (
    <DraggableSelector
      minTime={9}              // required
      maxTime={14}             // required
      dates={dates}            // required, required default: []
      timeSlots={times}        // required, required default: []
      setTimeslots={setTimes}  // required
    />
  );
};

export default App;

2. When using Typescript:

import { useState } from 'react';
import { DraggableSelector, TimeSlot } from "react-draggable-selector";

/*
interface TimeSlot {
  day: number;
  date: string;
  minTime: string;  // '09:00', '14:00'
  maxTime: string;  // '09:30', '14:30'
}
*/

function App () {
  const [dates, setDates] = useState<Date[]>([]);  // Should inject sorted, not duplicated Date[]
  const [times, setTimes] = useState<TimeSlot[]>([]);

  return (
    <DraggableSelector
      minTime={9}              // required, type: 'number'
      maxTime={14}             // required, type: 'number'
      dates={dates}            // required, type: 'Date[]', required default: []
      timeSlots={times}        // required, type: 'TimeSlot[]', required default: []
      setTimeslots={setTimes}  // required, type: 'React.Dispatch<React.SetStateAction<TimeSlot[]>>'
    />
  );
};

export default App;

3. Props

3.1. Required Props

Name (Prop)TypeDescriptionDefault valueRequired
datesDate[]Selected dates, you can making a selection for that date. Required default value is []-✔️
minTimenumberThe start time to display. Type it in 24-hour notation and write it as follows, 9-✔️
maxTimenumberThe last time to display. Type it in 24-hour notation and write it as follows, 18-✔️
timeSlotsTimeSlot[]Array of selected time cells. You can also convert the information from output into a Date object and use it.-✔️
setTimeSlotsReact.Dispatch<React.SetStateAction<TimeSlot[]>>The setState function of the selectedTimeSlots.-✔️

3.2. Optional Props

Name (Prop)TypeDescriptionDefault valueRequired
timeUnit5 | 10 | 15 | 20 | 30 | 60The time interval for the selector. The amount of time a cell has.30
dateFormatstringUse the date format method of dayjs. You can use the following link to set the formatting form. (https://day.js.org/docs/en/display/format)'M.D'
timeFormatstringUse the time format method of dayjs. You can use the following link to set the formatting form. (https://day.js.org/docs/en/display/format)'HH:mm A'
mode'date' | 'day'Decide whether to indicate all dates or by day of the week. (In the day version) If there is no day of the week corresponding to the selected date, the cell is blocked so that it cannot be selected.'day'
slotWidthnumberThe width of each slot. Assign the value in number.62
slotHeightnumberThe height of each slot. Assign the value in number.18
slotsMarginTopnumberThe margin-top of slots container. Assign the value in number.11
slotsMarginLeftnumberThe margin-left of slots container. Assign the value in number.20
maxWidthstringThe max-width of selector. Assign the value in string. e.g. 536px'546px'
maxHeightstringThe max-height of selector. Assign the value in string. e.g. 452px, 100%'452px'
defaultSlotColorstringThe default color of each slot. Assign the value in string. e.g. #FFFFFF'#FFFFFF'
selectedSlotColorstringThe color of each slot when it is selected. Assign the value in string. e.g. #FFF5E5'#b3c6d3'
disabledSlotColorstringThe color of each slot when it is disabled. Assign the value in string. e.g. #e1e1e1'#e1e1e1'
hoveredSlotColorstringThe color of each slot when it is hovered. Assign the value in string. e.g. #FFF5E5'#eef2f6'
slotsContainerBorderstringThe border of slots container. Assign the value in string. e.g. 1px solid #8c8d94'1px solid #8c8d94'
slotsContainerBorderRadiusstringThe border-radius of slots container. Assign the value in string. e.g. 0px, 5px'0px'

License

The MIT License.

Contribution & Issues & Bug report

Always welcome! I would appreciate it if you could leave it as an issue in the repository.

2.1.1

8 months ago

2.1.0

8 months ago

2.0.1

8 months ago

2.0.0

8 months ago

1.1.3

8 months ago

1.1.2

8 months ago

1.1.1

8 months ago

1.1.0

8 months ago

1.0.0

9 months ago

0.0.7

9 months ago

0.0.6

9 months ago

0.0.5

9 months ago

0.0.4

9 months ago

0.0.3

9 months ago

0.0.2

9 months ago

0.0.1

9 months ago