Git Product home page Git Product logo

react-google-calendar's Introduction

React Google Calendar

npm version Build Status

A react component that displays an event calendar using data from google's calendar api. It is intended to replace the embedded google calendar.

It handles reccuring events, deleted events, and changed events. It also handles and displays events of all lengths in a very similar way to google calendar and supports multiple calendars. All events are displayed in the user's timezone.

See it in action here or try it yourself in CodeSandbox here.

picture of calendar

Design inspired by this calendar and Google Calendar. Icons from Material Design.

Installation

1. npm install react react-dom @emotion/react
2. npm install @ericz1803/react-google-calendar

Usage

First, get an api key from here by following step 1.

Alternately, you can go to https://console.developers.google.com/flows/enableapi?apiid=calendar.

Then, get the calendar id from the google calendar. It will look something like [email protected].
You can find it by going to a calendar's settings and scrolling down to the section that is labelled Integrate calendar.

Basic Example

import React from "react";
import Calendar from "@ericz1803/react-google-calendar";

const API_KEY = "YOUR_API_KEY";
let calendars = [
  { calendarId: "YOUR_CALENDAR_ID" },
  {
    calendarId: "YOUR_CALENDAR_ID_2",
    color: "#B241D1", //optional, specify color of calendar 2 events
  },
];

class Example extends React.Component {
  render() {
    return (
      <div>
        <Calendar apiKey={API_KEY} calendars={calendars} />
      </div>
    );
  }
}

Properties

Parameter Type Description
apiKey string google api key (required)
calendars array of objects google calendar id and display color (required)
styles object styles (optional, see more below)
showArrow boolean shows arrow for events that span multiple months (optional, defaults to true)
showFooter boolean whether or not to show footer (optional, defaults to true)
language string Available options : EN, ES, PT, FR, SL, DE, PL, IS default: EN

Customization

You can customize the color of each calendar's events by specifying a color field with the calendar id (see examples).

To customize other aspects of the calendar (eg. borders, colors of the calendar), pass in a styles object. Each of the styles in the styles object should be an object style (the same as react inline styles) or an emotion css string style (see more here). If you choose to use emotion's css string styles, make sure to import { css } from "@emotion/react".

Style Keys

  • calendar
  • day
  • today
  • tooltip
  • event
  • eventText
  • eventCircle
  • multiEvent

Example With Customization

import React from "react";
import Calendar from "@ericz1803/react-google-calendar";
import { css } from "@emotion/react";

const API_KEY = "YOUR_API_KEY";
let calendars = [
  {
    calendarId: "[email protected]",
    color: "#B241D1",
  }, //add a color field to specify the color of a calendar
  { calendarId: "[email protected]" }, //without a specified color, it defaults to blue (#4786ff)
  {
    calendarId: "[email protected]",
    color: "rgb(63, 191, 63)",
  }, //accepts hex and rgb strings (doesn't work with color names)
];

let styles = {
  //you can use object styles (no import required)
  calendar: {
    borderWidth: "3px", //make outer edge of calendar thicker
  },

  //you can also use emotion's string styles
  today: css`
    /* highlight today by making the text red and giving it a red border */
    color: red;
    border: 1px solid red;
  `,
};

const language = "ES";

class Example extends React.Component {
  render() {
    return (
      <div>
        <Calendar
          apiKey={API_KEY}
          calendars={calendars}
          styles={styles}
          language={language}
        />
      </div>
    );
  }
}

Local Development

  1. git clone
  2. npm install
  3. npm run storybook // use storybook to test locally
  4. npm run build // build the project
  5. npm run test // run tests

License

MIT License

react-google-calendar's People

Contributors

blazejbatko avatar dependabot[bot] avatar diegorodriguez93 avatar ericz1803 avatar mikjori avatar selph avatar w1ckh3ad avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

react-google-calendar's Issues

Tooltip not working

When I click on a event, the tooltip does not appear. I see the following error in the console.
Any ideas?

image

TypeError: Cannot read properties of null (reading 'registered')

Hi Eric!

I would like to integrate my calendar into my app and I would like to use your solution, but I have a problem. When I run the application for the first time it works fine but after a refresh a nd later on, I got the following issue:

warn - ./node_modules/@ericz1803/react-google-calendar/dist/react-google-calendar.es.js
Module not found: Can't resolve './locale' in 'C:\git\MyRepo\node_modules@ericz1803\react-google-calendar\dist'

TypeError: Cannot read properties of null (reading 'registered')
at C:\git\MyRepo\node_modules@ericz1803\react-google-calendar\dist\react-google-calendar.umd.js:53:954
at C:\git\MyRepo\node_modules@ericz1803\react-google-calendar\dist\react-google-calendar.umd.js:52:2177
at renderWithHooks (C:\git\MyRepo\node_modules\react-dom\cjs\react-dom-server.browser.development.js:5658:16)
at renderForwardRef (C:\git\MyRepo\node_modules\react-dom\cjs\react-dom-server.browser.development.js:5842:18)
at renderElement (C:\git\MyRepo\node_modules\react-dom\cjs\react-dom-server.browser.development.js:6005:11)
at renderNodeDestructiveImpl (C:\git\MyRepo\node_modules\react-dom\cjs\react-dom-server.browser.development.js:6104:11)
at renderNodeDestructive (C:\git\MyRepo\node_modules\react-dom\cjs\react-dom-server.browser.development.js:6076:14)
at finishClassComponent (C:\git\MyRepo\node_modules\react-dom\cjs\react-dom-server.browser.development.js:5688:3)
at renderClassComponent (C:\git\MyRepo\node_modules\react-dom\cjs\react-dom-server.browser.development.js:5696:3)
at renderElement (C:\git\MyRepo\node_modules\react-dom\cjs\react-dom-server.browser.development.js:5943:7)

Do you have any idea whats the problem?

This is my packet.json dependencies:
"dependencies": { "@emotion/react": "^11.11.1", "@ericz1803/react-google-calendar": "^4.3.1", "@material-ui/core": "4.11.4", "@material-ui/icons": "^4.11.3", "classnames": "2.3.2", "moment": "2.29.4", "next": "12.2.5", "nouislider": "14.7.0", "prop-types": "15.8.1", "react": "^18.2.0", "react-datetime": "3.1.1", "react-dom": "^18.2.0", "react-slick": "0.29.0", "sass": "1.66.1", "styled-components": "5.3.5", "webpack": "5.88.2" }

calendar is empty

Hi, I've added the calendar and using the calendarId my gmail address, when I opened the calendar is render correctly but with no tasks, I'm pretty sure that the calendarId is correct because I can see in my google calendar configuration

image

also, if I clicked on "Add Calendar" in the bottom right corner, this goes to the google calendar site and display correctly my tasks.

is there any way to debug this?...I can't see any error log...

thank you

I'm using NextJS 14

Does not work with react 17

npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: [email protected]
npm ERR! Found: [email protected]
npm ERR! node_modules/react
npm ERR! react@"^17.0.2" from the root project
npm ERR! peer react@">=16.8.0" from @emotion/[email protected]
npm ERR! node_modules/@emotion/react
npm ERR! @emotion/react@"^11.4.1" from the root project
npm ERR! peer @emotion/react@"^11.1.1" from @ericz1803/[email protected]
npm ERR! node_modules/@ericz1803/react-google-calendar
npm ERR! @ericz1803/react-google-calendar@"" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer react@"^16.14.0" from @ericz1803/[email protected]
npm ERR! node_modules/@ericz1803/react-google-calendar
npm ERR! @ericz1803/react-google-calendar@"
" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR!

New Language

Hi Eric!

I love your calendar, can I send a PR with Spanish and a new prop to handle the language?

make days square

Yo thanks for the calendar it's pretty sick.

is it possible to add a simple way to make the calendar days square? changing aspect ration for the day key using styles prop breaks the layout it would be lovely to have an easy way to do that the squished days on mobile does not look good.

thanks!

Week view, filter calendar and tooltip.

I wonder if is possible to display the Week view calendar and if is possible to filter the events for each calendar created ?, And I have an issue with the tooltip, it never displays when I click on the event.

Tooltip not working

When I click on an even, the tooltip / pop-up does not open up.

How do you implement the tooltip?

Support for Next.js

It would be awesome if this component could support Next.js.
It doesn't work right now because this module is importing CSS from node_modules, which Next.js "cannot support".

I've been looking for a Google Calendar component for Next.js for quite a while now, and this one looks really nice. Too bad i can't use it =(

RU lang

,
RU: {
MONTHS: ["Январь", "Февраль", "Март", "Апрель", "Май", "Июнь", "Июль", "Август", "Сентябрь", "Октябрь", "Ноябрь", "Декабрь"],
DAYS: ["Вс", "Пн", "Вт", "Ср", "Чт", "Пт", "Сб"]
}

Add pls

Typo line 670 @index.js

Hi! I would like to say thank you for this module. It helps a lot.

Using v3 found a typo forgot to add '_' at new newEvent variable causing a undefined error

DE: Wrong weekday for date

When I switch the language from default (EN) to german (DE), the days at the top switch to it's expected position (in germany the first day of the week is monday), but the days from the month itself don't move. If 1st of Jan 2023 is a sunday in EN calendar, then it's a monday in DE calendar.

Usually you can choose "the first day of the week" to switch manually between monday and sunday, but I haven't found that option in this module.

lang-en-de

Unsupported RFC prop EXDATE

Hello
I was trying to implement your lib for nodejs.dev's new calendar.
I'm getting an unsupported error message any plans to support EXDATE?
The calendar id for nodejs.org is [email protected]

When I try the request with curl and my API key it works as expected with a 200 and a json response
curl https://www.googleapis.com/calendar/v3/calendars/[email protected]/events?key=key

parsestring.js:39 Uncaught Error: Unsupported RFC prop EXDATE in EXDATE;TZID=America/New_York:20171207T120000
    at parseLine (parsestring.js:39)
    at Array.map (<anonymous>)
    at Function.parseString (parsestring.js:7)
    at Function.getDatesFromRRule (index.js:753)
    at index.js:502
    at Array.forEach (<anonymous>)
    at Calendar.getRenderEvents (index.js:497)
    at Calendar.getRenderEvents (react-hot-loader.development.js:717)
    at Calendar.render (index.js:721)
    at finishClassComponent (react-dom.development.js:17161)
    at updateClassComponent (react-dom.development.js:17111)
    at beginWork (react-dom.development.js:18621)
    at HTMLUnknownElement.callCallback (react-dom.development.js:189)
    at Object.invokeGuardedCallbackDev (react-dom.development.js:238)
    at invokeGuardedCallback (react-dom.development.js:293)
    at beginWork$1 (react-dom.development.js:23204)
    at performUnitOfWork (react-dom.development.js:22155)
    at workLoopSync (react-dom.development.js:22131)
    at performSyncWorkOnRoot (react-dom.development.js:21757)
    at react-dom.development.js:11090
    at unstable_runWithPriority (scheduler.development.js:653)
    at runWithPriority$1 (react-dom.development.js:11040)
    at flushSyncCallbackQueueImpl (react-dom.development.js:11085)
    at flushSyncCallbackQueue (react-dom.development.js:11073)
    at scheduleUpdateOnFiber (react-dom.development.js:21200)
    at Object.enqueueSetState (react-dom.development.js:12640)
    at Calendar../node_modules/react/cjs/react.development.js.Component.setState (react.development.js:471)
    at Calendar._callee$ (index.js:193)
    at tryCatch (runtime.js:45)
    at Generator.invoke [as _invoke] (runtime.js:274)
    at Generator.prototype.<computed> [as next] (runtime.js:97)
    at asyncGeneratorStep (asyncToGenerator.js:3)
    at _next (asyncToGenerator.js:25)

Duplicate event

I'm having a duplication on my tested event in my React webpage, does anyone else experiencing this ?

Screen Shot 2022-10-04 at 10 35 33 AM

Cannot import this package due to missing types from `package.json#exports`

In a fresh NextJS project (14.3.2, pages router), I received an error that stated that the TypeScript compiler "could find types", but the package.json file did not export the "types" correctly.

View screenshot of error image

From my research the exports field supports a types field which can point to the types/index.d.ts file. I have an attempt in #72 but I wasn't confident in my abilities regarding typing a pre-built library, so I closed the PR in favor of an issue. Happy to help bugtest if you happen to know what is needed here.

Wrong event in wrong day

I set a time on January 1st, 2024, using Google Calendar. Then I changed this time to December 31st, 2023. However, after the modification, when viewed through the component, the time shifted to January 31st, 2024. But in Google Calendar, it shows as December 31st, 2023.

Getting a warning about importing 'trace' and Calendar import not working with next.js and typescript

I've installed @ericz1803/react-google-calendar through yarn.

Importing with import Calendar from "@ericz1803/react-google-calendar"; gives the warning JSX element type 'Calendar' does not have any construct or call signatures. However, the code still runs fine.
const Calendar = require('@ericz1803/react-google-calendar'); gives no warning, and also runs fine.
Is there any known errors when using Calendar with next.js and typescript?

Furthermore, when I run the code, this warning message appears for both the above import scenarios:

- warn ./node_modules/@ericz1803/react-google-calendar/dist/react-google-calendar.es.js
Module not found: Can't resolve './locale' in 'C:\Users\user\OneDrive\Documents\GitHub\Project\node_modules\@ericz1803\react-google-calendar\dist'   

Import trace for requested module:
./node_modules/@ericz1803/react-google-calendar/dist/react-google-calendar.es.js

Any idea why it is asking for trace, or how to fix it?

All Day events

How do we show all day events that span multiple days?

It seems that unless an event has a start and end time it won't show up on the calendar.

Module not found: Error: Can't resolve './locale' in

Hi @ericz1803, thanks for the awesome project.

We are using this component inside an mdx file using docusaurus. When running the build step, we are getting
the following errors:

[WARNING] {"moduleIdentifier":"/Users/gpenacastellanos/Desktop/develop/conda-forge/conda-dot-org/node_modules/@ericz1803/react-google-calendar/dist/react-google-calendar.es.js","moduleName":"./node_modules/@ericz1803/react-google-calendar/dist/react-google-calendar.es.js","loc":"2699:33-51","message":"Module not found: Error: Can't resolve './locale' in '/Users/gpenacastellanos/Desktop/develop/conda-forge/conda-dot-org/node_modules/@ericz1803/react-google-calendar/dist'","compilerPath":"client"}

[WARNING] {"moduleIdentifier":"/Users/gpenacastellanos/Desktop/develop/conda-forge/conda-dot-org/node_modules/@ericz1803/react-google-calendar/dist/react-google-calendar.es.js","moduleName":"./node_modules/@ericz1803/react-google-calendar/dist/react-google-calendar.es.js","loc":"2699:33-51","message":"Module not found: Error: Can't resolve './locale' in '/Users/gpenacastellanos/Desktop/develop/conda-forge/conda-dot-org/node_modules/@ericz1803/react-google-calendar/dist'","compilerPath":"server"}

I saw this issue #60, that seems related. Not sure what has changed recently 🤔

Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.