1.3.3 • Published 3 years ago

react-pick-calendar v1.3.3

Weekly downloads
40
License
MIT
Repository
github
Last release
3 years ago

npm

react-pick-calendar

A scrollable calendar with no division into months for React App.

Allows you to select dates and view information about dates

install and import

Install by executing npm i react-pick-calendar

Import by adding import Calendar from 'react-pick-calendar';

Use by adding <Calendar/>

terms

fDate - date string in YYYY-MM-DD format

busy - busy day color (red)

pick - picked day color (green)

days - Object containing properties fDate and Any values

day becomes busy

daysOff - Array containing fDate

day becomes busy

daysPick - Array containing fDate

day becomes pick

Calendar object - Object, the expected properties: days, daysOff, daysPick

const calendarObject = {
    days: {
        fDate: Any,
        fDate: Any,
        ...
    },
    daysOff: [fDate, fDate, ...],
    daysPick: [fDate, fDate, ...]
};

props

nametypedefaultdescription
editboolfalsetrue allow to edit daysPick
noOffsetboolfalsetrue cancel displaying the calendar from the first date in daysPick, if exist
getfuncLazy loading async function that to receives a content from the backend. It gets the Date objects - start and end. Should return a Calendar object
onChangefunc(daysPick, changedDays, pick) => {}A function after daysPick handle change
onDayobj{}An object with functions that provide to each Day: onMouseOver, onContextMenu, onTouchHold. Each function receives Day's information and the Date object.
maxPicknumber366Maximum size of daysPick
onErrorfuncA function executing in any error case
contentobjexternal Store
setContentfuncexternal Dispatch
triggerGetanyTrigger starting Get-function hook
triggerNewanyTrigger starting rerender hook
startDatestrfDate, the calendar first date. Otherwise infinite scrolling to past
endDatestrfDate, the calendar last date. Otherwise infinite scrolling to future

onChange

A function that receives variables after every handle change daysPick:

  • daysPick: fDate, fDate, ... - new daysPick property of Calendar object
  • changedDays: fDate, fDate, ... - array of changed dates
  • pick: bool - if true, changed days became pick, if false - otherwise

onDay

An object with functions that provide to each Day:

  • onMouseOver
  • onContextMenu
  • onTouchHold (combine of touchEvents)

Each function receives variables from Day component:

  • DOM element
  • Day's information - value form calendarObject.days[fDate]
  • date: Date object
  • dayOff: bool - true if calendarObject.daysOff includes this Day

Only defined functions will be executed.

function yourFunction(element, info, date, dayOff) {
    // your code
};

const onDay = {
    onMouseOver: action,
    onContextMenu: action,
    onTouchHold: action
};

external Store

You can convert this component to uncontrolled and use any external store.

content - store with Calendar object where each Array replaced by Set:

const content = {
    days: {
        fDate: Any,
        fDate: Any,
        ...
    },
    daysOff: new Set([fDate, fDate, ...]),
    daysPick: new Set([fDate, fDate, ...])
};

If setContent is undefined, content is the initial state for internal storage

setContent - dispatch, that receives a function that convert previous content to new content. It is working like setState(prevState => {}) from React.useState hook.

Example with React.useState hook:

import React from "react";
import Calendar from 'react-pick-calendar';

function MyComponent() {
    const [state, setState] = React.useState({
        days: {},
        daysOff: new Set(),
        daysPick: new Set()
    });

    return (<Calendar content={state} setContent={setState} />);
}

Example with MobX:

import React from "react";
import ReactDOM from "react-dom";
import { makeAutoObservable } from "mobx";
import { observer } from "mobx-react-lite";
import Calendar from 'react-pick-calendar';

class Store {
    state = {
        days: {},
        daysOff: new Set(),
        daysPick: new Set()
    }

    constructor() {
        makeAutoObservable(this)
    }

    setState(func) {
        this.state = func(this.state)
    }
}

const calendarStore = new Store();
const CalendarView = observer(({ store }) => <Calendar content={store.state} setContent={(func) => store.setState(func)} />);
ReactDOM.render(<CalendarView store={calendarStore} />, document.getElementById('root');
1.3.3

3 years ago

1.3.2

3 years ago

1.3.1

3 years ago

1.3.0

3 years ago

1.2.2

3 years ago

1.2.1

3 years ago

1.2.0

3 years ago

1.1.11

3 years ago

1.1.9

3 years ago

1.1.10

3 years ago

1.1.8

3 years ago

1.1.7

3 years ago

1.1.6

3 years ago

1.1.5

3 years ago

1.1.4

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.1.3

3 years ago

1.1.2

3 years ago

1.0.10

3 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago