Integrations / React
React
@litopis/react provides the LitopisDatePicker component.
Quick start
npm install @litopis/react @litopis/dom react react-dom
Add this component to src/App.tsx. It imports the picker and its base
stylesheet.
import { LitopisDatePicker } from "@litopis/react";
import "@litopis/dom/styles/base.css";
export default function App() {
return (
<main>
<LitopisDatePicker mode="popover" label="Appointment date" />
</main>
);
}
Interactive example
Value: current date
Controlled value
Keep the selected date in React state. Pass it to the picker with its change handler.
import { useState } from "react";
import { LitopisDatePicker, type LitopisDateValue } from "@litopis/react";
import "@litopis/dom/styles/base.css";
function App() {
const [date, setDate] = useState<LitopisDateValue | null>(null);
return (
<LitopisDatePicker
mode="popover"
label="Start date"
value={date}
onValueChange={setDate}
/>
);
}
Controller ref
The forwarded ref implements DatePickerController. Use it to call methods
such as open(), close() and getISOValue().
import { useRef } from "react";
import type { DatePickerController } from "@litopis/dom";
const pickerRef = useRef<DatePickerController | null>(null);
<LitopisDatePicker ref={pickerRef} />
<button onClick={() => pickerRef.current?.open()}>Open calendar</button>
Range
Keep the same component. A range is controlled with range and emits
onRangeChange.
const [stay, setStay] = useState({ start: null, end: null });
<LitopisDatePicker
selection="range"
layout="split"
name={{ start: "from", end: "to" }}
range={stay}
onRangeChange={setStay}
/>
Custom input
Pass an input child with slot="input". Litopis keeps its classes and
placeholder while supplying the picker behavior and accessibility attributes.
<LitopisDatePicker value={date} onValueChange={setDate}>
<input slot="input" className="my-input" placeholder="Choose a date" />
</LitopisDatePicker>
Styling
Pass className to the component root. Import one Litopis stylesheet in
your application entry.