Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: Details Block #181

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/blocks/Blocks.astro
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
import type { AnyBlock } from './Blocks';
import DetailsBlock from './DetailsBlock/DetailsBlock.astro';
luukbrauckmann marked this conversation as resolved.
Show resolved Hide resolved
import EmbedBlock from './EmbedBlock/EmbedBlock.astro';
import ImageBlock from './ImageBlock/ImageBlock.astro';
import PagePartialBlock from './PagePartialBlock/PagePartialBlock.astro';
Expand All @@ -10,6 +11,7 @@ import VideoBlock from './VideoBlock/VideoBlock.astro';
import VideoEmbedBlock from './VideoEmbedBlock/VideoEmbedBlock.astro';

const blocksByTypename = {
DetailsBlockRecord: DetailsBlock,
EmbedBlockRecord: EmbedBlock,
ImageBlockRecord: ImageBlock,
PagePartialBlockRecord: PagePartialBlock,
Expand Down
4 changes: 3 additions & 1 deletion src/blocks/Blocks.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
import {
DetailsBlockFragment,
EmbedBlockFragment,
ImageBlockFragment,
PagePartialBlockFragment,
Expand All @@ -10,6 +11,7 @@ import {
} from '@lib/types/datocms';

export type AnyBlock =
| DetailsBlockFragment
| EmbedBlockFragment
| ImageBlockFragment
| PagePartialBlockFragment
Expand Down
34 changes: 34 additions & 0 deletions src/blocks/DetailsBlock/DetailsBlock.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
import type { DetailsBlockFragment } from '@lib/types/datocms';

interface Props {
block: DetailsBlockFragment;
}

const { block } = Astro.props;
const splitCharacter = '|';
---

<dl data-layout={block.layout}>
{
Object.entries(block.details).map(([key, value]) => (
<>
<dt>{key}</dt>
{(value as string).split(splitCharacter).map((splitValue) => (
<dd>{splitValue}</dd>
jbmoelker marked this conversation as resolved.
Show resolved Hide resolved
))}
</>
))
}
</dl>

<style>
dl[data-layout="horizontal"] {
display: grid;
grid-template-columns: max-content 1fr;
}

dl[data-layout="horizontal"] dd {
grid-column: 2;
}
</style>
4 changes: 4 additions & 0 deletions src/blocks/DetailsBlock/DetailsBlock.fragment.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
fragment DetailsBlock on DetailsBlockRecord {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please make sure to also include the migration for this block in the PR. We might be blocked by #164 by this 🤷 .

details
layout
}
1 change: 1 addition & 0 deletions src/blocks/DetailsBlock/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as DetailsBlock } from './DetailsBlock.astro';
4 changes: 4 additions & 0 deletions src/pages/[locale]/[...path]/_index.query.graphql
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#import '@blocks/DetailsBlock/DetailsBlock.fragment.graphql'
#import '@blocks/EmbedBlock/EmbedBlock.fragment.graphql'
#import '@blocks/ImageBlock/ImageBlock.fragment.graphql'
#import '@blocks/InternalLink/ParentPage.fragment.graphql'
Expand All @@ -24,6 +25,9 @@ query Page($locale: SiteLocale!, $slug: String!) {
...ParentPage
bodyBlocks {
__typename
... on DetailsBlockRecord {
...DetailsBlock
}
... on EmbedBlockRecord {
...EmbedBlock
}
Expand Down
4 changes: 4 additions & 0 deletions src/pages/[locale]/_404.query.graphql
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#import '@blocks/DetailsBlock/DetailsBlock.fragment.graphql'
#import '@blocks/EmbedBlock/EmbedBlock.fragment.graphql'
#import '@blocks/ImageBlock/ImageBlock.fragment.graphql'
#import '@blocks/PagePartialBlock/PagePartialBlock.fragment.graphql'
Expand All @@ -12,6 +13,9 @@ query NotFoundPage($locale: SiteLocale!) {
title
bodyBlocks {
__typename
... on DetailsBlockRecord {
...DetailsBlock
}
... on EmbedBlockRecord {
...EmbedBlock
}
Expand Down
4 changes: 4 additions & 0 deletions src/pages/[locale]/_index.query.graphql
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#import '@blocks/DetailsBlock/DetailsBlock.fragment.graphql'
#import '@blocks/EmbedBlock/EmbedBlock.fragment.graphql'
#import '@blocks/ImageBlock/ImageBlock.fragment.graphql'
#import '@blocks/PagePartialBlock/PagePartialBlock.fragment.graphql'
Expand All @@ -17,6 +18,9 @@ query HomePage($locale: SiteLocale!) {
}
bodyBlocks {
__typename
... on DetailsBlockRecord {
...DetailsBlock
}
... on EmbedBlockRecord {
...EmbedBlock
}
Expand Down
Loading