Skip to content

Commit

Permalink
refactor: Pure FC with multiple update (#812)
Browse files Browse the repository at this point in the history
* init

* value of it

* switch focus

* feat: support focus

* cache all

* reverse support

* feat: vertical support

* feat: track support

* feat: base styles

* feat: marks

* feat: align with marks

* feat: align with steps

* feat: click to move to close value

* chore: click slide to move

* feat: dot

* feat: included

* feat: dragging mark

* ts def update

* keyboard of it

* multiple ranges

* pushable

* resolve pushable cache

* track draggable

* docs: all range

* dotStyle & activeDotStyle

* fix: dead loop

* fix: control draggable

* docs: slider examples

* docs: all docs

* chore: all props

* test: base test case

* fix: keyboard align logic

* test: test case

* test: part range test

* test: pushable

* refactor: move into useOffset

* refactor: offset of values

* chore: support steps

* chore: next values offset

* chore: keyboard pushable

* refactor: same logic of drag

* chore: clean up

* test: allowCross & pushable

* test: tmp

* test: back of react test lib

* test: range

* test: mv to react test lib

* feat: touch-able

* test: touch test

* test: test of it

* test: all legacy test

* chore: clean up

* test: Slider full coverage

* test: More test case

* test: full coverage
  • Loading branch information
zombieJ authored Feb 28, 2022
1 parent 9d6dcc5 commit c33764e
Show file tree
Hide file tree
Showing 52 changed files with 3,064 additions and 3,517 deletions.
102 changes: 55 additions & 47 deletions assets/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
@tooltip-arrow-width: 4px;
@tooltip-distance: @tooltip-arrow-width+4;
@tooltip-arrow-color: @tooltip-bg;
@ease-out-quint : cubic-bezier(0.23, 1, 0.32, 1);
@ease-in-quint : cubic-bezier(0.755, 0.05, 0.855, 0.06);
@ease-out-quint: cubic-bezier(0.23, 1, 0.32, 1);
@ease-in-quint: cubic-bezier(0.755, 0.05, 0.855, 0.06);

.borderBox() {
box-sizing: border-box;
Expand All @@ -23,40 +23,40 @@

.@{prefixClass} {
position: relative;
width: 100%;
height: 14px;
padding: 5px 0;
width: 100%;
border-radius: @border-radius-base;
touch-action: none;
.borderBox();

&-rail {
position: absolute;
width: 100%;
background-color: #e9e9e9;
height: 4px;
background-color: #e9e9e9;
border-radius: @border-radius-base;
}

&-track {
position: absolute;
left: 0;
height: 4px;
border-radius: @border-radius-base;
background-color: tint(@primary-color, 60%);
border-radius: @border-radius-base;
}

&-handle {
position: absolute;
width: 14px;
height: 14px;
margin-top: -5px;
background-color: #fff;
border: solid 2px tint(@primary-color, 50%);
border-radius: 50%;
cursor: pointer;
cursor: -webkit-grab;
margin-top: -5px;
cursor: grab;
border-radius: 50%;
border: solid 2px tint(@primary-color, 50%);
background-color: #fff;
opacity: 0.8;
touch-action: pan-x;

&-dragging&-dragging&-dragging {
Expand All @@ -66,6 +66,7 @@

&:focus {
outline: none;
box-shadow: 0 0 0 3px tint(@primary-color, 50%);
}

&-click-focused:focus {
Expand Down Expand Up @@ -96,10 +97,10 @@
&-mark-text {
position: absolute;
display: inline-block;
vertical-align: middle;
color: #999;
text-align: center;
vertical-align: middle;
cursor: pointer;
color: #999;

&-active {
color: #666;
Expand All @@ -111,19 +112,20 @@
width: 100%;
height: 4px;
background: transparent;
pointer-events: none;
}

&-dot {
position: absolute;
bottom: -2px;
margin-left: -4px;
width: 8px;
height: 8px;
border: 2px solid #e9e9e9;
// margin-left: -4px;
vertical-align: middle;
background-color: #fff;
cursor: pointer;
border: 2px solid #e9e9e9;
border-radius: 50%;
vertical-align: middle;
cursor: pointer;
&-active {
border-color: tint(@primary-color, 50%);
}
Expand All @@ -139,15 +141,17 @@
background-color: @disabledColor;
}

.@{prefixClass}-handle, .@{prefixClass}-dot {
.@{prefixClass}-handle,
.@{prefixClass}-dot {
background-color: #fff;
border-color: @disabledColor;
box-shadow: none;
background-color: #fff;
cursor: not-allowed;
}

.@{prefixClass}-mark-text, .@{prefixClass}-dot {
cursor: not-allowed!important;
.@{prefixClass}-mark-text,
.@{prefixClass}-dot {
cursor: not-allowed !important;
}
}
}
Expand All @@ -159,17 +163,18 @@

.@{prefixClass} {
&-rail {
height: 100%;
width: 4px;
height: 100%;
}

&-track {
left: 5px;
bottom: 0;
left: 5px;
width: 4px;
}

&-handle {
margin-top: 0;
margin-left: -5px;
touch-action: pan-y;
}
Expand All @@ -181,50 +186,53 @@
}

&-step {
height: 100%;
width: 4px;
height: 100%;
}

&-dot {
left: 2px;
margin-bottom: -4px;
&:first-child {
margin-bottom: -4px;
}
&:last-child {
margin-bottom: -4px;
}
margin-left: -2px;
// margin-bottom: -4px;
// &:first-child {
// margin-bottom: -4px;
// }
// &:last-child {
// margin-bottom: -4px;
// }
}
}
}

.motion-common() {
animation-duration: .3s;
animation-fill-mode: both;
display: block !important;
animation-duration: 0.3s;
animation-fill-mode: both;
}

.make-motion(@className, @keyframeName) {
.@{className}-enter, .@{className}-appear {
.@{className}-enter,
.@{className}-appear {
.motion-common();
animation-play-state: paused;
}
.@{className}-leave {
.motion-common();
animation-play-state: paused;
}
.@{className}-enter.@{className}-enter-active, .@{className}-appear.@{className}-appear-active {
animation-name: ~"@{keyframeName}In";
.@{className}-enter.@{className}-enter-active,
.@{className}-appear.@{className}-appear-active {
animation-name: ~'@{keyframeName}In';
animation-play-state: running;
}
.@{className}-leave.@{className}-leave-active {
animation-name: ~"@{keyframeName}Out";
animation-name: ~'@{keyframeName}Out';
animation-play-state: running;
}
}
.zoom-motion(@className, @keyframeName) {
.make-motion(@className, @keyframeName);
.@{className}-enter, .@{className}-appear {
.@{className}-enter,
.@{className}-appear {
transform: scale(0, 0); // need this by yiminghe
animation-timing-function: @ease-out-quint;
}
Expand All @@ -236,32 +244,32 @@

@keyframes rcSliderTooltipZoomDownIn {
0% {
opacity: 0;
transform-origin: 50% 100%;
transform: scale(0, 0);
transform-origin: 50% 100%;
opacity: 0;
}
100% {
transform-origin: 50% 100%;
transform: scale(1, 1);
transform-origin: 50% 100%;
}
}

@keyframes rcSliderTooltipZoomDownOut {
0% {
transform-origin: 50% 100%;
transform: scale(1, 1);
transform-origin: 50% 100%;
}
100% {
opacity: 0;
transform-origin: 50% 100%;
transform: scale(0, 0);
transform-origin: 50% 100%;
opacity: 0;
}
}

.@{prefixClass}-tooltip {
position: absolute;
left: -9999px;
top: -9999px;
left: -9999px;
visibility: visible;

.borderBox();
Expand All @@ -275,12 +283,12 @@
}

&-inner {
padding: 6px 2px;
min-width: 24px;
height: 24px;
padding: 6px 2px;
color: @tooltip-color;
font-size: 12px;
line-height: 1;
color: @tooltip-color;
text-align: center;
text-decoration: none;
background-color: @tooltip-bg;
Expand Down
3 changes: 3 additions & 0 deletions docs/demo/debug.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## debug

<code src="../examples/debug.tsx">
2 changes: 1 addition & 1 deletion docs/demo/handle.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
## handle

<code src="../examples/handle.jsx">
<code src="../examples/handle.tsx">
2 changes: 1 addition & 1 deletion docs/demo/marks.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
## marks

<code src="../examples/marks.jsx">
<code src="../examples/marks.tsx">
2 changes: 1 addition & 1 deletion docs/demo/range.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
## range

<code src="../examples/range.jsx">
<code src="../examples/range.tsx">
2 changes: 1 addition & 1 deletion docs/demo/slider.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
## slider

<code src="../examples/slider.jsx">
<code src="../examples/slider.tsx">
2 changes: 1 addition & 1 deletion docs/demo/vertical.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
## vertical

<code src="../examples/vertical.jsx">
<code src="../examples/vertical.tsx">
82 changes: 82 additions & 0 deletions docs/examples/components/TooltipSlider.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import * as React from 'react';
import 'rc-tooltip/assets/bootstrap.css';
import Slider from 'rc-slider';
import type { SliderProps } from 'rc-slider';
import raf from 'rc-util/lib/raf';
import Tooltip from 'rc-tooltip';

const HandleTooltip = (props: {
value: number;
children: React.ReactElement;
visible: boolean;
tipFormatter?: (value: number) => React.ReactNode;
}) => {
const { value, children, visible, tipFormatter = (val) => `${val} %`, ...restProps } = props;

const tooltipRef = React.useRef<any>();
const rafRef = React.useRef<number | null>(null);

function cancelKeepAlign() {
raf.cancel(rafRef.current!);
}

function keepAlign() {
rafRef.current = raf(() => {
tooltipRef.current?.forcePopupAlign();
});
}

React.useEffect(() => {
if (visible) {
keepAlign();
} else {
cancelKeepAlign();
}

return cancelKeepAlign;
}, [value, visible]);

return (
<Tooltip
placement="top"
overlay={tipFormatter(value)}
overlayInnerStyle={{ minHeight: 'auto' }}
ref={tooltipRef}
visible={visible}
{...restProps}
>
{children}
</Tooltip>
);
};

export const handleRender: SliderProps['handleRender'] = (node, props) => {
return (
<HandleTooltip value={props.value} visible={props.dragging}>
{node}
</HandleTooltip>
);
};

const TooltipSlider = ({
tipFormatter,
tipProps,
...props
}: SliderProps & { tipFormatter?: (value: number) => React.ReactNode; tipProps: any }) => {
const tipHandleRender: SliderProps['handleRender'] = (node, handleProps) => {
return (
<HandleTooltip
value={handleProps.value}
visible={handleProps.dragging}
tipFormatter={tipFormatter}
{...tipProps}
>
{node}
</HandleTooltip>
);
};

return <Slider {...props} handleRender={tipHandleRender} />;
};

export default TooltipSlider;
Loading

1 comment on commit c33764e

@vercel
Copy link

@vercel vercel bot commented on c33764e Feb 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.