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/atoms/links/link.stories.tsx | 13 +++++++++++++ src/components/atoms/links/link.tsx | 14 ++++++-------- src/components/atoms/links/nav-link.tsx | 4 ++-- src/components/atoms/links/sharing-link.tsx | 4 ++-- src/components/atoms/links/social-link.tsx | 10 ++++++---- 5 files changed, 29 insertions(+), 16 deletions(-) (limited to 'src/components/atoms/links') diff --git a/src/components/atoms/links/link.stories.tsx b/src/components/atoms/links/link.stories.tsx index e5a8b0a..569c874 100644 --- a/src/components/atoms/links/link.stories.tsx +++ b/src/components/atoms/links/link.stories.tsx @@ -15,6 +15,19 @@ export default { required: true, }, }, + className: { + control: { + type: 'text', + }, + description: 'Set additional classnames.', + table: { + category: 'Styles', + }, + type: { + name: 'string', + required: false, + }, + }, external: { control: { type: 'boolean', diff --git a/src/components/atoms/links/link.tsx b/src/components/atoms/links/link.tsx index a61158f..87f11fc 100644 --- a/src/components/atoms/links/link.tsx +++ b/src/components/atoms/links/link.tsx @@ -2,11 +2,11 @@ import NextLink from 'next/link'; import { FC } from 'react'; import styles from './link.module.scss'; -type LinkProps = { +export type LinkProps = { /** - * Set additional classes to the link. + * Set additional classnames to the link. */ - classes?: string; + className?: string; /** * True if it is an external link. Default: false. */ @@ -28,24 +28,22 @@ type LinkProps = { */ const Link: FC = ({ children, - classes, + className = '', href, lang, external = false, }) => { - const additionalClasses = classes || ''; - return external ? ( {children} ) : ( - {children} + {children} ); }; diff --git a/src/components/atoms/links/nav-link.tsx b/src/components/atoms/links/nav-link.tsx index 7c6fede..25c0e7d 100644 --- a/src/components/atoms/links/nav-link.tsx +++ b/src/components/atoms/links/nav-link.tsx @@ -1,5 +1,5 @@ import Link from 'next/link'; -import { FC, ReactNode } from 'react'; +import { VFC, ReactNode } from 'react'; import styles from './nav-link.module.scss'; export type NavLinkProps = { @@ -22,7 +22,7 @@ export type NavLinkProps = { * * Render a navigation link. */ -const NavLink: FC = ({ href, label, logo }) => { +const NavLink: VFC = ({ href, label, logo }) => { return ( diff --git a/src/components/atoms/links/sharing-link.tsx b/src/components/atoms/links/sharing-link.tsx index ca53ef9..3cd2dd1 100644 --- a/src/components/atoms/links/sharing-link.tsx +++ b/src/components/atoms/links/sharing-link.tsx @@ -1,4 +1,4 @@ -import { FC } from 'react'; +import { VFC } from 'react'; import { useIntl } from 'react-intl'; import styles from './sharing-link.module.scss'; @@ -26,7 +26,7 @@ export type SharingLinkProps = { * * Render a sharing link. */ -const SharingLink: FC = ({ medium, url }) => { +const SharingLink: VFC = ({ medium, url }) => { const intl = useIntl(); const text = intl.formatMessage( { diff --git a/src/components/atoms/links/social-link.tsx b/src/components/atoms/links/social-link.tsx index 489c8b4..8c7c790 100644 --- a/src/components/atoms/links/social-link.tsx +++ b/src/components/atoms/links/social-link.tsx @@ -2,14 +2,16 @@ import GithubIcon from '@assets/images/social-media/github.svg'; import GitlabIcon from '@assets/images/social-media/gitlab.svg'; import LinkedInIcon from '@assets/images/social-media/linkedin.svg'; import TwitterIcon from '@assets/images/social-media/twitter.svg'; -import { FC } from 'react'; +import { VFC } from 'react'; import styles from './social-link.module.scss'; -type SocialLinkProps = { +export type SocialWebsite = 'Github' | 'Gitlab' | 'LinkedIn' | 'Twitter'; + +export type SocialLinkProps = { /** * The social website name. */ - name: 'Github' | 'Gitlab' | 'LinkedIn' | 'Twitter'; + name: SocialWebsite; /** * The social profile url. */ @@ -21,7 +23,7 @@ type SocialLinkProps = { * * Render a social icon link. */ -const SocialLink: FC = ({ name, url }) => { +const SocialLink: VFC = ({ name, url }) => { /** * Retrieve a social link icon by id. * @param {string} id - The social website id. -- cgit v1.2.3