Skip to content

Commit

Permalink
add focusable HOC
Browse files Browse the repository at this point in the history
  • Loading branch information
John-Paul-Larkin committed Oct 24, 2024
1 parent faf56c7 commit a29c6e4
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 24 deletions.
13 changes: 13 additions & 0 deletions components/Focusable/Focusable.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import React, { cloneElement, ReactElement } from "react";

interface FocusableProps {
children: ReactElement;
}

const Focusable: React.FC<FocusableProps> = ({ children }) => {
return cloneElement(children, {
className: `${children.props.className} rounded-md focus:outline-none focus:ring-white focus-visible:ring-2 focus-visible:ring-pink-600 focus-visible:ring-offset-pink-600`,
});
};

export default Focusable;
55 changes: 31 additions & 24 deletions components/Footer/Footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
twitterUrl,
youtubeUrl,
} from "../../config/site_settings";
import Focusable from "../Focusable/Focusable";

const navigation = {
main: footerNav,
Expand Down Expand Up @@ -55,37 +56,43 @@ const Footer = () => {
{navigation.main.map((item) => (
<div key={item.name} className="px-5 py-2">
{item.href.includes("http") ? (
<a
href={item.href}
target="_blank"
rel="noopener noreferrer"
className="focus-style p-1 text-base text-neutral-600 hover:text-neutral-500 dark:text-neutral-500 dark:hover:text-neutral-400"
>
{item.name}
</a>
<Focusable>
<a
href={item.href}
target="_blank"
rel="noopener noreferrer"
className="p-1 text-base text-neutral-600 hover:text-neutral-500 dark:text-neutral-500 dark:hover:text-neutral-400"
>
{item.name}
</a>
</Focusable>
) : (
<Link
className="focus-style p-1 text-base text-neutral-600 hover:text-neutral-500 dark:text-neutral-500 dark:hover:text-neutral-400"
href={item.href}
>
{item.name}
</Link>
<Focusable>
<Link
className="p-1 text-base text-neutral-600 hover:text-neutral-500 dark:text-neutral-500 dark:hover:text-neutral-400"
href={item.href}
>
{item.name}
</Link>
</Focusable>
)}
</div>
))}
</nav>
<div className="mt-8 flex justify-center space-x-8">
{navigation.social.map((item) => (
<a
key={item.name}
href={item.href}
target="_blank"
rel="noopener noreferrer"
className={`focus-style rounded-md p-1 transition-all duration-300 hover:scale-105 hover:text-white hover:brightness-110 focus:scale-105 focus:text-white focus:brightness-110 ${item.customStyle.toLowerCase()}`}
>
<span className="sr-only">{item.name}</span>
<item.icon className="h-6 w-6" aria-hidden="true" />
</a>
<Focusable>
<a
key={item.name}
href={item.href}
target="_blank"
rel="noopener noreferrer"
className={`rounded-md p-1 transition-all duration-300 hover:scale-105 hover:text-white hover:brightness-110 focus:scale-105 focus:text-white focus:brightness-110 ${item.customStyle.toLowerCase()}`}
>
<span className="sr-only">{item.name}</span>
<item.icon className="h-6 w-6" aria-hidden="true" />
</a>
</Focusable>
))}
</div>
<p className="mt-8 text-center text-xs text-neutral-600 dark:text-neutral-500">
Expand Down

0 comments on commit a29c6e4

Please sign in to comment.