From 5c75a302c2203cb3ebf31233121026b4775662cf Mon Sep 17 00:00:00 2001 From: Armand Philippot Date: Fri, 8 Apr 2022 19:32:58 +0200 Subject: chore(icons): accept a classname as prop --- src/components/atoms/icons/arrow.stories.tsx | 19 ++++++++++-- src/components/atoms/icons/arrow.test.tsx | 4 +-- src/components/atoms/icons/arrow.tsx | 16 ++++++---- src/components/atoms/icons/career.stories.tsx | 15 +++++++++ src/components/atoms/icons/career.tsx | 13 ++++++-- src/components/atoms/icons/cc-by-sa.stories.tsx | 15 +++++++++ src/components/atoms/icons/cc-by-sa.test.tsx | 6 ++-- src/components/atoms/icons/cc-by-sa.tsx | 13 ++++++-- src/components/atoms/icons/close.stories.tsx | 15 +++++++++ src/components/atoms/icons/close.tsx | 13 ++++++-- src/components/atoms/icons/cog.stories.tsx | 15 +++++++++ src/components/atoms/icons/cog.tsx | 13 ++++++-- .../atoms/icons/computer-screen.stories.tsx | 15 +++++++++ src/components/atoms/icons/computer-screen.tsx | 13 ++++++-- src/components/atoms/icons/envelop.stories.tsx | 15 +++++++++ src/components/atoms/icons/envelop.tsx | 13 ++++++-- src/components/atoms/icons/hamburger.stories.tsx | 13 ++++++++ src/components/atoms/icons/hamburger.tsx | 11 +++++-- src/components/atoms/icons/home.stories.tsx | 15 +++++++++ src/components/atoms/icons/home.tsx | 13 ++++++-- .../atoms/icons/magnifying-glass.stories.tsx | 15 +++++++++ src/components/atoms/icons/magnifying-glass.tsx | 13 ++++++-- src/components/atoms/icons/moon.stories.tsx | 28 +++++++++++++++++ src/components/atoms/icons/moon.tsx | 13 ++++++-- src/components/atoms/icons/plus-minus.stories.tsx | 36 ++-------------------- src/components/atoms/icons/plus-minus.test.tsx | 15 +++------ src/components/atoms/icons/plus-minus.tsx | 24 +++------------ src/components/atoms/icons/posts-stack.stories.tsx | 15 +++++++++ src/components/atoms/icons/posts-stack.tsx | 13 ++++++-- src/components/atoms/icons/sun.stories.tsx | 28 +++++++++++++++++ src/components/atoms/icons/sun.tsx | 10 ++++-- 31 files changed, 363 insertions(+), 112 deletions(-) (limited to 'src') diff --git a/src/components/atoms/icons/arrow.stories.tsx b/src/components/atoms/icons/arrow.stories.tsx index 52b5126..96ce1d8 100644 --- a/src/components/atoms/icons/arrow.stories.tsx +++ b/src/components/atoms/icons/arrow.stories.tsx @@ -5,15 +5,25 @@ export default { title: 'Atoms/Icons', component: ArrowIcon, argTypes: { + className: { + control: { + type: 'text', + }, + description: 'Set additional classnames.', + table: { + category: 'Styles', + }, + type: { + name: 'string', + required: false, + }, + }, direction: { control: { type: 'select', }, description: 'An arrow icon.', options: ['bottom', 'left', 'right', 'top'], - table: { - defaultValue: { summary: 'right' }, - }, type: { name: 'string', required: false, @@ -27,3 +37,6 @@ const Template: ComponentStory = (args) => ( ); export const Arrow = Template.bind({}); +Arrow.args = { + direction: 'right', +}; diff --git a/src/components/atoms/icons/arrow.test.tsx b/src/components/atoms/icons/arrow.test.tsx index 01813ce..502dcc1 100644 --- a/src/components/atoms/icons/arrow.test.tsx +++ b/src/components/atoms/icons/arrow.test.tsx @@ -2,8 +2,8 @@ import { render } from '@test-utils'; import Arrow from './arrow'; describe('Arrow', () => { - it('renders an arrow icon', () => { - const { container } = render(); + it('renders an arrow icon oriented to the right', () => { + const { container } = render(); expect(container).toBeDefined(); }); }); diff --git a/src/components/atoms/icons/arrow.tsx b/src/components/atoms/icons/arrow.tsx index f50d117..5f3c460 100644 --- a/src/components/atoms/icons/arrow.tsx +++ b/src/components/atoms/icons/arrow.tsx @@ -1,13 +1,17 @@ -import { FC } from 'react'; +import { VFC } from 'react'; import styles from './arrow.module.scss'; -type ArrowDirection = 'top' | 'right' | 'bottom' | 'left'; +export type ArrowDirection = 'top' | 'right' | 'bottom' | 'left'; -type ArrowProps = { +export type ArrowProps = { + /** + * Set additional classnames to the icon. + */ + className?: string; /** * The arrow direction. Default: right. */ - direction?: ArrowDirection; + direction: ArrowDirection; }; /** @@ -15,9 +19,9 @@ type ArrowProps = { * * Render a svg arrow icon. */ -const Arrow: FC = ({ direction = 'right' }) => { +const Arrow: VFC = ({ className = '', direction }) => { const directionClass = styles[`icon--${direction}`]; - const classes = `${styles.icon} ${directionClass}`; + const classes = `${styles.icon} ${directionClass} ${className}`; if (direction === 'top') { return ( diff --git a/src/components/atoms/icons/career.stories.tsx b/src/components/atoms/icons/career.stories.tsx index 2c1d93a..8575cb9 100644 --- a/src/components/atoms/icons/career.stories.tsx +++ b/src/components/atoms/icons/career.stories.tsx @@ -4,6 +4,21 @@ import CareerIcon from './career'; export default { title: 'Atoms/Icons', component: CareerIcon, + argTypes: { + className: { + control: { + type: 'text', + }, + description: 'Set additional classnames.', + table: { + category: 'Styles', + }, + type: { + name: 'string', + required: false, + }, + }, + }, } as ComponentMeta; const Template: ComponentStory = (args) => ( diff --git a/src/components/atoms/icons/career.tsx b/src/components/atoms/icons/career.tsx index aecab1e..28edcc7 100644 --- a/src/components/atoms/icons/career.tsx +++ b/src/components/atoms/icons/career.tsx @@ -1,17 +1,24 @@ -import { FC } from 'react'; +import { VFC } from 'react'; import styles from './career.module.scss'; +export type CareerProps = { + /** + * Set additional classnames to the icon. + */ + className?: string; +}; + /** * Career Component * * Render a career svg icon. */ -const Career: FC = () => { +const Career: VFC = ({ className = '' }) => { return ( ; const Template: ComponentStory = (args) => ( diff --git a/src/components/atoms/icons/cc-by-sa.test.tsx b/src/components/atoms/icons/cc-by-sa.test.tsx index 03d54f7..adb03e4 100644 --- a/src/components/atoms/icons/cc-by-sa.test.tsx +++ b/src/components/atoms/icons/cc-by-sa.test.tsx @@ -1,9 +1,9 @@ -import { render } from '@test-utils'; +import { render, screen } from '@test-utils'; import CCBySA from './cc-by-sa'; describe('CCBySA', () => { it('renders a CC BY SA icon', () => { - const { container } = render(); - expect(container).toBeDefined(); + render(); + expect(screen.getByTitle('CC BY SA')).toBeInTheDocument(); }); }); diff --git a/src/components/atoms/icons/cc-by-sa.tsx b/src/components/atoms/icons/cc-by-sa.tsx index adc8b79..552504e 100644 --- a/src/components/atoms/icons/cc-by-sa.tsx +++ b/src/components/atoms/icons/cc-by-sa.tsx @@ -1,18 +1,25 @@ -import { FC } from 'react'; +import { VFC } from 'react'; import { useIntl } from 'react-intl'; import styles from './cc-by-sa.module.scss'; +export type CCBySAProps = { + /** + * Set additional classnames to the icon. + */ + className?: string; +}; + /** * CCBySA component * * Render a CC BY SA svg icon. */ -const CCBySA: FC = () => { +const CCBySA: VFC = ({ className = '' }) => { const intl = useIntl(); return ( diff --git a/src/components/atoms/icons/close.stories.tsx b/src/components/atoms/icons/close.stories.tsx index 265df7a..b1d88cd 100644 --- a/src/components/atoms/icons/close.stories.tsx +++ b/src/components/atoms/icons/close.stories.tsx @@ -4,6 +4,21 @@ import CloseIcon from './close'; export default { title: 'Atoms/Icons', component: CloseIcon, + argTypes: { + className: { + control: { + type: 'text', + }, + description: 'Set additional classnames.', + table: { + category: 'Styles', + }, + type: { + name: 'string', + required: false, + }, + }, + }, } as ComponentMeta; const Template: ComponentStory = (args) => ( diff --git a/src/components/atoms/icons/close.tsx b/src/components/atoms/icons/close.tsx index 80d904e..eb9ce7c 100644 --- a/src/components/atoms/icons/close.tsx +++ b/src/components/atoms/icons/close.tsx @@ -1,17 +1,24 @@ -import { FC } from 'react'; +import { VFC } from 'react'; import styles from './close.module.scss'; +export type CloseProps = { + /** + * Set additional classnames to the icon. + */ + className?: string; +}; + /** * Close component * * Render a close svg icon. */ -const Close: FC = () => { +const Close: VFC = ({ className = '' }) => { return ( ; const Template: ComponentStory = (args) => ( diff --git a/src/components/atoms/icons/cog.tsx b/src/components/atoms/icons/cog.tsx index bed19ce..df6d54d 100644 --- a/src/components/atoms/icons/cog.tsx +++ b/src/components/atoms/icons/cog.tsx @@ -1,17 +1,24 @@ -import { FC } from 'react'; +import { VFC } from 'react'; import styles from './cog.module.scss'; +export type CogProps = { + /** + * Set additional classnames to the icon. + */ + className?: string; +}; + /** * Cog component * * Render a cog svg icon. */ -const Cog: FC = () => { +const Cog: VFC = ({ className = '' }) => { return ( diff --git a/src/components/atoms/icons/computer-screen.stories.tsx b/src/components/atoms/icons/computer-screen.stories.tsx index 317b4b6..46e3ad4 100644 --- a/src/components/atoms/icons/computer-screen.stories.tsx +++ b/src/components/atoms/icons/computer-screen.stories.tsx @@ -4,6 +4,21 @@ import ComputerScreenIcon from './computer-screen'; export default { title: 'Atoms/Icons', component: ComputerScreenIcon, + argTypes: { + className: { + control: { + type: 'text', + }, + description: 'Set additional classnames.', + table: { + category: 'Styles', + }, + type: { + name: 'string', + required: false, + }, + }, + }, } as ComponentMeta; const Template: ComponentStory = (args) => ( diff --git a/src/components/atoms/icons/computer-screen.tsx b/src/components/atoms/icons/computer-screen.tsx index c9c869d..310836f 100644 --- a/src/components/atoms/icons/computer-screen.tsx +++ b/src/components/atoms/icons/computer-screen.tsx @@ -1,17 +1,24 @@ -import { FC } from 'react'; +import { VFC } from 'react'; import styles from './computer-screen.module.scss'; +export type ComputerScreenProps = { + /** + * Set additional classnames to the icon. + */ + className?: string; +}; + /** * ComputerScreen component * * Render a computer screen svg icon. */ -const ComputerScreen: FC = () => { +const ComputerScreen: VFC = ({ className = '' }) => { return ( ; const Template: ComponentStory = (args) => ( diff --git a/src/components/atoms/icons/envelop.tsx b/src/components/atoms/icons/envelop.tsx index a846a45..7b50d1d 100644 --- a/src/components/atoms/icons/envelop.tsx +++ b/src/components/atoms/icons/envelop.tsx @@ -1,17 +1,24 @@ -import { FC } from 'react'; +import { VFC } from 'react'; import styles from './envelop.module.scss'; +export type EnvelopProps = { + /** + * Set additional classnames to the icon. + */ + className?: string; +}; + /** * Envelop Component * * Render an envelop svg icon. */ -const Envelop: FC = () => { +const Envelop: VFC = ({ className = '' }) => { return ( = ({ isActive }) => { +const Hamburger: FC = ({ className = '', isActive }) => { const stateClass = isActive ? `${styles['icon--active']}` : ''; - const iconClasses = `${styles.icon} ${stateClass}`; + const iconClasses = `${styles.icon} ${stateClass} ${className}`; return ; }; diff --git a/src/components/atoms/icons/home.stories.tsx b/src/components/atoms/icons/home.stories.tsx index 59eb477..b1c995c 100644 --- a/src/components/atoms/icons/home.stories.tsx +++ b/src/components/atoms/icons/home.stories.tsx @@ -4,6 +4,21 @@ import HomeIcon from './home'; export default { title: 'Atoms/Icons', component: HomeIcon, + argTypes: { + className: { + control: { + type: 'text', + }, + description: 'Set additional classnames.', + table: { + category: 'Styles', + }, + type: { + name: 'string', + required: false, + }, + }, + }, } as ComponentMeta; const Template: ComponentStory = (args) => ( diff --git a/src/components/atoms/icons/home.tsx b/src/components/atoms/icons/home.tsx index 90d3a14..71bbc4a 100644 --- a/src/components/atoms/icons/home.tsx +++ b/src/components/atoms/icons/home.tsx @@ -1,17 +1,24 @@ -import { FC } from 'react'; +import { VFC } from 'react'; import styles from './home.module.scss'; +export type HomeProps = { + /** + * Set additional classnames to the icon. + */ + className?: string; +}; + /** * Home component. * * Render a home svg icon. */ -const Home: FC = () => { +const Home: VFC = ({ className = '' }) => { return ( ; const Template: ComponentStory = (args) => ( diff --git a/src/components/atoms/icons/magnifying-glass.tsx b/src/components/atoms/icons/magnifying-glass.tsx index 547dd00..445ef10 100644 --- a/src/components/atoms/icons/magnifying-glass.tsx +++ b/src/components/atoms/icons/magnifying-glass.tsx @@ -1,17 +1,24 @@ -import { FC } from 'react'; +import { VFC } from 'react'; import styles from './magnifying-glass.module.scss'; +export type MagnifyingGlassProps = { + /** + * Set additional classnames to the icon. + */ + className?: string; +}; + /** * MagnifyingGlass component * * Render a magnifying glass svg icon. */ -const MagnifyingGlass: FC = () => { +const MagnifyingGlass: VFC = ({ className = '' }) => { return ( ; const Template: ComponentStory = (args) => ( diff --git a/src/components/atoms/icons/moon.tsx b/src/components/atoms/icons/moon.tsx index 82b0ef6..4f52319 100644 --- a/src/components/atoms/icons/moon.tsx +++ b/src/components/atoms/icons/moon.tsx @@ -1,14 +1,21 @@ -import { FC } from 'react'; +import { VFC } from 'react'; import styles from './moon.module.scss'; type MoonProps = { + /** + * Set additional classnames to the icon. + */ + className?: string; + /** + * The SVG title. + */ title?: string; }; -const Moon: FC = ({ title }) => { +const Moon: VFC = ({ className = '', title }) => { return ( diff --git a/src/components/atoms/icons/plus-minus.stories.tsx b/src/components/atoms/icons/plus-minus.stories.tsx index 1b5086a..ffa28f2 100644 --- a/src/components/atoms/icons/plus-minus.stories.tsx +++ b/src/components/atoms/icons/plus-minus.stories.tsx @@ -4,44 +4,14 @@ import PlusMinusIcon from './plus-minus'; export default { title: 'Atoms/Icons', component: PlusMinusIcon, - args: { - ariaHidden: true, - }, argTypes: { - additionalClasses: { - control: { - type: 'text', - }, - description: 'Set additional classes.', - table: { - category: 'Options', - }, - type: { - name: 'string', - required: false, - }, - }, - ariaHidden: { - control: { - type: 'boolean', - }, - description: 'Should be hidden for accessibility.', - table: { - category: 'Options', - defaultValue: { summary: true }, - }, - type: { - name: 'boolean', - required: false, - }, - }, - ariaLabel: { + className: { control: { type: 'text', }, - description: 'An accessible name.', + description: 'Set additional classnames.', table: { - category: 'Options', + category: 'Styles', }, type: { name: 'string', diff --git a/src/components/atoms/icons/plus-minus.test.tsx b/src/components/atoms/icons/plus-minus.test.tsx index 96c2ad0..6903c7a 100644 --- a/src/components/atoms/icons/plus-minus.test.tsx +++ b/src/components/atoms/icons/plus-minus.test.tsx @@ -1,16 +1,9 @@ -import { render, screen } from '@test-utils'; +import { render } from '@test-utils'; import PlusMinus from './plus-minus'; describe('PlusMinus', () => { - it('renders a plus icon', () => { - render(); - expect(screen.getByLabelText('Plus icon')).toHaveClass('icon--plus'); - }); - - it('renders a minus icon', () => { - render( - - ); - expect(screen.getByLabelText('Minus icon')).toHaveClass('icon--minus'); + it('renders a plus/minus icon', () => { + const { container } = render(); + expect(container).toBeDefined(); }); }); diff --git a/src/components/atoms/icons/plus-minus.tsx b/src/components/atoms/icons/plus-minus.tsx index 1a6f7b0..78aa14a 100644 --- a/src/components/atoms/icons/plus-minus.tsx +++ b/src/components/atoms/icons/plus-minus.tsx @@ -3,17 +3,9 @@ import styles from './plus-minus.module.scss'; type PlusMinusProps = { /** - * Adds additional classes. + * Set additional classnames to the icon. */ - additionalClasses?: string; - /** - * An accessible name. - */ - ariaLabel?: string; - /** - * Should be hidden for accessibility. Default: true. - */ - ariaHidden?: boolean; + className?: string; /** * Which state should be displayed. */ @@ -25,19 +17,13 @@ type PlusMinusProps = { * * Render a plus or a minus icon. */ -const PlusMinus: FC = ({ - additionalClasses, - ariaHidden = true, - ariaLabel, - state, -}) => { +const PlusMinus: FC = ({ className, state }) => { const stateClass = `icon--${state}`; return (
); }; diff --git a/src/components/atoms/icons/posts-stack.stories.tsx b/src/components/atoms/icons/posts-stack.stories.tsx index e2206c2..46bb39f 100644 --- a/src/components/atoms/icons/posts-stack.stories.tsx +++ b/src/components/atoms/icons/posts-stack.stories.tsx @@ -4,6 +4,21 @@ import PostsStackIcon from './posts-stack'; export default { title: 'Atoms/Icons', component: PostsStackIcon, + argTypes: { + className: { + control: { + type: 'text', + }, + description: 'Set additional classnames.', + table: { + category: 'Styles', + }, + type: { + name: 'string', + required: false, + }, + }, + }, } as ComponentMeta; const Template: ComponentStory = (args) => ( diff --git a/src/components/atoms/icons/posts-stack.tsx b/src/components/atoms/icons/posts-stack.tsx index 22069ac..1998d25 100644 --- a/src/components/atoms/icons/posts-stack.tsx +++ b/src/components/atoms/icons/posts-stack.tsx @@ -1,17 +1,24 @@ -import { FC } from 'react'; +import { VFC } from 'react'; import styles from './posts-stack.module.scss'; +export type PostsStackProps = { + /** + * Set additional classnames to the icon. + */ + className?: string; +}; + /** * Posts stack component. * * Render a posts stack svg icon. */ -const PostsStack: FC = () => { +const PostsStack: VFC = ({ className = '' }) => { return ( ; const Template: ComponentStory = (args) => ( diff --git a/src/components/atoms/icons/sun.tsx b/src/components/atoms/icons/sun.tsx index 6caad9c..fa9d922 100644 --- a/src/components/atoms/icons/sun.tsx +++ b/src/components/atoms/icons/sun.tsx @@ -1,7 +1,11 @@ -import { FC } from 'react'; +import { VFC } from 'react'; import styles from './sun.module.scss'; type SunProps = { + /** + * Set additional classnames to the icon. + */ + className?: string; /** * The SVG title. */ @@ -13,10 +17,10 @@ type SunProps = { * * Render a svg sun icon. */ -const Sun: FC = ({ title }) => { +const Sun: VFC = ({ className = '', title }) => { return ( -- cgit v1.2.3