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/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 +++++++++++++++++++++++ 5 files changed, 122 insertions(+) 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/images/logo') 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