From 782a5a1e794a9a8ef6b0b892cd3f386ed583c680 Mon Sep 17 00:00:00 2001 From: Armand Philippot Date: Fri, 22 Apr 2022 18:56:32 +0200 Subject: chore: add a SectionedLayout component --- .../sectioned/sectioned-layout.stories.tsx | 68 ++++++++++++++++++++++ .../templates/sectioned/sectioned-layout.test.tsx | 34 +++++++++++ .../templates/sectioned/sectioned-layout.tsx | 43 ++++++++++++++ 3 files changed, 145 insertions(+) create mode 100644 src/components/templates/sectioned/sectioned-layout.stories.tsx create mode 100644 src/components/templates/sectioned/sectioned-layout.test.tsx create mode 100644 src/components/templates/sectioned/sectioned-layout.tsx (limited to 'src') diff --git a/src/components/templates/sectioned/sectioned-layout.stories.tsx b/src/components/templates/sectioned/sectioned-layout.stories.tsx new file mode 100644 index 0000000..9ff3b75 --- /dev/null +++ b/src/components/templates/sectioned/sectioned-layout.stories.tsx @@ -0,0 +1,68 @@ +import { ComponentMeta, ComponentStory } from '@storybook/react'; +import { IntlProvider } from 'react-intl'; +import SectionedLayoutComponent from './sectioned-layout'; + +/** + * SectionedLayout - Storybook Meta + */ +export default { + title: 'Templates/Sectioned', + component: SectionedLayoutComponent, + argTypes: { + sections: { + description: 'The different sections.', + type: { + name: 'object', + required: true, + value: {}, + }, + }, + }, + decorators: [ + (Story) => ( + +
+ +
+
+ ), + ], + parameters: { + layout: 'fullscreen', + }, +} as ComponentMeta; + +const Template: ComponentStory = (args) => ( + +); + +const sections = [ + { + title: 'Section 1', + content: + '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.', + }, + { + title: 'Section 2', + content: + 'Reprehenderit aut magnam ut quos. Voluptatibus beatae et. Earum non atque voluptatum illum rem distinctio repellat.', + }, + { + title: 'Section 3', + content: + 'Placeat rem dolores dolore illum earum officia dolore. Ut est ducimus. Officia eveniet pariatur ut laboriosam voluptatibus aut doloremque natus quis.', + }, + { + title: 'Section 4', + content: + '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.', + }, +]; + +/** + * 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 new file mode 100644 index 0000000..334d1cc --- /dev/null +++ b/src/components/templates/sectioned/sectioned-layout.test.tsx @@ -0,0 +1,34 @@ +import { render, screen } from '@test-utils'; +import SectionedLayout from './sectioned-layout'; + +const sections = [ + { + title: 'Section 1', + content: + '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.', + }, + { + title: 'Section 2', + content: + 'Reprehenderit aut magnam ut quos. Voluptatibus beatae et. Earum non atque voluptatum illum rem distinctio repellat.', + }, + { + title: 'Section 3', + content: + 'Placeat rem dolores dolore illum earum officia dolore. Ut est ducimus. Officia eveniet pariatur ut laboriosam voluptatibus aut doloremque natus quis.', + }, + { + title: 'Section 4', + content: + '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.', + }, +]; + +describe('SectionedLayout', () => { + it('renders the correct number of section', () => { + render(); + expect(screen.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 new file mode 100644 index 0000000..36ca039 --- /dev/null +++ b/src/components/templates/sectioned/sectioned-layout.tsx @@ -0,0 +1,43 @@ +import Section, { + type SectionProps, + type SectionVariant, +} from '@components/atoms/layout/section'; +import { FC } from 'react'; +import Layout from '../layout/layout'; + +export type Section = Pick; + +export type SectionedLayoutProps = { + /** + * An array of objects describing each section. + */ + sections: Section[]; +}; + +/** + * SectionedLayout component + * + * Render a sectioned layout. + */ +const SectionedLayout: FC = ({ sections }) => { + const getSections = (items: SectionProps[]) => { + return items.map((section, index) => { + const variant: SectionVariant = index % 2 ? 'light' : 'dark'; + const isLastSection = index === items.length - 1; + + return ( +
+ ); + }); + }; + + return {getSections(sections)}; +}; + +export default SectionedLayout; -- cgit v1.2.3