UNPKG

@kadconsulting/dry

Version:
25 lines 1.27 kB
import { jsx as _jsx } from "react/jsx-runtime"; import './DateInputPicker.scss'; const DateInputPicker = ({ value, onChange, minDate, maxDate, disabled, }) => { const handleDateChange = (event) => { const [year, month, day] = event.target.value?.split('-'); let selectedDate = null; if (event.target.value && year && month && day) { selectedDate = new Date(parseInt(year), parseInt(month) - 1, parseInt(day)); } onChange(selectedDate); }; const formatDate = (date) => { if (!date) { return ''; } const dateObj = new Date(date); const year = dateObj.getFullYear(); const month = (dateObj.getMonth() + 1).toString().padStart(2, '0'); const day = dateObj.getDate().toString().padStart(2, '0'); return `${year}-${month}-${day}`; }; return (_jsx("div", { className: 'date-input-picker', children: _jsx("input", { disabled: disabled, type: 'date', className: 'date-input-picker__input', value: value ? formatDate(value) : '', onChange: handleDateChange, min: minDate ? formatDate(minDate) : undefined, max: maxDate ? formatDate(maxDate) : undefined }) })); }; export default DateInputPicker; //# sourceMappingURL=DateInputPicker.js.map