From a5df28fad0dae266a857ae110c43b3cb8b23c996 Mon Sep 17 00:00:00 2001 From: Armand Philippot Date: Fri, 8 Apr 2022 19:41:40 +0200 Subject: refactor: use a consistent classname prop and avoid children prop I was using the FunctionComponent type for some component that do not use children. So I change the type to VoidFunctionComponent to avoid mistakes. I also rename all the "classes" or "additionalClasses" props to "className" to keep consistency between each components. --- src/components/molecules/modals/modal.stories.tsx | 13 ++++++++++++ src/components/molecules/modals/modal.tsx | 22 ++++++++++++++++----- .../molecules/modals/tooltip.stories.tsx | 23 ++++++++++++++++++++++ src/components/molecules/modals/tooltip.tsx | 15 +++++++++----- 4 files changed, 63 insertions(+), 10 deletions(-) (limited to 'src/components/molecules/modals') diff --git a/src/components/molecules/modals/modal.stories.tsx b/src/components/molecules/modals/modal.stories.tsx index b68a24b..bd7d9f4 100644 --- a/src/components/molecules/modals/modal.stories.tsx +++ b/src/components/molecules/modals/modal.stories.tsx @@ -15,6 +15,19 @@ export default { required: true, }, }, + className: { + control: { + type: 'text', + }, + description: 'Set additional classnames to the modal.', + table: { + category: 'Styles', + }, + type: { + name: 'string', + required: false, + }, + }, icon: { control: { type: 'select', diff --git a/src/components/molecules/modals/modal.tsx b/src/components/molecules/modals/modal.tsx index 4dc3b0a..ce12e7a 100644 --- a/src/components/molecules/modals/modal.tsx +++ b/src/components/molecules/modals/modal.tsx @@ -1,17 +1,29 @@ import Heading from '@components/atoms/headings/heading'; +import { CogProps } from '@components/atoms/icons/cog'; +import { MagnifyingGlassProps } from '@components/atoms/icons/magnifying-glass'; import dynamic from 'next/dynamic'; -import { FC, ReactNode } from 'react'; +import { FC } from 'react'; import styles from './modal.module.scss'; export type Icons = 'cogs' | 'search'; export type ModalProps = { + /** + * Set additional classnames. + */ + className?: string; + /** + * A icon to illustrate the modal. + */ icon?: Icons; + /** + * The modal title. + */ title?: string; }; -const CogIcon = dynamic(() => import('@components/atoms/icons/cog')); -const SearchIcon = dynamic( +const CogIcon = dynamic(() => import('@components/atoms/icons/cog')); +const SearchIcon = dynamic( () => import('@components/atoms/icons/magnifying-glass') ); @@ -20,7 +32,7 @@ const SearchIcon = dynamic( * * Render a modal component with an optional title and icon. */ -const Modal: FC = ({ children, icon, title }) => { +const Modal: FC = ({ children, className = '', icon, title }) => { const getIcon = (id: Icons) => { switch (id) { case 'cogs': @@ -33,7 +45,7 @@ const Modal: FC = ({ children, icon, title }) => { }; return ( -
+
{title && ( {icon && {getIcon(icon)}} diff --git a/src/components/molecules/modals/tooltip.stories.tsx b/src/components/molecules/modals/tooltip.stories.tsx index a57cf34..63fc71d 100644 --- a/src/components/molecules/modals/tooltip.stories.tsx +++ b/src/components/molecules/modals/tooltip.stories.tsx @@ -5,6 +5,19 @@ export default { title: 'Molecules/Modals', component: TooltipComponent, argTypes: { + className: { + control: { + type: 'text', + }, + description: 'Set additional classnames to the tooltip.', + table: { + category: 'Styles', + }, + type: { + name: 'string', + required: false, + }, + }, content: { control: { type: 'text', @@ -15,6 +28,16 @@ export default { required: true, }, }, + icon: { + control: { + type: 'text', + }, + description: 'The tooltip icon.', + type: { + name: 'string', + required: true, + }, + }, title: { control: { type: 'text', diff --git a/src/components/molecules/modals/tooltip.tsx b/src/components/molecules/modals/tooltip.tsx index ceb0b14..73f36e7 100644 --- a/src/components/molecules/modals/tooltip.tsx +++ b/src/components/molecules/modals/tooltip.tsx @@ -1,12 +1,12 @@ import List, { type ListItem } from '@components/atoms/lists/list'; -import { FC, ReactNode } from 'react'; +import { ReactNode, VFC } from 'react'; import styles from './tooltip.module.scss'; export type TooltipProps = { /** - * Set additional classes to the tooltip wrapper. + * Set additional classnames to the tooltip wrapper. */ - classes?: string; + className?: string; /** * The tooltip body. */ @@ -26,7 +26,12 @@ export type TooltipProps = { * * Render a tooltip modal. */ -const Tooltip: FC = ({ classes = '', content, icon, title }) => { +const Tooltip: VFC = ({ + className = '', + content, + icon, + title, +}) => { /** * Format an array of strings to an array of object with id and value. * @@ -40,7 +45,7 @@ const Tooltip: FC = ({ classes = '', content, icon, title }) => { }; return ( -
+
{icon} {title} -- cgit v1.2.3