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/forms/comment-form.stories.tsx | 2 +- .../organisms/forms/comment-form.test.tsx | 2 +- src/components/organisms/forms/comment-form.tsx | 58 +++++++++++----------- .../organisms/forms/contact-form.stories.tsx | 2 +- .../organisms/forms/contact-form.test.tsx | 2 +- src/components/organisms/forms/contact-form.tsx | 44 ++++++++-------- src/components/organisms/forms/index.ts | 3 ++ .../organisms/forms/search-form.stories.tsx | 2 +- .../organisms/forms/search-form.test.tsx | 2 +- src/components/organisms/forms/search-form.tsx | 30 +++++------ .../organisms/images/gallery.stories.tsx | 4 +- src/components/organisms/images/gallery.test.tsx | 4 +- src/components/organisms/images/gallery.tsx | 6 +-- src/components/organisms/images/index.ts | 1 + src/components/organisms/index.ts | 6 +++ .../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 ++++++------ src/components/organisms/modals/index.ts | 2 + .../organisms/modals/search-modal.stories.tsx | 2 +- .../organisms/modals/search-modal.test.tsx | 2 +- src/components/organisms/modals/search-modal.tsx | 20 ++++---- .../organisms/modals/settings-modal.stories.tsx | 2 +- .../organisms/modals/settings-modal.test.tsx | 2 +- src/components/organisms/modals/settings-modal.tsx | 33 ++++++------ src/components/organisms/toolbar/index.ts | 4 ++ .../organisms/toolbar/main-nav.stories.tsx | 2 +- src/components/organisms/toolbar/main-nav.test.tsx | 2 +- src/components/organisms/toolbar/main-nav.tsx | 31 ++++++------ .../organisms/toolbar/search.stories.tsx | 2 +- src/components/organisms/toolbar/search.test.tsx | 2 +- src/components/organisms/toolbar/search.tsx | 19 +++---- .../organisms/toolbar/settings.stories.tsx | 2 +- src/components/organisms/toolbar/settings.test.tsx | 2 +- src/components/organisms/toolbar/settings.tsx | 20 ++++---- .../organisms/toolbar/toolbar.stories.tsx | 2 +- src/components/organisms/toolbar/toolbar.test.tsx | 2 +- src/components/organisms/toolbar/toolbar.tsx | 25 ++++------ .../organisms/widgets/image-widget.stories.tsx | 2 +- .../organisms/widgets/image-widget.test.tsx | 2 +- src/components/organisms/widgets/image-widget.tsx | 16 +++--- src/components/organisms/widgets/index.ts | 5 ++ .../widgets/links-list-widget.stories.tsx | 2 +- .../organisms/widgets/links-list-widget.test.tsx | 2 +- .../organisms/widgets/links-list-widget.tsx | 19 +++---- .../organisms/widgets/sharing.stories.tsx | 2 +- src/components/organisms/widgets/sharing.test.tsx | 2 +- src/components/organisms/widgets/sharing.tsx | 12 ++--- .../organisms/widgets/social-media.stories.tsx | 2 +- .../organisms/widgets/social-media.test.tsx | 2 +- src/components/organisms/widgets/social-media.tsx | 10 ++-- .../widgets/table-of-contents.stories.tsx | 2 +- .../organisms/widgets/table-of-contents.test.tsx | 2 +- .../organisms/widgets/table-of-contents.tsx | 16 +++--- 80 files changed, 335 insertions(+), 342 deletions(-) create mode 100644 src/components/organisms/forms/index.ts create mode 100644 src/components/organisms/images/index.ts create mode 100644 src/components/organisms/index.ts create mode 100644 src/components/organisms/layout/index.ts create mode 100644 src/components/organisms/modals/index.ts create mode 100644 src/components/organisms/toolbar/index.ts create mode 100644 src/components/organisms/widgets/index.ts (limited to 'src/components/organisms') diff --git a/src/components/organisms/forms/comment-form.stories.tsx b/src/components/organisms/forms/comment-form.stories.tsx index 1a9e7b7..a6069e6 100644 --- a/src/components/organisms/forms/comment-form.stories.tsx +++ b/src/components/organisms/forms/comment-form.stories.tsx @@ -1,5 +1,5 @@ import { ComponentMeta, ComponentStory } from '@storybook/react'; -import CommentForm from './comment-form'; +import { CommentForm } from './comment-form'; const saveComment = async () => { /** Do nothing. */ diff --git a/src/components/organisms/forms/comment-form.test.tsx b/src/components/organisms/forms/comment-form.test.tsx index 10119ce..f11c449 100644 --- a/src/components/organisms/forms/comment-form.test.tsx +++ b/src/components/organisms/forms/comment-form.test.tsx @@ -1,5 +1,5 @@ import { render, screen } from '../../../../tests/utils'; -import CommentForm from './comment-form'; +import { CommentForm } from './comment-form'; const saveComment = async () => { /** Do nothing. */ diff --git a/src/components/organisms/forms/comment-form.tsx b/src/components/organisms/forms/comment-form.tsx index a823977..e4140dd 100644 --- a/src/components/organisms/forms/comment-form.tsx +++ b/src/components/organisms/forms/comment-form.tsx @@ -1,13 +1,15 @@ import { FC, ReactNode, useState } from 'react'; import { useIntl } from 'react-intl'; -import Button from '../../atoms/buttons/button'; -import Form, { type FormProps } from '../../atoms/forms/form'; -import Heading, { - type HeadingProps, +import { + Button, + Form, + type FormProps, + Heading, type HeadingLevel, -} from '../../atoms/headings/heading'; -import Spinner from '../../atoms/loaders/spinner'; -import LabelledField from '../../molecules/forms/labelled-field'; + type HeadingProps, + Spinner, +} from '../../atoms'; +import { LabelledField } from '../../molecules'; import styles from './comment-form.module.scss'; export type CommentFormData = { @@ -46,7 +48,7 @@ export type CommentFormProps = Pick & { titleLevel?: HeadingLevel; }; -const CommentForm: FC = ({ +export const CommentForm: FC = ({ Notice, parentId, saveComment, @@ -119,55 +121,55 @@ const CommentForm: FC = ({ return (
{title && ( - + {title} )} @@ -73,4 +64,9 @@ const SearchForm: ForwardRefRenderFunction< ); }; -export default forwardRef(SearchForm); +/** + * SearchForm component + * + * Render a search form. + */ +export const SearchForm = forwardRef(SearchFormWithRef); diff --git a/src/components/organisms/images/gallery.stories.tsx b/src/components/organisms/images/gallery.stories.tsx index b1c308e..8b68777 100644 --- a/src/components/organisms/images/gallery.stories.tsx +++ b/src/components/organisms/images/gallery.stories.tsx @@ -1,6 +1,6 @@ import { ComponentMeta, ComponentStory } from '@storybook/react'; -import ResponsiveImage from '../../molecules/images/responsive-image'; -import Gallery from './gallery'; +import { ResponsiveImage } from '../../molecules'; +import { Gallery } from './gallery'; /** * Gallery - Storybook Meta diff --git a/src/components/organisms/images/gallery.test.tsx b/src/components/organisms/images/gallery.test.tsx index 611262e..6fb7567 100644 --- a/src/components/organisms/images/gallery.test.tsx +++ b/src/components/organisms/images/gallery.test.tsx @@ -1,6 +1,6 @@ import { render, screen } from '../../../../tests/utils'; -import ResponsiveImage from '../../molecules/images/responsive-image'; -import Gallery from './gallery'; +import { ResponsiveImage } from '../../molecules'; +import { Gallery } from './gallery'; const columns = 3; diff --git a/src/components/organisms/images/gallery.tsx b/src/components/organisms/images/gallery.tsx index 8b73ce1..ae773f6 100644 --- a/src/components/organisms/images/gallery.tsx +++ b/src/components/organisms/images/gallery.tsx @@ -1,5 +1,5 @@ import { Children, FC, ReactElement } from 'react'; -import { type ResponsiveImageProps } from '../../molecules/images/responsive-image'; +import { type ResponsiveImageProps } from '../../molecules'; import styles from './gallery.module.scss'; export type GalleryColumn = 2 | 3 | 4; @@ -20,7 +20,7 @@ export type GalleryProps = { * * Render a gallery of images. */ -const Gallery: FC = ({ children, columns }) => { +export const Gallery: FC = ({ children, columns }) => { const columnsClass = `wrapper--${columns}-columns`; return ( @@ -31,5 +31,3 @@ const Gallery: FC = ({ children, columns }) => { ); }; - -export default Gallery; diff --git a/src/components/organisms/images/index.ts b/src/components/organisms/images/index.ts new file mode 100644 index 0000000..de0da26 --- /dev/null +++ b/src/components/organisms/images/index.ts @@ -0,0 +1 @@ +export * from './gallery'; diff --git a/src/components/organisms/index.ts b/src/components/organisms/index.ts new file mode 100644 index 0000000..8dfc61b --- /dev/null +++ b/src/components/organisms/index.ts @@ -0,0 +1,6 @@ +export * from './forms'; +export * from './images'; +export * from './layout'; +export * from './modals'; +export * from './toolbar'; +export * from './widgets'; 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 ( <>