react-datetime-picker
Advanced tools
Comparing version
/// <reference types="react" /> | ||
import PropTypes from 'prop-types'; | ||
import { isMaxDate, isMinDate } from './shared/propTypes'; | ||
import type { Detail } from './shared/types'; | ||
@@ -50,5 +49,5 @@ type DateTimeInputProps = { | ||
locale: PropTypes.Requireable<string>; | ||
maxDate: typeof isMaxDate; | ||
maxDate: PropTypes.Validator<Date | null | undefined>; | ||
maxDetail: PropTypes.Requireable<"hour" | "minute" | "second">; | ||
minDate: typeof isMinDate; | ||
minDate: PropTypes.Validator<Date | null | undefined>; | ||
minuteAriaLabel: PropTypes.Requireable<string>; | ||
@@ -55,0 +54,0 @@ minutePlaceholder: PropTypes.Requireable<string>; |
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { isMaxDate, isMinDate } from '../shared/propTypes'; | ||
type NativeInputProps = { | ||
@@ -20,4 +19,4 @@ ariaLabel?: string; | ||
disabled: PropTypes.Requireable<boolean>; | ||
maxDate: typeof isMaxDate; | ||
minDate: typeof isMinDate; | ||
maxDate: PropTypes.Validator<Date | null | undefined>; | ||
minDate: PropTypes.Validator<Date | null | undefined>; | ||
name: PropTypes.Requireable<string>; | ||
@@ -24,0 +23,0 @@ onChange: PropTypes.Requireable<(...args: any[]) => any>; |
@@ -6,3 +6,2 @@ import React from 'react'; | ||
import Clock from 'react-clock'; | ||
import { isMaxDate, isMinDate } from './shared/propTypes'; | ||
import type { ClassName, CloseReason, Detail, LooseValue, OpenReason, Value } from './shared/types'; | ||
@@ -98,5 +97,5 @@ type Icon = React.ReactElement | string; | ||
locale: PropTypes.Requireable<string>; | ||
maxDate: typeof isMaxDate; | ||
maxDate: PropTypes.Validator<Date | null | undefined>; | ||
maxDetail: PropTypes.Requireable<string>; | ||
minDate: typeof isMinDate; | ||
minDate: PropTypes.Validator<Date | null | undefined>; | ||
minuteAriaLabel: PropTypes.Requireable<string>; | ||
@@ -120,3 +119,3 @@ minutePlaceholder: PropTypes.Requireable<string>; | ||
showLeadingZeros: PropTypes.Requireable<boolean>; | ||
value: PropTypes.Requireable<NonNullable<NonNullable<string | Date | null | undefined> | (NonNullable<string | Date | null | undefined> | null | undefined)[] | null | undefined>>; | ||
value: PropTypes.Requireable<NonNullable<NonNullable<string | Date | null | undefined> | import("./shared/types").Range<NonNullable<string | Date | null | undefined>> | null | undefined>>; | ||
yearAriaLabel: PropTypes.Requireable<string>; | ||
@@ -123,0 +122,0 @@ yearPlaceholder: PropTypes.Requireable<string>; |
@@ -99,3 +99,3 @@ "use strict"; | ||
} | ||
setIsClockOpen(false); | ||
setIsClockOpen(isClockOpen ? false : isClockOpen); | ||
setIsCalendarOpen(true); | ||
@@ -133,3 +133,3 @@ if (onCalendarOpen) { | ||
} | ||
setIsCalendarOpen(false); | ||
setIsCalendarOpen(isCalendarOpen ? false : isCalendarOpen); | ||
setIsClockOpen(true); | ||
@@ -187,4 +187,2 @@ if (onClockOpen) { | ||
disabled || | ||
isCalendarOpen || | ||
isClockOpen || | ||
!openWidgetsOnFocus || | ||
@@ -197,11 +195,19 @@ event.target.dataset.select === 'true') { | ||
case 'month': | ||
case 'year': | ||
case 'year': { | ||
if (isCalendarOpen) { | ||
return; | ||
} | ||
openCalendar({ reason: 'focus' }); | ||
break; | ||
} | ||
case 'hour12': | ||
case 'hour24': | ||
case 'minute': | ||
case 'second': | ||
case 'second': { | ||
if (isClockOpen) { | ||
return; | ||
} | ||
openClock({ reason: 'focus' }); | ||
break; | ||
} | ||
default: | ||
@@ -330,3 +336,3 @@ } | ||
var isValue = prop_types_1.default.oneOfType([prop_types_1.default.string, prop_types_1.default.instanceOf(Date)]); | ||
var isValueOrValueArray = prop_types_1.default.oneOfType([isValue, prop_types_1.default.arrayOf(isValue)]); | ||
var isValueOrValueArray = prop_types_1.default.oneOfType([isValue, (0, propTypes_1.rangeOf)(isValue)]); | ||
DateTimePicker.propTypes = { | ||
@@ -333,0 +339,0 @@ amPmAriaLabel: prop_types_1.default.string, |
import DateTimePicker from './DateTimePicker'; | ||
import type { DateTimePickerProps } from './DateTimePicker'; | ||
export type { DateTimePickerProps } from './DateTimePicker'; | ||
export { DateTimePicker }; | ||
export type { DateTimePickerProps }; | ||
export default DateTimePicker; |
import PropTypes from 'prop-types'; | ||
export declare function isMinDate(props: Record<string, unknown>, propName: string, componentName: string): Error | null; | ||
export declare function isMaxDate(props: Record<string, unknown>, propName: string, componentName: string): Error | null; | ||
import type { Requireable, Validator } from 'prop-types'; | ||
import type { Range } from './types'; | ||
export declare const isMinDate: Validator<Date | null | undefined>; | ||
export declare const isMaxDate: Validator<Date | null | undefined>; | ||
export declare const isValueType: PropTypes.Requireable<string>; | ||
export declare const rangeOf: <T>(type: PropTypes.Requireable<T>) => PropTypes.Requireable<Range<T>>; |
@@ -15,7 +15,7 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.isValueType = exports.isMaxDate = exports.isMinDate = void 0; | ||
exports.rangeOf = exports.isValueType = exports.isMaxDate = exports.isMinDate = void 0; | ||
var prop_types_1 = __importDefault(require("prop-types")); | ||
var allViews = ['hour', 'minute', 'second']; | ||
var allValueTypes = __spreadArray([], allViews, true); | ||
function isMinDate(props, propName, componentName) { | ||
var isMinDate = function isMinDate(props, propName, componentName) { | ||
var _a = props, _b = propName, minDate = _a[_b]; | ||
@@ -33,5 +33,5 @@ if (!minDate) { | ||
return null; | ||
} | ||
}; | ||
exports.isMinDate = isMinDate; | ||
function isMaxDate(props, propName, componentName) { | ||
var isMaxDate = function isMaxDate(props, propName, componentName) { | ||
var _a = props, _b = propName, maxDate = _a[_b]; | ||
@@ -49,4 +49,8 @@ if (!maxDate) { | ||
return null; | ||
} | ||
}; | ||
exports.isMaxDate = isMaxDate; | ||
exports.isValueType = prop_types_1.default.oneOf(allValueTypes); | ||
var rangeOf = function (type) { | ||
return prop_types_1.default.arrayOf(type); | ||
}; | ||
exports.rangeOf = rangeOf; |
@@ -1,2 +0,2 @@ | ||
type Range<T> = [T, T]; | ||
export type Range<T> = [T, T]; | ||
export type AmPmType = 'am' | 'pm'; | ||
@@ -10,2 +10,1 @@ export type ClassName = string | null | undefined | (string | null | undefined)[]; | ||
export type Value = Date | null; | ||
export {}; |
/// <reference types="react" /> | ||
import PropTypes from 'prop-types'; | ||
import { isMaxDate, isMinDate } from './shared/propTypes'; | ||
import type { Detail } from './shared/types'; | ||
@@ -50,5 +49,5 @@ type DateTimeInputProps = { | ||
locale: PropTypes.Requireable<string>; | ||
maxDate: typeof isMaxDate; | ||
maxDate: PropTypes.Validator<Date | null | undefined>; | ||
maxDetail: PropTypes.Requireable<"hour" | "minute" | "second">; | ||
minDate: typeof isMinDate; | ||
minDate: PropTypes.Validator<Date | null | undefined>; | ||
minuteAriaLabel: PropTypes.Requireable<string>; | ||
@@ -55,0 +54,0 @@ minutePlaceholder: PropTypes.Requireable<string>; |
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { isMaxDate, isMinDate } from '../shared/propTypes'; | ||
type NativeInputProps = { | ||
@@ -20,4 +19,4 @@ ariaLabel?: string; | ||
disabled: PropTypes.Requireable<boolean>; | ||
maxDate: typeof isMaxDate; | ||
minDate: typeof isMinDate; | ||
maxDate: PropTypes.Validator<Date | null | undefined>; | ||
minDate: PropTypes.Validator<Date | null | undefined>; | ||
name: PropTypes.Requireable<string>; | ||
@@ -24,0 +23,0 @@ onChange: PropTypes.Requireable<(...args: any[]) => any>; |
@@ -6,3 +6,2 @@ import React from 'react'; | ||
import Clock from 'react-clock'; | ||
import { isMaxDate, isMinDate } from './shared/propTypes'; | ||
import type { ClassName, CloseReason, Detail, LooseValue, OpenReason, Value } from './shared/types'; | ||
@@ -98,5 +97,5 @@ type Icon = React.ReactElement | string; | ||
locale: PropTypes.Requireable<string>; | ||
maxDate: typeof isMaxDate; | ||
maxDate: PropTypes.Validator<Date | null | undefined>; | ||
maxDetail: PropTypes.Requireable<string>; | ||
minDate: typeof isMinDate; | ||
minDate: PropTypes.Validator<Date | null | undefined>; | ||
minuteAriaLabel: PropTypes.Requireable<string>; | ||
@@ -120,3 +119,3 @@ minutePlaceholder: PropTypes.Requireable<string>; | ||
showLeadingZeros: PropTypes.Requireable<boolean>; | ||
value: PropTypes.Requireable<NonNullable<NonNullable<string | Date | null | undefined> | (NonNullable<string | Date | null | undefined> | null | undefined)[] | null | undefined>>; | ||
value: PropTypes.Requireable<NonNullable<NonNullable<string | Date | null | undefined> | import("./shared/types").Range<NonNullable<string | Date | null | undefined>> | null | undefined>>; | ||
yearAriaLabel: PropTypes.Requireable<string>; | ||
@@ -123,0 +122,0 @@ yearPlaceholder: PropTypes.Requireable<string>; |
@@ -32,3 +32,3 @@ var __assign = (this && this.__assign) || function () { | ||
import DateTimeInput from './DateTimeInput'; | ||
import { isMaxDate, isMinDate } from './shared/propTypes'; | ||
import { isMaxDate, isMinDate, rangeOf } from './shared/propTypes'; | ||
var baseClassName = 'react-datetime-picker'; | ||
@@ -72,3 +72,3 @@ var outsideActionEvents = ['mousedown', 'focusin', 'touchstart']; | ||
} | ||
setIsClockOpen(false); | ||
setIsClockOpen(isClockOpen ? false : isClockOpen); | ||
setIsCalendarOpen(true); | ||
@@ -106,3 +106,3 @@ if (onCalendarOpen) { | ||
} | ||
setIsCalendarOpen(false); | ||
setIsCalendarOpen(isCalendarOpen ? false : isCalendarOpen); | ||
setIsClockOpen(true); | ||
@@ -160,4 +160,2 @@ if (onClockOpen) { | ||
disabled || | ||
isCalendarOpen || | ||
isClockOpen || | ||
!openWidgetsOnFocus || | ||
@@ -170,11 +168,19 @@ event.target.dataset.select === 'true') { | ||
case 'month': | ||
case 'year': | ||
case 'year': { | ||
if (isCalendarOpen) { | ||
return; | ||
} | ||
openCalendar({ reason: 'focus' }); | ||
break; | ||
} | ||
case 'hour12': | ||
case 'hour24': | ||
case 'minute': | ||
case 'second': | ||
case 'second': { | ||
if (isClockOpen) { | ||
return; | ||
} | ||
openClock({ reason: 'focus' }); | ||
break; | ||
} | ||
default: | ||
@@ -302,3 +308,3 @@ } | ||
var isValue = PropTypes.oneOfType([PropTypes.string, PropTypes.instanceOf(Date)]); | ||
var isValueOrValueArray = PropTypes.oneOfType([isValue, PropTypes.arrayOf(isValue)]); | ||
var isValueOrValueArray = PropTypes.oneOfType([isValue, rangeOf(isValue)]); | ||
DateTimePicker.propTypes = { | ||
@@ -305,0 +311,0 @@ amPmAriaLabel: PropTypes.string, |
import DateTimePicker from './DateTimePicker'; | ||
import type { DateTimePickerProps } from './DateTimePicker'; | ||
export type { DateTimePickerProps } from './DateTimePicker'; | ||
export { DateTimePicker }; | ||
export type { DateTimePickerProps }; | ||
export default DateTimePicker; |
import PropTypes from 'prop-types'; | ||
export declare function isMinDate(props: Record<string, unknown>, propName: string, componentName: string): Error | null; | ||
export declare function isMaxDate(props: Record<string, unknown>, propName: string, componentName: string): Error | null; | ||
import type { Requireable, Validator } from 'prop-types'; | ||
import type { Range } from './types'; | ||
export declare const isMinDate: Validator<Date | null | undefined>; | ||
export declare const isMaxDate: Validator<Date | null | undefined>; | ||
export declare const isValueType: PropTypes.Requireable<string>; | ||
export declare const rangeOf: <T>(type: PropTypes.Requireable<T>) => PropTypes.Requireable<Range<T>>; |
@@ -13,3 +13,3 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { | ||
var allValueTypes = __spreadArray([], allViews, true); | ||
export function isMinDate(props, propName, componentName) { | ||
export var isMinDate = function isMinDate(props, propName, componentName) { | ||
var _a = props, _b = propName, minDate = _a[_b]; | ||
@@ -27,4 +27,4 @@ if (!minDate) { | ||
return null; | ||
} | ||
export function isMaxDate(props, propName, componentName) { | ||
}; | ||
export var isMaxDate = function isMaxDate(props, propName, componentName) { | ||
var _a = props, _b = propName, maxDate = _a[_b]; | ||
@@ -42,3 +42,6 @@ if (!maxDate) { | ||
return null; | ||
} | ||
}; | ||
export var isValueType = PropTypes.oneOf(allValueTypes); | ||
export var rangeOf = function (type) { | ||
return PropTypes.arrayOf(type); | ||
}; |
@@ -1,2 +0,2 @@ | ||
type Range<T> = [T, T]; | ||
export type Range<T> = [T, T]; | ||
export type AmPmType = 'am' | 'pm'; | ||
@@ -10,2 +10,1 @@ export type ClassName = string | null | undefined | (string | null | undefined)[]; | ||
export type Value = Date | null; | ||
export {}; |
{ | ||
"name": "react-datetime-picker", | ||
"version": "5.2.0", | ||
"version": "5.2.1", | ||
"description": "A date range picker for your React app.", | ||
@@ -18,3 +18,3 @@ "main": "dist/cjs/index.js", | ||
"clean": "rimraf dist", | ||
"copy-styles": "node ./copy-styles.mjs", | ||
"copy-styles": "node --loader ts-node/esm ./copy-styles.ts", | ||
"lint": "eslint . --ext .js,.jsx,.ts,.tsx", | ||
@@ -25,3 +25,3 @@ "prepack": "yarn clean && yarn build", | ||
"tsc": "tsc --noEmit", | ||
"unit": "vitest run" | ||
"unit": "vitest" | ||
}, | ||
@@ -60,4 +60,5 @@ "keywords": [ | ||
"@testing-library/user-event": "^14.4.0", | ||
"@types/node": "*", | ||
"eslint": "^8.26.0", | ||
"eslint-config-wojtekmaj": "^0.8.3", | ||
"eslint-config-wojtekmaj": "^0.8.4", | ||
"husky": "^8.0.0", | ||
@@ -70,2 +71,3 @@ "jsdom": "^21.1.0", | ||
"rimraf": "^3.0.0", | ||
"ts-node": "^10.9.1", | ||
"typescript": "^5.0.0", | ||
@@ -79,2 +81,6 @@ "vitest": "^0.30.1", | ||
}, | ||
"publishConfig": { | ||
"access": "public", | ||
"provenance": true | ||
}, | ||
"files": [ | ||
@@ -81,0 +87,0 @@ "dist", |
import DateTimePicker from './DateTimePicker'; | ||
import type { DateTimePickerProps } from './DateTimePicker'; | ||
export type { DateTimePickerProps } from './DateTimePicker'; | ||
export { DateTimePicker }; | ||
export type { DateTimePickerProps }; | ||
export default DateTimePicker; |
import PropTypes from 'prop-types'; | ||
import type { Requireable, Validator } from 'prop-types'; | ||
import type { Range } from './types'; | ||
const allViews = ['hour', 'minute', 'second']; | ||
const allValueTypes = [...allViews]; | ||
export function isMinDate(props: Record<string, unknown>, propName: string, componentName: string) { | ||
export const isMinDate: Validator<Date | null | undefined> = function isMinDate( | ||
props, | ||
propName, | ||
componentName, | ||
) { | ||
const { [propName]: minDate } = props; | ||
@@ -28,5 +35,9 @@ | ||
return null; | ||
} | ||
}; | ||
export function isMaxDate(props: Record<string, unknown>, propName: string, componentName: string) { | ||
export const isMaxDate: Validator<Date | null | undefined> = function isMaxDate( | ||
props, | ||
propName, | ||
componentName, | ||
) { | ||
const { [propName]: maxDate } = props; | ||
@@ -53,4 +64,8 @@ | ||
return null; | ||
} | ||
}; | ||
export const isValueType = PropTypes.oneOf(allValueTypes); | ||
export const rangeOf = <T>(type: Requireable<T>): Requireable<Range<T>> => { | ||
return PropTypes.arrayOf(type) as Requireable<Range<T>>; | ||
}; |
@@ -1,2 +0,2 @@ | ||
type Range<T> = [T, T]; | ||
export type Range<T> = [T, T]; | ||
@@ -3,0 +3,0 @@ export type AmPmType = 'am' | 'pm'; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
306828
0.63%6239
0.71%18
12.5%