DateTimePicker

Date time picker control.

Example

lumamejevesadi
import { useState } from "react";
import { Button } from "swash/Button";
import { DateTimePicker } from "swash/controls/DateTimePicker";

export const Example = () => {
  const initialValue = { date: "1989-05-21", time: "02:00:00" };
  const [value, setValue] = useState(initialValue);

  return (
    <div className="flex items-center gap-3">
      <DateTimePicker value={value} onChange={setValue} />
      <Button type="button" onClick={() => setValue(initialValue)}>
        Reset
      </Button>
    </div>
  );
};

Disable past

Use disablePast prop to prevent selecting a date in the past.

lumamejevesadi
import { useState } from "react";
import { Button } from "swash/Button";
import { DateTimePicker } from "swash/controls/DateTimePicker";

export const Example = () => {
  const initialValue = { date: "1989-05-21", time: "02:00:00" };
  const [value, setValue] = useState(initialValue);

  return (
    <div className="flex items-center gap-3">
      <DateTimePicker value={value} onChange={setValue} disablePast/>
      <Button type="button" onClick={() => setValue(initialValue)}>
        Reset
      </Button>
    </div>
  );
};

Disabled

Use disabled prop to disable control.

lumamejevesadi
import { useState } from "react";
import { Button } from "swash/Button";
import { DateTimePicker } from "swash/controls/DateTimePicker";

export const Example = () => {
  const initialValue = { date: "1989-05-21", time: "02:00:00" };
  const [value, setValue] = useState(initialValue);

  return (
    <div className="flex items-center gap-3">
      <DateTimePicker value={value} onChange={setValue} disabled/>
      <Button type="button" onClick={() => setValue(initialValue)}>
        Reset
      </Button>
    </div>
  );
};

API

Props

React propsValue(s)Description
valuestring / nullActual field value.
onChange(value: string) => voidTriggered when the date changes.