Skip to content

Commit

Permalink
feat(react-slider): adjust slider thumb position (#32424)
Browse files Browse the repository at this point in the history
  • Loading branch information
dmytrokirpa authored Nov 13, 2024
1 parent 4046b33 commit bb568eb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "minor",
"comment": "feat: adjust thumb positioning",
"packageName": "@fluentui/react-slider",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ export const sliderClassNames: SlotClassNames<SliderSlots> = {

// Internal CSS variables
const thumbSizeVar = `--fui-Slider__thumb--size`;
const innerThumbRadiusVar = `--fui-Slider__inner-thumb--radius`;
const thumbPositionVar = `--fui-Slider__thumb--position`;
const railSizeVar = `--fui-Slider__rail--size`;
const railColorVar = `--fui-Slider__rail--color`;
const progressColorVar = `--fui-Slider__progress--color`;
Expand Down Expand Up @@ -40,12 +42,14 @@ const useRootStyles = makeStyles({

small: {
[thumbSizeVar]: '16px',
[innerThumbRadiusVar]: '5px',
[railSizeVar]: '2px',
minHeight: '24px',
},

medium: {
[thumbSizeVar]: '20px',
[innerThumbRadiusVar]: '6px',
[railSizeVar]: '4px',
minHeight: '32px',
},
Expand Down Expand Up @@ -172,7 +176,7 @@ const useRailStyles = makeStyles({
'::before': {
width: `var(${railSizeVar})`,
top: '-1px',
bottom: '1px',
bottom: '-1px',
},
},
});
Expand All @@ -182,6 +186,10 @@ const useRailStyles = makeStyles({
*/
const useThumbStyles = makeStyles({
thumb: {
// Ensure the thumb stays within the track boundaries.
// When the value is at 0% or 100%, the distance from the track edge
// to the thumb center equals the inner thumb radius.
[`${thumbPositionVar}`]: `clamp(var(${innerThumbRadiusVar}), var(${sliderProgressVar}), calc(100% - var(${innerThumbRadiusVar})))`,
gridRowStart: '2',
gridRowEnd: '2',
gridColumnStart: '2',
Expand Down Expand Up @@ -214,11 +222,11 @@ const useThumbStyles = makeStyles({
},
horizontal: {
transform: 'translateX(-50%)',
left: `var(${sliderProgressVar})`,
left: `var(${thumbPositionVar})`,
},
vertical: {
transform: 'translateY(50%)',
bottom: `var(${sliderProgressVar})`,
bottom: `var(${thumbPositionVar})`,
},
});

Expand Down

0 comments on commit bb568eb

Please sign in to comment.