GithubHelp home page GithubHelp logo

yasseralsaidi / date-range-picker-for-shadcn Goto Github PK

View Code? Open in Web Editor NEW

This project forked from johnpolacek/date-range-picker-for-shadcn

0.0 0.0 0.0 269 KB

DateRangePicker is a reusable component for shadcn using Radix UI and Tailwind CSS. Includes preset date ranges, text entry, calendar selection and date comparison

Home Page: https://date-range-picker-for-shadcn-demo.vercel.app/

License: MIT License

JavaScript 8.50% TypeScript 91.50%

date-range-picker-for-shadcn's Introduction

DateRangePicker Component

DateRangePicker is a reusable component built for Shadcn using beautifully designed components from Radix UI and Tailwind CSS. It provides a dropdown interface to allow users to select or enter a range of dates and includes additional options such as preset date ranges and an optional date comparison feature.

View the Demo

Installation

The DateRangePicker depends on the following components from shadcn:

If you are using the CLI for installation, you can do this:

npx shadcn-ui@latest add button calendar label popover switch

The DateRangePicker uses icons from Radix UI so you will need to install that or update the component to use a different library.

npm install @radix-ui/react-icons

Next, copy and paste the code from the /src directory for DateInput and DateRangePicker into your project and customize to your needs. The code is yours.

Props

Name Type Default Description
onUpdate function - Callback function that is called when the date range is updated. The function receives an object containing the selected date range and, if the compare feature is enabled, the compare date range.
initialDateFrom Date or string Today’s Date The initial start date for the main date range.
initialDateTo Date or string - The initial end date for the main date range.
initialCompareFrom Date or string - The initial start date for the compare date range.
initialCompareTo Date or string - The initial end date for the compare date range.
align string 'end' The alignment of the dropdown popover. Options are 'start', 'center', or 'end'.
locale string 'en-US' The locale used for date formatting.
showCompare boolean true Whether to show the compare date range feature.

Example

<DateRangePicker
  onUpdate={(values) => console.log(values)}
  initialDateFrom="2023-01-01"
  initialDateTo="2023-12-31"
  align="start"
  locale="en-GB"
  showCompare={false}
/>

This example creates a DateRangePicker component with an initial date range from January 1, 2023 to December 31, 2023. The dropdown popover is aligned to the start of the trigger button, the dates are formatted according to the 'en-GB' locale, and the compare feature is hidden. The onUpdate function logs the selected date range to the console.

date-range-picker-for-shadcn's People

Contributors

johnpolacek avatar johnpolacek-veg avatar wbsdickson 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.