Getting started
Install
bash
npm install patrojsRequires React 18 or 19.
Import the stylesheet once, wherever your app already loads global CSS:
js
import 'patrojs/style.css';Calendar
tsx
import { Calendar } from 'patrojs';
function App() {
return <Calendar calendar='BS' onChange={(value) => console.log(value?.ad, value?.bs)} />;
}Datepicker
tsx
import { Datepicker } from 'patrojs';
function App() {
return <Datepicker label='Date' onChange={(value) => console.log(value?.ad)} />;
}Datepicker renders a field that opens Calendar in a popover; picking a day closes it and fills the field. Add editable to let people type the date as well.
Both start with nothing selected, showing the current month. Pass defaultValue={new Date()} to start on today.
onChange payload
onChange receives a PatroDate: the picked day in both calendar systems, plus a real Date:
ts
{
date: Date;
ad: '2026-10-29';
bs: '2083-07-12';
}(In range mode it's { start: PatroDate | null; end: PatroDate | null } instead; see Date ranges.)
Testing
Jest can't load CSS, so map the stylesheet import to an empty module:
js
// jest.config.js
moduleNameMapper: { '\\.css$': '<rootDir>/test/styleMock.js' }, // styleMock.js: module.exports = {};Pass today to pin the date, so tests and screenshots don't change from day to day:
tsx
<Calendar today={new Date(2026, 9, 29)} />Next
- Controlled vs uncontrolled: how the value and the displayed month are managed
- Forms: native submission, validation, typing dates
- Server rendering: Next.js, Remix
- Props reference: every prop, in one table