-
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: DatePicker and DateRangePicker (#1544)
## π Changes - Fix calendar styles - Add DatePicker and DateRangePicker ## β Checklist Easy UI has certain UX standards that must be met. In general, non-trivial changes should meet the following criteria: - [ ] ~Visuals match Design Specs in Figma~(There is no design spec) - [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
bc670f5
commit 15a0b00
Showing
22 changed files
with
1,400 additions
and
42 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: Create DatePicker and DaterangePicker |
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
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,64 @@ | ||
import React from "react"; | ||
import { useDateField, useDateSegment, useLocale } from "react-aria"; | ||
import { | ||
useDateFieldState, | ||
DateFieldState, | ||
DateSegment as DateSegmentType, | ||
} from "react-stately"; | ||
import { createCalendar } from "@internationalized/date"; | ||
import { DateValue } from "@react-types/calendar"; | ||
import { HorizontalStack } from "../HorizontalStack"; | ||
import { classNames } from "../utilities/css"; | ||
|
||
import styles from "./DatePicker.module.scss"; | ||
|
||
type DateFieldFieldProps = { | ||
isDisabled?: boolean; | ||
isReadOnly?: boolean; | ||
isInvalid?: boolean; | ||
isOpen?: boolean; | ||
defaultOpen?: boolean; | ||
value?: DateValue | null; | ||
onChange?: (value: DateValue | null) => void; | ||
}; | ||
export function DateFieldField(props: DateFieldFieldProps) { | ||
const dateFieldRef = React.useRef(null); | ||
const { locale } = useLocale(); | ||
const state = useDateFieldState({ ...props, locale, createCalendar }); | ||
const { fieldProps } = useDateField(props, state, dateFieldRef); | ||
|
||
return ( | ||
<div {...fieldProps} ref={dateFieldRef}> | ||
<HorizontalStack blockAlign="center"> | ||
{state.segments.map((segment, i) => ( | ||
<DateSegment key={i} segment={segment} state={state} /> | ||
))} | ||
</HorizontalStack> | ||
</div> | ||
); | ||
} | ||
|
||
type DateSegmentProps = { | ||
segment: DateSegmentType; | ||
state: DateFieldState; | ||
}; | ||
|
||
function DateSegment(props: DateSegmentProps) { | ||
const { segment, state } = props; | ||
const { type } = segment; | ||
const dateSegmentRef = React.useRef(null); | ||
const { segmentProps } = useDateSegment(segment, state, dateSegmentRef); | ||
|
||
return ( | ||
<div | ||
{...segmentProps} | ||
ref={dateSegmentRef} | ||
className={classNames( | ||
styles.DateSegment, | ||
type === "literal" && !state.value && styles.literalSegment, | ||
)} | ||
> | ||
{segment.text} | ||
</div> | ||
); | ||
} |
Oops, something went wrong.