From 4f1181581e177dd80a76165a0f930ef4577f9c6a Mon Sep 17 00:00:00 2001 From: Armand Philippot Date: Wed, 22 Nov 2023 19:07:25 +0100 Subject: refactor(components): integrate sectioned page template into Page * replace Section component by a generic one (other components should be able to use it) * add a PageSection component * add `hasSections` prop to Page component * remove sectioned-page template --- src/components/templates/sectioned/index.ts | 1 - .../sectioned/sectioned-layout.fixtures.tsx | 59 ---------------------- .../sectioned/sectioned-layout.stories.tsx | 58 --------------------- .../templates/sectioned/sectioned-layout.test.tsx | 21 -------- .../templates/sectioned/sectioned-layout.tsx | 51 ------------------- 5 files changed, 190 deletions(-) delete mode 100644 src/components/templates/sectioned/index.ts delete mode 100644 src/components/templates/sectioned/sectioned-layout.fixtures.tsx delete mode 100644 src/components/templates/sectioned/sectioned-layout.stories.tsx delete mode 100644 src/components/templates/sectioned/sectioned-layout.test.tsx delete mode 100644 src/components/templates/sectioned/sectioned-layout.tsx (limited to 'src/components/templates/sectioned') diff --git a/src/components/templates/sectioned/index.ts b/src/components/templates/sectioned/index.ts deleted file mode 100644 index a8c6045..0000000 --- a/src/components/templates/sectioned/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './sectioned-layout'; diff --git a/src/components/templates/sectioned/sectioned-layout.fixtures.tsx b/src/components/templates/sectioned/sectioned-layout.fixtures.tsx deleted file mode 100644 index 0da8e7d..0000000 --- a/src/components/templates/sectioned/sectioned-layout.fixtures.tsx +++ /dev/null @@ -1,59 +0,0 @@ -/* eslint-disable react/jsx-no-literals */ -import { Heading } from '../../atoms'; -import type { PageSection } from './sectioned-layout'; - -export const sections: PageSection[] = [ - { - id: 'section-1', - children: ( - <> - Section 1 -
- Qui suscipit ea et aut dicta. Quia ut dignissimos. Sapiente beatae - voluptatem quis et. Nemo vitae magni. Nihil iste officia est sed esse - molestiae doloribus. Quia temporibus nobis ea fuga quis incidunt - doloribus eaque. -
- - ), - }, - { - id: 'section-2', - children: ( - <> - Section 2 -
- Reprehenderit aut magnam ut quos. Voluptatibus beatae et. Earum non - atque voluptatum illum rem distinctio repellat. -
- - ), - }, - { - id: 'section-3', - children: ( - <> - Section 3 -
- Placeat rem dolores dolore illum earum officia dolore. Ut est ducimus. - Officia eveniet pariatur ut laboriosam voluptatibus aut doloremque - natus quis. -
- - ), - }, - { - id: 'section-4', - children: ( - <> - Section 4 -
- Vitae facere ipsa eum sunt debitis veritatis dolorem labore qui. - Dolores recusandae omnis aut. Repudiandae quia neque porro in - blanditiis. A atque minima fugit. Totam quidem voluptas natus velit - at. -
- - ), - }, -]; diff --git a/src/components/templates/sectioned/sectioned-layout.stories.tsx b/src/components/templates/sectioned/sectioned-layout.stories.tsx deleted file mode 100644 index 0336b7a..0000000 --- a/src/components/templates/sectioned/sectioned-layout.stories.tsx +++ /dev/null @@ -1,58 +0,0 @@ -import type { ComponentMeta, ComponentStory } from '@storybook/react'; -import { LayoutBase } from '../layout/layout.stories'; -import { SectionedLayout as SectionedLayoutComponent } from './sectioned-layout'; -import { sections } from './sectioned-layout.fixtures'; - -/** - * SectionedLayout - Storybook Meta - */ -export default { - title: 'Templates/Sectioned', - component: SectionedLayoutComponent, - args: { - breadcrumbSchema: [], - }, - argTypes: { - breadcrumbSchema: { - control: { - type: null, - }, - description: 'The JSON schema for breadcrumb items.', - type: { - name: 'object', - required: true, - value: {}, - }, - }, - sections: { - description: 'The different sections.', - type: { - name: 'object', - required: true, - value: {}, - }, - }, - }, - decorators: [ - (Story) => ( - - - - ), - ], - parameters: { - layout: 'fullscreen', - }, -} as ComponentMeta; - -const Template: ComponentStory = (args) => ( - -); - -/** - * Sectioned Layout Stories - Default - */ -export const Sectioned = Template.bind({}); -Sectioned.args = { - sections, -}; diff --git a/src/components/templates/sectioned/sectioned-layout.test.tsx b/src/components/templates/sectioned/sectioned-layout.test.tsx deleted file mode 100644 index 372b0fb..0000000 --- a/src/components/templates/sectioned/sectioned-layout.test.tsx +++ /dev/null @@ -1,21 +0,0 @@ -import { describe, expect, it } from '@jest/globals'; -import type { BreadcrumbList } from 'schema-dts'; -import { render, screen as rtlScreen } from '../../../../tests/utils'; -import { SectionedLayout } from './sectioned-layout'; -import { sections } from './sectioned-layout.fixtures'; - -const breadcrumbSchema: BreadcrumbList['itemListElement'][] = []; - -describe('SectionedLayout', () => { - it('renders the correct number of section', () => { - render( - - ); - expect( - rtlScreen.getAllByRole('heading', { name: /^Section/ }) - ).toHaveLength(sections.length); - }); -}); diff --git a/src/components/templates/sectioned/sectioned-layout.tsx b/src/components/templates/sectioned/sectioned-layout.tsx deleted file mode 100644 index 6d58e83..0000000 --- a/src/components/templates/sectioned/sectioned-layout.tsx +++ /dev/null @@ -1,51 +0,0 @@ -import Script from 'next/script'; -import type { FC } from 'react'; -import type { BreadcrumbList } from 'schema-dts'; -import { Section, type SectionProps, type SectionVariant } from '../../atoms'; - -export type PageSection = Required>; - -export type SectionedLayoutProps = { - /** - * The breadcrumb JSON schema. - */ - breadcrumbSchema: BreadcrumbList['itemListElement'][]; - /** - * An array of objects describing each section. - */ - sections: PageSection[]; -}; - -/** - * SectionedLayout component - * - * Render a sectioned layout. - */ -export const SectionedLayout: FC = ({ - breadcrumbSchema, - sections, -}) => { - const getSections = (items: PageSection[]) => - items.map((section, index) => { - const variant: SectionVariant = index % 2 ? 'light' : 'dark'; - const isLastSection = index === items.length - 1; - - return ( -
- {section.children} -
- ); - }); - - return ( - <> -