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. --- .../organisms/layout/cards-list.stories.tsx | 5 +++- .../organisms/layout/cards-list.test.tsx | 2 +- src/components/organisms/layout/cards-list.tsx | 14 ++++----- .../organisms/layout/comment.fixture.tsx | 5 +--- .../organisms/layout/comment.stories.tsx | 10 +++---- src/components/organisms/layout/comment.test.tsx | 2 +- src/components/organisms/layout/comment.tsx | 27 ++++++++---------- .../organisms/layout/comments-list.stories.tsx | 10 +++---- .../organisms/layout/comments-list.test.tsx | 2 +- src/components/organisms/layout/comments-list.tsx | 8 ++---- src/components/organisms/layout/footer.stories.tsx | 2 +- src/components/organisms/layout/footer.test.tsx | 2 +- src/components/organisms/layout/footer.tsx | 22 +++++++-------- src/components/organisms/layout/header.stories.tsx | 2 +- src/components/organisms/layout/header.test.tsx | 2 +- src/components/organisms/layout/header.tsx | 8 ++---- src/components/organisms/layout/index.ts | 9 ++++++ .../organisms/layout/no-results.stories.tsx | 2 +- .../organisms/layout/no-results.test.tsx | 2 +- src/components/organisms/layout/no-results.tsx | 8 ++---- .../organisms/layout/overview.stories.tsx | 2 +- src/components/organisms/layout/overview.test.tsx | 2 +- src/components/organisms/layout/overview.tsx | 18 +++++++----- .../organisms/layout/posts-list.stories.tsx | 2 +- .../organisms/layout/posts-list.test.tsx | 2 +- src/components/organisms/layout/posts-list.tsx | 26 ++++++++--------- .../organisms/layout/summary.stories.tsx | 2 +- src/components/organisms/layout/summary.test.tsx | 2 +- src/components/organisms/layout/summary.tsx | 33 ++++++++++++---------- 29 files changed, 117 insertions(+), 116 deletions(-) create mode 100644 src/components/organisms/layout/index.ts (limited to 'src/components/organisms/layout') diff --git a/src/components/organisms/layout/cards-list.stories.tsx b/src/components/organisms/layout/cards-list.stories.tsx index c19220a..b5f697a 100644 --- a/src/components/organisms/layout/cards-list.stories.tsx +++ b/src/components/organisms/layout/cards-list.stories.tsx @@ -1,5 +1,8 @@ import { ComponentMeta, ComponentStory } from '@storybook/react'; -import CardsListComponent, { type CardsListItem } from './cards-list'; +import { + CardsList as CardsListComponent, + type CardsListItem, +} from './cards-list'; /** * CardsList - Storybook Meta diff --git a/src/components/organisms/layout/cards-list.test.tsx b/src/components/organisms/layout/cards-list.test.tsx index 6a0ff7c..968a349 100644 --- a/src/components/organisms/layout/cards-list.test.tsx +++ b/src/components/organisms/layout/cards-list.test.tsx @@ -1,5 +1,5 @@ import { render, screen } from '../../../../tests/utils'; -import CardsList, { type CardsListItem } from './cards-list'; +import { CardsList, type CardsListItem } from './cards-list'; const items: CardsListItem[] = [ { diff --git a/src/components/organisms/layout/cards-list.tsx b/src/components/organisms/layout/cards-list.tsx index 12ec7d9..e3d1156 100644 --- a/src/components/organisms/layout/cards-list.tsx +++ b/src/components/organisms/layout/cards-list.tsx @@ -1,6 +1,6 @@ import { FC } from 'react'; -import List, { type ListItem, type ListProps } from '../../atoms/lists/list'; -import Card, { type CardProps } from '../../molecules/layout/card'; +import { List, type ListItem, type ListProps } from '../../atoms'; +import { Card, type CardProps } from '../../molecules'; import styles from './cards-list.module.scss'; export type CardsListItem = Omit & { @@ -27,7 +27,7 @@ export type CardsListProps = Pick & * * Return a list of Card components. */ -const CardsList: FC = ({ +export const CardsList: FC = ({ className = '', items, kind = 'unordered', @@ -47,11 +47,11 @@ const CardsList: FC = ({ id, value: ( ), }; @@ -60,11 +60,9 @@ const CardsList: FC = ({ return ( ); }; - -export default CardsList; diff --git a/src/components/organisms/layout/comment.fixture.tsx b/src/components/organisms/layout/comment.fixture.tsx index 57a4389..eee7981 100644 --- a/src/components/organisms/layout/comment.fixture.tsx +++ b/src/components/organisms/layout/comment.fixture.tsx @@ -1,7 +1,4 @@ -import { - getFormattedDate, - getFormattedTime, -} from '../../../utils/helpers/dates'; +import { getFormattedDate, getFormattedTime } from '../../../utils/helpers'; import { CommentProps } from './comment'; export const author = { diff --git a/src/components/organisms/layout/comment.stories.tsx b/src/components/organisms/layout/comment.stories.tsx index 7a8ac95..a73ba23 100644 --- a/src/components/organisms/layout/comment.stories.tsx +++ b/src/components/organisms/layout/comment.stories.tsx @@ -1,5 +1,5 @@ import { ComponentMeta, ComponentStory } from '@storybook/react'; -import CommentComponent from './comment'; +import { Comment } from './comment'; import { data } from './comment.fixture'; const saveComment = async () => { @@ -11,7 +11,7 @@ const saveComment = async () => { */ export default { title: 'Organisms/Layout/Comment', - component: CommentComponent, + component: Comment, args: { canReply: true, saveComment, @@ -104,10 +104,10 @@ export default { }, }, }, -} as ComponentMeta; +} as ComponentMeta; -const Template: ComponentStory = (args) => ( - +const Template: ComponentStory = (args) => ( + ); /** diff --git a/src/components/organisms/layout/comment.test.tsx b/src/components/organisms/layout/comment.test.tsx index 5ea8c6f..6414371 100644 --- a/src/components/organisms/layout/comment.test.tsx +++ b/src/components/organisms/layout/comment.test.tsx @@ -1,5 +1,5 @@ import { render, screen } from '../../../../tests/utils'; -import Comment from './comment'; +import { Comment } from './comment'; import { author, data, diff --git a/src/components/organisms/layout/comment.tsx b/src/components/organisms/layout/comment.tsx index 23073ad..e2a42bf 100644 --- a/src/components/organisms/layout/comment.tsx +++ b/src/components/organisms/layout/comment.tsx @@ -3,12 +3,11 @@ import Script from 'next/script'; import { FC, useCallback, useState } from 'react'; import { useIntl } from 'react-intl'; import { type Comment as CommentSchema, type WithContext } from 'schema-dts'; -import { type SingleComment } from '../../../types/app'; -import useSettings from '../../../utils/hooks/use-settings'; -import Button from '../../atoms/buttons/button'; -import Link from '../../atoms/links/link'; -import Meta from '../../molecules/layout/meta'; -import CommentForm, { type CommentFormProps } from '../forms/comment-form'; +import { type SingleComment } from '../../../types'; +import { useSettings } from '../../../utils/hooks'; +import { Button, Link } from '../../atoms'; +import { Meta } from '../../molecules'; +import { CommentForm, type CommentFormProps } from '../forms'; import styles from './comment.module.scss'; export type CommentProps = Pick< @@ -27,7 +26,7 @@ export type CommentProps = Pick< * * Render a single comment. */ -const Comment: FC = ({ +export const Comment: FC = ({ approved, canReply = true, content, @@ -107,13 +106,13 @@ const Comment: FC = ({ return ( <>