Skip to content

Commit 4739142

Browse files
committed
fix: better behavior with adaptive font size
1 parent 9b95e3b commit 4739142

2 files changed

Lines changed: 40 additions & 5 deletions

File tree

static/sass/_snapcraft_snap-details.scss

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,4 +106,39 @@
106106
opacity: 0.3;
107107
}
108108
}
109+
110+
.p-package-header {
111+
container: pkgname / inline-size;
112+
113+
&__name {
114+
display: inline-block;
115+
white-space: nowrap;
116+
117+
.p-tooltip__message {
118+
font-weight: 400;
119+
}
120+
121+
--length: 40; // default value, it should be overridden via inline styles on the element
122+
--fs-ratio: 1.765; // height/width (1rem/1ch) ratio measured in the browser
123+
// we take the full width of the container and divide it by the number of characters in the
124+
// package name (+2 to account for the parentheses): this is the horizontal space that each
125+
// character has on average; we multiply this by the fs-ratio to get the font size
126+
--target-font-size: calc(
127+
(100cqw / (2 + var(--length))) * var(--fs-ratio)
128+
);
129+
// we limit the font size to the smallest and largest available sizes
130+
--max-font-size: #{map-get($settings-text-h1-mobile, font-size)}rem; // size of the title
131+
--min-font-size: #{map-get($settings-text-h5-mobile, font-size)}rem; // smallest size we allow
132+
font-size: clamp(
133+
var(--min-font-size),
134+
var(--target-font-size),
135+
var(--max-font-size)
136+
);
137+
138+
@media (min-width: $breakpoint-heading-threshold) {
139+
--min-font-size: #{map-get($settings-text-h5, font-size)}rem;
140+
--max-font-size: #{map-get($settings-text-h1, font-size)}rem;
141+
}
142+
}
143+
}
109144
}

templates/store/package_header/_package_header_data.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,16 @@
3939
developer_validation,
4040
STAR_DEVELOPER,
4141
VERIFIED_PUBLISHER) -%}
42-
<div class="p-section--shallow">
42+
<div class="p-section--shallow p-package-header">
4343
<h1 class="u-sv-1" data-live="title">
4444
{{ package_title }}
4545

4646
{# check if the package title could be misleading #}
4747
{% if package_title.replace(" ", "-").lower() != package_name %}
48-
<span class="p-heading--5 p-tooltip--btm-center" aria-label='(registered as "{{ package_name }}")'>
49-
({{ package_name }})
50-
<span class="p-tooltip__message" style="font-weight: 400">Package name</span>
51-
</span>
48+
<span class="p-tooltip--btm-center p-package-header__name" style="--length: {{ package_name | length }};" aria-label='(registered as "{{ package_name }}")'>
49+
({{ package_name }})
50+
<span class="p-tooltip__message">Package name</span>
51+
</span>
5252
{% endif %}
5353
</h1>
5454
<div class="u-hide--medium u-hide--large">

0 commit comments

Comments
 (0)