GithubHelp home page GithubHelp logo

l2develop96 / datepicker Goto Github PK

View Code? Open in Web Editor NEW

This project forked from uselessdev/datepicker

0.0 0.0 0.0 1.47 MB

A simple datepicker with Chakra-UI and date-fns

Home Page: https://uselessdev-datepicker.netlify.app

License: Other

JavaScript 2.17% TypeScript 97.83%

datepicker's Introduction

Datepicker

All Contributors

A simple datepicker component build with date-fns and Chakra-UI.

Table of Contents

Requisites

You need to install date-fns and chakra-ui in order to use this library.

yarn add date-fns

To install chakra-ui follow their guide here.

Installation and Usage

After install these dependencies you can now install the library and use this as below:

yarn add @uselessdev/datepicker

Before to use this you can create your own theme or use the default one.

import { ChakraProvider } from '@chakra-ui/react'
import {
  Calendar,
  CalendarDefaultTheme,
  CalendarControls,
  CalendarPrevButton,
  CalendarNextButton,
  CalendarMonths,
  CalendarMonth,
  CalendarMonthName,
  CalendarWeek,
  CalendarDays,
} from '@uselessdev/datepicker'

export function App() {
  const [dates, setDates] = useState()

  const handleSelectDate = (values) => setDates(values)

  return (
    return (
      <ChakraProvider theme={CalendarDefaultTheme}>
        <Calendar value={dates} onSelectDate={handleSelectDate}>
          <CalendarControls>
            <CalendarPrevButton />
            <CalendarNextButton />
          </CalendarControls>

          <CalendarMonths>
            <CalendarMonth>
              <CalendarMonthName />
              <CalendarWeek />
              <CalendarDays />
            </CalendarMonth>
          </CalendarMonths>
        </Calendar>
      </ChakraProvider>
    )
  )
}

note that the example above doens't render an input but only the calendar

If you want to use this with inputs and a popover you can see this example

Customizing

You can fully customize the Calendar component using the extendTheme provided by chakra-ui, you can see an example below.

In your theme you can overrides the default theme (you can see all available components keys for theme customization here)

import { extendTheme } from '@chakra-ui/react'
import { CalendarDefaultTheme } from '@uselessdev/datepicker'

export const theme = extendTheme(CalendarDefaultTheme, {
  components: {
    Calendar: {
      parts: ['calendar'],

      baseStyle: {
        calendar: {
          borderWidth: '6px',
          borderColor: 'pink.400',
          rounded: 'none',
          shadow: 'none',
          boxShadow: '32px 16px 0 6px #3B4DCC'
        },
      },
    },

    CalendarControl: {
      parts: ['button'],

      baseStyle: {
        button: {
          h: 6,
          px: 2,
          rounded: 'none',
          fontSize: 'sm',
          color: 'white',
          bgColor: 'pink.400',

          _hover: {
            bgColor: 'pink.200',
          },

          _focus: {
            outline: 'none',
          },
        },
      },
    }
  },
})

Now you can use this theme in ChakraProvider:

import { ChakraProvider } from '@chakra-ui/react'
import { theme } from './theme'

function App() {
  return (
    <ChakraProvider theme={theme}>
      {/* children... */}
    </ChakraProvider>
  )
}

Theses changes will produce the following results in Calendar:

Customized calendar

Available components theme keys

Key name Description Parts
Calendar A multipart component this is reponsible for the calendar it self. calendar, months
CalendarMonth Responsible to style one month block. month, name, week, weekday, days
CalendarDay Applies styles to individual day. This is the only single part component. --
CalendarControl Applies styles to prev and next months. controls, button

License

This code is under the Apache-2.0 License

Contributors โœจ

Thanks goes to these wonderful people (emoji key):

Wallace Batista
Wallace Batista

๐Ÿ’ป ๐Ÿค”
Leonardo Elias
Leonardo Elias

๐Ÿ’ป
kivi
kivi

๐Ÿ’ป
Guilherme Teixeira
Guilherme Teixeira

๐Ÿ’ป
Brano Zavracky
Brano Zavracky

๐Ÿ’ป
O. Qudah
O. Qudah

๐Ÿ“–
Tom Chen
Tom Chen

๐Ÿ“– ๐Ÿ’ป
Alexandre Stahmer
Alexandre Stahmer

๐Ÿ’ป
Raphael da Rocha Pinto Barboza
Raphael da Rocha Pinto Barboza

๐Ÿ’ป
Greg Leuch
Greg Leuch

๐Ÿ’ป

This project follows the all-contributors specification. Contributions of any kind welcome!

datepicker's People

Contributors

uselessdev avatar allcontributors[bot] avatar tomchentw avatar astahmer avatar leonardoelias avatar branikclimbs avatar curiouslycory avatar gleuch avatar ggteixeira avatar basicpixel avatar raphaelrochap avatar kivi 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.