Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 11 additions & 1 deletion src/content/Components/Dock/Dock.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Children, cloneElement, useEffect, useMemo, useRef, useState } from 're

import './Dock.css';

function DockItem({ children, className = '', onClick, mouseX, spring, distance, magnification, baseItemSize }) {
function DockItem({ children, className = '', onClick, mouseX, spring, distance, magnification, baseItemSize, label }) {
const ref = useRef(null);
const isHovered = useMotionValue(0);

Expand All @@ -20,6 +20,13 @@ function DockItem({ children, className = '', onClick, mouseX, spring, distance,
const targetSize = useTransform(mouseDistance, [-distance, 0, distance], [baseItemSize, magnification, baseItemSize]);
const size = useSpring(targetSize, spring);

const handleKeyDown = e => {
if (e.key === 'Enter' || e.key === ' ') {
e.preventDefault();
onClick?.();
}
};

return (
<motion.div
ref={ref}
Expand All @@ -36,6 +43,8 @@ function DockItem({ children, className = '', onClick, mouseX, spring, distance,
tabIndex={0}
role="button"
aria-haspopup="true"
aria-label={label}
onKeyDown={handleKeyDown}
>
{Children.map(children, child => cloneElement(child, { isHovered }))}
</motion.div>
Expand Down Expand Up @@ -122,6 +131,7 @@ export default function Dock({
distance={distance}
magnification={magnification}
baseItemSize={baseItemSize}
label={item.label}
>
<DockIcon>{item.icon}</DockIcon>
<DockLabel>{item.label}</DockLabel>
Expand Down
12 changes: 11 additions & 1 deletion src/tailwind/Components/Dock/Dock.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { motion, useMotionValue, useSpring, useTransform, AnimatePresence } from 'motion/react';
import { Children, cloneElement, useEffect, useMemo, useRef, useState } from 'react';

function DockItem({ children, className = '', onClick, mouseX, spring, distance, magnification, baseItemSize }) {
function DockItem({ children, className = '', onClick, mouseX, spring, distance, magnification, baseItemSize, label }) {
const ref = useRef(null);
const isHovered = useMotionValue(0);

Expand All @@ -18,6 +18,13 @@ function DockItem({ children, className = '', onClick, mouseX, spring, distance,
const targetSize = useTransform(mouseDistance, [-distance, 0, distance], [baseItemSize, magnification, baseItemSize]);
const size = useSpring(targetSize, spring);

const handleKeyDown = e => {
if (e.key === 'Enter' || e.key === ' ') {
e.preventDefault();
onClick?.();
}
};

return (
<motion.div
ref={ref}
Expand All @@ -30,10 +37,12 @@ function DockItem({ children, className = '', onClick, mouseX, spring, distance,
onFocus={() => isHovered.set(1)}
onBlur={() => isHovered.set(0)}
onClick={onClick}
onKeyDown={handleKeyDown}
className={`relative inline-flex items-center justify-center rounded-full bg-[#120F17] border-neutral-700 border-2 shadow-md ${className}`}
tabIndex={0}
role="button"
aria-haspopup="true"
aria-label={label}
>
{Children.map(children, child => cloneElement(child, { isHovered }))}
</motion.div>
Expand Down Expand Up @@ -120,6 +129,7 @@ export default function Dock({
distance={distance}
magnification={magnification}
baseItemSize={baseItemSize}
label={item.label}
>
<DockIcon>{item.icon}</DockIcon>
<DockLabel>{item.label}</DockLabel>
Expand Down
14 changes: 13 additions & 1 deletion src/ts-default/Components/Dock/Dock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ type DockItemProps = {
distance: number;
baseItemSize: number;
magnification: number;
label?: React.ReactNode;
};

function DockItem({
Expand All @@ -50,7 +51,8 @@ function DockItem({
spring,
distance,
magnification,
baseItemSize
baseItemSize,
label
}: DockItemProps) {
const ref = useRef<HTMLDivElement>(null);
const isHovered = useMotionValue(0);
Expand All @@ -66,6 +68,13 @@ function DockItem({
const targetSize = useTransform(mouseDistance, [-distance, 0, distance], [baseItemSize, magnification, baseItemSize]);
const size = useSpring(targetSize, spring);

const handleKeyDown = (e: React.KeyboardEvent<HTMLDivElement>) => {
if (e.key === 'Enter' || e.key === ' ') {
e.preventDefault();
onClick?.();
}
};

return (
<motion.div
ref={ref}
Expand All @@ -78,10 +87,12 @@ function DockItem({
onFocus={() => isHovered.set(1)}
onBlur={() => isHovered.set(0)}
onClick={onClick}
onKeyDown={handleKeyDown}
className={`dock-item ${className}`}
tabIndex={0}
role="button"
aria-haspopup="true"
aria-label={typeof label === 'string' ? label : undefined}
>
{Children.map(children, child =>
React.isValidElement(child)
Expand Down Expand Up @@ -184,6 +195,7 @@ export default function Dock({
distance={distance}
magnification={magnification}
baseItemSize={baseItemSize}
label={item.label}
>
<DockIcon>{item.icon}</DockIcon>
<DockLabel>{item.label}</DockLabel>
Expand Down
14 changes: 13 additions & 1 deletion src/ts-tailwind/Components/Dock/Dock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type DockItemProps = {
distance: number;
baseItemSize: number;
magnification: number;
label?: React.ReactNode;
};

function DockItem({
Expand All @@ -48,7 +49,8 @@ function DockItem({
spring,
distance,
magnification,
baseItemSize
baseItemSize,
label
}: DockItemProps) {
const ref = useRef<HTMLDivElement>(null);
const isHovered = useMotionValue(0);
Expand All @@ -64,6 +66,13 @@ function DockItem({
const targetSize = useTransform(mouseDistance, [-distance, 0, distance], [baseItemSize, magnification, baseItemSize]);
const size = useSpring(targetSize, spring);

const handleKeyDown = (e: React.KeyboardEvent<HTMLDivElement>) => {
if (e.key === 'Enter' || e.key === ' ') {
e.preventDefault();
onClick?.();
}
};

return (
<motion.div
ref={ref}
Expand All @@ -76,10 +85,12 @@ function DockItem({
onFocus={() => isHovered.set(1)}
onBlur={() => isHovered.set(0)}
onClick={onClick}
onKeyDown={handleKeyDown}
className={`relative inline-flex items-center justify-center rounded-full bg-[#120F17] border-neutral-700 border-2 shadow-md ${className}`}
tabIndex={0}
role="button"
aria-haspopup="true"
aria-label={typeof label === 'string' ? label : undefined}
>
{Children.map(children, child =>
React.isValidElement(child)
Expand Down Expand Up @@ -179,6 +190,7 @@ export default function Dock({
distance={distance}
magnification={magnification}
baseItemSize={baseItemSize}
label={item.label}
>
<DockIcon>{item.icon}</DockIcon>
<DockLabel>{item.label}</DockLabel>
Expand Down