Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(docs): date-picker dx #4103

Open
wants to merge 2 commits into
base: refactor/overall-dx
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions apps/docs/content/components/date-picker/controlled.raw.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import {DatePicker} 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="flex flex-row gap-2">
<div className="w-full flex flex-col gap-y-2">
<DatePicker
className="max-w-[284px]"
label="Date (controlled)"
value={value}
onChange={setValue}
/>
<p className="text-default-500 text-sm">
Selected date: {value ? formatter.format(value.toDate(getLocalTimeZone())) : "--"}
</p>
</div>
<DatePicker
className="max-w-[284px]"
defaultValue={parseDate("2024-04-04")}
label="Date (uncontrolled)"
/>
</div>
);
}
31 changes: 31 additions & 0 deletions apps/docs/content/components/date-picker/controlled.raw.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import React from "react";
import {DatePicker} 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="flex flex-row gap-2">
<div className="w-full flex flex-col gap-y-2">
<DatePicker
className="max-w-[284px]"
label="Date (controlled)"
value={value}
onChange={setValue}
/>
<p className="text-default-500 text-sm">
Selected date: {value ? formatter.format(value.toDate(getLocalTimeZone())) : "--"}
</p>
</div>
<DatePicker
className="max-w-[284px]"
defaultValue={parseDate("2024-04-04")}
label="Date (uncontrolled)"
/>
</div>
);
}
49 changes: 6 additions & 43 deletions apps/docs/content/components/date-picker/controlled.ts
Original file line number Diff line number Diff line change
@@ -1,52 +1,15 @@
const App = `import {DatePicker} 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="flex flex-row gap-2">
<div className="w-full flex flex-col gap-y-2">
<DatePicker className="max-w-[284px]" label="Date (controlled)" value={value} onChange={setValue} />
<p className="text-default-500 text-sm">
Selected date: {value ? formatter.format(value.toDate(getLocalTimeZone())) : "--"}
</p>
</div>
<DatePicker className="max-w-[284px]" defaultValue={parseDate("2024-04-04")} label="Date (uncontrolled)" />
</div>
);
}`;

const AppTs = `import {DatePicker} 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="flex flex-row gap-2">
<div className="w-full flex flex-col gap-y-2">
<DatePicker className="max-w-[284px]" label="Date (controlled)" value={value} onChange={setValue} />
<p className="text-default-500 text-sm">
Selected date: {value ? formatter.format(value.toDate(getLocalTimeZone())) : "--"}
</p>
</div>
<DatePicker className="max-w-[284px]" defaultValue={parseDate("2024-04-04")} label="Date (uncontrolled)" />
</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,
};
13 changes: 13 additions & 0 deletions apps/docs/content/components/date-picker/description.raw.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import {DatePicker} from "@nextui-org/react";

export default function App() {
return (
<div className="flex w-full flex-wrap md:flex-nowrap gap-4">
<DatePicker
className="max-w-[284px]"
description={"This is my birth date."}
label="Birth date"
/>
</div>
);
}
14 changes: 1 addition & 13 deletions apps/docs/content/components/date-picker/description.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,4 @@
const App = `import {DatePicker} from "@nextui-org/react";

export default function App() {
return (
<div className="flex w-full flex-wrap md:flex-nowrap gap-4">
<DatePicker
label="Birth date"
className="max-w-[284px]"
description={"This is my birth date."}
/>
</div>
);
}`;
import App from "./description.raw.jsx?raw";

const react = {
"/App.jsx": App,
Expand Down
9 changes: 9 additions & 0 deletions apps/docs/content/components/date-picker/disabled.raw.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import {DatePicker} from "@nextui-org/react";

export default function App() {
return (
<div className="flex w-full flex-wrap md:flex-nowrap gap-4">
<DatePicker isDisabled className="max-w-[284px]" label="Birth date" />
</div>
);
}
14 changes: 1 addition & 13 deletions apps/docs/content/components/date-picker/disabled.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,4 @@
const App = `import {DatePicker} from "@nextui-org/react";

export default function App() {
return (
<div className="flex w-full flex-wrap md:flex-nowrap gap-4">
<DatePicker
label="Birth date"
className="max-w-[284px]"
isDisabled
/>
</div>
);
}`;
import App from "./disabled.raw.jsx?raw";

const react = {
"/App.jsx": App,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import {DatePicker} from "@nextui-org/react";

export default function App() {
return (
<div className="flex w-full flex-wrap md:flex-nowrap gap-4">
<DatePicker
isInvalid
className="max-w-[284px]"
errorMessage={(value) => {
if (value.isInvalid) {
return "Please enter a valid date.";
}
}}
label="Birth date"
/>
</div>
);
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,4 @@
const App = `import {DatePicker} from "@nextui-org/react";

export default function App() {
return (
<div className="flex w-full flex-wrap md:flex-nowrap gap-4">
<DatePicker
label="Birth date"
className="max-w-[284px]"
isInvalid
errorMessage={(value) => {
if (value.isInvalid) {
return "Please enter a valid date.";
}
}}
/>
</div>
);
}`;
import App from "./error-message-function.raw.jsx?raw";

const react = {
"/App.jsx": App,
Expand Down
14 changes: 14 additions & 0 deletions apps/docs/content/components/date-picker/error-message.raw.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import {DatePicker} from "@nextui-org/react";

export default function App() {
return (
<div className="flex w-full flex-wrap md:flex-nowrap gap-4">
<DatePicker
isInvalid
className="max-w-[284px]"
errorMessage="Please enter a valid date."
label="Birth date"
/>
</div>
);
}
15 changes: 1 addition & 14 deletions apps/docs/content/components/date-picker/error-message.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,4 @@
const App = `import {DatePicker} from "@nextui-org/react";

export default function App() {
return (
<div className="flex w-full flex-wrap md:flex-nowrap gap-4">
<DatePicker
label="Birth date"
className="max-w-[284px]"
isInvalid
errorMessage="Please enter a valid date."
/>
</div>
);
}`;
import App from "./error-message.raw.jsx?raw";

const react = {
"/App.jsx": App,
Expand Down
32 changes: 32 additions & 0 deletions apps/docs/content/components/date-picker/granularity.raw.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import {DatePicker} 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">
<DatePicker
className="max-w-md"
granularity="second"
label="Date and time"
value={date}
onChange={setDate}
/>
<DatePicker
className="max-w-md"
granularity="day"
label="Date"
value={date}
onChange={setDate}
/>
<DatePicker className="max-w-md" granularity="second" label="Event date" />
<DatePicker
className="max-w-md"
granularity="second"
label="Event date"
placeholderValue={now("America/New_York")}
/>
</div>
);
}
33 changes: 33 additions & 0 deletions apps/docs/content/components/date-picker/granularity.raw.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import React from "react";
import {DatePicker} 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">
<DatePicker
className="max-w-md"
granularity="second"
label="Date and time"
value={date}
onChange={setDate}
/>
<DatePicker
className="max-w-md"
granularity="day"
label="Date"
value={date}
onChange={setDate}
/>
<DatePicker className="max-w-md" granularity="second" label="Event date" />
<DatePicker
className="max-w-md"
granularity="second"
label="Event date"
placeholderValue={now("America/New_York")}
/>
</div>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import {DatePicker} from "@nextui-org/react";
import {parseAbsoluteToLocal} from "@internationalized/date";
import {I18nProvider} from "@react-aria/i18n";

export default function App() {
let [date, setDate] = React.useState(parseAbsoluteToLocal("2021-04-07T18:45:22Z"));

return (
<div className="flex flex-col gap-4">
<I18nProvider locale="hi-IN-u-ca-indian">
<DatePicker
showMonthAndYearPickers
className="max-w-md"
label="Appointment date"
value={date}
variant="bordered"
onChange={setDate}
/>
</I18nProvider>
</div>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import React from "react";
import {DatePicker} from "@nextui-org/react";
import {DateValue, parseAbsoluteToLocal} from "@internationalized/date";
import {I18nProvider} from "@react-aria/i18n";

export default function App() {
let [date, setDate] = React.useState<DateValue>(parseAbsoluteToLocal("2021-04-07T18:45:22Z"));

return (
<div className="flex flex-col gap-4">
<I18nProvider locale="hi-IN-u-ca-indian">
<DatePicker
showMonthAndYearPickers
className="max-w-md"
label="Appointment date"
value={date}
variant="bordered"
onChange={setDate}
/>
</I18nProvider>
</div>
);
}
Loading