diff options
| author | Armand Philippot <git@armandphilippot.com> | 2023-09-28 18:19:00 +0200 |
|---|---|---|
| committer | Armand Philippot <git@armandphilippot.com> | 2023-10-24 12:25:00 +0200 |
| commit | 3272ac336da52364ace5ed76d8f609d4088ffc06 (patch) | |
| tree | 3bfffa119ddfffce6313def2932824f2719ad4b7 | |
| parent | 837e0e904c40f7b87561c34ca3f49edd5d8d1c52 (diff) | |
refactor(components): make Logo component ESlint compliant
I also renamed the title prop to heading because title already exists
as HTML attribute.
| -rw-r--r-- | src/components/atoms/images/logo.test.tsx | 10 | ||||
| -rw-r--r-- | src/components/atoms/images/logo.tsx | 45 | ||||
| -rw-r--r-- | src/components/atoms/images/logo/index.ts | 1 | ||||
| -rw-r--r-- | src/components/atoms/images/logo/logo.module.scss (renamed from src/components/atoms/images/logo.module.scss) | 0 | ||||
| -rw-r--r-- | src/components/atoms/images/logo/logo.stories.tsx (renamed from src/components/atoms/images/logo.stories.tsx) | 6 | ||||
| -rw-r--r-- | src/components/atoms/images/logo/logo.test.tsx | 13 | ||||
| -rw-r--r-- | src/components/atoms/images/logo/logo.tsx | 46 | ||||
| -rw-r--r-- | src/components/molecules/images/flipping-logo.tsx | 23 |
8 files changed, 78 insertions, 66 deletions
diff --git a/src/components/atoms/images/logo.test.tsx b/src/components/atoms/images/logo.test.tsx deleted file mode 100644 index 06301d0..0000000 --- a/src/components/atoms/images/logo.test.tsx +++ /dev/null @@ -1,10 +0,0 @@ -import { describe, expect, it } from '@jest/globals'; -import { render, screen } from '../../../../tests/utils'; -import { Logo } from './logo'; - -describe('Logo', () => { - it('renders a logo with a title', () => { - render(<Logo title="My title" />); - expect(screen.getByTitle('My title')).toBeInTheDocument(); - }); -}); diff --git a/src/components/atoms/images/logo.tsx b/src/components/atoms/images/logo.tsx deleted file mode 100644 index 491539d..0000000 --- a/src/components/atoms/images/logo.tsx +++ /dev/null @@ -1,45 +0,0 @@ -import { FC, SVGAttributes } from 'react'; -import styles from './logo.module.scss'; - -export type LogoProps = SVGAttributes<SVGElement> & { - /** - * SVG Image title. - */ - title?: string; -}; - -/** - * Logo component. - * - * Render a SVG logo. - */ -export const Logo: FC<LogoProps> = ({ title, ...props }) => { - return ( - <svg - {...props} - className={styles.wrapper} - viewBox="0 0 512 512" - xmlns="http://www.w3.org/2000/svg" - > - {title ? <title>{title}</title> : null} - <path className={styles['bg-left']} d="M 0,0 H 506 L 0,506 Z" /> - <path className={styles['bg-right']} d="M 512,512 H 6 L 512,6 Z" /> - <path - className={styles['letter-shadow']} - d="m 66.049088,353.26557 h 57.233082 l 15.4763,-40.00476 h 56.64908 l 15.76831,40.00476 h 57.2331 L 196.28357,165.21398 h -58.10911 z m 80.009522,-79.42552 21.02441,-55.18904 21.02439,55.18904 z" - /> - <path - className={styles['letter']} - d="m 59.569539,346.78602 h 57.233081 l 15.4763,-40.00476 H 188.928 l 15.76831,40.00476 h 57.2331 L 189.80402,158.73443 h -58.10911 z m 80.009521,-79.42552 21.02441,-55.18904 21.02439,55.18904 z" - /> - <path - className={styles['letter-shadow']} - d="m 288.84935,353.26557 h 54.89704 v -50.51696 h 40.88078 c 42.04881,0 68.91332,-28.61654 68.91332,-68.32931 0,-38.5447 -21.60841,-69.20532 -67.74528,-69.20532 h -96.94586 z m 54.89704,-92.56578 v -53.437 h 29.78458 c 16.35231,0 23.94446,10.51221 23.94446,27.15651 0,15.47629 -8.46817,26.28049 -25.40449,26.28049 z" - /> - <path - className={styles['letter']} - d="m 282.3698,346.78602 h 54.89704 v -50.51696 h 40.88078 c 42.04881,0 68.91332,-28.61654 68.91332,-68.3293 0,-38.54471 -21.60841,-69.20533 -67.74528,-69.20533 H 282.3698 Z m 54.89704,-92.56578 v -53.437 h 29.78458 c 16.35231,0 23.94446,10.51221 23.94446,27.15652 0,15.47628 -8.46817,26.28048 -25.40449,26.28048 z" - /> - </svg> - ); -}; diff --git a/src/components/atoms/images/logo/index.ts b/src/components/atoms/images/logo/index.ts new file mode 100644 index 0000000..cb6151d --- /dev/null +++ b/src/components/atoms/images/logo/index.ts @@ -0,0 +1 @@ +export * from './logo'; diff --git a/src/components/atoms/images/logo.module.scss b/src/components/atoms/images/logo/logo.module.scss index bd4ee90..bd4ee90 100644 --- a/src/components/atoms/images/logo.module.scss +++ b/src/components/atoms/images/logo/logo.module.scss diff --git a/src/components/atoms/images/logo.stories.tsx b/src/components/atoms/images/logo/logo.stories.tsx index bf19b34..cfccb65 100644 --- a/src/components/atoms/images/logo.stories.tsx +++ b/src/components/atoms/images/logo/logo.stories.tsx @@ -1,14 +1,14 @@ -import { ComponentMeta, ComponentStory } from '@storybook/react'; +import type { ComponentMeta, ComponentStory } from '@storybook/react'; import { Logo as LogoComponent } from './logo'; /** * Logo - Storybook Meta */ export default { - title: 'Atoms/Illustrations/Images', + title: 'Atoms/Images', component: LogoComponent, argTypes: { - title: { + heading: { control: { type: 'text', }, diff --git a/src/components/atoms/images/logo/logo.test.tsx b/src/components/atoms/images/logo/logo.test.tsx new file mode 100644 index 0000000..26fe6c3 --- /dev/null +++ b/src/components/atoms/images/logo/logo.test.tsx @@ -0,0 +1,13 @@ +import { describe, expect, it } from '@jest/globals'; +import { render, screen as rtlScreen } from '@testing-library/react'; +import { Logo } from './logo'; + +describe('Logo', () => { + it('renders a logo with a title', () => { + const heading = 'enim quaerat veritatis'; + + render(<Logo heading={heading} />); + + expect(rtlScreen.getByRole('img')).toHaveAccessibleName(heading); + }); +}); diff --git a/src/components/atoms/images/logo/logo.tsx b/src/components/atoms/images/logo/logo.tsx new file mode 100644 index 0000000..5c575a5 --- /dev/null +++ b/src/components/atoms/images/logo/logo.tsx @@ -0,0 +1,46 @@ +/* eslint-disable react/jsx-no-literals */ +import type { FC, SVGAttributes } from 'react'; +import styles from './logo.module.scss'; + +export type LogoProps = Omit<SVGAttributes<SVGElement>, 'role'> & { + /** + * Define an accessible title for the logo. + */ + heading?: string; +}; + +/** + * Logo component. + * + * Render a SVG logo. + */ +export const Logo: FC<LogoProps> = ({ heading, ...props }) => ( + // eslint-disable-next-line jsx-a11y/prefer-tag-over-role -- Valid on SVG + <svg + {...props} + className={styles.wrapper} + role="img" + viewBox="0 0 512 512" + xmlns="http://www.w3.org/2000/svg" + > + {heading ? <title>{heading}</title> : null} + <path className={styles['bg-left']} d="M 0,0 H 506 L 0,506 Z" /> + <path className={styles['bg-right']} d="M 512,512 H 6 L 512,6 Z" /> + <path + className={styles['letter-shadow']} + d="m 66.049088,353.26557 h 57.233082 l 15.4763,-40.00476 h 56.64908 l 15.76831,40.00476 h 57.2331 L 196.28357,165.21398 h -58.10911 z m 80.009522,-79.42552 21.02441,-55.18904 21.02439,55.18904 z" + /> + <path + className={styles.letter} + d="m 59.569539,346.78602 h 57.233081 l 15.4763,-40.00476 H 188.928 l 15.76831,40.00476 h 57.2331 L 189.80402,158.73443 h -58.10911 z m 80.009521,-79.42552 21.02441,-55.18904 21.02439,55.18904 z" + /> + <path + className={styles['letter-shadow']} + d="m 288.84935,353.26557 h 54.89704 v -50.51696 h 40.88078 c 42.04881,0 68.91332,-28.61654 68.91332,-68.32931 0,-38.5447 -21.60841,-69.20532 -67.74528,-69.20532 h -96.94586 z m 54.89704,-92.56578 v -53.437 h 29.78458 c 16.35231,0 23.94446,10.51221 23.94446,27.15651 0,15.47629 -8.46817,26.28049 -25.40449,26.28049 z" + /> + <path + className={styles.letter} + d="m 282.3698,346.78602 h 54.89704 v -50.51696 h 40.88078 c 42.04881,0 68.91332,-28.61654 68.91332,-68.3293 0,-38.54471 -21.60841,-69.20533 -67.74528,-69.20533 H 282.3698 Z m 54.89704,-92.56578 v -53.437 h 29.78458 c 16.35231,0 23.94446,10.51221 23.94446,27.15652 0,15.47628 -8.46817,26.28048 -25.40449,26.28048 z" + /> + </svg> +); diff --git a/src/components/molecules/images/flipping-logo.tsx b/src/components/molecules/images/flipping-logo.tsx index 64e69ca..703d5d6 100644 --- a/src/components/molecules/images/flipping-logo.tsx +++ b/src/components/molecules/images/flipping-logo.tsx @@ -1,5 +1,9 @@ -import Image, { type ImageProps } from 'next/image'; -import { ForwardedRef, forwardRef, ForwardRefRenderFunction } from 'react'; +import NextImage, { type ImageProps } from 'next/image'; +import { + type ForwardedRef, + forwardRef, + type ForwardRefRenderFunction, +} from 'react'; import { Logo, type LogoProps } from '../../atoms'; import styles from './flipping-logo.module.scss'; @@ -15,7 +19,7 @@ export type FlippingLogoProps = { /** * Logo image title. */ - logoTitle?: LogoProps['title']; + logoTitle?: LogoProps['heading']; /** * Photo url. */ @@ -29,20 +33,23 @@ const FlippingLogoWithRef: ForwardRefRenderFunction< { className = '', altText, logoTitle, photo, ...props }, ref: ForwardedRef<HTMLDivElement> ) => { + const wrapperClass = `${styles.logo} ${className}`; + const size = 100; + return ( - <div className={`${styles.logo} ${className}`} ref={ref}> + <div className={wrapperClass} ref={ref}> <div className={styles.logo__front}> - <Image + <NextImage {...props} alt={altText} - height="100" + height={size} src={photo} style={{ objectFit: 'cover' }} - width="100" + width={size} /> </div> <div className={styles.logo__back}> - <Logo title={logoTitle} /> + <Logo heading={logoTitle} /> </div> </div> ); |
