-
Notifications
You must be signed in to change notification settings - Fork 348
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(components): date and time fields (#6036)
* feat: date range picker * WIP * cleanp * time field * cleanup
- Loading branch information
1 parent
141f523
commit b31d7ca
Showing
10 changed files
with
277 additions
and
20 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
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,71 @@ | ||
import React, { forwardRef, Ref } from "react"; | ||
import { | ||
DateField as AriaDateField, | ||
DateFieldProps as AriaDateFieldProps, | ||
DateValue, | ||
} from "react-aria-components"; | ||
import { css } from "@emotion/react"; | ||
|
||
import { fieldBaseCSS } from "../field/styles"; | ||
|
||
export type DateFieldProps<T extends DateValue> = AriaDateFieldProps<T>; | ||
|
||
const dateFieldCSS = css` | ||
--date-field-vertical-padding: 6px; | ||
--date-field-horizontal-padding: 8px; | ||
color: var(--ac-global-text-color-900); | ||
.react-aria-DateInput { | ||
display: flex; | ||
padding: var(--date-field-vertical-padding) | ||
var(--date-field-horizontal-padding); | ||
border: var(--ac-global-border-size-thin) solid | ||
var(--ac-global-input-field-border-color); | ||
border-radius: var(--ac-global-rounding-small); | ||
background-color: var(--ac-global-input-field-background-color); | ||
width: fit-content; | ||
min-width: 150px; | ||
white-space: nowrap; | ||
forced-color-adjust: none; | ||
&[data-focus-within] { | ||
outline: 1px solid var(--ac-global-color-primary); | ||
outline-offset: -1px; | ||
} | ||
} | ||
.react-aria-DateSegment { | ||
padding: 0 2px; | ||
font-variant-numeric: tabular-nums; | ||
text-align: end; | ||
color: var(--ac-global-text-color-900); | ||
&[data-type="literal"] { | ||
padding: 0; | ||
} | ||
&[data-placeholder] { | ||
color: var(--ac-text-color-placeholder); | ||
font-style: italic; | ||
} | ||
&:focus { | ||
color: var(--ac-highlight-foreground); | ||
background: var(--ac-highlight-background); | ||
outline: none; | ||
border-radius: var(--ac-global-rounding-small); | ||
caret-color: transparent; | ||
} | ||
} | ||
`; | ||
function DateField<T extends DateValue>( | ||
props: DateFieldProps<T>, | ||
ref: Ref<HTMLDivElement> | ||
) { | ||
return ( | ||
<AriaDateField css={css(fieldBaseCSS, dateFieldCSS)} {...props} ref={ref} /> | ||
); | ||
} | ||
|
||
const _DateField = forwardRef(DateField); | ||
export { _DateField as DateField }; |
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,72 @@ | ||
import React, { forwardRef, Ref } from "react"; | ||
import { | ||
TimeField as AriaTimeField, | ||
TimeFieldProps as AriaTimeFieldProps, | ||
TimeValue, | ||
} from "react-aria-components"; | ||
import { css } from "@emotion/react"; | ||
|
||
import { fieldBaseCSS } from "../field/styles"; | ||
|
||
export type TimeFieldProps<T extends TimeValue> = AriaTimeFieldProps<T>; | ||
|
||
const timeFieldCSS = css` | ||
--date-field-vertical-padding: 6px; | ||
--date-field-horizontal-padding: 8px; | ||
color: var(--ac-global-text-color-900); | ||
.react-aria-DateInput { | ||
display: flex; | ||
padding: var(--date-field-vertical-padding) | ||
var(--date-field-horizontal-padding); | ||
border: var(--ac-global-border-size-thin) solid | ||
var(--ac-global-input-field-border-color); | ||
border-radius: var(--ac-global-rounding-small); | ||
background-color: var(--ac-global-input-field-background-color); | ||
width: fit-content; | ||
min-width: 150px; | ||
white-space: nowrap; | ||
forced-color-adjust: none; | ||
&[data-focus-within] { | ||
outline: 1px solid var(--ac-global-color-primary); | ||
outline-offset: -1px; | ||
} | ||
} | ||
.react-aria-DateSegment { | ||
padding: 0 2px; | ||
font-variant-numeric: tabular-nums; | ||
text-align: end; | ||
color: var(--ac-global-text-color-900); | ||
&[data-type="literal"] { | ||
padding: 0; | ||
} | ||
&[data-placeholder] { | ||
color: var(--ac-text-color-placeholder); | ||
font-style: italic; | ||
} | ||
&:focus { | ||
color: var(--ac-highlight-foreground); | ||
background: var(--ac-highlight-background); | ||
outline: none; | ||
border-radius: var(--ac-global-rounding-small); | ||
caret-color: transparent; | ||
} | ||
} | ||
`; | ||
|
||
function TimeField<T extends TimeValue>( | ||
props: TimeFieldProps<T>, | ||
ref: Ref<HTMLDivElement> | ||
) { | ||
return ( | ||
<AriaTimeField css={css(fieldBaseCSS, timeFieldCSS)} {...props} ref={ref} /> | ||
); | ||
} | ||
|
||
const _TimeField = forwardRef(TimeField); | ||
export { _TimeField as TimeField }; |
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 |
---|---|---|
@@ -1,3 +1,6 @@ | ||
export { DateInput, DateSegment } from "react-aria-components"; | ||
export * from "./LastNTimeRangeContext"; | ||
export * from "./LastNTimeRangePicker"; | ||
export * from "./ConnectedLastNTimeRangePicker"; | ||
export * from "./DateField"; | ||
export * from "./TimeField"; |
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,35 @@ | ||
import React from "react"; | ||
import { Meta, StoryFn } from "@storybook/react"; | ||
|
||
import { | ||
DateField, | ||
DateFieldProps, | ||
DateInput, | ||
DateSegment, | ||
DateValue, | ||
Label, | ||
} from "@phoenix/components"; | ||
|
||
const meta: Meta = { | ||
title: "DateField", | ||
component: DateField, | ||
parameters: { | ||
layout: "centered", | ||
}, | ||
}; | ||
|
||
export default meta; | ||
|
||
const Template: StoryFn<DateFieldProps<DateValue>> = (args) => ( | ||
<DateField {...args}> | ||
<Label>Birth date</Label> | ||
<DateInput>{(segment) => <DateSegment segment={segment} />}</DateInput> | ||
</DateField> | ||
); | ||
|
||
/** | ||
* DateFields are used to type in dates within the UI | ||
*/ | ||
export const Default = Template.bind({}); | ||
|
||
Default.args = {}; |
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,35 @@ | ||
import React from "react"; | ||
import { Meta, StoryFn } from "@storybook/react"; | ||
|
||
import { | ||
DateInput, | ||
DateSegment, | ||
Label, | ||
TimeField, | ||
TimeFieldProps, | ||
TimeValue, | ||
} from "@phoenix/components"; | ||
|
||
const meta: Meta = { | ||
title: "TimeField", | ||
component: TimeField, | ||
parameters: { | ||
layout: "centered", | ||
}, | ||
}; | ||
|
||
export default meta; | ||
|
||
const Template: StoryFn<TimeFieldProps<TimeValue>> = (args) => ( | ||
<TimeField {...args}> | ||
<Label>Event time</Label> | ||
<DateInput>{(segment) => <DateSegment segment={segment} />}</DateInput> | ||
</TimeField> | ||
); | ||
|
||
/** | ||
* DateFields are used to type in dates within the UI | ||
*/ | ||
export const Default = Template.bind({}); | ||
|
||
Default.args = {}; |