From 3272ac336da52364ace5ed76d8f609d4088ffc06 Mon Sep 17 00:00:00 2001 From: Armand Philippot Date: Thu, 28 Sep 2023 18:19:00 +0200 Subject: refactor(components): make Logo component ESlint compliant I also renamed the title prop to heading because title already exists as HTML attribute. --- src/components/atoms/images/logo.module.scss | 28 -------------- src/components/atoms/images/logo.stories.tsx | 34 ----------------- src/components/atoms/images/logo.test.tsx | 10 ----- src/components/atoms/images/logo.tsx | 45 ---------------------- src/components/atoms/images/logo/index.ts | 1 + src/components/atoms/images/logo/logo.module.scss | 28 ++++++++++++++ src/components/atoms/images/logo/logo.stories.tsx | 34 +++++++++++++++++ src/components/atoms/images/logo/logo.test.tsx | 13 +++++++ src/components/atoms/images/logo/logo.tsx | 46 +++++++++++++++++++++++ 9 files changed, 122 insertions(+), 117 deletions(-) delete mode 100644 src/components/atoms/images/logo.module.scss delete mode 100644 src/components/atoms/images/logo.stories.tsx delete mode 100644 src/components/atoms/images/logo.test.tsx delete mode 100644 src/components/atoms/images/logo.tsx create mode 100644 src/components/atoms/images/logo/index.ts create mode 100644 src/components/atoms/images/logo/logo.module.scss create mode 100644 src/components/atoms/images/logo/logo.stories.tsx create mode 100644 src/components/atoms/images/logo/logo.test.tsx create mode 100644 src/components/atoms/images/logo/logo.tsx (limited to 'src/components/atoms') diff --git a/src/components/atoms/images/logo.module.scss b/src/components/atoms/images/logo.module.scss deleted file mode 100644 index bd4ee90..0000000 --- a/src/components/atoms/images/logo.module.scss +++ /dev/null @@ -1,28 +0,0 @@ -@use "../../../styles/abstracts/functions" as fun; - -.wrapper { - width: var(--logo-size, fun.convert-px(100)); - height: var(--logo-size, fun.convert-px(100)); - max-width: 100%; - max-height: 100%; -} - -.bg-left { - fill: var(--color-primary-light); -} - -.bg-right { - fill: var(--color-primary-dark); -} - -.letter { - fill: var(--color-fg-inverted); - stroke: var(--color-primary-darker); - stroke-width: 5; -} - -.letter-shadow { - fill: var(--color-shadow-darker); - stroke: var(--color-shadow-darker); - stroke-width: 5; -} diff --git a/src/components/atoms/images/logo.stories.tsx b/src/components/atoms/images/logo.stories.tsx deleted file mode 100644 index bf19b34..0000000 --- a/src/components/atoms/images/logo.stories.tsx +++ /dev/null @@ -1,34 +0,0 @@ -import { ComponentMeta, ComponentStory } from '@storybook/react'; -import { Logo as LogoComponent } from './logo'; - -/** - * Logo - Storybook Meta - */ -export default { - title: 'Atoms/Illustrations/Images', - component: LogoComponent, - argTypes: { - title: { - control: { - type: 'text', - }, - description: 'The SVG title.', - table: { - category: 'Accessibility', - }, - type: { - name: 'string', - required: false, - }, - }, - }, -} as ComponentMeta; - -const Template: ComponentStory = (args) => ( - -); - -/** - * Images Stories - Logo - */ -export const Logo = Template.bind({}); 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(); - 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 & { - /** - * SVG Image title. - */ - title?: string; -}; - -/** - * Logo component. - * - * Render a SVG logo. - */ -export const Logo: FC = ({ title, ...props }) => { - return ( - - {title ? {title} : null} - - - - - - - - ); -}; 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/logo.module.scss b/src/components/atoms/images/logo/logo.module.scss new file mode 100644 index 0000000..bd4ee90 --- /dev/null +++ b/src/components/atoms/images/logo/logo.module.scss @@ -0,0 +1,28 @@ +@use "../../../styles/abstracts/functions" as fun; + +.wrapper { + width: var(--logo-size, fun.convert-px(100)); + height: var(--logo-size, fun.convert-px(100)); + max-width: 100%; + max-height: 100%; +} + +.bg-left { + fill: var(--color-primary-light); +} + +.bg-right { + fill: var(--color-primary-dark); +} + +.letter { + fill: var(--color-fg-inverted); + stroke: var(--color-primary-darker); + stroke-width: 5; +} + +.letter-shadow { + fill: var(--color-shadow-darker); + stroke: var(--color-shadow-darker); + stroke-width: 5; +} diff --git a/src/components/atoms/images/logo/logo.stories.tsx b/src/components/atoms/images/logo/logo.stories.tsx new file mode 100644 index 0000000..cfccb65 --- /dev/null +++ b/src/components/atoms/images/logo/logo.stories.tsx @@ -0,0 +1,34 @@ +import type { ComponentMeta, ComponentStory } from '@storybook/react'; +import { Logo as LogoComponent } from './logo'; + +/** + * Logo - Storybook Meta + */ +export default { + title: 'Atoms/Images', + component: LogoComponent, + argTypes: { + heading: { + control: { + type: 'text', + }, + description: 'The SVG title.', + table: { + category: 'Accessibility', + }, + type: { + name: 'string', + required: false, + }, + }, + }, +} as ComponentMeta; + +const Template: ComponentStory = (args) => ( + +); + +/** + * Images Stories - Logo + */ +export const Logo = Template.bind({}); 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(); + + 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, 'role'> & { + /** + * Define an accessible title for the logo. + */ + heading?: string; +}; + +/** + * Logo component. + * + * Render a SVG logo. + */ +export const Logo: FC = ({ heading, ...props }) => ( + // eslint-disable-next-line jsx-a11y/prefer-tag-over-role -- Valid on SVG + + {heading ? {heading} : null} + + + + + + + +); -- cgit v1.2.3