@loykin/datetime-range 0.0.1-dev.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.
- package/LICENSE +21 -0
- package/README.md +26 -0
- package/dist/index.cjs +1666 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +168 -0
- package/dist/index.d.ts +168 -0
- package/dist/index.js +1627 -0
- package/dist/index.js.map +1 -0
- package/dist/styles.css +142 -0
- package/dist/styles.d.ts +1 -0
- package/package.json +73 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import React__default from 'react';
|
|
3
|
+
import { DayPicker } from 'react-day-picker';
|
|
4
|
+
|
|
5
|
+
type DateTimeRangeType = 'absolute' | 'relative';
|
|
6
|
+
/** Controls which time fields are shown in absolute mode. */
|
|
7
|
+
type DatetimePrecision = 'date' | 'hour' | 'minute' | 'second';
|
|
8
|
+
type ValidationErrorType = 'validation' | 'range' | 'empty' | null;
|
|
9
|
+
type DateTimeRelativeFormat = 'Seconds ago' | 'Minutes ago' | 'Hours ago' | 'Days ago' | 'Weeks ago' | 'Months ago' | 'Years ago';
|
|
10
|
+
interface DateTimeRangeValue {
|
|
11
|
+
type: DateTimeRangeType;
|
|
12
|
+
absoluteValue?: Date;
|
|
13
|
+
relativeValue?: number | string;
|
|
14
|
+
relativeFormat?: DateTimeRelativeFormat;
|
|
15
|
+
relativeNow?: boolean;
|
|
16
|
+
}
|
|
17
|
+
interface QuickPreset {
|
|
18
|
+
label: string;
|
|
19
|
+
start: DateTimeRangeValue;
|
|
20
|
+
end: DateTimeRangeValue;
|
|
21
|
+
}
|
|
22
|
+
interface DatetimeRangeLabels {
|
|
23
|
+
start?: string;
|
|
24
|
+
end?: string;
|
|
25
|
+
quickRanges?: string;
|
|
26
|
+
apply?: string;
|
|
27
|
+
cancel?: string;
|
|
28
|
+
absolute?: string;
|
|
29
|
+
relative?: string;
|
|
30
|
+
amount?: string;
|
|
31
|
+
now?: string;
|
|
32
|
+
nowDescription?: string;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
interface DatetimeRangeProps {
|
|
36
|
+
startTime: DateTimeRangeValue;
|
|
37
|
+
endTime: DateTimeRangeValue;
|
|
38
|
+
onChange: (startTime: DateTimeRangeValue, endTime: DateTimeRangeValue) => void;
|
|
39
|
+
/** Quick presets shown in the left panel. @default QUICK_PRESETS */
|
|
40
|
+
quickPresets?: QuickPreset[];
|
|
41
|
+
/** Show the quick ranges left panel. @default true */
|
|
42
|
+
showQuickRanges?: boolean;
|
|
43
|
+
/** Show the Absolute tab. @default true */
|
|
44
|
+
showAbsolute?: boolean;
|
|
45
|
+
/** Show the Relative tab. @default true */
|
|
46
|
+
showRelative?: boolean;
|
|
47
|
+
/** Controls time field granularity in absolute mode. @default 'second' */
|
|
48
|
+
precision?: DatetimePrecision;
|
|
49
|
+
/** Available units in the relative picker. @default RELATIVE_FORMATS */
|
|
50
|
+
relativeFormats?: DateTimeRelativeFormat[];
|
|
51
|
+
/** Minimum selectable date. */
|
|
52
|
+
min?: Date;
|
|
53
|
+
/** Maximum selectable date. */
|
|
54
|
+
max?: Date;
|
|
55
|
+
/** IANA timezone string (e.g. "Asia/Seoul"). */
|
|
56
|
+
timezone?: string;
|
|
57
|
+
/** Use 12-hour clock format. @default false */
|
|
58
|
+
use12HourFormat?: boolean;
|
|
59
|
+
/** Show the "Now" toggle in relative mode. @default true */
|
|
60
|
+
showNow?: boolean;
|
|
61
|
+
/** Disable the entire component. @default false */
|
|
62
|
+
disabled?: boolean;
|
|
63
|
+
/** Override UI labels for i18n. */
|
|
64
|
+
labels?: DatetimeRangeLabels;
|
|
65
|
+
/** Popover alignment relative to trigger. @default "start" */
|
|
66
|
+
popoverAlign?: 'start' | 'center' | 'end';
|
|
67
|
+
/** Popover side relative to trigger. @default "bottom" */
|
|
68
|
+
popoverSide?: 'top' | 'bottom' | 'left' | 'right';
|
|
69
|
+
/**
|
|
70
|
+
* Render a custom trigger element.
|
|
71
|
+
* `triggerProps` must be spread onto the interactive element so the popover works correctly.
|
|
72
|
+
*/
|
|
73
|
+
renderTrigger?: (triggerProps: React__default.ComponentPropsWithRef<'button'>, state: {
|
|
74
|
+
open: boolean;
|
|
75
|
+
startTime: DateTimeRangeValue;
|
|
76
|
+
endTime: DateTimeRangeValue;
|
|
77
|
+
}) => React__default.ReactElement;
|
|
78
|
+
className?: string;
|
|
79
|
+
}
|
|
80
|
+
declare function DatetimeRange({ startTime, endTime, onChange, quickPresets, showQuickRanges, showAbsolute, showRelative, precision, relativeFormats, min, max, timezone, use12HourFormat, showNow, disabled, labels: labelsProp, popoverAlign, popoverSide, renderTrigger, className, }: DatetimeRangeProps): React__default.JSX.Element;
|
|
81
|
+
|
|
82
|
+
type CalendarProps = Omit<React.ComponentProps<typeof DayPicker>, 'mode'>;
|
|
83
|
+
interface DateTimePanelProps {
|
|
84
|
+
value: Date | undefined;
|
|
85
|
+
/** Called immediately on every change when `immediate` is true. Called on Done otherwise. */
|
|
86
|
+
onChangeAction: (date: Date | undefined, isSuccess?: boolean) => void;
|
|
87
|
+
min?: Date;
|
|
88
|
+
max?: Date;
|
|
89
|
+
timezone?: string;
|
|
90
|
+
disabled?: boolean;
|
|
91
|
+
/** Controls which time fields are shown. 'date' hides time entirely. @default 'second' */
|
|
92
|
+
precision?: DatetimePrecision;
|
|
93
|
+
use12HourFormat?: boolean;
|
|
94
|
+
clearable?: boolean;
|
|
95
|
+
/** When true, hides Cancel/Done buttons and propagates changes immediately. */
|
|
96
|
+
immediate?: boolean;
|
|
97
|
+
isError?: boolean;
|
|
98
|
+
compareValue?: Date;
|
|
99
|
+
title?: string;
|
|
100
|
+
validateDateRange?: (currentValue: Date, compareValue?: Date) => {
|
|
101
|
+
isValid: boolean;
|
|
102
|
+
errorType: 'validation' | 'range' | 'empty' | null;
|
|
103
|
+
};
|
|
104
|
+
getRangeErrorMessage?: (errorType: 'validation' | 'range' | 'empty' | null, title?: string) => string;
|
|
105
|
+
}
|
|
106
|
+
declare function DateTimePanel({ value, onChangeAction, min, max, timezone, precision, use12HourFormat, immediate, isError, compareValue, title, validateDateRange, getRangeErrorMessage, ...props }: DateTimePanelProps & CalendarProps): React.JSX.Element;
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* DatetimeSegmentInput
|
|
110
|
+
*
|
|
111
|
+
* Segmented date-time input: [YYYY]-[MM]-[DD] [HH]:[mm]:[ss]
|
|
112
|
+
*
|
|
113
|
+
* - Click or Tab to focus individual segments
|
|
114
|
+
* - Type digits → auto-advance when segment is full
|
|
115
|
+
* - Arrow Up/Down → increment/decrement
|
|
116
|
+
* - Backspace → clear segment
|
|
117
|
+
* - Calls onChange with a new Date when any segment commits
|
|
118
|
+
*/
|
|
119
|
+
|
|
120
|
+
interface DatetimeSegmentInputProps {
|
|
121
|
+
value: Date;
|
|
122
|
+
onChange: (date: Date) => void;
|
|
123
|
+
disabled?: boolean;
|
|
124
|
+
className?: string;
|
|
125
|
+
isError?: boolean;
|
|
126
|
+
/** Controls which fields are visible. @default 'second' */
|
|
127
|
+
precision?: DatetimePrecision;
|
|
128
|
+
}
|
|
129
|
+
declare function DatetimeSegmentInput({ value, onChange, disabled, className, isError, precision, }: DatetimeSegmentInputProps): React__default.JSX.Element;
|
|
130
|
+
|
|
131
|
+
declare const RELATIVE_FORMATS: DateTimeRelativeFormat[];
|
|
132
|
+
declare const QUICK_PRESETS: QuickPreset[];
|
|
133
|
+
/** Converts a DateTimeRangeValue to a Date object. */
|
|
134
|
+
declare function toDate(value: DateTimeRangeValue): Date;
|
|
135
|
+
/** Converts a DateTimeRangeValue to Unix timestamp in milliseconds. */
|
|
136
|
+
declare function toTimestampMs(value: DateTimeRangeValue): number;
|
|
137
|
+
/** Converts a DateTimeRangeValue to Unix timestamp in seconds. */
|
|
138
|
+
declare function toTimestamp(value: DateTimeRangeValue): number;
|
|
139
|
+
/** Formats a DateTimeRangeValue for display in the trigger button. */
|
|
140
|
+
declare function toDisplayString(value: DateTimeRangeValue, options?: {
|
|
141
|
+
precision?: DatetimePrecision;
|
|
142
|
+
}): string;
|
|
143
|
+
/**
|
|
144
|
+
* Converts a DateTimeRangeValue to a Grafana-compatible URL string.
|
|
145
|
+
* @example
|
|
146
|
+
* toUrlString({ type: 'relative', relativeNow: true }) // "now"
|
|
147
|
+
* toUrlString({ type: 'relative', relativeValue: '5', relativeFormat: 'Minutes ago' }) // "now-5m"
|
|
148
|
+
* toUrlString({ type: 'absolute', absoluteValue: new Date() }) // "1709654400000"
|
|
149
|
+
*/
|
|
150
|
+
declare function toUrlString(value: DateTimeRangeValue): string;
|
|
151
|
+
/**
|
|
152
|
+
* Parses a Grafana-compatible URL string into a DateTimeRangeValue.
|
|
153
|
+
* @example
|
|
154
|
+
* fromUrlString("now") // { type: 'relative', relativeNow: true }
|
|
155
|
+
* fromUrlString("now-5m") // { type: 'relative', relativeValue: '5', relativeFormat: 'Minutes ago' }
|
|
156
|
+
* fromUrlString("1234567890000") // { type: 'absolute', absoluteValue: Date }
|
|
157
|
+
*/
|
|
158
|
+
declare function fromUrlString(urlString: string): DateTimeRangeValue;
|
|
159
|
+
/** Creates a relative "now" value. */
|
|
160
|
+
declare function relativeNow(): DateTimeRangeValue;
|
|
161
|
+
/** Creates a relative value like "5 Minutes ago". */
|
|
162
|
+
declare function relativeAgo(value: number, format: DateTimeRelativeFormat): DateTimeRangeValue;
|
|
163
|
+
/** Creates an absolute value from a Date. */
|
|
164
|
+
declare function absoluteDate(date: Date): DateTimeRangeValue;
|
|
165
|
+
/** Validates that start < end. Returns error message or null. */
|
|
166
|
+
declare function validateRange(start: DateTimeRangeValue, end: DateTimeRangeValue): ValidationErrorType;
|
|
167
|
+
|
|
168
|
+
export { type CalendarProps, DateTimePanel, type DateTimePanelProps, type DateTimeRangeValue, type DateTimeRelativeFormat, type DatetimePrecision, DatetimeRange, type DatetimeRangeLabels, type DatetimeRangeProps, DatetimeSegmentInput, type DatetimeSegmentInputProps, QUICK_PRESETS, type QuickPreset, RELATIVE_FORMATS, type ValidationErrorType, absoluteDate, fromUrlString, relativeAgo, relativeNow, toDate, toDisplayString, toTimestamp, toTimestampMs, toUrlString, validateRange };
|