An open API service indexing awesome lists of open source software.

https://github.com/dirheimerb/headless-calendar


https://github.com/dirheimerb/headless-calendar

Last synced: 12 months ago
JSON representation

Awesome Lists containing this project

README

          

Headless calendar for react

# Headless calendar for react

A zero dependency library for react, with unstyled and controlled components to build your own agenda. Simple to use while allowing fully customization (markup is all yours!)

🔧 Flexible

✅ Controlled

🚀 Performant

🤯 Unstyled

↔️ Support for dragging and resizing events


## [📖 All examples and documentation here!](https://react-headless-calendar.vercel.app/)


## 🚧🚧 This repo is under heavy development 🚧🚧


Use your markup and custom logic to achieve virtually anything!

![full-example](./assets/full-example.gif)

A bit of [framer-motion](https://www.framer.com/motion/) was used to make the navigation look smooth - [See code](https://github.com/lucassaid/react-headless-agenda/blob/main/stories/full-examples/LimitIsTheSky.stories.tsx)


You can easily adapt it for mobile!

![vertical_example](./assets/vertical_example.gif)


# Installation

```bash
npm i react-headless-calendar
```

```bash
yarn add react-headless-calendar
```

```bash
pnpm add react-headless-calendar
```




# Usage

All examples use [date-fns](https://www.npmjs.com/package/date-fns) but you can use the library of your choice to manipulate dates.

## ``

Our parent component. Just provide a start day, and some events.

```tsx
import { startOfWeek, addHours } from 'date-fns'

// only `start` and `end` are required!
const events = [
{
id: 'event1',
someTitle: 'Hey there!',
start: new Date(),
end: addHours(new Date(), 5),
}
]

```

This is a controlled component. The agenda will NOT have an "inner" state in sync with `events` or `startDate`. Instead, it will fire an event for you to update your state when needed.


## ``

It lets you render whatever you need to, for each day. For example, let's render its name and number:

![days header](./assets/days_header.png)

```tsx
import { format } from 'date-fns';



{({ date }) => (

{format(date, 'ccc d')}

)}

;
```


Now the fun part, render your events!

![day](./assets/day.png)

```tsx
// `events` is an array containing only the events for the current day

{({ date, containerRef, events }) => (


{events.map(({ event, top, bottom }) => (

{event.someTitle}

))}

)}

```




That's it! You also have `

---

PR's are welcome!