@flywire/react-headlessui
Advanced tools
Comparing version 0.2.0-1 to 0.2.1
@@ -6,3 +6,3 @@ "use strict"; | ||
const utils_1 = require("../../utils"); | ||
const useDatePicker = ({ dateFormat = utils_1.DATE_FORMAT, name, value, onBlur, onChange, }) => { | ||
const useDatePicker = ({ dateFormat = utils_1.DEFAULT_DATE_FORMAT, name, value, onBlur, onChange, }) => { | ||
const [nativeValue, setNativeValue] = (0, react_1.useState)(value ? (0, utils_1.toNativeDatePickerFormat)(value, dateFormat) : ''); | ||
@@ -19,3 +19,12 @@ const handleChange = ({ target: { value, valueAsDate, validity }, }) => { | ||
const _onChange = (validity, date) => { | ||
const formattedDate = (0, utils_1.formatNativeDate)(validity, date, dateFormat); | ||
let formattedDate; | ||
if (isDateInvalid(validity)) { | ||
formattedDate = 'invalid'; | ||
} | ||
else if (isDateEmpty(validity, date)) { | ||
formattedDate = undefined; | ||
} | ||
else { | ||
formattedDate = (0, utils_1.formatDate)(date, dateFormat); | ||
} | ||
onChange === null || onChange === void 0 ? void 0 : onChange(name, formattedDate); | ||
@@ -30,1 +39,7 @@ }; | ||
exports.useDatePicker = useDatePicker; | ||
const isDateEmpty = (validity, date) => { | ||
return validity.valueMissing || date === null; | ||
}; | ||
const isDateInvalid = (validity) => { | ||
return validity.badInput; | ||
}; |
@@ -1,5 +0,5 @@ | ||
export declare const DATE_FORMAT = "MM/DD/YYYY"; | ||
export declare const DEFAULT_DATE_FORMAT = "MM/DD/YYYY"; | ||
export declare const NATIVE_FORMAT = "YYYY-MM-DD"; | ||
export declare const toNativeDatePickerFormat: (date: string, format?: string) => string; | ||
export declare const formatNativeDate: (validity: ValidityState, date: Date | null, dateFormat: string) => string | undefined; | ||
export declare const toNativeDatePickerFormat: (date: string, dateFormat?: string) => string; | ||
export declare const formatDate: (date: Date, dateFormat: string) => string; | ||
//# sourceMappingURL=formatDate.d.ts.map |
@@ -6,19 +6,15 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.formatNativeDate = exports.toNativeDatePickerFormat = exports.NATIVE_FORMAT = exports.DATE_FORMAT = void 0; | ||
exports.formatDate = exports.toNativeDatePickerFormat = exports.NATIVE_FORMAT = exports.DEFAULT_DATE_FORMAT = void 0; | ||
const dayjs_1 = __importDefault(require("dayjs")); | ||
const customParseFormat_1 = __importDefault(require("dayjs/plugin/customParseFormat")); | ||
dayjs_1.default.extend(customParseFormat_1.default); | ||
exports.DATE_FORMAT = 'MM/DD/YYYY'; | ||
exports.DEFAULT_DATE_FORMAT = 'MM/DD/YYYY'; | ||
exports.NATIVE_FORMAT = 'YYYY-MM-DD'; | ||
const toNativeDatePickerFormat = (date, format = exports.DATE_FORMAT) => { | ||
return (0, dayjs_1.default)(date, format, true).format(exports.NATIVE_FORMAT); | ||
const toNativeDatePickerFormat = (date, dateFormat = exports.DEFAULT_DATE_FORMAT) => { | ||
return (0, dayjs_1.default)(date, dateFormat, true).format(exports.NATIVE_FORMAT); | ||
}; | ||
exports.toNativeDatePickerFormat = toNativeDatePickerFormat; | ||
const formatNativeDate = (validity, date, dateFormat) => { | ||
if (validity.badInput) | ||
return 'invalid'; | ||
if (validity.valueMissing || date === null) | ||
return undefined; | ||
const formatDate = (date, dateFormat) => { | ||
return (0, dayjs_1.default)(date.toISOString()).format(dateFormat); | ||
}; | ||
exports.formatNativeDate = formatNativeDate; | ||
exports.formatDate = formatDate; |
import { useState, } from 'react'; | ||
import { DATE_FORMAT, formatNativeDate, toNativeDatePickerFormat, } from '../../utils'; | ||
export const useDatePicker = ({ dateFormat = DATE_FORMAT, name, value, onBlur, onChange, }) => { | ||
import { DEFAULT_DATE_FORMAT, formatDate, toNativeDatePickerFormat, } from '../../utils'; | ||
export const useDatePicker = ({ dateFormat = DEFAULT_DATE_FORMAT, name, value, onBlur, onChange, }) => { | ||
const [nativeValue, setNativeValue] = useState(value ? toNativeDatePickerFormat(value, dateFormat) : ''); | ||
@@ -15,3 +15,12 @@ const handleChange = ({ target: { value, valueAsDate, validity }, }) => { | ||
const _onChange = (validity, date) => { | ||
const formattedDate = formatNativeDate(validity, date, dateFormat); | ||
let formattedDate; | ||
if (isDateInvalid(validity)) { | ||
formattedDate = 'invalid'; | ||
} | ||
else if (isDateEmpty(validity, date)) { | ||
formattedDate = undefined; | ||
} | ||
else { | ||
formattedDate = formatDate(date, dateFormat); | ||
} | ||
onChange === null || onChange === void 0 ? void 0 : onChange(name, formattedDate); | ||
@@ -25,1 +34,7 @@ }; | ||
}; | ||
const isDateEmpty = (validity, date) => { | ||
return validity.valueMissing || date === null; | ||
}; | ||
const isDateInvalid = (validity) => { | ||
return validity.badInput; | ||
}; |
@@ -1,5 +0,5 @@ | ||
export declare const DATE_FORMAT = "MM/DD/YYYY"; | ||
export declare const DEFAULT_DATE_FORMAT = "MM/DD/YYYY"; | ||
export declare const NATIVE_FORMAT = "YYYY-MM-DD"; | ||
export declare const toNativeDatePickerFormat: (date: string, format?: string) => string; | ||
export declare const formatNativeDate: (validity: ValidityState, date: Date | null, dateFormat: string) => string | undefined; | ||
export declare const toNativeDatePickerFormat: (date: string, dateFormat?: string) => string; | ||
export declare const formatDate: (date: Date, dateFormat: string) => string; | ||
//# sourceMappingURL=formatDate.d.ts.map |
import dayjs from 'dayjs'; | ||
import customParseFormat from 'dayjs/plugin/customParseFormat'; | ||
dayjs.extend(customParseFormat); | ||
export const DATE_FORMAT = 'MM/DD/YYYY'; | ||
export const DEFAULT_DATE_FORMAT = 'MM/DD/YYYY'; | ||
export const NATIVE_FORMAT = 'YYYY-MM-DD'; | ||
export const toNativeDatePickerFormat = (date, format = DATE_FORMAT) => { | ||
return dayjs(date, format, true).format(NATIVE_FORMAT); | ||
export const toNativeDatePickerFormat = (date, dateFormat = DEFAULT_DATE_FORMAT) => { | ||
return dayjs(date, dateFormat, true).format(NATIVE_FORMAT); | ||
}; | ||
export const formatNativeDate = (validity, date, dateFormat) => { | ||
if (validity.badInput) | ||
return 'invalid'; | ||
if (validity.valueMissing || date === null) | ||
return undefined; | ||
export const formatDate = (date, dateFormat) => { | ||
return dayjs(date.toISOString()).format(dateFormat); | ||
}; |
@@ -15,3 +15,3 @@ (function (factory) { | ||
const utils_1 = require("../../utils"); | ||
const useDatePicker = ({ dateFormat = utils_1.DATE_FORMAT, name, value, onBlur, onChange, }) => { | ||
const useDatePicker = ({ dateFormat = utils_1.DEFAULT_DATE_FORMAT, name, value, onBlur, onChange, }) => { | ||
const [nativeValue, setNativeValue] = (0, react_1.useState)(value ? (0, utils_1.toNativeDatePickerFormat)(value, dateFormat) : ''); | ||
@@ -28,3 +28,12 @@ const handleChange = ({ target: { value, valueAsDate, validity }, }) => { | ||
const _onChange = (validity, date) => { | ||
const formattedDate = (0, utils_1.formatNativeDate)(validity, date, dateFormat); | ||
let formattedDate; | ||
if (isDateInvalid(validity)) { | ||
formattedDate = 'invalid'; | ||
} | ||
else if (isDateEmpty(validity, date)) { | ||
formattedDate = undefined; | ||
} | ||
else { | ||
formattedDate = (0, utils_1.formatDate)(date, dateFormat); | ||
} | ||
onChange === null || onChange === void 0 ? void 0 : onChange(name, formattedDate); | ||
@@ -39,2 +48,8 @@ }; | ||
exports.useDatePicker = useDatePicker; | ||
const isDateEmpty = (validity, date) => { | ||
return validity.valueMissing || date === null; | ||
}; | ||
const isDateInvalid = (validity) => { | ||
return validity.badInput; | ||
}; | ||
}); |
@@ -1,5 +0,5 @@ | ||
export declare const DATE_FORMAT = "MM/DD/YYYY"; | ||
export declare const DEFAULT_DATE_FORMAT = "MM/DD/YYYY"; | ||
export declare const NATIVE_FORMAT = "YYYY-MM-DD"; | ||
export declare const toNativeDatePickerFormat: (date: string, format?: string) => string; | ||
export declare const formatNativeDate: (validity: ValidityState, date: Date | null, dateFormat: string) => string | undefined; | ||
export declare const toNativeDatePickerFormat: (date: string, dateFormat?: string) => string; | ||
export declare const formatDate: (date: Date, dateFormat: string) => string; | ||
//# sourceMappingURL=formatDate.d.ts.map |
@@ -15,20 +15,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) { | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.formatNativeDate = exports.toNativeDatePickerFormat = exports.NATIVE_FORMAT = exports.DATE_FORMAT = void 0; | ||
exports.formatDate = exports.toNativeDatePickerFormat = exports.NATIVE_FORMAT = exports.DEFAULT_DATE_FORMAT = void 0; | ||
const dayjs_1 = __importDefault(require("dayjs")); | ||
const customParseFormat_1 = __importDefault(require("dayjs/plugin/customParseFormat")); | ||
dayjs_1.default.extend(customParseFormat_1.default); | ||
exports.DATE_FORMAT = 'MM/DD/YYYY'; | ||
exports.DEFAULT_DATE_FORMAT = 'MM/DD/YYYY'; | ||
exports.NATIVE_FORMAT = 'YYYY-MM-DD'; | ||
const toNativeDatePickerFormat = (date, format = exports.DATE_FORMAT) => { | ||
return (0, dayjs_1.default)(date, format, true).format(exports.NATIVE_FORMAT); | ||
const toNativeDatePickerFormat = (date, dateFormat = exports.DEFAULT_DATE_FORMAT) => { | ||
return (0, dayjs_1.default)(date, dateFormat, true).format(exports.NATIVE_FORMAT); | ||
}; | ||
exports.toNativeDatePickerFormat = toNativeDatePickerFormat; | ||
const formatNativeDate = (validity, date, dateFormat) => { | ||
if (validity.badInput) | ||
return 'invalid'; | ||
if (validity.valueMissing || date === null) | ||
return undefined; | ||
const formatDate = (date, dateFormat) => { | ||
return (0, dayjs_1.default)(date.toISOString()).format(dateFormat); | ||
}; | ||
exports.formatNativeDate = formatNativeDate; | ||
exports.formatDate = formatDate; | ||
}); |
{ | ||
"name": "@flywire/react-headlessui", | ||
"version": "0.2.0-1", | ||
"version": "0.2.1", | ||
"description": "Headless UI components", | ||
@@ -5,0 +5,0 @@ "main": "./dist/umd/index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
280001
4732