• Stars
    star
    164
  • Rank 228,598 (Top 5 %)
  • Language
    TypeScript
  • License
    Other
  • Created almost 3 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A simple datepicker with Chakra-UI and date-fns

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!

More Repositories

1

expressive

A simple and small boilerplate for NodeJS with Express
JavaScript
16
star
2

react-gmaps

Wrapper component to gmaps
JavaScript
9
star
3

next-starter

A nextjs starter with chakra-ui, typescript and pwa settings.
TypeScript
6
star
4

bookshelf

A small graphql server build with TypeScript, ApolloServer with Node interface
TypeScript
5
star
5

mfe

microfronend example
JavaScript
5
star
6

exemplo-react-redux

JavaScript
3
star
7

balance

TypeScript
3
star
8

react-forms-examples

JavaScript
3
star
9

next-rss

A simple package for create RSS to a markdown based blog.
TypeScript
3
star
10

simple-calendar

A simple calendar with moment and css grid.
JavaScript
2
star
11

bookr

Repo pra acompanhar a série de artigos sobre GraphQL.
TypeScript
2
star
12

fc-video-catalog-laravel

PHP
1
star
13

iamwallace

Supposed to be my newsite
TypeScript
1
star
14

fullcycle-grpc

Go
1
star
15

fullcycle-docker-node

JavaScript
1
star
16

fullcycle-docker-challenge

:code:
Dockerfile
1
star
17

lojinha-current

client application
TypeScript
1
star
18

microfrontend-first-example

JavaScript
1
star
19

iamlistening

Uma aplicação simples pra testar o Netlify Functions.
JavaScript
1
star
20

go-cards

Learning Go
Go
1
star
21

superstore

Vamo criar um e-commerce.
TypeScript
1
star
22

graphql-relay-spec

This repo is just for study, I'm trying to implement a graphql server using relay-spec but it's hard as hell 😭
JavaScript
1
star
23

github-user-search

Uma aplicação simples pra buscar usuários e seus repositórios do github.
TypeScript
1
star
24

dotfiles

My personal dotfiles
Shell
1
star
25

action-rpg

Companion repository for https://www.youtube.com/playlist?list=PL9FzW-m48fn2SlrW0KoLT4n5egNdX-W9a
GDScript
1
star
26

rust-guessing-game

just learning 🦀
Rust
1
star
27

parser

css parser to transform inline style to classes
JavaScript
1
star
28

react-native-animations

estudando um pouco de animações com coisas nativas do RN 🤔
JavaScript
1
star