From f861e6a269ba9f62700776d3cd13b644a9e836d4 Mon Sep 17 00:00:00 2001 From: Armand Philippot Date: Wed, 20 Sep 2023 16:38:54 +0200 Subject: refactor: use named export for everything except pages Next expect a default export for pages so only those components should use default exports. Everything else should use named exports to reduce the number of import statements. --- src/components/atoms/headings/heading.tsx | 34 ++++++++++++++----------------- 1 file changed, 15 insertions(+), 19 deletions(-) (limited to 'src/components/atoms/headings/heading.tsx') diff --git a/src/components/atoms/headings/heading.tsx b/src/components/atoms/headings/heading.tsx index b1e4c5f..b1b6164 100644 --- a/src/components/atoms/headings/heading.tsx +++ b/src/components/atoms/headings/heading.tsx @@ -3,13 +3,14 @@ import { ForwardedRef, forwardRef, ForwardRefRenderFunction, + HTMLAttributes, ReactNode, } from 'react'; import styles from './heading.module.scss'; export type HeadingLevel = 1 | 2 | 3 | 4 | 5 | 6; -export type HeadingProps = { +export type HeadingProps = HTMLAttributes & { /** * The title alignment. Default: left; */ @@ -18,14 +19,6 @@ export type HeadingProps = { * The heading body. */ children: ReactNode; - /** - * Set additional classnames. - */ - className?: string; - /** - * The heading id. - */ - id?: string; /** * Use an heading element or only its styles. Default: false. */ @@ -57,23 +50,19 @@ const TitleTag = forwardRef< ); TitleTag.displayName = 'TitleTag'; -/** - * Heading component. - * - * Render an HTML heading element or a paragraph with heading styles. - */ -const Heading: ForwardRefRenderFunction< +const HeadingWithRef: ForwardRefRenderFunction< HTMLHeadingElement | HTMLParagraphElement, HeadingProps > = ( { alignment = 'left', children, - className, + className = '', id, isFake = false, level, withMargin = true, + ...props }, ref: ForwardedRef ) => { @@ -81,17 +70,24 @@ const Heading: ForwardRefRenderFunction< const levelClass = `heading--${level}`; const alignmentClass = `heading--${alignment}`; const marginClass = withMargin ? 'heading--margin' : 'heading--regular'; + const headingClass = `${styles.heading} ${styles[levelClass]} ${styles[alignmentClass]} ${styles[marginClass]} ${className}`; return ( {children} ); }; -export default forwardRef(Heading); +/** + * Heading component. + * + * Render an HTML heading element or a paragraph with heading styles. + */ +export const Heading = forwardRef(HeadingWithRef); -- cgit v1.2.3