Skip to content

Commit

Permalink
release: 1.0.5
Browse files Browse the repository at this point in the history
  • Loading branch information
hoangdevnull committed Aug 22, 2024
1 parent c63989a commit 51e8c9a
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 3 deletions.
2 changes: 1 addition & 1 deletion react-calendar-kit/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-calendar-kit",
"version": "1.0.4",
"version": "1.0.5",
"license": "MIT",
"main": "./dist/index.js",
"module": "./dist/index.mjs",
Expand Down
5 changes: 3 additions & 2 deletions react-calendar-kit/src/calendar/calendar-root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useLocale } from '@react-aria/i18n';
import { mergeProps } from '@react-aria/utils';
import { VisuallyHidden } from '@react-aria/visually-hidden';

import { cn, mergeStyles } from '../utils';
import { cn, mergeStyles, withAttr } from '../utils';
import Button from './button';
import { type CalendarHeaderLayout } from './calendar';
import { useCalendarContext } from './calendar-context';
Expand Down Expand Up @@ -120,6 +120,7 @@ const CalendarRoot = forwardRef((props: CalendarRootProps, ref: ForwardedRef<HTM
calendarProps?.style,
styles?.root
)}
data-picker-expanded={withAttr(isPickerExpanded)}
className={cn(className, classNames.root)}
ref={ref}
>
Expand Down Expand Up @@ -152,7 +153,7 @@ const CalendarRoot = forwardRef((props: CalendarRootProps, ref: ForwardedRef<HTM
onClick={() => state.focusNextPage()}
/>
</VisuallyHidden>
{footer}
{isPickerExpanded ? null : footer}
</div>
);
});
Expand Down
29 changes: 29 additions & 0 deletions website/src/docs/date-picker-with-time.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import React from 'react';
import { useDatePicker, type UseDatePickerProps } from 'react-calendar-kit';

import CalendarButton from './calendar-button';
import { CK } from './calendar-primitives';

const DatePickerWithTime = (props: UseDatePickerProps) => {
const { ref, state, getCalendarProps, getTimeInputProps, getDateInputProps, getDialogProps, getTriggerProps } =
useDatePicker(props);

return (
<div>
<CK.DateInput {...getDateInputProps} ref={ref} endContent={<CalendarButton {...getTriggerProps} />} />
{state.isOpen ? (
<div {...getDialogProps}>
<CK.Calendar
{...getCalendarProps}
visibleMonths={1}
weekdayStyle="short"
withPicker
footer={<CK.TimeInput {...getTimeInputProps} />}
/>
</div>
) : null}
</div>
);
};

export default DatePickerWithTime;
4 changes: 4 additions & 0 deletions website/src/pages/_meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
"title": "Date Picker",
"href": "/date-picker"
},
"date-picker-with-time": {
"title": "Date Picker With Time field ",
"href": "/date-picker-with-time"
},
"date-range-picker": {
"title": "Date Range Picker",
"href": "/date-range-picker"
Expand Down
78 changes: 78 additions & 0 deletions website/src/pages/date-picker-with-time.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
---
title: Date Picker
---

import DatePicker from '@/docs/date-picker-with-time';

# Date Picker

<div className="my-8">
<DatePicker />
</div>

DatePickers combine a `DateInput` and a `Calendar` to allow users to enter or select a date and time value.

For better customization we only expose the `useDatePicker` hook to let use have a free way to use your own styles

## API Reference

### TimeInput Props

| Property | Type | Description | Default |
| :---------------------- | :------------------------------------------------ | :----------------------------------------------------------------------------------------------------------------------------------: | ------: |
| label | `ReactNode` | The content to display as the label. | - |
| value | `DateValue` | The current value of the date input (controlled). | - |
| defaultValue | `DateValue` | The default value of the date input (uncontrolled). | - |
| placeholderValue | `DateValue` | A placeholder time that influences the format of the placeholder shown when no value is selected. Defaults current date at midnight. | - |
| minValue | `DateValue` | The minimum allowed date that a user may select. | - |
| maxValue | `DateValue` | The maximum allowed date that a user may select. | - |
| locale | `string` | The locale to display and edit the value according to. | - |
| errorMessage | `ReactNode \| (v: ValidationResult) => ReactNode` | An error message for the date input. | - |
| startContent | `ReactNode` | Element to be rendered in the left side of the date input. | - |
| endContent | `ReactNode` | Element to be rendered in the right side of the date input. | - |
| isRequired | `boolean` | Whether user input is required on the input before form submission. | `false` |
| isReadOnly | `boolean` | Whether the input can be selected but not changed by the user. | - |
| isDisabled | `boolean` | Whether the input is disabled. | `false` |
| isInvalid | `boolean` | Whether the input value is invalid. | `false` |
| createCalendar | `(name: string) => Calendar` | A function that creates a Calendar object for a given calendar identifier. | - |
| isDateUnavailable | `(date: DateValue) => boolean` | Callback that is called for each date of the calendar. If it returns true, then the date is unavailable. | - |
| autoFocus | `boolean` | Whether the element should receive focus on render. | `false` |
| hourCycle | `12` \| `24` | Whether to display the time in 12 or 24 hour format. This is determined by the user's locale. | - |
| granularity | `hour` \| `minute` \| `second` | Determines the smallest unit that is displayed in the date picker. Typically "day" for dates. | - |
| hideTimeZone | `boolean` | Whether to hide the time zone abbreviation. | `false` |
| shouldForceLeadingZeros | `boolean` | Whether to always show leading zeros in the month, day, and hour fields. | `true` |
| open | `boolean` | Open the calendar picker. | `-` |
| defaultOpen | `boolean` | Open the calendar picker for default - (uncountrolled). | `-` |
| onOpenChange | `(open: boolean) => void;` | Trigger when open state Change | `-` |
| dateInputProps | `DateInputProps` | Props to be passed to the time `DateInput` component. | `-` |
| calendarProps | `CalendarProps` | Props to be passed to the time `Calendar` component. | `-` |
| timeInputProps | `TimeInputProps` | Props to be passed to the time `TimeInput` component. | `-` |

## Usage

To use the `DatePicker` component, import `useDatePicker` from the library and use it like below.

```tsx
import React from 'react';
import { useDatePicker, type UseDatePickerProps } from 'react-calendar-kit';

import CalendarButton from './calendar-button';
import { CK } from './calendar-primitives';

const DatePicker = (props: UseDatePickerProps) => {
const { ref, state, getCalendarProps, getDateInputProps, getDialogProps, getTriggerProps } = useDatePicker(props);

return (
<div>
<CK.DateInput {...getDateInputProps} ref={ref} endContent={<CalendarButton {...getTriggerProps} />} />
{state.isOpen ? (
<div {...getDialogProps}>
<CK.Calendar {...getCalendarProps} visibleMonths={1} weekdayStyle="short" withPicker />
</div>
) : null}
</div>
);
};

export default DatePicker;
```

0 comments on commit 51e8c9a

Please sign in to comment.