From 333446ee14ef25bec3d499381bf4be175a891a9f Mon Sep 17 00:00:00 2001 From: Bruno Henriques Date: Fri, 22 Nov 2024 14:28:16 +0000 Subject: [PATCH] docs: add DatePicker & TimePicker --- .../docs/src/pages/components/date-picker.mdx | 196 ++++++++++++++++++ .../docs/src/pages/components/time-picker.mdx | 102 +++++++++ 2 files changed, 298 insertions(+) create mode 100644 apps/docs/src/pages/components/date-picker.mdx create mode 100644 apps/docs/src/pages/components/time-picker.mdx diff --git a/apps/docs/src/pages/components/date-picker.mdx b/apps/docs/src/pages/components/date-picker.mdx new file mode 100644 index 0000000000..f57b400916 --- /dev/null +++ b/apps/docs/src/pages/components/date-picker.mdx @@ -0,0 +1,196 @@ +import { + datePickerClasses, + HvDatePicker, + theme, +} from "@hitachivantara/uikit-react-core"; + +import Playground from "@docs/components/code/Playground"; +import { Description } from "@docs/components/page/Description"; +import { Page } from "@docs/components/page/Page"; +import { getComponentData } from "@docs/utils/component"; + +export const getStaticProps = async ({ params }) => { + const meta = await getComponentData("DatePicker", "core", datePickerClasses); + return { props: { ssg: { meta } } }; +}; + + + + + + + +### Actions + +Use the `showActions` property to display Apply/Cancel buttons at the bottom. + +```tsx live + +``` + +### Custom labels + +Use the `labels` object to customize the internal labels of the date picker. + +```jsx live + +``` + +### Controlled + +```tsx live +import { useState } from "react"; + +export default function Demo() { + const [date, setDate] = useState(new Date("2020-01-02")); + const [open, setOpen] = useState(false); + + const addDay = () => { + if (!date) return; + setDate(new Date(date.setDate(date.getDate() + 1))); + }; + + const toggleOpen = () => setOpen((o) => !o); + + return ( + <> + setDate(d!)} + onToggle={toggleOpen} + /> + + +1 Day + + + {open ? "Close" : "Open"} + + + ); +} +``` + +### Range mode + +Use `rangeMode` to enable the selection of a range of dates. When doing so, use `startValue` and `endValue` to set the initial values, instead of the `value` prop. + +```jsx live + +``` + +### Restricted selection + +You can restrict the selection of dates by setting the `minimumDate` and `maximumDate` properties. + +```jsx live + +``` + +### Selection list + +Custom content can be added to the Date Picker by using the `startAdornment` property. This can be used to display a list of predefined dates, for example. + +```tsx live +import { useState } from "react"; + +export default function Demo() { + const [date, setDate] = useState(new Date("2020-09-05")); + + const options = ( + + + Today + + + Yesterday + + { + setDate((d) => { + const newDate = new Date(d); + newDate.setDate(1); + return newDate; + }); + }} + > + Start of the month + + { + setDate((d) => { + const newDate = new Date(d); + newDate.setDate(1); + newDate.setMonth(0); + return newDate; + }); + }} + > + Start of year + + + ); + + return ( + {options}} + value={date} + onChange={(newDate) => setDate(newDate)} + /> + ); +} +``` + +### Related components + +- [`HvInput`](/components/input) +- [`HvTimePicker`](/components/time-picker) + + diff --git a/apps/docs/src/pages/components/time-picker.mdx b/apps/docs/src/pages/components/time-picker.mdx new file mode 100644 index 0000000000..a0d62156f2 --- /dev/null +++ b/apps/docs/src/pages/components/time-picker.mdx @@ -0,0 +1,102 @@ +import { + HvTimePicker, + theme, + timePickerClasses, +} from "@hitachivantara/uikit-react-core"; + +import Playground from "@docs/components/code/Playground"; +import { Description } from "@docs/components/page/Description"; +import { Page } from "@docs/components/page/Page"; +import { getComponentData } from "@docs/utils/component"; + +export const getStaticProps = async ({ params }) => { + const meta = await getComponentData("TimePicker", "core", timePickerClasses); + return { props: { ssg: { meta } } }; +}; + + + + + + + +### Form + +A Time Picker usage inside a `form` element. Give `HvTimePicker` a `name`, and it will be included in the form data, +following the time [`input` format](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/time) specification. + +```jsx live +
{ + event.preventDefault(); + const formData = new FormData(event.currentTarget); + alert(JSON.stringify(Object.fromEntries(formData))); + }} +> + +
+ + Submit + + +``` + +### Controlled + +```tsx live +import { useState } from "react"; + +export default function Demo() { + const [value, setValue] = useState(null); + + const prettyValue = value + ? `${value.hours}h ${value.minutes}'${value.seconds}"` + : "—"; + + return ( +
+ Date: {prettyValue} + + { + setValue((d) => d && { ...d, minutes: (d.minutes + 1) % 60 }); + }} + > + +1 minute + +
+ ); +} +``` + +### Related components + +- [`HvInput`](/components/input) +- [`HvDatePicker`](/components/date-picker) + +