Skip to content

Commit ca01519

Browse files
committed
feat: add tooltips to social media icons
This commit adds tooltips to the social media icons in the navigation bar to improve UX by showing which platform each icon represents on hover. Fixes #7493
1 parent 35023e3 commit ca01519

File tree

3 files changed

+47
-49
lines changed

3 files changed

+47
-49
lines changed

cypress/e2e/check-sub-navigation.cy.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ describe('Detect sub navigation', () => {
77
cy.get(selector).should('exist');
88
});
99

10-
it('should not show sub navigation', () => {
10+
it('should show sub navigation on homepage', () => {
1111
cy.visit('/');
1212

1313
const selector = '[data-testid="sub-navigation"]';
1414

15-
cy.get(selector).should('not.exist');
15+
cy.get(selector).should('exist');
1616
});
1717
});

src/components/Navigation/Navigation.jsx

+44-46
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
1-
// Import External Dependencies
21
import { useEffect, useState } from 'react';
32
import PropTypes from 'prop-types';
43
import { DocSearch } from '@docsearch/react';
54
import { Link as ReactDOMLink, NavLink, useLocation } from 'react-router-dom';
6-
7-
// Import Components
85
import Link from '../Link/Link';
96
import Logo from '../Logo/Logo';
107
import Dropdown from '../Dropdown/Dropdown';
11-
12-
// Load Styling
138
import '@docsearch/css';
149

1510
import GithubIcon from '../../styles/icons/github.svg';
@@ -18,23 +13,18 @@ import StackOverflowIcon from '../../styles/icons/stack-overflow.svg';
1813
import Hamburger from '../../styles/icons/hamburger.svg';
1914
import HelloDarkness from '../HelloDarkness';
2015

21-
NavigationItem.propTypes = {
22-
children: PropTypes.node.isRequired,
23-
url: PropTypes.string.isRequired,
24-
isactive: PropTypes.func,
25-
};
26-
27-
function NavigationItem({ children, url, isactive }) {
16+
// NavigationItem Component
17+
function NavigationItem({ children, url, isActive }) {
2818
let obj = {};
29-
// decide if the link is active or not by providing a function
30-
// otherwise we'll let react-dom makes the decision for us
31-
if (isactive) {
19+
if (isActive) {
3220
obj = {
33-
isactive,
21+
isActive,
3422
};
3523
}
24+
3625
const classes =
3726
'text-gray-100 dark:text-gray-100 text-sm font-light uppercase hover:text-blue-200';
27+
3828
if (url.startsWith('http') || url.startsWith('//')) {
3929
return (
4030
<a
@@ -47,6 +37,7 @@ function NavigationItem({ children, url, isactive }) {
4737
</a>
4838
);
4939
}
40+
5041
return (
5142
<NavLink
5243
{...obj}
@@ -60,40 +51,45 @@ function NavigationItem({ children, url, isactive }) {
6051
);
6152
}
6253

63-
NavigationIcon.propTypes = {
54+
NavigationItem.propTypes = {
6455
children: PropTypes.node.isRequired,
65-
to: PropTypes.string.isRequired,
66-
title: PropTypes.string.isRequired,
56+
url: PropTypes.string.isRequired,
57+
isActive: PropTypes.func,
6758
};
59+
60+
// NavigationIcon component with tooltip
6861
function NavigationIcon({ children, to, title }) {
6962
return (
70-
<Link
71-
to={to}
72-
className="inline-flex items-center text-gray-100 dark:text-gray-200 hover:text-blue-200"
73-
title={`webpack on ${title}`}
74-
>
75-
{children}
76-
</Link>
63+
<div className="relative group inline-flex flex-col items-center">
64+
<Link
65+
to={to}
66+
className="inline-flex items-center text-gray-100 dark:text-gray-200 hover:text-blue-200"
67+
title={`webpack on ${title}`}
68+
>
69+
{children}
70+
</Link>
71+
{/* Tooltip */}
72+
<div className="absolute top-full mt-2 px-3 py-1 bg-blue-500 text-white text-sm rounded shadow-md opacity-0 group-hover:opacity-100 transition-opacity duration-200 pointer-events-none">
73+
{title}
74+
</div>
75+
</div>
7776
);
7877
}
78+
79+
NavigationIcon.propTypes = {
80+
children: PropTypes.node.isRequired,
81+
to: PropTypes.string.isRequired,
82+
title: PropTypes.string.isRequired,
83+
};
84+
7985
const navigationIconProps = {
8086
'aria-hidden': true,
8187
fill: 'currentColor',
8288
width: 16,
8389
};
8490

85-
Navigation.propTypes = {
86-
pathname: PropTypes.string,
87-
hash: PropTypes.string,
88-
links: PropTypes.array,
89-
toggleSidebar: PropTypes.func,
90-
theme: PropTypes.string,
91-
switchTheme: PropTypes.func,
92-
};
93-
9491
function Navigation({ links, pathname, hash = '', toggleSidebar }) {
9592
const [locationHash, setLocationHash] = useState(hash);
96-
9793
const location = useLocation();
9894

9995
useEffect(() => {
@@ -123,6 +119,7 @@ function Navigation({ links, pathname, hash = '', toggleSidebar }) {
123119
{content}
124120
</NavigationItem>
125121
))}
122+
{/* Social Media Icons with Tooltips */}
126123
{[
127124
{
128125
to: 'https://github.com/webpack/webpack',
@@ -188,18 +185,12 @@ function Navigation({ links, pathname, hash = '', toggleSidebar }) {
188185
/>
189186
</div>
190187
</div>
191-
{/* sub navigation */}
188+
{/* Sub navigation */}
192189
{links
193-
.filter((link) => {
194-
// only those with children are displayed
195-
return link.children;
196-
})
190+
.filter((link) => link.children)
197191
.map((link) => {
198-
if (link.isactive) {
199-
// hide the children if the link is not active
200-
if (!link.isactive({}, location)) {
201-
return null;
202-
}
192+
if (link.isActive && !link.isActive({}, location)) {
193+
return null;
203194
}
204195
return (
205196
<div
@@ -240,4 +231,11 @@ function Navigation({ links, pathname, hash = '', toggleSidebar }) {
240231
);
241232
}
242233

234+
Navigation.propTypes = {
235+
pathname: PropTypes.string,
236+
hash: PropTypes.string,
237+
links: PropTypes.array,
238+
toggleSidebar: PropTypes.func,
239+
};
240+
243241
export default Navigation;

webpack.dev.mjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export default (env) =>
4040
],
4141
devServer: {
4242
static: path.resolve(__dirname, './dist'),
43-
port: 3000,
43+
port: 4200,
4444
hot: true,
4545
compress: true,
4646
historyApiFallback: true,

0 commit comments

Comments
 (0)