選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

styles.ts 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. import { Theme } from '@mui/material';
  2. /**
  3. * The vertical padding for the display name.
  4. */
  5. export const DISPLAY_NAME_VERTICAL_PADDING = 4;
  6. /**
  7. * Returns the typography for stage participant display name badge.
  8. *
  9. * @param {Theme} theme - The current theme.
  10. * @returns {ITypographyType}
  11. */
  12. export function getStageParticipantTypography(theme: Theme) {
  13. return theme.typography.bodyShortRegularLarge;
  14. }
  15. /**
  16. * Returns the range of possible values for the font size for the stage participant display name badge.
  17. *
  18. * @param {Theme} theme - The current theme.
  19. * @returns {ILimits}
  20. */
  21. export function getStageParticipantFontSizeRange(theme: Theme) {
  22. return {
  23. max: theme.typography.bodyShortRegularLarge.fontSize,
  24. min: theme.typography.bodyShortRegularSmall.fontSize
  25. };
  26. }
  27. /**
  28. * Returns the range of possible values for the line height for the stage participant display name badge.
  29. *
  30. * @param {Theme} theme - The current theme.
  31. * @returns {ILimits}
  32. */
  33. export function getStageParticipantLineHeightRange(theme: Theme) {
  34. return {
  35. max: theme.typography.bodyShortRegularLarge.lineHeight,
  36. min: theme.typography.bodyShortRegularSmall.lineHeight
  37. };
  38. }
  39. /**
  40. * Returns the height + padding for stage participant display name badge.
  41. *
  42. * @param {Theme} theme - The current theme.
  43. * @param {number} clientHeight - The height of the visible area.
  44. * @returns {number}
  45. */
  46. export function getStageParticipantNameLabelHeight(theme: Theme, clientHeight?: number) {
  47. const lineHeight = getStageParticipantNameLabelLineHeight(theme, clientHeight);
  48. return lineHeight + DISPLAY_NAME_VERTICAL_PADDING;
  49. }
  50. /**
  51. * Returns the height + padding for stage participant display name badge.
  52. *
  53. * @param {Theme} theme - The current theme.
  54. * @param {number} clientHeight - The height of the visible area.
  55. * @returns {number}
  56. */
  57. export function getStageParticipantNameLabelLineHeight(theme: Theme, clientHeight?: number) {
  58. return scaleFontProperty(clientHeight, getStageParticipantLineHeightRange(theme));
  59. }
  60. interface ILimits {
  61. max: number;
  62. min: number;
  63. }
  64. /**
  65. * The default clint height limits used by scaleFontProperty.
  66. */
  67. const DEFAULT_CLIENT_HEIGHT_LIMITS = {
  68. min: 300,
  69. max: 960
  70. };
  71. /**
  72. * Scales a css font property depending on the passed screen size.
  73. * Note: The result will be in the range of the specified propValueLimits. Also if the current screen height is
  74. * more/less than the values in screenLimits parameter the result will be the max/min of the propValuesLimits.
  75. *
  76. * @param {number|undefined} screenHeight - The current screen height.
  77. * @param {ILimits} propValuesLimits - The max and min value for the font property that we are scaling.
  78. * @param {ILimits} screenHeightLimits - The max and min value for screen height.
  79. * @returns {number} - The scaled prop value.
  80. */
  81. export function scaleFontProperty(
  82. screenHeight: number | undefined,
  83. propValuesLimits: ILimits,
  84. screenHeightLimits: ILimits = DEFAULT_CLIENT_HEIGHT_LIMITS) {
  85. if (typeof screenHeight !== 'number') {
  86. return propValuesLimits.max;
  87. }
  88. const { max: maxPropSize, min: minPropSize } = propValuesLimits;
  89. const { max: maxHeight, min: minHeight } = screenHeightLimits;
  90. const propSizePerPxHeight = (maxPropSize - minPropSize) / (maxHeight - minHeight);
  91. return Math.round(
  92. (Math.max(Math.min(screenHeight, maxHeight), minHeight) - minHeight) * propSizePerPxHeight
  93. ) + minPropSize;
  94. }