@lemonadejs/calendar
Version:
LemonadeJS reactive JavaScript calendar plugin
74 lines (67 loc) • 2.92 kB
TypeScript
/**
* Official Type definitions for the LemonadeJS plugins
* https://lemonadejs.net/docs/plugins/calendar
* Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
*/
import React from 'react';
import Calendar from './index';
declare namespace CalendarReact {
/**
* React-idiomatic camelCase aliases for the lemonadejs callbacks. The
* wrapper drops the leading `self` argument before invoking these — the
* instance is available via the forwarded ref.
*
* The lowercase names from `Calendar.Options` (e.g. `onchange`) still
* work for legacy compatibility, but new code should prefer these.
*/
interface ReactCallbacks {
/** Fired when the value changes (date selection or `setValue`). */
onChange?: (value: string | number) => void;
/** Fired when the cursor moves between cells (e.g. via arrow keys). */
onUpdate?: (value: string) => void;
/** Fired when the modal opens. */
onOpen?: () => void;
/**
* Fired when the modal closes. `origin` is `'button'`, `'escape'`,
* `'focusout'`, or any custom string passed to `close({ origin })`.
*/
onClose?: (origin: string) => void;
/**
* Wired to the bound input element's native DOM `change` event.
* Renamed from the legacy `onChange` to free that name for
* `onChange` (the date-selection callback above).
*/
onInputChange?: (e: Event) => void;
}
/** Wrapper-only props (the wrapping `<div>` accepts these). */
interface DOMProps {
className?: string;
style?: React.CSSProperties;
children?: React.ReactNode;
}
/**
* Re-export the underlying type namespace so consumers can write
* import { Calendar } from '@lemonadejs/calendar/react';
* import type { Calendar as CalendarNS } from '@lemonadejs/calendar/react';
* and get `CalendarNS.Options`, `CalendarNS.Instance`, etc. The same
* applies through the `@calendarjs/react` aggregate.
*/
export type Options = Calendar.Options;
export type Instance = Calendar.Instance;
export type ValidRange = Calendar.ValidRange;
export type ValidRangeItem = Calendar.ValidRangeItem;
export type CloseOptions = Calendar.CloseOptions;
}
// Interface (not const) so the value type declaration-merges with the
// namespace above. That merge carries the type members along with the
// React component value when the default export is re-exported.
interface CalendarReact extends React.MemoExoticComponent<
React.ForwardRefExoticComponent<
Omit<Calendar.Options, 'onchange' | 'onupdate' | 'onclose' | 'onopen' | 'onChange'>
& CalendarReact.ReactCallbacks
& CalendarReact.DOMProps
& React.RefAttributes<Calendar.Instance>
>
> {}
declare const CalendarReact: CalendarReact;
export default CalendarReact;