Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update navbar design and improve search UI #1084

Merged
merged 34 commits into from
Nov 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
03491d5
Update navbar design
lhsazevedo Oct 3, 2024
89c598e
Add new search modal dialog
lhsazevedo Oct 3, 2024
8650771
Add search modal e2e tests
lhsazevedo Oct 3, 2024
d0da0c8
Remove Hogan.js and typeahead.js
lhsazevedo Oct 2, 2024
831f80c
Update playwright snapshots
lhsazevedo Oct 3, 2024
b17b606
Fix e2e and visual tests
lhsazevedo Oct 4, 2024
0048ef1
Avoid page shift when opening the search modal
lhsazevedo Oct 4, 2024
b83f783
Match search label and input placeholder text
lhsazevedo Oct 4, 2024
23003ff
Increase contrast for accessibility
lhsazevedo Oct 5, 2024
cd0754b
Halve the transition duration of the search modal
lhsazevedo Oct 4, 2024
07da74b
Reduce search scrollbar width
lhsazevedo Oct 5, 2024
ec7e9b9
Darken release background to better fit the navbar
lhsazevedo Oct 5, 2024
7146752
Fallback search when Javascript is disabled
lhsazevedo Oct 6, 2024
535b25d
Remove logo alt text
lhsazevedo Oct 6, 2024
b8bb98c
Fix modal input type and aria-label
lhsazevedo Oct 6, 2024
75a3e38
Use <kbd> tag
lhsazevedo Oct 6, 2024
9fe9ed1
Use correct CSS methodology
lhsazevedo Oct 6, 2024
4c062ec
Avoid search flash on mobile
lhsazevedo Oct 6, 2024
21b220e
Fix e2e and visual tests
lhsazevedo Oct 6, 2024
afaaa2e
Progressively enhance mobile menu and search
lhsazevedo Oct 11, 2024
2f3da84
Add e2e tests for JS disabled search and menu
lhsazevedo Oct 12, 2024
ae5a14c
Invalidate old search cache format
lhsazevedo Oct 21, 2024
97a865b
Use a single kbd tag for each arrow key
lhsazevedo Oct 21, 2024
6a4dcd1
Fix leftover vars
lhsazevedo Oct 21, 2024
2d89914
Use current language in legacy global search
lhsazevedo Oct 21, 2024
e35fe6e
Add missing docblocks and improve existing ones
lhsazevedo Oct 22, 2024
1fa0853
Use language parameter from outer scope
lhsazevedo Oct 22, 2024
d2d68a0
Format search.js
lhsazevedo Oct 22, 2024
39bc218
Tone down result hover background color
lhsazevedo Oct 22, 2024
0d5a896
Update visual tests snapshots
lhsazevedo Oct 22, 2024
f97426e
Add search modal visual test
lhsazevedo Oct 23, 2024
eb7a39d
Fix visual tests snapshots
lhsazevedo Oct 23, 2024
614a1ad
Close offcanvas menu by outside click
saundefined Oct 31, 2024
d54e103
Sync class name with master
lhsazevedo Oct 31, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 67 additions & 1 deletion include/footer.inc
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ if (!empty($_SERVER['BASE_PAGE'])
<!-- External and third party libraries. -->
<script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>
<?php
$jsfiles = ["ext/hogan-3.0.2.min.js", "ext/typeahead.jquery.min.js", "ext/FuzzySearch.min.js", "ext/mousetrap.min.js", "ext/jquery.scrollTo.min.js", "search.js", "common.js"];
$jsfiles = ["ext/FuzzySearch.min.js", "ext/mousetrap.min.js", "ext/jquery.scrollTo.min.js", "search.js", "common.js"];
foreach ($jsfiles as $filename) {
$path = dirname(__DIR__) . '/js/' . $filename;
echo '<script src="/cached.php?t=' . @filemtime($path) . '&amp;f=/js/' . $filename . '"></script>' . "\n";
Expand All @@ -108,5 +108,71 @@ if (!empty($_SERVER['BASE_PAGE'])

<a id="toTop" href="javascript:;"><span id="toTopHover"></span><img width="40" height="40" alt="To Top" src="/images/[email protected]"></a>

<div id="search-modal__backdrop" class="search-modal__backdrop">
<div
role="dialog"
aria-label="Search modal"
id="search-modal"
class="search-modal"
>
<div class="search-modal__header">
<div class="search-modal__form">
<div class="search-modal__input-icon">
<!-- https://feathericons.com search -->
<svg xmlns="http://www.w3.org/2000/svg"
aria-hidden="true"
width="24"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
>
<circle cx="11" cy="11" r="8"></circle>
<line x1="21" y1="21" x2="16.65" y2="16.65"></line>
</svg>
</div>
<input
type="search"
id="search-modal__input"
class="search-modal__input"
placeholder="Search docs"
aria-label="Search docs"
/>
</div>

<button aria-label="Close" class="search-modal__close">
<!-- https://pictogrammers.com/library/mdi/icon/close/ -->
<svg
xmlns="http://www.w3.org/2000/svg"
aria-hidden="true"
width="24"
viewBox="0 0 24 24"
>
<path d="M19,6.41L17.59,5L12,10.59L6.41,5L5,6.41L10.59,12L5,17.59L6.41,19L12,13.41L17.59,19L19,17.59L13.41,12L19,6.41Z"/>
</svg>
</button>
</div>
<div
role="listbox"
aria-label="Search results"
id="search-modal__results"
class="search-modal__results"
></div>
<div class="search-modal__helper-text">
<div>
<kbd>↑</kbd> and <kbd>↓</kbd> to navigate •
<kbd>Enter</kbd> to select •
<kbd>Esc</kbd> to close
</div>
<div>
Press <kbd>Enter</kbd> without
selection to search using Google
</div>
</div>
</div>
</div>

</body>
</html>
172 changes: 152 additions & 20 deletions include/header.inc
Original file line number Diff line number Diff line change
Expand Up @@ -94,27 +94,159 @@ if (!isset($config["languages"])) {
</head>
<body class="<?php echo $curr; ?> <?php echo $classes; ?>">

<nav id="head-nav" class="navbar navbar-fixed-top">
<div class="navbar-inner clearfix">
<a href="/" class="brand"><img src="/images/logos/php-logo.svg" width="48" height="24" alt="php"></a>
<div id="mainmenu-toggle-overlay"></div>
<input type="checkbox" id="mainmenu-toggle">
<ul class="nav">
<li class="<?php echo $curr == "downloads" ? "active" : ""?>"><a href="/downloads">Downloads</a></li>
<li class="<?php echo $curr == "docs" ? "active" : ""?>"><a href="/docs.php">Documentation</a></li>
<li class="<?php echo $curr == "community" ? "active" : ""?>"><a href="/get-involved" >Get Involved</a></li>
<li class="<?php echo $curr == "help" ? "active" : ""?>"><a href="/support">Help</a></li>
<li class="<?php echo $curr === "php8" ? "active" : "" ?>">
<a href="/releases/8.3/index.php">
<img src="/images/php8/logo_php8_3.svg" alt="php8.3" height="22" width="60">
</a>
</li>
</ul>
<form class="navbar-search" id="topsearch" action="/search.php">
<input type="hidden" name="show" value="quickref">
<input type="search" name="pattern" class="search-query" placeholder="Search" accesskey="s">
</form>
<nav class="navbar navbar-fixed-top">
<div class="navbar__inner">
<a href="/" aria-label="PHP Home" class="navbar__brand">
<img
src="/images/logos/php-logo-white.svg"
aria-hidden="true"
width="80"
height="40"
>
</a>

<div
id="navbar__offcanvas"
tabindex="-1"
class="navbar__offcanvas"
aria-label="Menu"
>
<button
id="navbar__close-button"
class="navbar__icon-item navbar_icon-item--visually-aligned navbar__close-button"
>
<svg xmlns="http://www.w3.org/2000/svg" width="24" viewBox="0 0 24 24" fill="currentColor"><path d="M19,6.41L17.59,5L12,10.59L6.41,5L5,6.41L10.59,12L5,17.59L6.41,19L12,13.41L17.59,19L19,17.59L13.41,12L19,6.41Z" /></svg>
</button>

<ul class="navbar__nav">
<?php foreach (get_nav_items() as $entry): ?>
<?php
$isActive = $curr == $entry->id;
$activeClass = $isActive ? 'navbar__link--active' : '';
$releaseClass = $entry->image ? 'navbar__release' : '';
?>
<li class="navbar__item">
<a
href="<?= $entry->href ?>"
<?= $isActive ? 'aria-current="page"' : '' ?>
class="navbar__link <?= "$activeClass $releaseClass" ?>"
>
<?php if ($entry->image): ?>
<img src="<?= $entry->image ?>" alt="<?= $entry->name ?>">
<?php else: ?>
<?= $entry->name ?>
<?php endif; ?>
</a>
</li>
<?php endforeach; ?>
</ul>
</div>

<div class="navbar__right">
<?php
// https://feathericons.com search
$searchIcon = <<<SVG
<svg
xmlns="http://www.w3.org/2000/svg"
aria-hidden="true"
width="24"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
>
<circle cx="11" cy="11" r="8"></circle>
<line x1="21" y1="21" x2="16.65" y2="16.65"></line>
</svg>
SVG;

// https://pictogrammers.com/library/mdi/icon/menu/
$menuIcon = <<<SVG
<svg xmlns="http://www.w3.org/2000/svg"
aria-hidden="true"
width="24"
viewBox="0 0 24 24"
fill="currentColor"
>
<path d="M3,6H21V8H3V6M3,11H21V13H3V11M3,16H21V18H3V16Z" />
</svg>
SVG;
?>

<!-- Desktop default search -->
<form
action="/manual-lookup.php"
class="navbar__search-form"
>
<label for="navbar__search-input" aria-label="Search docs">
<?= $searchIcon ?>
</label>
<input
type="search"
name="pattern"
id="navbar__search-input"
class="navbar__search-input"
placeholder="Search docs"
accesskey="s"
>
<input type="hidden" name="scope" value="quickref">
</form>

<!-- Desktop encanced search -->
<button
id="navbar__search-button"
class="navbar__search-button"
hidden
>
<?= $searchIcon ?>
Search docs
</button>

<!-- Mobile default items -->
<a
id="navbar__search-link"
href="/lookup-form.php"
aria-label="Search docs"
class="navbar__icon-item navbar__search-link"
>
<?= $searchIcon ?>
</a>
<a
id="navbar__menu-link"
href="/menu.php"
aria-label="Menu"
class="navbar__icon-item navbar_icon-item--visually-aligned navbar_menu-link"
>
<?= $menuIcon ?>
</a>

<!-- Mobile enhanced items -->
<button
id="navbar__search-button-mobile"
aria-label="Search docs"
class="navbar__icon-item navbar__search-button-mobile"
hidden
>
<?= $searchIcon ?>
</button>
<button
id="navbar__menu-button"
aria-label="Menu"
class="navbar__icon-item navbar_icon-item--visually-aligned"
hidden
>
<?= $menuIcon ?>
</button>
</div>

<div
id="navbar__backdrop"
class="navbar__backdrop"
></div>
</div>

<div id="flash-message"></div>
</nav>
<?php if (!empty($config["headsup"])): ?>
Expand Down
34 changes: 34 additions & 0 deletions include/layout.inc
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php

use phpweb\Navigation\NavItem;

$_SERVER['STATIC_ROOT'] = $MYSITE;
$_SERVER['MYSITE'] = $MYSITE;

Expand Down Expand Up @@ -481,6 +484,37 @@ function site_footer(array $config = []): void
require __DIR__ . "/footer.inc";
}

function get_nav_items(): array {
return [
new NavItem(
name: 'Downloads',
href: '/downloads.php',
id: 'downloads',
),
new NavItem(
name: 'Documentation',
href: '/docs.php',
id: 'docs',
),
new NavItem(
name: 'Get Involved',
href: '/get-involved.php',
id: 'community',
),
new NavItem(
name: 'Help',
href: '/support.php',
id: 'help',
),
new NavItem(
name: 'PHP 8.3',
href: '/releases/8.3/index.php',
id: 'php8',
image: '/images/php8/logo_php8_3.svg',
)
];
}

function get_news_changes()
{
include __DIR__ . "/pregen-news.inc";
Expand Down
Loading
Loading