Coder Social home page Coder Social logo

biko8 / chakra-dayzed-datepicker Goto Github PK

View Code? Open in Web Editor NEW

This project forked from aboveyunhai/chakra-dayzed-datepicker

0.0 0.0 0.0 1.99 MB

Chakra UI + Dayzed = datepicker

License: MIT License

JavaScript 0.83% TypeScript 97.82% HTML 1.36%

chakra-dayzed-datepicker's Introduction

A Simple Chakra Datepicker based on Dayzed.

npm version Downloads

Every individual component is using Chakra UI. So it should respect all Chakra UI Configs without problem.

The componenent itself has to use some date library

Highly recommend just copy/paste the source code from /src to customize however you want.

Install the dependency

Npm

npm i date-fns dayzed
npm i chakra-dayzed-datepicker

Yarn:

yarn add date-fns dayzed
yarn add chakra-dayzed-datepicker

Basic usage

Single

  const [date, setDate] = useState(new Date());
  
  <SingleDatepicker
    name="date-input"
    date={date}
    onDateChange={setDate}
  />

Range:

Note that this list will have one value during the selection process. Your system won't work if you try to control this directly as [startDate, endDate] because we'll try to set selectedDates to [intermediateSelection] and the length of the resulting selectedDates is meaningful to the datepicker.

  const [selectedDates, setSelectedDates] = useState<Date[]>([new Date(), new Date()]);
  
  <RangeDatepicker
    selectedDates={selectedDates}
    onDateChange={setSelectedDates}
  />

propsConfigs:

dateNavBtnProps extends from ButtonProps of Chakra-UI This allows you to override the default behavior however your want as long as supported by Chakra-UI.

dayOfMonthBtnProps = {
  defaultBtnProps,
  isInRangeBtnProp,
  selectedBtnProps,
  todayBtnProps
}

dayOfMonthBtnProps allows you to customzie date btn style based on the state.
Style precedence: default < isInRange < seleted < today.


Example:

  propsConfigs={{
    dateNavBtnProps: {
      colorScheme: "blue",
      variant: "outline"
    },
    dayOfMonthBtnProps: {
      defaultBtnProps: {
        borderColor: "red.300",
        _hover: {
          background: 'blue.400',
        }
      },
      isInRangeBtnProps: {
        color: "yellow",
      },
      selectedBtnProps: {
        background: "blue.200",
        color: "green",
      },
      todayBtnProps: {
        background: "teal.400",
      }
    },
    inputProps: {
      size: "sm"
    }
  }}

configs:

Non Chakra-related configurations :

  configs={{
    dateFormat: 'yyyy-MM-dd',
    dayNames: 'abcdefg'.split(''), // length of 7
    monthNames: 'ABCDEFGHIJKL'.split(''), // length of 12
    firstDayOfWeek: 2, // default is 0, the dayNames[0], which is Sunday if you don't specify your own dayNames,
  }}

other props:

Name Type Default value Description
name string undefined name attribute for <input /> element
usePortal boolean undefined to prevent parent styles from clipping or hiding content
defaultIsOpen boolean undefined open the date panel at the beginning
minDate Date undefined minimum date
maxDate Date undefined maximum date

For version < [email protected]:
dayOfMonthBtnProps extends from ButtonProps and has only selectedBg support,

  dayOfMonthBtnProps: {
    borderColor: "red.300",
    selectedBg: "blue.200",
    _hover: {
      bg: 'blue.400',
    }
  },

chakra-dayzed-datepicker's People

Contributors

abhishekmg avatar aboveyunhai avatar adobs avatar biko8 avatar david-morris avatar jcdogo 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.