Skip to content

Commit 8c14961

Browse files
committed
fix: Add default values if flagship var not set
If the variable is not set, the calc() will fail and the layout can break in non flagship contexts. Adding 0px default value where suitable
1 parent 8a600db commit 8c14961

File tree

2 files changed

+22
-11
lines changed

2 files changed

+22
-11
lines changed

react/MuiCozyTheme/helpers.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,3 +196,10 @@ export const makeContainedButtonStyle = (theme, color) => ({
196196
}
197197
}
198198
})
199+
200+
/**
201+
* @param {string} position one of `"top"` or `"bottom"`
202+
* @returns {string} `var(--flagship-${position}-height, 0px)`
203+
*/
204+
export const getFlagshipCssVar = position =>
205+
`var(--flagship-${position}-height, 0px)`

react/MuiCozyTheme/makeOverrides.js

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import {
44
makeChipStyleByColor,
55
makeSecondaryButtonStyle,
66
makeTextButtonStyle,
7-
makeContainedButtonStyle
7+
makeContainedButtonStyle,
8+
getFlagshipCssVar
89
} from './helpers'
910

1011
const SWITCH_BAR_WIDTH = 25
@@ -428,26 +429,27 @@ export const makeOverrides = theme => ({
428429
},
429430
paperFullScreen: {
430431
'& .cozyDialogActions': {
431-
paddingBottom:
432-
'calc(env(safe-area-inset-bottom) + var(--flagship-bottom-height))'
432+
paddingBottom: `calc(env(safe-area-inset-bottom) + ${getFlagshipCssVar(
433+
'bottom'
434+
)})`
433435
},
434436
// Can't do that within the stylus file because we need to only target
435437
// the fullscreen dialog
436438
'& [class*="DialogCloseButton"]': {
437-
transform: 'translateY(var(--flagship-top-height))'
439+
transform: `translateY(${getFlagshipCssVar('top')})`
438440
},
439441
'& [class*="DialogBackButton"]': {
440-
transform: 'translateY(var(--flagship-top-height))'
442+
transform: `translateY(${getFlagshipCssVar('top')})`
441443
},
442444
// 0.75rm === MuiDialogTitle.root.sm
443445
// we should not target specifically flagship-app since
444446
// we should only rely on the css var. But this is for
445447
// another time.
446448
'.flagship-app & .cozyDialogTitle': {
447-
paddingTop: 'calc(var(--flagship-top-height) + 0.75rem) !important'
449+
paddingTop: `calc(${getFlagshipCssVar('top')} + 0.75rem) !important`
448450
},
449451
'.flagship-app & .cozyDialogContent': {
450-
marginBottom: 'var(--flagship-bottom-height) !important'
452+
marginBottom: `${getFlagshipCssVar('bottom')} !important`
451453
}
452454
}
453455
},
@@ -506,13 +508,15 @@ export const makeOverrides = theme => ({
506508
'& .dialogContentWrapper': {
507509
flexGrow: 1,
508510
'&:not(.withActions)': {
509-
paddingBottom:
510-
'calc(env(safe-area-inset-bottom) + var(--flagship-bottom-height) + 16px)'
511+
paddingBottom: `calc(env(safe-area-inset-bottom) + ${getFlagshipCssVar(
512+
'bottom'
513+
)} + 16px)`
511514
}
512515
},
513516
'& .cozyDialogActions': {
514-
paddingBottom:
515-
'calc(env(safe-area-inset-bottom) + var(--flagship-bottom-height) + 16px)'
517+
paddingBottom: `calc(env(safe-area-inset-bottom) + ${getFlagshipCssVar(
518+
'bottom'
519+
)} + 16px)`
516520
}
517521
}
518522
},

0 commit comments

Comments
 (0)