Skip to content

Commit

Permalink
feat: add storybook story for paragraph
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasGross committed Dec 27, 2024
1 parent 50baa47 commit 6031a57
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 19 deletions.
2 changes: 1 addition & 1 deletion components/global/footer/Footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Icon from "../../shared/icon/Icon"

export default function Footer() {
return (
<footer className="mt-20 bg-background-overlay py-12">
<footer className="bg-background-overlay py-12">
<div className="content-container">
<div className="grid grid-cols-1 gap-8 md:grid-cols-2 lg:grid-cols-4">
<div>
Expand Down
5 changes: 2 additions & 3 deletions components/pages/basicPageLayout/BasicPageLayout.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import React from "react"

import ParagraphVideo from "@/components/paragraphs/ParagraphGoVideo/ParagraphVideo"
import ParagraphResolver from "@/components/paragraphs/ParagraphResolver"
import { NodeGoPage, ParagraphUnion } from "@/lib/graphql/generated/dpl-cms/graphql"
import { NodeGoPage } from "@/lib/graphql/generated/dpl-cms/graphql"

function BasicPageLayout({ pageData }: { pageData: NodeGoPage }) {
const { paragraphs } = pageData

return (
<div className="gap-y-paragraph-spacing flex flex-col">
<div className="flex flex-col gap-y-paragraph-spacing">
<ParagraphResolver paragraphs={paragraphs ?? []} />
</div>
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import type { Meta, StoryObj } from "@storybook/react"

import { darkModeDecorator } from "@/.storybook/decorators"
import ParagraphGoVideo from "@/components/paragraphs/paragraphGoVideo/ParagraphGoVideo"

const meta = {
title: "components/ParagraphGoVideo",
component: ParagraphGoVideo,
parameters: {
layout: "centered",
},
args: {
goVideoTitle: "Naja Marie Aidt - Oevelser i moerke",
src: "https://media.videotool.dk/?vn=557_2024111913325696587632242634",
},
} satisfies Meta<typeof ParagraphGoVideo>

export default meta
type Story = StoryObj<typeof meta>

export const Default: Story = {
args: {
goVideoTitle: "Naja Marie Aidt - Oeveser i moerke",
},

render: args => <ParagraphGoVideo {...args}>ParagraphGoVideo</ParagraphGoVideo>,
}

export const DarkMode: Story = {
decorators: [darkModeDecorator],
render: args => <ParagraphGoVideo {...args}>ParagraphGoVideo</ParagraphGoVideo>,
}
24 changes: 11 additions & 13 deletions components/paragraphs/ParagraphGoVideo/ParagraphGoVideo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ import React, { useEffect } from "react"

import type { ParagraphGoVideo } from "@/lib/graphql/generated/dpl-cms/graphql"

export default function ParagraphGoVideo(paragraphGoVideo: ParagraphGoVideo) {
type ParagraphGoVideoProps = {
goVideoTitle: ParagraphGoVideo["goVideoTitle"]
src: string
}

export default function ParagraphGoVideo(paragraphGoVideo: ParagraphGoVideoProps) {
const [mounted, setMounted] = React.useState(false)

useEffect(() => {
Expand All @@ -20,23 +25,16 @@ export default function ParagraphGoVideo(paragraphGoVideo: ParagraphGoVideo) {
</div>

<div className="col-span-6 lg:col-span-12">
{mounted && (
<div className="relative aspect-16/9 w-full overflow-hidden rounded-base">
<div className="relative aspect-16/9 w-full overflow-hidden rounded-base">
{mounted && (
<iframe
aria-label="Naja Marie Aidt - Oevelser i moerke"
aria-label={title || "Video"}
className="absolute inset-0 h-full w-full"
style={{
position: "absolute",
top: 0,
left: 0,
width: "100%!important",
height: "100%!important",
}}
src="https://media.videotool.dk/?vn=557_2024111913325696587632242634"
allowFullScreen
allow="autoplay; fullscreen"></iframe>
</div>
)}
)}
</div>
</div>
</div>
)
Expand Down
6 changes: 4 additions & 2 deletions components/paragraphs/ParagraphResolver.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import React from "react"

import { ParagraphUnion } from "@/lib/graphql/generated/dpl-cms/graphql"

import ParagraphGoVideo from "./ParagraphGoVideo/ParagraphGoVideo"
import { ParagraphErrorBoundary } from "./paragraphErrorBoundary/paragraphErrorBoundary"
import ParagraphGoVideo from "./paragraphGoVideo/ParagraphGoVideo"

function ParagraphResolver({ paragraphs }: { paragraphs: ParagraphUnion[] }) {
const components = {
Expand All @@ -17,10 +17,12 @@ function ParagraphResolver({ paragraphs }: { paragraphs: ParagraphUnion[] }) {
}

const DynamicComponentType = components[type as keyof typeof components] || null
if (DynamicComponentType === null) return null

return (
<ParagraphErrorBoundary key={index}>
{DynamicComponentType ? <DynamicComponentType key={index} {...paragraph} /> : null}
{/* @ts-ignore TODO: figure out how to type dynamically imported components */}
<DynamicComponentType key={index} {...paragraph} />
</ParagraphErrorBoundary>
)
})
Expand Down

0 comments on commit 6031a57

Please sign in to comment.