-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
fix(react-slider): Export internal CSS vars #33682
base: master
Are you sure you want to change the base?
Changes from all commits
eaca8dd
0346814
857497f
8975b05
df41a58
c7e819e
2e64e9b
42e5850
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"type": "patch", | ||
"comment": "fix: exported internal CSS variables", | ||
"packageName": "@fluentui/react-slider", | ||
"email": "[email protected]", | ||
"dependentChangeType": "patch" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,21 +12,31 @@ 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`; | ||
const thumbColorVar = `--fui-Slider__thumb--color`; | ||
|
||
export const sliderCSSVars = { | ||
sliderDirectionVar: `--fui-Slider--direction`, | ||
sliderInnerThumbRadiusVar: `--fui-Slider__inner-thumb--radius`, | ||
sliderProgressVar: `--fui-Slider--progress`, | ||
sliderProgressColorVar: `--fui-Slider__progress--color`, | ||
sliderRailSizeVar: `--fui-Slider__rail--size`, | ||
sliderRailColorVar: `--fui-Slider__rail--color`, | ||
sliderStepsPercentVar: `--fui-Slider--steps-percent`, | ||
sliderThumbColorVar: `--fui-Slider__thumb--color`, | ||
sliderThumbSizeVar: `--fui-Slider__thumb--size`, | ||
}; | ||
|
||
const { sliderDirectionVar, sliderStepsPercentVar, sliderProgressVar } = sliderCSSVars; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. deconstructing all the vars out here saves a bunch of code below. 61 vars with sliderCSSVars prefix. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added it this way because of this comment: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If there is good reason to remove the destructuring, that's fine. |
||
const { | ||
sliderDirectionVar, | ||
sliderInnerThumbRadiusVar, | ||
sliderProgressVar, | ||
sliderProgressColorVar, | ||
sliderRailSizeVar, | ||
sliderRailColorVar, | ||
sliderStepsPercentVar, | ||
sliderThumbColorVar, | ||
sliderThumbSizeVar, | ||
} = sliderCSSVars; | ||
|
||
/** | ||
* Styles for the root slot | ||
|
@@ -41,64 +51,64 @@ const useRootStyles = makeStyles({ | |
}, | ||
|
||
small: { | ||
[thumbSizeVar]: '16px', | ||
[innerThumbRadiusVar]: '5px', | ||
[railSizeVar]: '2px', | ||
[sliderThumbSizeVar]: '16px', | ||
[sliderInnerThumbRadiusVar]: '5px', | ||
[sliderRailSizeVar]: '2px', | ||
minHeight: '24px', | ||
}, | ||
|
||
medium: { | ||
[thumbSizeVar]: '20px', | ||
[innerThumbRadiusVar]: '6px', | ||
[railSizeVar]: '4px', | ||
[sliderThumbSizeVar]: '20px', | ||
[sliderInnerThumbRadiusVar]: '6px', | ||
[sliderRailSizeVar]: '4px', | ||
minHeight: '32px', | ||
}, | ||
|
||
horizontal: { | ||
minWidth: '120px', | ||
// 3x3 grid with the rail and thumb in the center cell [2,2] and the hidden input stretching across all cells | ||
gridTemplateRows: `1fr var(${thumbSizeVar}) 1fr`, | ||
gridTemplateColumns: `1fr calc(100% - var(${thumbSizeVar})) 1fr`, | ||
gridTemplateRows: `1fr var(${sliderThumbSizeVar}) 1fr`, | ||
gridTemplateColumns: `1fr calc(100% - var(${sliderThumbSizeVar})) 1fr`, | ||
}, | ||
|
||
vertical: { | ||
minHeight: '120px', | ||
// 3x3 grid with the rail and thumb in the center cell [2,2] and the hidden input stretching across all cells | ||
gridTemplateRows: `1fr calc(100% - var(${thumbSizeVar})) 1fr`, | ||
gridTemplateColumns: `1fr var(${thumbSizeVar}) 1fr`, | ||
gridTemplateRows: `1fr calc(100% - var(${sliderThumbSizeVar})) 1fr`, | ||
gridTemplateColumns: `1fr var(${sliderThumbSizeVar}) 1fr`, | ||
}, | ||
|
||
enabled: { | ||
[railColorVar]: tokens.colorNeutralStrokeAccessible, | ||
[progressColorVar]: tokens.colorCompoundBrandBackground, | ||
[thumbColorVar]: tokens.colorCompoundBrandBackground, | ||
[sliderRailColorVar]: tokens.colorNeutralStrokeAccessible, | ||
[sliderProgressColorVar]: tokens.colorCompoundBrandBackground, | ||
[sliderThumbColorVar]: tokens.colorCompoundBrandBackground, | ||
':hover': { | ||
[thumbColorVar]: tokens.colorCompoundBrandBackgroundHover, | ||
[progressColorVar]: tokens.colorCompoundBrandBackgroundHover, | ||
[sliderThumbColorVar]: tokens.colorCompoundBrandBackgroundHover, | ||
[sliderProgressColorVar]: tokens.colorCompoundBrandBackgroundHover, | ||
}, | ||
':active': { | ||
[thumbColorVar]: tokens.colorCompoundBrandBackgroundPressed, | ||
[progressColorVar]: tokens.colorCompoundBrandBackgroundPressed, | ||
[sliderThumbColorVar]: tokens.colorCompoundBrandBackgroundPressed, | ||
[sliderProgressColorVar]: tokens.colorCompoundBrandBackgroundPressed, | ||
}, | ||
'@media (forced-colors: active)': { | ||
[railColorVar]: 'CanvasText', | ||
[thumbColorVar]: 'Highlight', | ||
[progressColorVar]: 'Highlight', | ||
[sliderRailColorVar]: 'CanvasText', | ||
[sliderThumbColorVar]: 'Highlight', | ||
[sliderProgressColorVar]: 'Highlight', | ||
':hover': { | ||
[thumbColorVar]: 'Highlight', | ||
[progressColorVar]: 'Highlight', | ||
[sliderThumbColorVar]: 'Highlight', | ||
[sliderProgressColorVar]: 'Highlight', | ||
}, | ||
}, | ||
}, | ||
|
||
disabled: { | ||
[thumbColorVar]: tokens.colorNeutralForegroundDisabled, | ||
[railColorVar]: tokens.colorNeutralBackgroundDisabled, | ||
[progressColorVar]: tokens.colorNeutralForegroundDisabled, | ||
[sliderThumbColorVar]: tokens.colorNeutralForegroundDisabled, | ||
[sliderRailColorVar]: tokens.colorNeutralBackgroundDisabled, | ||
[sliderProgressColorVar]: tokens.colorNeutralForegroundDisabled, | ||
'@media (forced-colors: active)': { | ||
[railColorVar]: 'GrayText', | ||
[thumbColorVar]: 'GrayText', | ||
[progressColorVar]: 'GrayText', | ||
[sliderRailColorVar]: 'GrayText', | ||
[sliderCSSVars.sliderThumbColorVar]: 'GrayText', | ||
[sliderCSSVars.sliderProgressColorVar]: 'GrayText', | ||
}, | ||
}, | ||
|
||
|
@@ -129,9 +139,9 @@ const useRailStyles = makeStyles({ | |
// Background gradient represents the progress of the slider | ||
backgroundImage: `linear-gradient( | ||
var(${sliderDirectionVar}), | ||
var(${progressColorVar}) 0%, | ||
var(${progressColorVar}) var(${sliderProgressVar}), | ||
var(${railColorVar}) var(${sliderProgressVar}) | ||
var(${sliderProgressColorVar}) 0%, | ||
var(${sliderProgressColorVar}) var(${sliderProgressVar}), | ||
var(${sliderRailColorVar}) var(${sliderProgressVar}) | ||
)`, | ||
outlineWidth: '1px', | ||
outlineStyle: 'solid', | ||
|
@@ -162,19 +172,19 @@ const useRailStyles = makeStyles({ | |
|
||
horizontal: { | ||
width: '100%', | ||
height: `var(${railSizeVar})`, | ||
height: `var(${sliderRailSizeVar})`, | ||
'::before': { | ||
left: '-1px', | ||
right: '-1px', | ||
height: `var(${railSizeVar})`, | ||
height: `var(${sliderRailSizeVar})`, | ||
}, | ||
}, | ||
|
||
vertical: { | ||
width: `var(${railSizeVar})`, | ||
width: `var(${sliderRailSizeVar})`, | ||
height: '100%', | ||
'::before': { | ||
width: `var(${railSizeVar})`, | ||
width: `var(${sliderRailSizeVar})`, | ||
top: '-1px', | ||
bottom: '-1px', | ||
}, | ||
|
@@ -189,20 +199,20 @@ const useThumbStyles = makeStyles({ | |
// 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})))`, | ||
[`${thumbPositionVar}`]: `clamp(var(${sliderInnerThumbRadiusVar}), var(${sliderProgressVar}), calc(100% - var(${sliderInnerThumbRadiusVar})))`, | ||
gridRowStart: '2', | ||
gridRowEnd: '2', | ||
gridColumnStart: '2', | ||
gridColumnEnd: '2', | ||
position: 'absolute', | ||
width: `var(${thumbSizeVar})`, | ||
height: `var(${thumbSizeVar})`, | ||
width: `var(${sliderThumbSizeVar})`, | ||
height: `var(${sliderThumbSizeVar})`, | ||
pointerEvents: 'none', | ||
outlineStyle: 'none', | ||
forcedColorAdjust: 'none', | ||
borderRadius: tokens.borderRadiusCircular, | ||
boxShadow: `0 0 0 calc(var(${thumbSizeVar}) * .2) ${tokens.colorNeutralBackground1} inset`, | ||
backgroundColor: `var(${thumbColorVar})`, | ||
boxShadow: `0 0 0 calc(var(${sliderThumbSizeVar}) * .2) ${tokens.colorNeutralBackground1} inset`, | ||
backgroundColor: `var(${sliderThumbColorVar})`, | ||
'::before': { | ||
position: 'absolute', | ||
top: '0px', | ||
|
@@ -212,12 +222,12 @@ const useThumbStyles = makeStyles({ | |
borderRadius: tokens.borderRadiusCircular, | ||
boxSizing: 'border-box', | ||
content: "''", | ||
border: `calc(var(${thumbSizeVar}) * .05) solid ${tokens.colorNeutralStroke1}`, | ||
border: `calc(var(${sliderThumbSizeVar}) * .05) solid ${tokens.colorNeutralStroke1}`, | ||
}, | ||
}, | ||
disabled: { | ||
'::before': { | ||
border: `calc(var(${thumbSizeVar}) * .05) solid ${tokens.colorNeutralForegroundDisabled}`, | ||
border: `calc(var(${sliderThumbSizeVar}) * .05) solid ${tokens.colorNeutralForegroundDisabled}`, | ||
}, | ||
}, | ||
horizontal: { | ||
|
@@ -248,12 +258,12 @@ const useInputStyles = makeStyles({ | |
cursor: 'default', | ||
}, | ||
horizontal: { | ||
height: `var(${thumbSizeVar})`, | ||
height: `var(${sliderThumbSizeVar})`, | ||
width: '100%', | ||
}, | ||
vertical: { | ||
height: '100%', | ||
width: `var(${thumbSizeVar})`, | ||
width: `var(${sliderThumbSizeVar})`, | ||
'-webkit-appearance': 'slider-vertical', | ||
}, | ||
}); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import * as React from 'react'; | ||
import { useId, Label, Slider, makeStyles, sliderCSSVars, tokens } from '@fluentui/react-components'; | ||
|
||
const { sliderProgressColorVar, sliderRailColorVar, sliderThumbColorVar, sliderThumbSizeVar } = sliderCSSVars; | ||
|
||
const useStyles = makeStyles({ | ||
enabled: { | ||
[sliderProgressColorVar]: '#ff0764', | ||
[sliderRailColorVar]: tokens.colorNeutralForeground1, | ||
[sliderThumbColorVar]: '#ff0764', | ||
':hover': { | ||
[sliderThumbColorVar]: '#d60d58', | ||
[sliderProgressColorVar]: '#d60d58', | ||
':active': { | ||
[sliderThumbColorVar]: '#b91150', | ||
[sliderProgressColorVar]: '#b91150', | ||
}, | ||
}, | ||
}, | ||
thumb: { | ||
[sliderThumbSizeVar]: '16px', | ||
boxShadow: `0 0 0 calc(var(${sliderThumbSizeVar}) * .2) ${tokens.colorTransparentBackground} inset`, | ||
'::before': { | ||
content: 'unset', | ||
}, | ||
}, | ||
}); | ||
|
||
export const Customized = () => { | ||
const id = useId(); | ||
const styles = useStyles(); | ||
|
||
return ( | ||
<> | ||
<Label htmlFor={id}>Customized slider</Label> | ||
<Slider className={styles.enabled} thumb={{ className: styles.thumb }} defaultValue={20} size="small" id={id} /> | ||
</> | ||
); | ||
}; | ||
|
||
Customized.parameters = { | ||
docs: { | ||
description: { | ||
story: 'Customized slider using its variables', | ||
}, | ||
}, | ||
}; |
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.
🕵🏾♀️ visual regressions to review in the fluentuiv9 Visual Regression Report
Avatar Converged 2 screenshots
Drawer 1 screenshots