npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

simple-date-range-calendar

v2.0.7

Published

A React date range calendar component

Downloads

641

Readme

React Date Range Calendar

React Date Range Calendar is a flexible and customizable date range calendar component for React applications. This library allows you to easily select date ranges with an intuitive interface, offering several themes out-of-the-box with full support for creating your own themes. You can also customize the appearance directly via props such as borderRadius and width.

Installation

Install the library using npm or yarn:

npm install simple-date-range-calendar
# or
yarn add simple-date-range-calendar

Basic Usage (No Theme)

If you prefer not to use a theme, you can directly use the Calendar component as shown below. The component will use the default Material UI styles.

import React from 'react';
import { Calendar } from 'simple-date-range-calendar';

const App = () => {
  return (
    <div>
      <Calendar startDate={new Date()} endDate={new Date()} />
    </div>
  );
};

export default App;

Usage with Theme

The calendar component supports optional theming via the ThemeProvider from Material UI. Here's how to use the Calendar component with theming:

import React from 'react';
import { ThemeProvider } from '@mui/material';
import { Calendar, lightTheme } from 'simple-date-range-calendar';

const App = () => {
  return (
    <ThemeProvider theme={lightTheme}>
      <Calendar startDate={new Date()} endDate={new Date()} />
    </ThemeProvider>
  );
};

export default App;

Props

The Calendar component accepts the following props:

| Prop | Type | Description | | ----------------------- | ---------------------------------------------------------- | ---------------------------------------------------------------------- | | startDate | Date \| null | Optional. The starting date of the selected range. Defaults to null. | | endDate | Date \| null | Optional. The ending date of the selected range. Defaults to null. | | onDateRangeChange | (startDate: Date \| null, endDate: Date \| null) => void | Optional. Callback triggered whenever the date range changes. | | onDateRangeIsSelected | (startDate: Date, endDate: Date) => void | Optional. Callback triggered when the date range is fully selected. | | styles | object | Optional. Custom styles like borderRadius and width. | | styles.borderRadius | number | Optional. Border radius of the calendar. Defaults to 25. | | styles.width | number \| string | Optional. Width of the calendar. Defaults to 280px. |

Example of Custom borderRadius and width

You can customize the appearance by passing a styles prop to modify the borderRadius and width of the calendar:

import React from 'react';
import { Calendar } from 'simple-date-range-calendar';

const App = () => {
  return (
    <Calendar
      startDate={new Date()}
      endDate={new Date()}
      styles={{ borderRadius: 15, width: 350 }}
    />
  );
};

export default App;

Themes

The library provides several themes out-of-the-box. A theme in this library uses the standard Material UI theming system.

Available Default Themes

You can use any of the following default themes:

  • Pink Theme
  • Royal Blue Theme
  • Green Theme
  • Light Theme
  • Dark Theme

Using Default Themes

Here’s how to use one of the default themes with the calendar:

import React from 'react';
import { ThemeProvider } from '@mui/material';
import { Calendar, royalBlueTheme } from 'simple-date-range-calendar';

const App = () => {
  return (
    <ThemeProvider theme={royalBlueTheme}>
      <Calendar startDate={new Date()} endDate={new Date()} />
    </ThemeProvider>
  );
};

export default App;

Extending an Existing Theme

You can extend any of the predefined themes by using Material UI's createTheme and deepmerge utilities. Here’s an example of how to extend the Royal Blue Theme and override just the background and text colors:

import { createTheme } from '@mui/material';
import { deepmerge, royalBlueTheme } from '@mui/utils';

const customTheme = createTheme(
  deepmerge(royalBlueTheme, {
    palette: {
      background: {
        default: '#f0f0f0', // New default background color
        paper: '#ffffff', // New paper background color
      },
      text: {
        primary: '#123456', // New primary text color
      },
    },
  }),
);

Full Example with Theme Selector

Here is a full example that includes multiple themes and allows you to switch between them dynamically:

import { useState } from 'react';
import { Container, Typography, Box, ThemeProvider } from '@mui/material';
import {
  Calendar,
  darkTheme,
  greenTheme,
  lightTheme,
  pinkTheme,
  royalBlueTheme,
} from 'simple-date-range-calendar';
import { addDays } from 'date-fns';

const themes = [
  { name: 'Pink', theme: pinkTheme },
  { name: 'Royal Blue', theme: royalBlueTheme },
  { name: 'Green', theme: greenTheme },
  { name: 'Light', theme: lightTheme },
  { name: 'Dark', theme: darkTheme },
];

const App = () => {
  const [themeIndex, setThemeIndex] = useState(0);
  const currentTheme = themes[themeIndex].theme;

  return (
    <ThemeProvider theme={currentTheme}>
      <Box
        sx={{
          minHeight: '100vh',
          display: 'flex',
          flexDirection: 'column',
          justifyContent: 'center',
          alignItems: 'center',
          backgroundColor: currentTheme.palette.background.default,
        }}
      >
        <Typography variant="h2" color={currentTheme.palette.text.secondary}>
          {themes[themeIndex].name}
        </Typography>
        <Container maxWidth="sm" sx={{ textAlign: 'center', mt: 4 }}>
          <Calendar startDate={addDays(new Date(), -15)} endDate={new Date()} />
        </Container>
      </Box>
    </ThemeProvider>
  );
};

export default App;

License

This project is licensed under the MIT License. See the LICENSE file for more details.