GithubHelp home page GithubHelp logo

prefeitura-rio / calendariog20 Goto Github PK

View Code? Open in Web Editor NEW
0.0 3.0 1.0 1.97 MB

Home Page: https://prefeitura-rio.github.io/calendarioG20/

License: MIT License

TypeScript 91.52% HTML 1.91% CSS 5.15% JavaScript 1.42%

calendariog20'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

calendariog20's People

Contributors

lucastavarex avatar

Watchers

 avatar  avatar  avatar

Forkers

prefeitura-rio

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.