-
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
Draft
ValentinaKozlova
wants to merge
4
commits into
microsoft:master
Choose a base branch
from
ValentinaKozlova:fix/slider-export-vars
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+76
−66
Draft
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
change/@fluentui-react-slider-fd76d130-d916-4372-8ebb-4570aa203878.json
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,7 @@ | ||
{ | ||
"type": "patch", | ||
"comment": "fix: exported internal CSS variables", | ||
"packageName": "@fluentui/react-slider", | ||
"email": "[email protected]", | ||
"dependentChangeType": "patch" | ||
} |
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 |
---|---|---|
|
@@ -11,23 +11,19 @@ export const sliderClassNames: SlotClassNames<SliderSlots> = { | |
input: 'fui-Slider__input', | ||
}; | ||
|
||
// 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`, | ||
sliderThumbPositionVar: `--fui-Slider__thumb--position`, | ||
}; | ||
|
||
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. |
||
|
||
/** | ||
* Styles for the root slot | ||
*/ | ||
|
@@ -41,64 +37,64 @@ const useRootStyles = makeStyles({ | |
}, | ||
|
||
small: { | ||
[thumbSizeVar]: '16px', | ||
[innerThumbRadiusVar]: '5px', | ||
[railSizeVar]: '2px', | ||
[sliderCSSVars.sliderThumbSizeVar]: '16px', | ||
[sliderCSSVars.sliderInnerThumbRadiusVar]: '5px', | ||
[sliderCSSVars.sliderRailSizeVar]: '2px', | ||
minHeight: '24px', | ||
}, | ||
|
||
medium: { | ||
[thumbSizeVar]: '20px', | ||
[innerThumbRadiusVar]: '6px', | ||
[railSizeVar]: '4px', | ||
[sliderCSSVars.sliderThumbSizeVar]: '20px', | ||
[sliderCSSVars.sliderInnerThumbRadiusVar]: '6px', | ||
[sliderCSSVars.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(${sliderCSSVars.sliderThumbSizeVar}) 1fr`, | ||
gridTemplateColumns: `1fr calc(100% - var(${sliderCSSVars.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(${sliderCSSVars.sliderThumbSizeVar})) 1fr`, | ||
gridTemplateColumns: `1fr var(${sliderCSSVars.sliderThumbSizeVar}) 1fr`, | ||
}, | ||
|
||
enabled: { | ||
[railColorVar]: tokens.colorNeutralStrokeAccessible, | ||
[progressColorVar]: tokens.colorCompoundBrandBackground, | ||
[thumbColorVar]: tokens.colorCompoundBrandBackground, | ||
[sliderCSSVars.sliderRailColorVar]: tokens.colorNeutralStrokeAccessible, | ||
[sliderCSSVars.sliderProgressColorVar]: tokens.colorCompoundBrandBackground, | ||
[sliderCSSVars.sliderThumbColorVar]: tokens.colorCompoundBrandBackground, | ||
':hover': { | ||
[thumbColorVar]: tokens.colorCompoundBrandBackgroundHover, | ||
[progressColorVar]: tokens.colorCompoundBrandBackgroundHover, | ||
[sliderCSSVars.sliderThumbColorVar]: tokens.colorCompoundBrandBackgroundHover, | ||
[sliderCSSVars.sliderProgressColorVar]: tokens.colorCompoundBrandBackgroundHover, | ||
}, | ||
':active': { | ||
[thumbColorVar]: tokens.colorCompoundBrandBackgroundPressed, | ||
[progressColorVar]: tokens.colorCompoundBrandBackgroundPressed, | ||
[sliderCSSVars.sliderThumbColorVar]: tokens.colorCompoundBrandBackgroundPressed, | ||
[sliderCSSVars.sliderProgressColorVar]: tokens.colorCompoundBrandBackgroundPressed, | ||
}, | ||
'@media (forced-colors: active)': { | ||
[railColorVar]: 'CanvasText', | ||
[thumbColorVar]: 'Highlight', | ||
[progressColorVar]: 'Highlight', | ||
[sliderCSSVars.sliderRailColorVar]: 'CanvasText', | ||
[sliderCSSVars.sliderThumbColorVar]: 'Highlight', | ||
[sliderCSSVars.sliderProgressColorVar]: 'Highlight', | ||
':hover': { | ||
[thumbColorVar]: 'Highlight', | ||
[progressColorVar]: 'Highlight', | ||
[sliderCSSVars.sliderThumbColorVar]: 'Highlight', | ||
[sliderCSSVars.sliderProgressColorVar]: 'Highlight', | ||
}, | ||
}, | ||
}, | ||
|
||
disabled: { | ||
[thumbColorVar]: tokens.colorNeutralForegroundDisabled, | ||
[railColorVar]: tokens.colorNeutralBackgroundDisabled, | ||
[progressColorVar]: tokens.colorNeutralForegroundDisabled, | ||
[sliderCSSVars.sliderThumbColorVar]: tokens.colorNeutralForegroundDisabled, | ||
[sliderCSSVars.sliderRailColorVar]: tokens.colorNeutralBackgroundDisabled, | ||
[sliderCSSVars.sliderProgressColorVar]: tokens.colorNeutralForegroundDisabled, | ||
'@media (forced-colors: active)': { | ||
[railColorVar]: 'GrayText', | ||
[thumbColorVar]: 'GrayText', | ||
[progressColorVar]: 'GrayText', | ||
[sliderCSSVars.sliderRailColorVar]: 'GrayText', | ||
[sliderCSSVars.sliderThumbColorVar]: 'GrayText', | ||
[sliderCSSVars.sliderProgressColorVar]: 'GrayText', | ||
}, | ||
}, | ||
|
||
|
@@ -128,10 +124,10 @@ const useRailStyles = makeStyles({ | |
forcedColorAdjust: 'none', | ||
// 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(${sliderCSSVars.sliderDirectionVar}), | ||
var(${sliderCSSVars.sliderProgressColorVar}) 0%, | ||
var(${sliderCSSVars.sliderProgressColorVar}) var(${sliderCSSVars.sliderProgressVar}), | ||
var(${sliderCSSVars.sliderRailColorVar}) var(${sliderCSSVars.sliderProgressVar}) | ||
)`, | ||
outlineWidth: '1px', | ||
outlineStyle: 'solid', | ||
|
@@ -141,40 +137,40 @@ const useRailStyles = makeStyles({ | |
position: 'absolute', | ||
// Repeating gradient represents the steps if provided | ||
backgroundImage: `repeating-linear-gradient( | ||
var(${sliderDirectionVar}), | ||
var(${sliderCSSVars.sliderDirectionVar}), | ||
#0000 0%, | ||
#0000 calc(var(${sliderStepsPercentVar}) - 1px), | ||
${tokens.colorNeutralBackground1} calc(var(${sliderStepsPercentVar}) - 1px), | ||
${tokens.colorNeutralBackground1} var(${sliderStepsPercentVar}) | ||
#0000 calc(var(${sliderCSSVars.sliderStepsPercentVar}) - 1px), | ||
${tokens.colorNeutralBackground1} calc(var(${sliderCSSVars.sliderStepsPercentVar}) - 1px), | ||
${tokens.colorNeutralBackground1} var(${sliderCSSVars.sliderStepsPercentVar}) | ||
)`, | ||
// force steps to use HighlightText for high contrast mode | ||
'@media (forced-colors: active)': { | ||
backgroundImage: `repeating-linear-gradient( | ||
var(${sliderDirectionVar}), | ||
var(${sliderCSSVars.sliderDirectionVar}), | ||
#0000 0%, | ||
#0000 calc(var(${sliderStepsPercentVar}) - 1px), | ||
HighlightText calc(var(${sliderStepsPercentVar}) - 1px), | ||
HighlightText var(${sliderStepsPercentVar}) | ||
#0000 calc(var(${sliderCSSVars.sliderStepsPercentVar}) - 1px), | ||
HighlightText calc(var(${sliderCSSVars.sliderStepsPercentVar}) - 1px), | ||
HighlightText var(${sliderCSSVars.sliderStepsPercentVar}) | ||
)`, | ||
}, | ||
}, | ||
}, | ||
|
||
horizontal: { | ||
width: '100%', | ||
height: `var(${railSizeVar})`, | ||
height: `var(${sliderCSSVars.sliderRailSizeVar})`, | ||
'::before': { | ||
left: '-1px', | ||
right: '-1px', | ||
height: `var(${railSizeVar})`, | ||
height: `var(${sliderCSSVars.sliderRailSizeVar})`, | ||
}, | ||
}, | ||
|
||
vertical: { | ||
width: `var(${railSizeVar})`, | ||
width: `var(${sliderCSSVars.sliderRailSizeVar})`, | ||
height: '100%', | ||
'::before': { | ||
width: `var(${railSizeVar})`, | ||
width: `var(${sliderCSSVars.sliderRailSizeVar})`, | ||
top: '-1px', | ||
bottom: '-1px', | ||
}, | ||
|
@@ -189,20 +185,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})))`, | ||
[`${sliderCSSVars.sliderThumbPositionVar}`]: `clamp(var(${sliderCSSVars.sliderInnerThumbRadiusVar}), var(${sliderCSSVars.sliderProgressVar}), calc(100% - var(${sliderCSSVars.sliderInnerThumbRadiusVar})))`, | ||
gridRowStart: '2', | ||
gridRowEnd: '2', | ||
gridColumnStart: '2', | ||
gridColumnEnd: '2', | ||
position: 'absolute', | ||
width: `var(${thumbSizeVar})`, | ||
height: `var(${thumbSizeVar})`, | ||
width: `var(${sliderCSSVars.sliderThumbSizeVar})`, | ||
height: `var(${sliderCSSVars.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(${sliderCSSVars.sliderThumbSizeVar}) * .2) ${tokens.colorNeutralBackground1} inset`, | ||
backgroundColor: `var(${sliderCSSVars.sliderThumbColorVar})`, | ||
'::before': { | ||
position: 'absolute', | ||
top: '0px', | ||
|
@@ -212,21 +208,21 @@ const useThumbStyles = makeStyles({ | |
borderRadius: tokens.borderRadiusCircular, | ||
boxSizing: 'border-box', | ||
content: "''", | ||
border: `calc(var(${thumbSizeVar}) * .05) solid ${tokens.colorNeutralStroke1}`, | ||
border: `calc(var(${sliderCSSVars.sliderThumbSizeVar}) * .05) solid ${tokens.colorNeutralStroke1}`, | ||
}, | ||
}, | ||
disabled: { | ||
'::before': { | ||
border: `calc(var(${thumbSizeVar}) * .05) solid ${tokens.colorNeutralForegroundDisabled}`, | ||
border: `calc(var(${sliderCSSVars.sliderThumbSizeVar}) * .05) solid ${tokens.colorNeutralForegroundDisabled}`, | ||
}, | ||
}, | ||
horizontal: { | ||
transform: 'translateX(-50%)', | ||
left: `var(${thumbPositionVar})`, | ||
left: `var(${sliderCSSVars.sliderThumbPositionVar})`, | ||
}, | ||
vertical: { | ||
transform: 'translateY(50%)', | ||
bottom: `var(${thumbPositionVar})`, | ||
bottom: `var(${sliderCSSVars.sliderThumbPositionVar})`, | ||
}, | ||
}); | ||
|
||
|
@@ -248,12 +244,12 @@ const useInputStyles = makeStyles({ | |
cursor: 'default', | ||
}, | ||
horizontal: { | ||
height: `var(${thumbSizeVar})`, | ||
height: `var(${sliderCSSVars.sliderThumbSizeVar})`, | ||
width: '100%', | ||
}, | ||
vertical: { | ||
height: '100%', | ||
width: `var(${thumbSizeVar})`, | ||
width: `var(${sliderCSSVars.sliderThumbSizeVar})`, | ||
'-webkit-appearance': 'slider-vertical', | ||
}, | ||
}); | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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