Skip to content

Commit a395784

Browse files
alisinabhjosevalim
andcommitted
Add warning for stale version of documentation
Co-Authored-By: Philip Davies <[email protected]> Rename latestVersion to isStale and use boolean Co-Authored-By: Austin Ziegler <[email protected]> Revert "Rename latestVersion to isStale and use boolean" This reverts commit 8ef47f0. Use "Go to latest" link Use actual URL for Go to latest link Adjust select width Fix openVersionSelect function Revert "Adjust select width" This reverts commit 5835e2e. Use width calculation select width Update assets/css/sidebar.css Co-authored-by: José Valim <[email protected]> Update assets/css/sidebar.css Co-authored-by: José Valim <[email protected]>
1 parent 878735d commit a395784

File tree

6 files changed

+50
-2
lines changed

6 files changed

+50
-2
lines changed

assets/css/custom-props/common.css

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@
5252
--black: hsl(0, 0%, 0%);
5353
--black-opacity-10: hsla(0, 0%, 0%, 10%);
5454
--black-opacity-50: hsla(0, 0%, 0%, 50%);
55+
--orangeDark: hsl(30, 90%, 40%);
56+
--orangeLight: hsl(30, 80%, 50%);
5557
}
5658

5759
@media screen and (max-width: 768px) {

assets/css/custom-props/theme-dark.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ body.dark {
8080
--sidebarHover: var(--white);
8181
--sidebarScrollbarThumb: var(--coldGray);
8282
--sidebarScrollbarTrack: var(--sidebarBackground);
83+
--sidebarStaleVersion: var(--orangeDark);
8384
--sidebarSubheadings: var(--gray400);
8485
--sidebarItem: var(--gray200);
8586
--sidebarInactiveItemBorder: var(--gray400);

assets/css/custom-props/theme-light.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
--sidebarHover: var(--black);
8181
--sidebarScrollbarThumb: var(--coldGrayLight);
8282
--sidebarScrollbarTrack: var(--sidebarBackground);
83+
--sidebarStaleVersion: var(--orangeLight);
8384
--sidebarSubheadings: var(--black);
8485
--sidebarItem: var(--black);
8586
--sidebarInactiveItemBorder: var(--gray500);

assets/css/sidebar.css

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,22 @@
109109
display: none;
110110
}
111111

112+
.sidebar .sidebar-staleVersion {
113+
display: inline;
114+
}
115+
116+
.sidebar .sidebar-staleVersion > a {
117+
color: var(--sidebarStaleVersion);
118+
font-weight: 400;
119+
}
120+
121+
.sidebar .sidebar-staleIcon {
122+
font-size: 18px;
123+
position: relative;
124+
top: 3px;
125+
line-height: 0;
126+
}
127+
112128
.sidebar .sidebar-list-nav {
113129
display: flex;
114130
margin: 0;

assets/js/handlebars/templates/versions-dropdown.handlebars

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,12 @@
1010
{{/each}}
1111
</select>
1212
</label>
13+
{{#if latestVersion}}
14+
<div class="sidebar-staleVersion">
15+
<a href="{{latestVersion}}" title="This version of package is not the latest version">
16+
<i class="ri-alert-line sidebar-staleIcon" aria-hidden="true"></i>
17+
<span>Go to latest</span>
18+
</a>
19+
</div>
20+
{{/if}}
1321
</form>

assets/js/sidebar/sidebar-version-select.js

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,32 @@ if (!isEmbedded) {
2626
isCurrentVersion: node.version === currentVersion
2727
}))
2828

29-
versionsContainer.innerHTML = versionsDropdownTemplate({ nodes })
29+
const latestVersionNode = versionNodes.find(node => node.latest)
30+
const latestVersion = latestVersionNode?.version !== currentVersion ? latestVersionNode?.url : null
3031

31-
qs(VERSIONS_DROPDOWN_SELECTOR).addEventListener('change', handleVersionSelected)
32+
versionsContainer.innerHTML = versionsDropdownTemplate({ nodes, latestVersion})
33+
34+
const select = qs(VERSIONS_DROPDOWN_SELECTOR)
35+
select.addEventListener('change', handleVersionSelected)
36+
adjustWidth(select)
3237
}
3338
}
3439

40+
// Function to adjust the width of the select element
41+
function adjustWidth (select) {
42+
// Create a temporary element to measure the width
43+
const temp = document.createElement('span')
44+
temp.style.visibility = 'hidden'
45+
temp.style.position = 'absolute'
46+
temp.style.whiteSpace = 'nowrap'
47+
temp.style.font = window.getComputedStyle(select).font
48+
temp.textContent = select.options[select.selectedIndex].text
49+
50+
document.body.appendChild(temp)
51+
select.style.width = `${temp.offsetWidth + 20}px`
52+
document.body.removeChild(temp)
53+
}
54+
3555
function handleVersionSelected (event) {
3656
const url = event.target.value
3757
const pathSuffix = window.location.pathname.split('/').pop() + window.location.hash

0 commit comments

Comments
 (0)