Skip to content
Snippets Groups Projects
Commit 33fb74e0 authored by Oisin Coveney's avatar Oisin Coveney
Browse files

Attempt a fix at font size scaling

parent 1ab2ce59
Branches
Tags
No related merge requests found
......@@ -218,3 +218,12 @@
pointer-events: all;
user-select: auto;
}
.ScalarValueContainer {
container-type: size;
container-name: scalar-value;
}
.ScalarValueElement {
font-size: calc(0.5rem + 10cqmin);
}
......@@ -3,7 +3,6 @@
*/
/* eslint-disable react/prop-types */
import cx from "classnames";
import { useMemo } from "react";
import { t } from "ttag";
import { Ellipsified } from "metabase/core/components/Ellipsified";
......@@ -23,54 +22,25 @@ import {
ScalarTitleContent,
ScalarValueWrapper,
} from "./ScalarValue.styled";
import { findSize, getMaxFontSize } from "./utils";
export const ScalarWrapper = ({ children }) => (
<ScalarRoot>{children}</ScalarRoot>
<ScalarRoot className={DashboardS.ScalarValueContainer}>
{children}
</ScalarRoot>
);
const ScalarValue = ({
value,
height,
width,
gridSize,
totalNumGridCols,
fontFamily,
}) => {
const ScalarValue = ({ value }) => {
const {
other: { number: numberTheme },
} = useMantineTheme();
const fontSize = useMemo(() => {
if (numberTheme?.value?.fontSize) {
return numberTheme.value?.fontSize;
}
return findSize({
text: value,
targetHeight: height,
targetWidth: width,
fontFamily: fontFamily ?? "Lato",
fontWeight: 700,
unit: "rem",
step: 0.2,
min: 1,
max: gridSize ? getMaxFontSize(gridSize.width, totalNumGridCols) : 4,
});
}, [
fontFamily,
gridSize,
height,
totalNumGridCols,
value,
width,
numberTheme?.value?.fontSize,
]);
return (
<ScalarValueWrapper
className={cx(DashboardS.ScalarValue, QueryBuilderS.ScalarValue)}
fontSize={fontSize}
className={cx(
DashboardS.ScalarValue,
DashboardS.ScalarValueElement,
QueryBuilderS.ScalarValue,
)}
lineHeight={numberTheme?.value?.lineHeight}
data-testid="scalar-value"
>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment