-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
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
[system] Add spacing
theme token to be used in theme.spacing()
#40224
Changes from all commits
f529b10
bb8f428
db80fc4
0a07aac
74193ab
768a882
3d5d4a1
6e4337e
a65da07
d219ae4
865e9f9
15113b1
90c494f
4fc3d5a
0f39d07
f524263
077fd51
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 |
---|---|---|
|
@@ -27,6 +27,9 @@ import gridClasses, { getGridUtilityClass } from './gridClasses'; | |
|
||
function getOffset(val) { | ||
const parse = parseFloat(val); | ||
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 (Number.isNaN(parse)) { | ||
return val; | ||
} | ||
return `${parse}${String(val).replace(String(parse), '') || 'px'}`; | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -1,8 +1,7 @@ | ||||||||
import deepmerge from '@mui/utils/deepmerge'; | ||||||||
import { | ||||||||
unstable_createGetCssVar as systemCreateGetCssVar, | ||||||||
unstable_prepareCssVars as prepareCssVars, | ||||||||
} from '@mui/system'; | ||||||||
import { unstable_createGetCssVar as systemCreateGetCssVar, createSpacing } from '@mui/system'; | ||||||||
import { createUnarySpacing } from '@mui/system/spacing'; | ||||||||
import { prepareCssVars } from '@mui/system/cssVars'; | ||||||||
import styleFunctionSx, { | ||||||||
unstable_defaultSxConfig as defaultSxConfig, | ||||||||
} from '@mui/system/styleFunctionSx'; | ||||||||
|
@@ -63,6 +62,22 @@ function setColorChannel(obj, key) { | |||||||
} | ||||||||
} | ||||||||
|
||||||||
function getSpacingVal(spacingInput) { | ||||||||
DiegoAndai marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
if (typeof spacingInput === 'number') { | ||||||||
return `${spacingInput}px`; | ||||||||
} | ||||||||
if (typeof spacingInput === 'string') { | ||||||||
return spacingInput; | ||||||||
} | ||||||||
if (typeof spacingInput === 'function') { | ||||||||
return getSpacingVal(spacingInput(1)); | ||||||||
} | ||||||||
if (Array.isArray(spacingInput)) { | ||||||||
return spacingInput; | ||||||||
} | ||||||||
return '8px'; | ||||||||
} | ||||||||
|
||||||||
const silent = (fn) => { | ||||||||
try { | ||||||||
return fn(); | ||||||||
|
@@ -124,6 +139,7 @@ export default function extendTheme(options = {}, ...args) { | |||||||
overlays: colorSchemesInput.dark?.overlays || defaultDarkOverlays, | ||||||||
}, | ||||||||
}, | ||||||||
spacing: getSpacingVal(input.spacing), | ||||||||
}; | ||||||||
|
||||||||
Object.keys(theme.colorSchemes).forEach((key) => { | ||||||||
|
@@ -414,7 +430,11 @@ export default function extendTheme(options = {}, ...args) { | |||||||
}); | ||||||||
theme.generateThemeVars = generateThemeVars; | ||||||||
theme.generateStyleSheets = generateStyleSheets; | ||||||||
theme.generateSpacing = function generateSpacing() { | ||||||||
return createSpacing(input.spacing, createUnarySpacing(this)); | ||||||||
}; | ||||||||
Comment on lines
+433
to
+435
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. Can't we do this?
Suggested change
Why do we need |
||||||||
theme.getColorSchemeSelector = (colorScheme) => `[${theme.attribute}="${colorScheme}"] &`; | ||||||||
theme.spacing = theme.generateSpacing(); | ||||||||
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.
Suggested change
|
||||||||
theme.shouldSkipGeneratingVar = shouldSkipGeneratingVar; | ||||||||
theme.unstable_sxConfig = { | ||||||||
...defaultSxConfig, | ||||||||
|
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.
Testing margin values should use Karma