@nepdatejs/react 0.0.0-bootstrap → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +73 -1
  3. package/dist/date-text-BT82cZ7i.cjs +84 -0
  4. package/dist/date-text-BT82cZ7i.cjs.map +1 -0
  5. package/dist/date-text-Df1gFksR.js +61 -0
  6. package/dist/date-text-Df1gFksR.js.map +1 -0
  7. package/dist/date-text-Dipetpbp.d.cts +37 -0
  8. package/dist/date-text-Dipetpbp.d.ts +37 -0
  9. package/dist/headless-6BuUOtOR.d.cts +194 -0
  10. package/dist/headless-BK0XRHKb.js +513 -0
  11. package/dist/headless-BK0XRHKb.js.map +1 -0
  12. package/dist/headless-CFZ06zLn.d.ts +194 -0
  13. package/dist/headless-HxTkvgbz.cjs +572 -0
  14. package/dist/headless-HxTkvgbz.cjs.map +1 -0
  15. package/dist/headless.cjs +11 -0
  16. package/dist/headless.d.cts +2 -0
  17. package/dist/headless.d.ts +2 -0
  18. package/dist/headless.js +2 -0
  19. package/dist/index.cjs +891 -0
  20. package/dist/index.cjs.map +1 -0
  21. package/dist/index.d.cts +245 -0
  22. package/dist/index.d.ts +245 -0
  23. package/dist/index.js +871 -0
  24. package/dist/index.js.map +1 -0
  25. package/dist/server.cjs +6 -0
  26. package/dist/server.d.cts +2 -0
  27. package/dist/server.d.ts +2 -0
  28. package/dist/server.js +1 -0
  29. package/package.json +107 -4
  30. package/src/bindings.ts +247 -0
  31. package/src/calendar-body.tsx +133 -0
  32. package/src/calendar.tsx +34 -0
  33. package/src/date-picker.tsx +350 -0
  34. package/src/date-range-picker.tsx +223 -0
  35. package/src/date-text.tsx +110 -0
  36. package/src/date-time-picker.tsx +287 -0
  37. package/src/headless.ts +21 -0
  38. package/src/hooks.ts +474 -0
  39. package/src/icons.tsx +35 -0
  40. package/src/index.ts +21 -0
  41. package/src/multi-date-picker.tsx +243 -0
  42. package/src/panel.ts +67 -0
  43. package/src/presets.tsx +44 -0
  44. package/src/server.ts +8 -0
  45. package/src/time-columns.tsx +60 -0
  46. package/src/use-store.ts +113 -0
@@ -0,0 +1,194 @@
1
+ import { ChangeEvent, KeyboardEvent, Ref, useEffect } from "react";
2
+ import { CalendarDate, CalendarSystem, LocaleCode } from "@nepdatejs/core";
3
+ import { CalendarActions, CalendarOptions, CalendarState, CalendarStore, DayCell, PickerCell } from "@nepdatejs/calendar";
4
+ import { DatePickerOptions, DatePickerState, DatePickerStore, DateRangePickerOptions, DateRangePickerState, DateRangePickerStore, DateTimePickerOptions, DateTimePickerState, DateTimePickerStore, MultiDatePickerOptions, MultiDatePickerState, MultiDatePickerStore, PresetState, RangeField } from "@nepdatejs/datepicker";
5
+ //#region src/bindings.d.ts
6
+ type DataAttrs = Record<`data-${string}`, string | boolean | undefined>;
7
+ interface ButtonProps extends DataAttrs {
8
+ type: "button";
9
+ tabIndex?: number;
10
+ disabled?: boolean;
11
+ "aria-label"?: string;
12
+ "aria-pressed"?: boolean;
13
+ "aria-current"?: "date";
14
+ onClick: () => void;
15
+ onFocus?: () => void;
16
+ onMouseEnter?: () => void;
17
+ }
18
+ interface GridProps {
19
+ role: "grid";
20
+ "aria-label": string;
21
+ ref: Ref<HTMLTableElement>;
22
+ onKeyDown: (event: KeyboardEvent) => void;
23
+ onMouseLeave: () => void;
24
+ }
25
+ /** Prop getters that turn a calendar store into accessible markup. */
26
+ interface CalendarBindings {
27
+ readonly state: CalendarState;
28
+ readonly actions: CalendarActions;
29
+ readonly getGridProps: () => GridProps;
30
+ readonly getDayProps: (cell: DayCell) => ButtonProps;
31
+ readonly getPrevProps: () => ButtonProps;
32
+ readonly getNextProps: () => ButtonProps;
33
+ /** The title buttons: month and year in the day view, the year (or page) otherwise. */
34
+ readonly getTitleButtons: () => {
35
+ key: string;
36
+ label: string;
37
+ props: ButtonProps;
38
+ }[];
39
+ readonly getOptionProps: (tile: PickerCell, index: number, tiles: readonly PickerCell[]) => ButtonProps;
40
+ /** Move focus into the grid (e.g. when a panel opens). */
41
+ readonly focusGrid: () => void;
42
+ }
43
+ declare function useCalendarBindings(state: CalendarState, actions: CalendarActions, locale: LocaleCode | undefined, options: {
44
+ /** The store's latest snapshot, to tell whether a key press changed anything. */
45
+ readonly getSnapshot: () => CalendarState;
46
+ readonly onDayActivate?: ((date: CalendarDate) => void) | undefined;
47
+ }): CalendarBindings;
48
+ //#endregion
49
+ //#region src/hooks.d.ts
50
+ /** A standalone calendar: state, actions and prop getters. */
51
+ declare function useCalendar(options?: CalendarOptions): CalendarBindings & {
52
+ store: CalendarStore;
53
+ };
54
+ interface InputProps {
55
+ id: string;
56
+ /** Left out for an inline picker, whose calendar is always in the page. */
57
+ role?: "combobox";
58
+ type: "text";
59
+ inputMode: "numeric";
60
+ autoComplete: "off";
61
+ value: string;
62
+ placeholder: string;
63
+ "aria-haspopup"?: "dialog";
64
+ "aria-expanded"?: boolean;
65
+ "aria-controls": string;
66
+ "aria-invalid"?: true;
67
+ "aria-describedby"?: string;
68
+ onChange: (event: ChangeEvent<HTMLInputElement>) => void;
69
+ onBlur: () => void;
70
+ onKeyDown: (event: KeyboardEvent<HTMLInputElement>) => void;
71
+ }
72
+ interface PanelProps {
73
+ id: string;
74
+ /** 'group' for an inline picker. */
75
+ role: "dialog" | "group";
76
+ "aria-label": string;
77
+ }
78
+ interface DatePickerBindings {
79
+ readonly state: DatePickerState;
80
+ readonly actions: DatePickerStore["actions"];
81
+ readonly store: DatePickerStore;
82
+ /** Prop getters for the panel's calendar. */
83
+ readonly calendar: CalendarBindings;
84
+ readonly ids: {
85
+ input: string;
86
+ panel: string;
87
+ hint: string;
88
+ };
89
+ getInputProps(extra?: {
90
+ id?: string | undefined;
91
+ }): InputProps;
92
+ getToggleProps(): ButtonProps & {
93
+ "aria-expanded": boolean;
94
+ "aria-controls": string;
95
+ };
96
+ getClearProps(): ButtonProps;
97
+ /** The BS/AD switch inside the input. */
98
+ getSwitchProps(): ButtonProps;
99
+ /** One button of the BS/AD segment in the panel footer. */
100
+ getCalendarOptionProps(calendar: CalendarSystem): ButtonProps;
101
+ getTodayProps(): ButtonProps;
102
+ getPanelProps(): PanelProps;
103
+ /** A shortcut button (see state.presets). */
104
+ getPresetProps(preset: PresetState): ButtonProps;
105
+ }
106
+ /** A BS/AD date picker without markup: wire the getters to your own elements. */
107
+ declare function useDatePicker(options?: DatePickerOptions & {
108
+ id?: string | undefined;
109
+ }): DatePickerBindings;
110
+ interface DateRangePickerBindings {
111
+ readonly state: DateRangePickerState;
112
+ readonly actions: DateRangePickerStore["actions"];
113
+ readonly store: DateRangePickerStore;
114
+ readonly calendar: CalendarBindings;
115
+ readonly ids: {
116
+ start: string;
117
+ end: string;
118
+ panel: string;
119
+ hint: string;
120
+ };
121
+ getInputProps(field: RangeField): Omit<InputProps, "onChange" | "onBlur"> & {
122
+ onChange: (event: ChangeEvent<HTMLInputElement>) => void;
123
+ onBlur: () => void;
124
+ };
125
+ getToggleProps(): ButtonProps & {
126
+ "aria-expanded": boolean;
127
+ "aria-controls": string;
128
+ };
129
+ getCalendarOptionProps(calendar: CalendarSystem): ButtonProps;
130
+ getPanelProps(): PanelProps;
131
+ getPresetProps(preset: PresetState): ButtonProps;
132
+ }
133
+ /** A BS/AD date range picker without markup. */
134
+ declare function useDateRangePicker(options?: DateRangePickerOptions): DateRangePickerBindings;
135
+ interface DateTimePickerBindings {
136
+ readonly state: DateTimePickerState;
137
+ readonly actions: DateTimePickerStore["actions"];
138
+ readonly store: DateTimePickerStore;
139
+ readonly calendar: CalendarBindings;
140
+ readonly ids: {
141
+ date: string;
142
+ time: string;
143
+ panel: string;
144
+ hint: string;
145
+ };
146
+ }
147
+ /** A BS/AD date + time picker without markup. The value is a zoned ISO timestamp. */
148
+ declare function useDateTimePicker(options?: DateTimePickerOptions & {
149
+ id?: string | undefined;
150
+ }): DateTimePickerBindings;
151
+ interface MultiDatePickerBindings {
152
+ readonly state: MultiDatePickerState;
153
+ readonly actions: MultiDatePickerStore["actions"];
154
+ readonly store: MultiDatePickerStore;
155
+ readonly calendar: CalendarBindings;
156
+ readonly ids: {
157
+ input: string;
158
+ panel: string;
159
+ hint: string;
160
+ };
161
+ getInputProps(): InputProps;
162
+ getToggleProps(): ButtonProps & {
163
+ "aria-expanded": boolean;
164
+ "aria-controls": string;
165
+ };
166
+ getClearProps(): ButtonProps;
167
+ getCalendarOptionProps(calendar: CalendarSystem): ButtonProps;
168
+ getPanelProps(): PanelProps;
169
+ }
170
+ /** A picker for several separate BS/AD days, without markup (PICK-001). */
171
+ declare function useMultiDatePicker(options?: MultiDatePickerOptions & {
172
+ id?: string | undefined;
173
+ }): MultiDatePickerBindings;
174
+ //#endregion
175
+ //#region src/use-store.d.ts
176
+ interface StoreLike<O, S> {
177
+ getState(): S;
178
+ subscribe(listener: () => void): () => void;
179
+ setOptions(changes: Partial<O>): void;
180
+ }
181
+ /**
182
+ * Create a store once and keep its options in step with props, without
183
+ * loops: functions are wrapped once so their identity never changes, and data
184
+ * options are compared by value, so inline objects and arrays are fine.
185
+ */
186
+ declare function useStore<O extends object, S, T extends StoreLike<O, S>>(create: (options: O) => T, options: O): {
187
+ store: T;
188
+ state: S;
189
+ };
190
+ /** Structural equality for plain data (dates, ranges, lists); identity for everything else. */
191
+ declare function deepEqual(a: unknown, b: unknown): boolean;
192
+ //#endregion
193
+ export { useCalendarBindings as _, DateTimePickerBindings as a, PanelProps as c, useDateRangePicker as d, useDateTimePicker as f, GridProps as g, CalendarBindings as h, DateRangePickerBindings as i, useCalendar as l, ButtonProps as m, useStore as n, InputProps as o, useMultiDatePicker as p, DatePickerBindings as r, MultiDatePickerBindings as s, deepEqual as t, useDatePicker as u };
194
+ //# sourceMappingURL=headless-CFZ06zLn.d.ts.map