2.7.1 • Published 2 months ago

@imbios/datepicker v2.7.1

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
2 months ago

Datepicker Component for Chakra-UI

npm version License: Apache-2.0 All Contributors

A powerful and simple-to-use datepicker component for web applications, built with date-fns for date management and styled using Chakra-UI, a modular and accessible component library. This README provides all the necessary information to get started, customize the component, and contribute to its development.

Table of Contents

Prerequisites

To integrate the datepicker into your project, ensure you have date-fns and Chakra-UI installed. These libraries are essential for date management and UI styling, respectively.

bun add date-fns

Follow the installation guide for Chakra-UI here to complete the setup.

Installation and Usage

Once the prerequisites are installed, add the datepicker component to your project using:

bun add @imbios/datepicker

Below is an example showcasing how to integrate the datepicker into your application, using Chakra-UI's provider for theming:

TODO: Update below example with newest date library agnostic approach

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

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

  const handleSelectDate = values => setDates(values)

  return (
    <ChakraProvider theme={CalendarDefaultTheme}>
      <Calendar value={dates} onSelectDate={handleSelectDate}>
        <CalendarControls>
          <CalendarPrevButton />
          <CalendarNextButton />
        </CalendarControls>
        <CalendarMonths>
          <CalendarMonth>
            <CalendarMonthName />
            <CalendarWeek />
            <CalendarDays />
          </CalendarMonth>
        </CalendarMonths>
      </Calendar>
    </ChakraProvider>
  )
}

Note: This example displays the calendar without an input field. For integration with inputs and popovers, refer to this detailed example.

Customizing the Datepicker

Customize the Calendar component using Chakra-UI's extendTheme feature. Below is an example showing how to override the default theme:

import { extendTheme } from '@chakra-ui/react'
import { CalendarDefaultTheme } from '@imbios/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',
          },
        },
      },
    },
  },
})

Theming: Available Components Theme Keys

Key nameDescriptionParts
CalendarA multipart component this is reponsible for the calendar it self.calendar, months
CalendarMonthResponsible to style one month block.month, name, week, weekday, days
CalendarDayApplies styles to individual day. This is the only single part component.--
CalendarControlApplies styles to prev and next months.controls, button

License

This project is licensed under the Apache-2.0 License, allowing for wide use and contribution.

Contributors ✨

Thanks goes to these wonderful people (emoji key):

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

2.7.1

2 months ago

2.7.1-canary.1

3 months ago

2.7.1-canary.0

3 months ago

2.7.0

3 months ago

1.0.0

8 months ago