diff --git a/www/apps/book/public/llms-full.txt b/www/apps/book/public/llms-full.txt index bd6a40b6d8..557900b791 100644 --- a/www/apps/book/public/llms-full.txt +++ b/www/apps/book/public/llms-full.txt @@ -82486,6 +82486,260 @@ import { DatePicker } from "@medusajs/ui" when the value is missing or invalid, or mark the field as required or invalid via ARIA. +## Examples + +*** + +### Controlled Date Picker + +Manage and store the value of the date picker in a state variable for controlled behavior. This is also useful for form integration. + +```tsx +"use client" + +import { DatePicker } from "@medusajs/ui" +import { useState } from "react" + +export default function DatePickerControlled() { + const [date, setDate] = useState(new Date()) + + return ( +
+ +
+ Selected date: {date ? date.toLocaleDateString() : "None"} +
+
+ ) +} + +``` + +### Date Picker With Time + +Enable time selection with different granularity levels for precise scheduling. + +```tsx +"use client" + +import { DatePicker } from "@medusajs/ui" + +export default function DatePickerWithTime() { + return ( +
+ +
+ ) +} + +``` + +### Min/Max Values + +Restrict date selection to a specific range by setting minimum and maximum values. + +In the example below, you can only select dates within the next 30 days. Dates outside the range are disabled. + +```tsx +"use client" + +import { DatePicker } from "@medusajs/ui" + +export default function DatePickerMinMax() { + const today = new Date() + const maxDate = new Date() + maxDate.setDate(today.getDate() + 30) // 30 days from today + + return ( +
+ +
+ ) +} + +``` + +### Disabled Dates + +Disable specific dates like weekends and holidays to prevent selection of unavailable dates. + +The example below disables weekends and holidays like Christmas. + +```tsx +"use client" + +import { DatePicker } from "@medusajs/ui" + +export default function DatePickerBusinessHours() { + return ( +
+ { + // Disable weekends and holidays + const day = date.getDay() + const isWeekend = day === 0 || day === 6 + + // Example: Disable specific holiday (Christmas) + const isChristmas = date.getMonth() === 11 && date.getDate() === 25 + + return isWeekend || isChristmas + }} + /> +
+ ) +} + +``` + +### Granularity Options + +Different levels of time precision from date-only to second-precision selection. + +```tsx +"use client" + +import { DatePicker } from "@medusajs/ui" + +export default function DatePickerGranularity() { + const defaultDate = new Date() + + return ( +
+
+
Date Only
+ +
+ +
+
Date and Time with Hour Precision
+ +
+ +
+
Date and Time with Minute Precision
+ +
+ +
+
Date and Time with Second Precision
+ +
+
+ ) +} + +``` + +### Form Integration + +The following example shows how to use the date picker in a form, with simulated form submission. + +```tsx +"use client" + +import { DatePicker, Button, Label } from "@medusajs/ui" +import { useState } from "react" + +export default function DatePickerForm() { + const [eventDate, setEventDate] = useState(null) + const [reminderDate, setReminderDate] = useState(null) + const [submitted, setSubmitted] = useState(false) + + const handleSubmit = (e: React.FormEvent) => { + e.preventDefault() + setSubmitted(true) + // Here you would typically send data to your API + setTimeout(() => setSubmitted(false), 5000) + } + + const isFormValid = eventDate && reminderDate + + return ( +
+
+
+

Schedule Event

+

+ Set up your event and reminder dates +

+
+ +
+
+ + +
+ +
+ + +
+
+ + +
+ + {submitted && ( +
+ Event scheduled for {eventDate?.toLocaleString()} with a reminder on {reminderDate?.toLocaleDateString()}. +
+ )} +
+ ) +} + +``` + # Drawer diff --git a/www/apps/ui/src/content/docs/components/date-picker.mdx b/www/apps/ui/src/content/docs/components/date-picker.mdx index 38008c79e6..11b1d31052 100644 --- a/www/apps/ui/src/content/docs/components/date-picker.mdx +++ b/www/apps/ui/src/content/docs/components/date-picker.mdx @@ -23,3 +23,47 @@ import { DatePicker } from "@medusajs/ui" --- + +## Examples + +--- + +### Controlled Date Picker + +Manage and store the value of the date picker in a state variable for controlled behavior. This is also useful for form integration. + + + +### Date Picker With Time + +Enable time selection with different granularity levels for precise scheduling. + + + +### Min/Max Values + +Restrict date selection to a specific range by setting minimum and maximum values. + +In the example below, you can only select dates within the next 30 days. Dates outside the range are disabled. + + + +### Disabled Dates + +Disable specific dates like weekends and holidays to prevent selection of unavailable dates. + +The example below disables weekends and holidays like Christmas. + + + +### Granularity Options + +Different levels of time precision from date-only to second-precision selection. + + + +### Form Integration + +The following example shows how to use the date picker in a form, with simulated form submission. + + diff --git a/www/apps/ui/src/examples/date-picker-business-hours.tsx b/www/apps/ui/src/examples/date-picker-business-hours.tsx new file mode 100644 index 0000000000..b6b8c97c0c --- /dev/null +++ b/www/apps/ui/src/examples/date-picker-business-hours.tsx @@ -0,0 +1,25 @@ +"use client" + +import { DatePicker } from "@medusajs/ui" + +export default function DatePickerBusinessHours() { + return ( +
+ { + // Disable weekends and holidays + const day = date.getDay() + const isWeekend = day === 0 || day === 6 + + // Example: Disable specific holiday (Christmas) + const isChristmas = date.getMonth() === 11 && date.getDate() === 25 + + return isWeekend || isChristmas + }} + /> +
+ ) +} diff --git a/www/apps/ui/src/examples/date-picker-controlled.tsx b/www/apps/ui/src/examples/date-picker-controlled.tsx new file mode 100644 index 0000000000..766149a2fd --- /dev/null +++ b/www/apps/ui/src/examples/date-picker-controlled.tsx @@ -0,0 +1,21 @@ +"use client" + +import { DatePicker } from "@medusajs/ui" +import { useState } from "react" + +export default function DatePickerControlled() { + const [date, setDate] = useState(new Date()) + + return ( +
+ +
+ Selected date: {date ? date.toLocaleDateString() : "None"} +
+
+ ) +} diff --git a/www/apps/ui/src/examples/date-picker-disabled-dates.tsx b/www/apps/ui/src/examples/date-picker-disabled-dates.tsx new file mode 100644 index 0000000000..065f9607e7 --- /dev/null +++ b/www/apps/ui/src/examples/date-picker-disabled-dates.tsx @@ -0,0 +1,20 @@ +"use client" + +import { DatePicker } from "@medusajs/ui" + +export default function DatePickerDisabledDates() { + // Disable weekends (Saturday and Sunday) + const isWeekend = (date: Date) => { + const day = date.getDay() + return day === 0 || day === 6 // Sunday = 0, Saturday = 6 + } + + return ( +
+ +
+ ) +} diff --git a/www/apps/ui/src/examples/date-picker-form.tsx b/www/apps/ui/src/examples/date-picker-form.tsx new file mode 100644 index 0000000000..755744cddd --- /dev/null +++ b/www/apps/ui/src/examples/date-picker-form.tsx @@ -0,0 +1,71 @@ +"use client" + +import { DatePicker, Button, Label } from "@medusajs/ui" +import { useState } from "react" + +export default function DatePickerForm() { + const [eventDate, setEventDate] = useState(null) + const [reminderDate, setReminderDate] = useState(null) + const [submitted, setSubmitted] = useState(false) + + const handleSubmit = (e: React.FormEvent) => { + e.preventDefault() + setSubmitted(true) + // Here you would typically send data to your API + setTimeout(() => setSubmitted(false), 5000) + } + + const isFormValid = eventDate && reminderDate + + return ( +
+
+
+

Schedule Event

+

+ Set up your event and reminder dates +

+
+ +
+
+ + +
+ +
+ + +
+
+ + +
+ + {submitted && ( +
+ Event scheduled for {eventDate?.toLocaleString()} with a reminder on {reminderDate?.toLocaleDateString()}. +
+ )} +
+ ) +} diff --git a/www/apps/ui/src/examples/date-picker-granularity.tsx b/www/apps/ui/src/examples/date-picker-granularity.tsx new file mode 100644 index 0000000000..0e76f929ef --- /dev/null +++ b/www/apps/ui/src/examples/date-picker-granularity.tsx @@ -0,0 +1,47 @@ +"use client" + +import { DatePicker } from "@medusajs/ui" + +export default function DatePickerGranularity() { + const defaultDate = new Date() + + return ( +
+
+
Date Only
+ +
+ +
+
Date and Time with Hour Precision
+ +
+ +
+
Date and Time with Minute Precision
+ +
+ +
+
Date and Time with Second Precision
+ +
+
+ ) +} diff --git a/www/apps/ui/src/examples/date-picker-min-max.tsx b/www/apps/ui/src/examples/date-picker-min-max.tsx new file mode 100644 index 0000000000..181d35c691 --- /dev/null +++ b/www/apps/ui/src/examples/date-picker-min-max.tsx @@ -0,0 +1,19 @@ +"use client" + +import { DatePicker } from "@medusajs/ui" + +export default function DatePickerMinMax() { + const today = new Date() + const maxDate = new Date() + maxDate.setDate(today.getDate() + 30) // 30 days from today + + return ( +
+ +
+ ) +} diff --git a/www/apps/ui/src/examples/date-picker-with-time.tsx b/www/apps/ui/src/examples/date-picker-with-time.tsx new file mode 100644 index 0000000000..5fa1a6c0c8 --- /dev/null +++ b/www/apps/ui/src/examples/date-picker-with-time.tsx @@ -0,0 +1,15 @@ +"use client" + +import { DatePicker } from "@medusajs/ui" + +export default function DatePickerWithTime() { + return ( +
+ +
+ ) +} diff --git a/www/apps/ui/src/registries/example-registry.tsx b/www/apps/ui/src/registries/example-registry.tsx index dcbfe579c4..561e683ab1 100644 --- a/www/apps/ui/src/registries/example-registry.tsx +++ b/www/apps/ui/src/registries/example-registry.tsx @@ -269,6 +269,44 @@ export const ExampleRegistry: ExampleRegistryType = { component: React.lazy(async () => import("@/examples/date-picker-demo")), file: "src/examples/date-picker-demo.tsx", }, + "date-picker-controlled": { + name: "date-picker-controlled", + component: React.lazy( + async () => import("@/examples/date-picker-controlled") + ), + file: "src/examples/date-picker-controlled.tsx", + }, + "date-picker-with-time": { + name: "date-picker-with-time", + component: React.lazy( + async () => import("@/examples/date-picker-with-time") + ), + file: "src/examples/date-picker-with-time.tsx", + }, + "date-picker-min-max": { + name: "date-picker-min-max", + component: React.lazy(async () => import("@/examples/date-picker-min-max")), + file: "src/examples/date-picker-min-max.tsx", + }, + "date-picker-business-hours": { + name: "date-picker-business-hours", + component: React.lazy( + async () => import("@/examples/date-picker-business-hours") + ), + file: "src/examples/date-picker-business-hours.tsx", + }, + "date-picker-granularity": { + name: "date-picker-granularity", + component: React.lazy( + async () => import("@/examples/date-picker-granularity") + ), + file: "src/examples/date-picker-granularity.tsx", + }, + "date-picker-form": { + name: "date-picker-form", + component: React.lazy(async () => import("@/examples/date-picker-form")), + file: "src/examples/date-picker-form.tsx", + }, "drawer-demo": { name: "drawer-demo", component: React.lazy(async () => import("@/examples/drawer-demo")),