Files
jitsi-meet/react/features/display-name/components/web/styles.ts
Hristo Terezov d5793c2445 Revert typography values in tokens to px from rem (#16026)
* Revert "feat(base/ui/native): Convert rem to px  (#15934)"

This reverts commit 057dc0e4d2.

* Revert "fix(StageParticipantNameLabel): size"

This reverts commit a01f4468a0.

* Revert "fix(subtitles): position part1"

This reverts commit 6c6ed8d7a8.

* Revert "fix(ITypographyType): wrong type of fontSize and lineHeight props"

This reverts commit bffcc9092b.

* revert(Tokens): font sizes and line heights back to px from rem

Turns out there are many places that does not expect rem. Temporary reverting this change from commit 6fa94b0bb4. We should bring it back along with proper handling of rem everywhere.
2025-05-13 18:34:25 -05:00

107 lines
3.4 KiB
TypeScript

import { Theme } from '@mui/material';
/**
* The vertical padding for the display name.
*/
export const DISPLAY_NAME_VERTICAL_PADDING = 4;
/**
* Returns the typography for stage participant display name badge.
*
* @param {Theme} theme - The current theme.
* @returns {ITypographyType}
*/
export function getStageParticipantTypography(theme: Theme) {
return theme.typography.bodyShortRegularLarge;
}
/**
* Returns the range of possible values for the font size for the stage participant display name badge.
*
* @param {Theme} theme - The current theme.
* @returns {ILimits}
*/
export function getStageParticipantFontSizeRange(theme: Theme) {
return {
max: theme.typography.bodyShortRegularLarge.fontSize,
min: theme.typography.bodyShortRegularSmall.fontSize
};
}
/**
* Returns the range of possible values for the line height for the stage participant display name badge.
*
* @param {Theme} theme - The current theme.
* @returns {ILimits}
*/
export function getStageParticipantLineHeightRange(theme: Theme) {
return {
max: theme.typography.bodyShortRegularLarge.lineHeight,
min: theme.typography.bodyShortRegularSmall.lineHeight
};
}
/**
* Returns the height + padding for stage participant display name badge.
*
* @param {Theme} theme - The current theme.
* @param {number} clientHeight - The height of the visible area.
* @returns {number}
*/
export function getStageParticipantNameLabelHeight(theme: Theme, clientHeight?: number) {
const lineHeight = getStageParticipantNameLabelLineHeight(theme, clientHeight);
return lineHeight + DISPLAY_NAME_VERTICAL_PADDING;
}
/**
* Returns the height + padding for stage participant display name badge.
*
* @param {Theme} theme - The current theme.
* @param {number} clientHeight - The height of the visible area.
* @returns {number}
*/
export function getStageParticipantNameLabelLineHeight(theme: Theme, clientHeight?: number) {
return scaleFontProperty(clientHeight, getStageParticipantLineHeightRange(theme));
}
interface ILimits {
max: number;
min: number;
}
/**
* The default clint height limits used by scaleFontProperty.
*/
const DEFAULT_CLIENT_HEIGHT_LIMITS = {
min: 300,
max: 960
};
/**
* Scales a css font property depending on the passed screen size.
* Note: The result will be in the range of the specified propValueLimits. Also if the current screen height is
* more/less than the values in screenLimits parameter the result will be the max/min of the propValuesLimits.
*
* @param {number|undefined} screenHeight - The current screen height.
* @param {ILimits} propValuesLimits - The max and min value for the font property that we are scaling.
* @param {ILimits} screenHeightLimits - The max and min value for screen height.
* @returns {number} - The scaled prop value.
*/
export function scaleFontProperty(
screenHeight: number | undefined,
propValuesLimits: ILimits,
screenHeightLimits: ILimits = DEFAULT_CLIENT_HEIGHT_LIMITS) {
if (typeof screenHeight !== 'number') {
return propValuesLimits.max;
}
const { max: maxPropSize, min: minPropSize } = propValuesLimits;
const { max: maxHeight, min: minHeight } = screenHeightLimits;
const propSizePerPxHeight = (maxPropSize - minPropSize) / (maxHeight - minHeight);
return Math.round(
(Math.max(Math.min(screenHeight, maxHeight), minHeight) - minHeight) * propSizePerPxHeight
) + minPropSize;
}