-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(docs): date input dx (#4100)
- Loading branch information
Showing
37 changed files
with
422 additions
and
399 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
apps/docs/content/components/date-input/controlled.raw.jsx
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,20 @@ | ||
import {DateInput} from "@nextui-org/react"; | ||
import {parseDate, getLocalTimeZone} from "@internationalized/date"; | ||
import {useDateFormatter} from "@react-aria/i18n"; | ||
|
||
export default function App() { | ||
const [value, setValue] = React.useState(parseDate("2024-04-04")); | ||
|
||
let formatter = useDateFormatter({dateStyle: "full"}); | ||
|
||
return ( | ||
<div className="w-full flex flex-row gap-2"> | ||
<div className="w-full flex flex-col gap-y-2"> | ||
<DateInput label="Date (controlled)" value={value} onChange={setValue} /> | ||
<p className="text-default-500 text-sm"> | ||
Selected date: {value ? formatter.format(value.toDate(getLocalTimeZone())) : "--"} | ||
</p> | ||
</div> | ||
</div> | ||
); | ||
} |
21 changes: 21 additions & 0 deletions
21
apps/docs/content/components/date-input/controlled.raw.tsx
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,21 @@ | ||
import React from "react"; | ||
import {DateInput} from "@nextui-org/react"; | ||
import {DateValue, parseDate, getLocalTimeZone} from "@internationalized/date"; | ||
import {useDateFormatter} from "@react-aria/i18n"; | ||
|
||
export default function App() { | ||
const [value, setValue] = React.useState<DateValue>(parseDate("2024-04-04")); | ||
|
||
let formatter = useDateFormatter({dateStyle: "full"}); | ||
|
||
return ( | ||
<div className="w-full flex flex-row gap-2"> | ||
<div className="w-full flex flex-col gap-y-2"> | ||
<DateInput label="Date (controlled)" value={value} onChange={setValue} /> | ||
<p className="text-default-500 text-sm"> | ||
Selected date: {value ? formatter.format(value.toDate(getLocalTimeZone())) : "--"} | ||
</p> | ||
</div> | ||
</div> | ||
); | ||
} |
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,50 +1,15 @@ | ||
const App = `import {DateInput} from "@nextui-org/react"; | ||
import {parseDate, getLocalTimeZone} from "@internationalized/date"; | ||
import {useDateFormatter} from "@react-aria/i18n"; | ||
export default function App() { | ||
const [value, setValue] = React.useState(parseDate("2024-04-04")); | ||
let formatter = useDateFormatter({dateStyle: "full"}); | ||
return ( | ||
<div className="w-full flex flex-row gap-2"> | ||
<div className="w-full flex flex-col gap-y-2"> | ||
<DateInput label="Date (controlled)" value={value} onChange={setValue} /> | ||
<p className="text-default-500 text-sm"> | ||
Selected date: {value ? formatter.format(value.toDate(getLocalTimeZone())) : "--"} | ||
</p> | ||
</div> | ||
</div> | ||
); | ||
}`; | ||
|
||
const AppTs = `import {DateInput} from "@nextui-org/react"; | ||
import {DateValue, parseDate, getLocalTimeZone} from "@internationalized/date"; | ||
import {useDateFormatter} from "@react-aria/i18n"; | ||
export default function App() { | ||
const [value, setValue] = React.useState<DateValue>(parseDate("2024-04-04")); | ||
let formatter = useDateFormatter({dateStyle: "full"}); | ||
return ( | ||
<div className="w-full flex flex-row gap-2"> | ||
<div className="w-full flex flex-col gap-y-2"> | ||
<DateInput label="Date (controlled)" value={value} onChange={setValue} /> | ||
<p className="text-default-500 text-sm"> | ||
Selected date: {value ? formatter.format(value.toDate(getLocalTimeZone())) : "--"} | ||
</p> | ||
</div> | ||
</div> | ||
); | ||
}`; | ||
import App from "./controlled.raw.jsx?raw"; | ||
import AppTs from "./controlled.raw.tsx?raw"; | ||
|
||
const react = { | ||
"/App.jsx": App, | ||
}; | ||
|
||
const reactTs = { | ||
"/App.tsx": AppTs, | ||
}; | ||
|
||
export default { | ||
...react, | ||
...reactTs, | ||
}; |
14 changes: 14 additions & 0 deletions
14
apps/docs/content/components/date-input/description.raw.jsx
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,14 @@ | ||
import {DateInput} from "@nextui-org/react"; | ||
import {CalendarDate} from "@internationalized/date"; | ||
|
||
export default function App() { | ||
return ( | ||
<div className="flex w-full flex-wrap md:flex-nowrap gap-4"> | ||
<DateInput | ||
description={"This is my birth date."} | ||
label={"Birth date"} | ||
placeholderValue={new CalendarDate(1995, 11, 6)} | ||
/> | ||
</div> | ||
); | ||
} |
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,15 @@ | ||
import {DateInput} from "@nextui-org/react"; | ||
import {CalendarDate, parseDate} from "@internationalized/date"; | ||
|
||
export default function App() { | ||
return ( | ||
<div className="flex w-full flex-wrap md:flex-nowrap gap-4"> | ||
<DateInput | ||
isDisabled | ||
defaultValue={parseDate("2024-04-04")} | ||
label={"Birth date"} | ||
placeholderValue={new CalendarDate(1995, 11, 6)} | ||
/> | ||
</div> | ||
); | ||
} |
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
22 changes: 22 additions & 0 deletions
22
apps/docs/content/components/date-input/error-message-function.raw.jsx
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,22 @@ | ||
import {DateInput} from "@nextui-org/react"; | ||
import {CalendarDate, parseDate} from "@internationalized/date"; | ||
|
||
export default function App() { | ||
return ( | ||
<div className="flex w-full flex-wrap md:flex-nowrap gap-4"> | ||
<DateInput | ||
isInvalid | ||
className="max-w-xs" | ||
defaultValue={parseDate("2024-04-04")} | ||
description={"This is my birth date."} | ||
errorMessage={(value) => { | ||
if (value.isInvalid) { | ||
return "Please enter a valid date."; | ||
} | ||
}} | ||
label={"Birth date"} | ||
placeholderValue={new CalendarDate(1995, 11, 6)} | ||
/> | ||
</div> | ||
); | ||
} |
23 changes: 1 addition & 22 deletions
23
apps/docs/content/components/date-input/error-message-function.ts
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
18 changes: 18 additions & 0 deletions
18
apps/docs/content/components/date-input/error-message.raw.jsx
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,18 @@ | ||
import {DateInput} from "@nextui-org/react"; | ||
import {CalendarDate, parseDate} from "@internationalized/date"; | ||
|
||
export default function App() { | ||
return ( | ||
<div className="flex w-full flex-wrap md:flex-nowrap gap-4"> | ||
<DateInput | ||
isInvalid | ||
className="max-w-xs" | ||
defaultValue={parseDate("2024-04-04")} | ||
description={"This is my birth date."} | ||
errorMessage="Please enter a valid date." | ||
label={"Birth date"} | ||
placeholderValue={new CalendarDate(1995, 11, 6)} | ||
/> | ||
</div> | ||
); | ||
} |
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
19 changes: 19 additions & 0 deletions
19
apps/docs/content/components/date-input/granularity.raw.jsx
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,19 @@ | ||
import {DateInput} from "@nextui-org/react"; | ||
import {now, parseAbsoluteToLocal} from "@internationalized/date"; | ||
|
||
export default function App() { | ||
let [date, setDate] = React.useState(parseAbsoluteToLocal("2021-04-07T18:45:22Z")); | ||
|
||
return ( | ||
<div className="w-full max-w-xl flex flex-col items-start gap-4"> | ||
<DateInput granularity="second" label="Date and time" value={date} onChange={setDate} /> | ||
<DateInput granularity="day" label="Date" value={date} onChange={setDate} /> | ||
<DateInput granularity="second" label="Event date" /> | ||
<DateInput | ||
granularity="second" | ||
label="Event date" | ||
placeholderValue={now("America/New_York")} | ||
/> | ||
</div> | ||
); | ||
} |
20 changes: 20 additions & 0 deletions
20
apps/docs/content/components/date-input/granularity.raw.tsx
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,20 @@ | ||
import React from "react"; | ||
import {DateInput} from "@nextui-org/react"; | ||
import {DateValue, now, parseAbsoluteToLocal} from "@internationalized/date"; | ||
|
||
export default function App() { | ||
let [date, setDate] = React.useState<DateValue>(parseAbsoluteToLocal("2021-04-07T18:45:22Z")); | ||
|
||
return ( | ||
<div className="w-full max-w-xl flex flex-col items-start gap-4"> | ||
<DateInput granularity="second" label="Date and time" value={date} onChange={setDate} /> | ||
<DateInput granularity="day" label="Date" value={date} onChange={setDate} /> | ||
<DateInput granularity="second" label="Event date" /> | ||
<DateInput | ||
granularity="second" | ||
label="Event date" | ||
placeholderValue={now("America/New_York")} | ||
/> | ||
</div> | ||
); | ||
} |
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,60 +1,15 @@ | ||
const App = `import {DateInput} from "@nextui-org/react"; | ||
import {now, parseAbsoluteToLocal} from "@internationalized/date"; | ||
import {useDateFormatter} from "@react-aria/i18n"; | ||
export default function App() { | ||
let [date, setDate] = React.useState(parseAbsoluteToLocal("2021-04-07T18:45:22Z")); | ||
return ( | ||
<div className="w-full max-w-xl flex flex-col items-start gap-4"> | ||
<DateInput | ||
granularity="second" | ||
label="Date and time" | ||
value={date} | ||
onChange={setDate} | ||
/> | ||
<DateInput granularity="day" label="Date" value={date} onChange={setDate} /> | ||
<DateInput granularity="second" label="Event date" /> | ||
<DateInput | ||
granularity="second" | ||
label="Event date" | ||
placeholderValue={now("America/New_York")} | ||
/> | ||
</div> | ||
); | ||
}`; | ||
|
||
const AppTs = `import {DateInput} from "@nextui-org/react"; | ||
import {DateValue, now, parseAbsoluteToLocal} from "@internationalized/date"; | ||
import {useDateFormatter} from "@react-aria/i18n"; | ||
export default function App() { | ||
let [date, setDate] = React.useState<DateValue>(parseAbsoluteToLocal("2021-04-07T18:45:22Z")); | ||
return ( | ||
<div className="w-full max-w-xl flex flex-col items-start gap-4"> | ||
<DateInput | ||
granularity="second" | ||
label="Date and time" | ||
value={date} | ||
onChange={setDate} | ||
/> | ||
<DateInput granularity="day" label="Date" value={date} onChange={setDate} /> | ||
<DateInput granularity="second" label="Event date" /> | ||
<DateInput | ||
granularity="second" | ||
label="Event date" | ||
placeholderValue={now("America/New_York")} | ||
/> | ||
</div> | ||
); | ||
}`; | ||
import App from "./granularity.raw.jsx?raw"; | ||
import AppTs from "./granularity.raw.tsx?raw"; | ||
|
||
const react = { | ||
"/App.jsx": App, | ||
}; | ||
|
||
const reactTs = { | ||
"/App.tsx": AppTs, | ||
}; | ||
|
||
export default { | ||
...react, | ||
...reactTs, | ||
}; |
14 changes: 14 additions & 0 deletions
14
apps/docs/content/components/date-input/hide-timezone.raw.jsx
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,14 @@ | ||
import {DateInput} from "@nextui-org/react"; | ||
import {parseZonedDateTime} from "@internationalized/date"; | ||
|
||
export default function App() { | ||
return ( | ||
<div className="w-full max-w-xl flex flex-row gap-4"> | ||
<DateInput | ||
hideTimeZone | ||
defaultValue={parseZonedDateTime("2022-11-07T00:45[America/Los_Angeles]")} | ||
label="Appointment time" | ||
/> | ||
</div> | ||
); | ||
} |
Oops, something went wrong.