cynx-ui 1.3.9 → 1.3.10
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/components/DatePicker.jsx +2 -20
- package/package.json +1 -1
|
@@ -42,32 +42,15 @@ function isSameDay(a, b) {
|
|
|
42
42
|
}
|
|
43
43
|
function isToday(y, m, d) { const t = new Date(); return t.getFullYear()===y && t.getMonth()===m && t.getDate()===d; }
|
|
44
44
|
|
|
45
|
-
export function DatePicker({ value, onChange, label, placeholder = 'Select date', badges = {}, minDate, maxDate, disabled, showStepper = true, stepperPosition, style }) {
|
|
45
|
+
export function DatePicker({ value, onChange, label, placeholder = 'Select date', badges = {}, minDate, maxDate, disabled, showStepper = true, stepperPosition = 'around', style }) {
|
|
46
46
|
const [open, setOpen] = useState(false);
|
|
47
47
|
const [view, setView] = useState('day'); // 'day' | 'month' | 'year'
|
|
48
48
|
const [cursor, setCursor] = useState(() => toDate(value) || new Date());
|
|
49
49
|
const [pos, setPos] = useState({ top: 0, left: 0, width: 0 });
|
|
50
|
-
const [localStepperPos, setLocalStepperPos] = useState(() => {
|
|
51
|
-
return typeof window !== 'undefined' ? (localStorage.getItem('datepicker_stepper_position') || 'around') : 'around';
|
|
52
|
-
});
|
|
53
50
|
const ref = useRef(null);
|
|
54
51
|
const btnRef = useRef(null);
|
|
55
52
|
const dropRef = useRef(null);
|
|
56
53
|
|
|
57
|
-
useEffect(() => {
|
|
58
|
-
function syncPos() {
|
|
59
|
-
if (typeof window !== 'undefined') {
|
|
60
|
-
setLocalStepperPos(localStorage.getItem('datepicker_stepper_position') || 'around');
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
window.addEventListener('storage', syncPos);
|
|
64
|
-
window.addEventListener('datepicker-pos-changed', syncPos);
|
|
65
|
-
return () => {
|
|
66
|
-
window.removeEventListener('storage', syncPos);
|
|
67
|
-
window.removeEventListener('datepicker-pos-changed', syncPos);
|
|
68
|
-
};
|
|
69
|
-
}, []);
|
|
70
|
-
|
|
71
54
|
const changeDay = (delta) => {
|
|
72
55
|
if (disabled) return;
|
|
73
56
|
const current = toDate(value) || new Date();
|
|
@@ -385,8 +368,7 @@ export function DatePicker({ value, onChange, label, placeholder = 'Select date'
|
|
|
385
368
|
</button>
|
|
386
369
|
);
|
|
387
370
|
|
|
388
|
-
const
|
|
389
|
-
const actualPos = stepperPosition || savedPos || 'around';
|
|
371
|
+
const actualPos = stepperPosition || 'around';
|
|
390
372
|
const showStepperEffective = showStepper && actualPos !== 'off';
|
|
391
373
|
const posMode = actualPos === 'left' || actualPos === 'start' ? 'left'
|
|
392
374
|
: actualPos === 'right' || actualPos === 'end' ? 'right'
|