-
-
Notifications
You must be signed in to change notification settings - Fork 777
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Pure FC with multiple update (#812)
* 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
Showing
52 changed files
with
3,064 additions
and
3,517 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
## debug | ||
|
||
<code src="../examples/debug.tsx"> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
Oops, something went wrong.
c33764e
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs: