Giter VIP home page Giter VIP logo

react-calendar-icon's Introduction

React Calendar Icon Badge

A date badge component in the shape of a familiar calendar icon with support for theming and localization.

Demo

npm install --save react-calendar-icon

Build Status

Usage

import React from "react";
import CalendarIcon from "react-calendar-icon";

export default function App(props) {
  return (
    <div>
      {/* ...  */}
      <CalendarIcon date={new Date()} />
    </div>
  );
}

Date formatting

The CalendarIcon component takes an optional prop options which can be used to adjust the way the date parts will be formatted. By default, the following configuration is used:

{
  header: { weekday: "long" },
  footer: { month: "long" },
  value: { day: "2-digit" },
  locale: []
}

The values for the header, footer and value sections of the icon are objects passed to (Date.prototype.toLocaleDateString())

import React from "react";
import CalendarIcon from "react-calendar-icon";

const dateOptions = {
  header: { weekday: "long" },
  footer: { month: "short" },
  value: { day: "2-digit" },
  locale: "nl"
};

export default function App(props) {
  return (
    <div>
      {/* ...  */}
      <CalendarIcon date={new Date()} options={dateOptions} />
    </div>
  );
}

Theming

It is possible to customize the look-and-feel of the icon by using a ThemeProvider component from styled-components. Add a calendarIcon member with the following attributes:

import React from "react";
import CalendarIcon from "react-calendar-icon";
import { ThemeProvider } from "styled-components";

const theme = {
  calendarIcon: {
    textColor: "white", // text color of the header and footer
    primaryColor: "#0da472", // background of the header and footer
    backgroundColor: "#fafafa"
  }
};

export default function App(props) {
  return (
    <ThemeProvider theme={theme}>
      {/* ...  */}
      <CalendarIcon date={new Date()} />
    </ThemeProvider>
  );
}

License

MIT

react-calendar-icon's People

Contributors

caub avatar deckstar avatar kkostov avatar renovate[bot] avatar

Stargazers

 avatar

Watchers

 avatar

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.