diff options
| author | Armand Philippot <git@armandphilippot.com> | 2022-04-08 19:41:40 +0200 |
|---|---|---|
| committer | Armand Philippot <git@armandphilippot.com> | 2022-04-08 19:41:40 +0200 |
| commit | a5df28fad0dae266a857ae110c43b3cb8b23c996 (patch) | |
| tree | a32ea390e90697dc51c3ccb9018de9da2ee4fac3 /src/components/molecules/modals/modal.tsx | |
| parent | 5c75a302c2203cb3ebf31233121026b4775662cf (diff) | |
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.
Diffstat (limited to 'src/components/molecules/modals/modal.tsx')
| -rw-r--r-- | src/components/molecules/modals/modal.tsx | 22 |
1 files changed, 17 insertions, 5 deletions
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<ReactNode>(() => import('@components/atoms/icons/cog')); -const SearchIcon = dynamic<ReactNode>( +const CogIcon = dynamic<CogProps>(() => import('@components/atoms/icons/cog')); +const SearchIcon = dynamic<MagnifyingGlassProps>( () => import('@components/atoms/icons/magnifying-glass') ); @@ -20,7 +32,7 @@ const SearchIcon = dynamic<ReactNode>( * * Render a modal component with an optional title and icon. */ -const Modal: FC<ModalProps> = ({ children, icon, title }) => { +const Modal: FC<ModalProps> = ({ children, className = '', icon, title }) => { const getIcon = (id: Icons) => { switch (id) { case 'cogs': @@ -33,7 +45,7 @@ const Modal: FC<ModalProps> = ({ children, icon, title }) => { }; return ( - <div className={styles.wrapper}> + <div className={`${styles.wrapper} ${className}`}> {title && ( <Heading isFake={true} level={3}> {icon && <span className={styles.icon}>{getIcon(icon)}</span>} |
