Skip to content

Commit

Permalink
chore: add accessibility, prefersReducedMotion
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick-1979 committed Oct 28, 2024
1 parent bd9d4d9 commit 671c02f
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions packages/extension-polkagate/src/components/VaadinIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ interface VaadinIconProps extends React.HTMLAttributes<HTMLElement> {
}

const VaadinIcon: React.FC<VaadinIconProps> = ({ float = false, icon, spin = false, style, ...props }) => {
const prefersReducedMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches;

useEffect(() => {
// Check if the animations are already injected
if (!document.getElementById('vaadin-icon-animation-keyframes')) {
Expand All @@ -34,12 +36,16 @@ const VaadinIcon: React.FC<VaadinIconProps> = ({ float = false, icon, spin = fal

// Combine inline styles with the animations if enabled
const combinedStyles: React.CSSProperties = {
animation: `${spin ? 'vaadinSpin 3s linear infinite' : ''} ${float ? 'float 2s ease-in-out infinite' : ''}`,
animation: `${spin && !prefersReducedMotion ? 'vaadinSpin 3s linear infinite' : ''} ${float && !prefersReducedMotion ? 'float 2s ease-in-out infinite' : ''}`,
...style
};

//@ts-ignore
return <vaadin-icon icon={icon} style={combinedStyles} {...props} />;
// @ts-ignore
return <vaadin-icon
icon={icon}
style={combinedStyles}
{...props}
/>;
};

export default VaadinIcon;

0 comments on commit 671c02f

Please sign in to comment.