-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: RangeCalendar and refactor Calendar (#1529)
## π Changes - Refactor <Calendar /> - Create <RangeCalendar /> ## β Checklist Easy UI has certain UX standards that must be met. In general, non-trivial changes should meet the following criteria: - [x] Visuals match Design Specs in Figma - [x] Stories accompany any component changes - [x] Code is in accordance with our style guide - [x] Design tokens are utilized - [x] Unit tests accompany any component changes - [x] TSDoc is written for any API surface area - [x] Specs are up-to-date - [x] Console is free from warnings - [x] No accessibility violations are reported - [x] Cross-browser check is performed (Chrome, Safari, Firefox) - [x] Changeset is added ~Strikethrough~ any items that are not applicable to this pull request. --------- Co-authored-by: Kevin Liu <[email protected]>
- Loading branch information
1 parent
e9b952e
commit 7d77749
Showing
13 changed files
with
672 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@easypost/easy-ui": minor | ||
--- | ||
|
||
feat: RangeCalendar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
import React, { ReactNode, HTMLAttributes } from "react"; | ||
import { AriaButtonProps } from "react-aria"; | ||
import { VerticalStack } from "../VerticalStack"; | ||
import { Text } from "../Text"; | ||
import { CalendarState, RangeCalendarState } from "@react-stately/calendar"; | ||
import { RefObject } from "@react-types/shared"; | ||
import { DateValue } from "@react-types/calendar"; | ||
import { CalendarHeader } from "./CalendarHeader"; | ||
import { CalendarGrid } from "./CalendarGrid"; | ||
import styles from "./Calendar.module.scss"; | ||
|
||
export type CalendarBaseStateProps = { | ||
/** | ||
* The minimum allowed date that a user may select. | ||
*/ | ||
minValue?: DateValue | null; | ||
/** | ||
* The maximum allowed date that a user may select. | ||
*/ | ||
maxValue?: DateValue | null; | ||
/** | ||
* Whether the calendar is disabled. | ||
* @default false | ||
*/ | ||
isDisabled?: boolean; | ||
/** | ||
* Whether the calendar value is immutable. | ||
* @default false | ||
*/ | ||
isReadOnly?: boolean; | ||
/** | ||
* Callback that is called for each date of the calendar. If | ||
* it returns true, then the date is unavailable. | ||
*/ | ||
isDateUnavailable?: (date: DateValue) => boolean; | ||
/** | ||
* Whether the current selection is invalid according to application logic. | ||
*/ | ||
isInvalid?: boolean; | ||
/** | ||
* An error message to display when the selected value is invalid. | ||
*/ | ||
errorMessage?: ReactNode; | ||
/** | ||
* Display the days falling into the other months. | ||
* @default false | ||
*/ | ||
showDaysOutsideCurrentMonth?: boolean; | ||
}; | ||
|
||
type CalendarBaseProps = { | ||
state: CalendarState | RangeCalendarState; | ||
isInvalid?: boolean; | ||
showDaysOutsideCurrentMonth?: boolean; | ||
errorMessage?: ReactNode; | ||
calendarProps: HTMLAttributes<HTMLElement>; | ||
nextButtonProps: AriaButtonProps; | ||
prevButtonProps: AriaButtonProps; | ||
errorMessageProps: HTMLAttributes<HTMLElement>; | ||
calendarRef: RefObject<HTMLDivElement | null>; | ||
}; | ||
|
||
export function CalendarBase(props: CalendarBaseProps) { | ||
const { | ||
state, | ||
isInvalid, | ||
errorMessage, | ||
calendarProps, | ||
nextButtonProps, | ||
prevButtonProps, | ||
calendarRef, | ||
showDaysOutsideCurrentMonth, | ||
...restProps | ||
} = props; | ||
return ( | ||
<VerticalStack gap="1"> | ||
<div {...calendarProps} className={styles.Calendar} ref={calendarRef}> | ||
<CalendarHeader | ||
state={state} | ||
calendarProps={calendarProps} | ||
prevButtonProps={prevButtonProps} | ||
nextButtonProps={nextButtonProps} | ||
/> | ||
<CalendarGrid | ||
state={state} | ||
showDaysOutsideCurrentMonth={showDaysOutsideCurrentMonth} | ||
{...restProps} | ||
/> | ||
</div> | ||
{isInvalid && ( | ||
<Text color="negative.500" variant="caption"> | ||
{errorMessage} | ||
</Text> | ||
)} | ||
</VerticalStack> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.