Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: reverse slider mode #2412

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"packages/*",
"icons"
],
"version": "5.11.0",
"version": "5.11.1-alpha.0",
"npmClient": "yarn",
"useWorkspaces": true,
"useNx": false
Expand Down
2 changes: 1 addition & 1 deletion packages/Slider/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@welcome-ui/slider",
"version": "5.6.1",
"version": "5.11.1-alpha.0",
"description": "Customizable design system with react • styled-components • styled-system and ariakit.",
"main": "dist/index.js",
"module": "dist/index.mjs",
Expand Down
12 changes: 10 additions & 2 deletions packages/Slider/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export interface SliderOptions
borderSelectorColor?: string
label?: string
hint?: string
reverse?: boolean
step?: number
type?: Type
values?: number[]
Expand All @@ -47,6 +48,7 @@ export const SliderComponent = forwardRef<'div', SliderProps>(
max,
min,
onChange,
reverse = false,
step = 1,
tooltip,
type,
Expand Down Expand Up @@ -114,15 +116,21 @@ export const SliderComponent = forwardRef<'div', SliderProps>(
// Updates the slider range when user drag the slider
useEffect(() => {
if (range.current) {
range.current.style.backgroundSize = `${getPercent(localValue)}% 100%`
if (!reverse) {
range.current.style.backgroundSize = `${getPercent(localValue)}% 100%`
} else {
const percentage = 100 - getPercent(localValue)
range.current.style.backgroundSize = `${percentage}%`
range.current.style.backgroundPosition = 'right'
}
}
if (tooltipRef.current) {
const fraction = getPercent(localValue) / 100
tooltipRef.current.style.left = `calc(${fraction * 100}% + ${
(0.5 - fraction) * thumbWidth
}px)`
}
}, [localValue, getPercent])
}, [localValue, getPercent, reverse])

// Give the possibility to the parent to modify the value from outside but we need to check if it respect the step
useEffect(() => {
Expand Down
Loading