Skip to content

Commit eada80d

Browse files
committed
feat: bar support
1 parent c682efa commit eada80d

File tree

3 files changed

+58
-8
lines changed

3 files changed

+58
-8
lines changed

assets/index.less

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,10 @@
113113
}
114114

115115
&-range-hover-start::after {
116-
border-left: 1px solid green!important;
116+
border-left: 1px solid green !important;
117117
}
118118
&-range-hover-end::after {
119-
border-right: 1px solid green!important;
119+
border-right: 1px solid green !important;
120120
}
121121

122122
&-today > &-inner {
@@ -292,6 +292,8 @@
292292
transform: rotate(-45deg);
293293
top: @arrow-size / 2 + 1px;
294294
left: @arrow-size;
295+
margin-left: 10px;
296+
transition: left 0.3s;
295297

296298
&::before,
297299
&::after {
@@ -329,5 +331,20 @@
329331
&-range {
330332
display: inline-flex;
331333
position: relative;
334+
335+
.@{prefix-cls}-active-bar {
336+
background: green;
337+
bottom: 0;
338+
height: 3px;
339+
pointer-events: none;
340+
transition: all 0.3s;
341+
opacity: 0;
342+
}
343+
344+
&-focused {
345+
.@{prefix-cls}-active-bar {
346+
opacity: 1;
347+
}
348+
}
332349
}
333350
}

examples/range.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ export default () => {
6565
allowClear
6666
ref={rangePickerRef}
6767
showTime
68+
style={{ width: 700 }}
6869
/>
6970
</div>
7071

src/RangePicker.tsx

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ function InnerRangePicker<DateType>(props: RangePickerProps<DateType>) {
209209
const panelDivRef = React.useRef<HTMLDivElement>(null);
210210
const startInputDivRef = React.useRef<HTMLDivElement>(null);
211211
const endInputDivRef = React.useRef<HTMLDivElement>(null);
212+
const separatorRef = React.useRef<HTMLDivElement>(null);
212213
const startInputRef = React.useRef<HTMLInputElement>(null);
213214
const endInputRef = React.useRef<HTMLInputElement>(null);
214215

@@ -707,7 +708,7 @@ function InnerRangePicker<DateType>(props: RangePickerProps<DateType>) {
707708
const showDoublePanel = currentMode === picker;
708709

709710
return (
710-
<>
711+
<div className={`${prefixCls}-range-panels`} ref={panelDivRef}>
711712
{renderPanel(showDoublePanel ? 'left' : false, {
712713
pickerValue: viewDate,
713714
onPickerValueChange: (newViewDate: DateType) => {
@@ -729,15 +730,22 @@ function InnerRangePicker<DateType>(props: RangePickerProps<DateType>) {
729730
);
730731
},
731732
})}
732-
</>
733+
</div>
733734
);
734735
}
735736
return renderPanel();
736737
}
737738

739+
let arrowLeft: number = 0;
740+
if (activePickerIndex && startInputDivRef.current && separatorRef.current) {
741+
// Arrow offset
742+
arrowLeft =
743+
startInputDivRef.current.offsetWidth + separatorRef.current.offsetWidth;
744+
}
745+
738746
const rangePanel = (
739747
<div style={{ minWidth: popupMinWidth }}>
740-
<div className={`${prefixCls}-range-arrow`} />
748+
<div className={`${prefixCls}-range-arrow`} style={{ left: arrowLeft }} />
741749

742750
{renderPanels()}
743751
</div>
@@ -780,12 +788,26 @@ function InnerRangePicker<DateType>(props: RangePickerProps<DateType>) {
780788
size: getInputSize(picker, formatList[0]),
781789
};
782790

791+
let activeBarLeft: number = 0;
792+
let activeBarWidth: number = 0;
793+
if (
794+
startInputDivRef.current &&
795+
endInputDivRef.current &&
796+
separatorRef.current
797+
) {
798+
if (activePickerIndex === 0) {
799+
activeBarWidth = startInputDivRef.current.offsetWidth;
800+
} else {
801+
activeBarLeft = arrowLeft;
802+
activeBarWidth = endInputDivRef.current.offsetWidth;
803+
}
804+
}
805+
783806
return (
784807
<PanelContext.Provider
785808
value={{
786809
operationRef,
787810
hideHeader: picker === 'time',
788-
panelRef: panelDivRef,
789811
onDateMouseEnter,
790812
onDateMouseLeave,
791813
}}
@@ -828,12 +850,14 @@ function InnerRangePicker<DateType>(props: RangePickerProps<DateType>) {
828850
{...inputSharedProps}
829851
/>
830852
</div>
831-
{separator}
853+
<div className={`${prefixCls}-range-separator`} ref={separatorRef}>
854+
{separator}
855+
</div>
832856
<div
833857
className={classNames(`${prefixCls}-input`, {
834858
[`${prefixCls}-input-active`]: activePickerIndex === 1,
835859
})}
836-
ref={startInputDivRef}
860+
ref={endInputDivRef}
837861
>
838862
<input
839863
disabled={mergedDisabled[1]}
@@ -846,6 +870,14 @@ function InnerRangePicker<DateType>(props: RangePickerProps<DateType>) {
846870
{...inputSharedProps}
847871
/>
848872
</div>
873+
<div
874+
className={`${prefixCls}-active-bar`}
875+
style={{
876+
left: activeBarLeft,
877+
width: activeBarWidth,
878+
position: 'absolute',
879+
}}
880+
/>
849881
{suffixNode}
850882
{clearNode}
851883
</div>

0 commit comments

Comments
 (0)