diff --git a/packages/main/src/components/Grid/__snapshots__/Grid.test.tsx.snap b/packages/main/src/components/Grid/__snapshots__/Grid.test.tsx.snap
index 54870f11545..8302d1523ce 100644
--- a/packages/main/src/components/Grid/__snapshots__/Grid.test.tsx.snap
+++ b/packages/main/src/components/Grid/__snapshots__/Grid.test.tsx.snap
@@ -6,7 +6,7 @@ exports[`Grid Custom Class Names and Styling 1`] = `
style="width: 60%; background-color: purple;"
>
[0-9]|1[0-1]))? ?([L](?
[0-9]|1[0-1]))? ?([M](?[0-9]|1[0-1]))? ?([S](?[0-9]|1[0-1]))?$/i;
+const SPAN_PATTERN = /^([X][L](?[1-9]|1[0-2]))? ?([L](?[1-9]|1[0-2]))? ?([M](?[1-9]|1[0-2]))? ?([S](?[1-9]|1[0-2]))?$/i;
-const getCurrentSpan = () => {
- const classList = document.querySelector('html').classList;
- const isXL = classList.contains('sapUiMedia-StdExt-LargeDesktop');
- const isL = !isXL && classList.contains('sapUiMedia-Std-Desktop');
- const isM = !isL && classList.contains('sapUiMedia-Std-Tablet');
- const isS = !isM && classList.contains('sapUiMedia-Std-Phone');
- return [false, isXL, isL, isM, isS].indexOf(true);
-};
+const DefaultSpanMap = new Map();
+DefaultSpanMap.set('Phone', 12);
+DefaultSpanMap.set('Tablet', 6);
+DefaultSpanMap.set('Desktop', 3);
+DefaultSpanMap.set('LargeDesktop', 3);
+
+const DefaultIndentMap = new Map();
+DefaultIndentMap.set('Phone', 0);
+DefaultIndentMap.set('Tablet', 0);
+DefaultIndentMap.set('Desktop', 0);
+DefaultIndentMap.set('LargeDesktop', 0);
-const getSpanFromString = (span) => {
- const currentSpan = getCurrentSpan();
+const getSpanFromString = (span, currentRange) => {
const spanConfig = SPAN_PATTERN.exec(span);
- return spanConfig[currentSpan]
- ? parseInt(spanConfig[currentSpan].replace(/[XLMS]{0,2}/g, ''), 10)
- : [undefined, 3, 3, 6, 12][currentSpan];
+ return spanConfig.groups[currentRange] ?? DefaultSpanMap.get(currentRange);
};
-const getIndentFromString = (indent) => {
- const currentSpan = getCurrentSpan();
+const getIndentFromString = (indent, currentRange) => {
const indentConfig = INDENT_PATTERN.exec(indent);
- return indentConfig[currentSpan]
- ? parseInt(indentConfig[currentSpan].replace(/[XLMS]{0,2}/g, ''), 10)
- : [undefined, 0, 0, 0, 0][currentSpan];
+ return indentConfig.groups[currentRange] ?? DefaultIndentMap.get(currentRange);
};
const useStyles = createComponentStyles(GridClasses, { name: 'Grid' });
@@ -114,6 +111,8 @@ const Grid: FC = forwardRef((props: GridPropTypes, ref: Ref = forwardRef((props: GridPropTypes, ref: Ref) => {
- const span = getSpanFromString(defaultSpan);
- const indentSpan = getIndentFromString(defaultIndent);
-
const gridSpanClasses = StyleClassHelper.of(classes.gridSpan);
if (child.props['data-layout'] && child.props['data-layout'].span) {
- const childSpan = getSpanFromString(child.props['data-layout'].span);
+ const childSpan = getSpanFromString(child.props['data-layout'].span, currentRange);
gridSpanClasses.put(classes[`gridSpan${childSpan}`]);
} else {
+ const span = getSpanFromString(defaultSpan, currentRange);
gridSpanClasses.put(classes[`gridSpan${span}`]);
}
+ const indentSpan = getIndentFromString(defaultIndent, currentRange);
if (child.props['data-layout'] && child.props['data-layout'].indent) {
- const childIndent = getIndentFromString(child.props['data-layout'].indent);
+ const childIndent = getIndentFromString(child.props['data-layout'].indent, currentRange);
if (childIndent && childIndent > 0) {
gridSpanClasses.put(classes[`gridIndent${childIndent}`]);
}