MCPcopy Create free account
hub / github.com/adobe/react-spectrum / updateTitleFontSize

Function updateTitleFontSize

packages/dev/docs/src/client.js:30–52  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

28
29// Size the title to fit the available space.
30function updateTitleFontSize() {
31 let fontSize = parseInt(window.getComputedStyle(title).fontSize, 10);
32
33 // Constrain font size to 58px, or 10% of the window width, whichever is smaller.
34 let maxFontSize = Math.min(58, Math.round(window.innerWidth * 0.1));
35 if (fontSize > maxFontSize) {
36 fontSize = maxFontSize;
37 title.style.fontSize = maxFontSize + 'px';
38 }
39
40 // If the font size is less than the maximum font size,
41 // increase the font size until it overflows.
42 while (fontSize < maxFontSize && title.scrollWidth <= title.clientWidth) {
43 fontSize++;
44 title.style.fontSize = fontSize + 'px';
45 }
46
47 // Reduce the font size until it doesn't overflow.
48 while (fontSize > 10 && title.scrollWidth > title.clientWidth + 1) {
49 fontSize--;
50 title.style.fontSize = fontSize + 'px';
51 }
52}
53
54updateTitleFontSize();
55

Callers 1

client.jsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected