Skip to content

Commit 30a196a

Browse files
committed
feat: Support auto adjust offset
1 parent 7d7572f commit 30a196a

File tree

4 files changed

+61
-25
lines changed

4 files changed

+61
-25
lines changed

assets/index.less

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,13 +284,25 @@
284284

285285
// Panel
286286
@arrow-size: 10px;
287+
288+
&-placement-topLeft {
289+
.@{prefix-cls}-range-arrow {
290+
bottom: @arrow-size / 2 + 1px;
291+
transform: rotate(135deg);
292+
}
293+
}
294+
&-placement-bottomLeft {
295+
.@{prefix-cls}-range-arrow {
296+
top: @arrow-size / 2 + 1px;
297+
transform: rotate(-45deg);
298+
}
299+
}
300+
287301
.@{prefix-cls}-range-arrow {
288302
position: absolute;
289303
width: @arrow-size;
290304
height: @arrow-size;
291305
z-index: 1;
292-
transform: rotate(-45deg);
293-
top: @arrow-size / 2 + 1px;
294306
left: @arrow-size;
295307
margin-left: 10px;
296308
transition: left 0.3s;
@@ -332,6 +344,10 @@
332344
display: inline-flex;
333345
position: relative;
334346

347+
&-wrapper {
348+
display: flex;
349+
}
350+
335351
.@{prefix-cls}-active-bar {
336352
background: green;
337353
bottom: 0;
@@ -347,4 +363,10 @@
347363
}
348364
}
349365
}
366+
367+
&-panel-container {
368+
display: inline-block;
369+
vertical-align: top;
370+
transition: margin 0.3s;
371+
}
350372
}

examples/range.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export default () => {
4949
{value ? `${formatDate(value[0])} ~ ${formatDate(value[1])}` : 'null'}
5050
</h2>
5151

52-
<div style={{ display: 'flex', flexWrap: 'wrap' }}>
52+
<div style={{ display: 'flex', flexWrap: 'wrap', paddingTop: 600 }}>
5353
<div style={{ margin: '0 8px' }}>
5454
<h3>Basic</h3>
5555
<RangePicker<Moment>

src/PickerPanel.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ function PickerPanel<DateType>(props: PickerPanelProps<DateType>) {
416416
}
417417

418418
let todayNode: React.ReactNode;
419-
if (showToday && mergedMode === 'date' && picker === 'date') {
419+
if (showToday && mergedMode === 'date' && picker === 'date' && !showTime) {
420420
todayNode = (
421421
<a
422422
className={`${prefixCls}-today-btn`}

src/RangePicker.tsx

Lines changed: 35 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -702,24 +702,36 @@ function InnerRangePicker<DateType>(props: RangePickerProps<DateType>) {
702702
);
703703
}
704704

705+
let arrowLeft: number = 0;
706+
let panelLeft: number = 0;
707+
if (
708+
activePickerIndex &&
709+
startInputDivRef.current &&
710+
separatorRef.current &&
711+
panelDivRef.current
712+
) {
713+
// Arrow offset
714+
arrowLeft =
715+
startInputDivRef.current.offsetWidth + separatorRef.current.offsetWidth;
716+
717+
if (arrowLeft > panelDivRef.current.offsetWidth) {
718+
panelLeft = arrowLeft;
719+
}
720+
}
721+
705722
function renderPanels() {
723+
let panels: React.ReactNode;
724+
706725
if (picker !== 'time' && !showTime) {
707726
const viewDate = viewDates[activePickerIndex];
708727
const nextViewDate = getClosingViewDate(viewDate, picker, generateConfig);
709728
const currentMode = mergedModes[activePickerIndex];
710729

711730
const showDoublePanel = currentMode === picker;
712731

713-
return (
714-
<div className={`${prefixCls}-panel-container`} ref={panelDivRef}>
715-
{renderPanel(showDoublePanel ? 'left' : false, {
716-
pickerValue: viewDate,
717-
onPickerValueChange: (newViewDate: DateType) => {
718-
setViewDates(
719-
updateValues(viewDates, newViewDate, activePickerIndex),
720-
);
721-
},
722-
})}
732+
panels = (
733+
<>
734+
{}
723735
{showDoublePanel &&
724736
renderPanel('right', {
725737
pickerValue: nextViewDate,
@@ -733,25 +745,27 @@ function InnerRangePicker<DateType>(props: RangePickerProps<DateType>) {
733745
);
734746
},
735747
})}
736-
</div>
748+
</>
737749
);
750+
} else {
751+
panels = renderPanel();
738752
}
739753
return (
740-
<div className={`${prefixCls}-panel-container`} ref={panelDivRef}>
741-
{renderPanel()}
754+
<div
755+
className={`${prefixCls}-panel-container`}
756+
style={{ marginLeft: panelLeft }}
757+
ref={panelDivRef}
758+
>
759+
{panels}
742760
</div>
743761
);
744762
}
745763

746-
let arrowLeft: number = 0;
747-
if (activePickerIndex && startInputDivRef.current && separatorRef.current) {
748-
// Arrow offset
749-
arrowLeft =
750-
startInputDivRef.current.offsetWidth + separatorRef.current.offsetWidth;
751-
}
752-
753764
const rangePanel = (
754-
<div style={{ minWidth: popupMinWidth }}>
765+
<div
766+
className={`${prefixCls}-range-wrapper`}
767+
style={{ minWidth: popupMinWidth }}
768+
>
755769
<div className={`${prefixCls}-range-arrow`} style={{ left: arrowLeft }} />
756770

757771
{renderPanels()}

0 commit comments

Comments
 (0)