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 4 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
45 changes: 45 additions & 0 deletions src/blocks/DetailsBlock/DetailsBlock.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---
import type { DetailsBlockFragment } from '@lib/types/datocms';

interface Props {
block: DetailsBlockFragment
}

const { block } = Astro.props;
const splitChar = '|';
luukbrauckmann marked this conversation as resolved.
Show resolved Hide resolved
const hasMultipleValues = (value: string) => value.includes(splitChar);
const splitValues = (value: string) => value.split(splitChar);
---

<dl class:list={['details-block', `details-block--${block.display}`]}>
luukbrauckmann marked this conversation as resolved.
Show resolved Hide resolved
luukbrauckmann marked this conversation as resolved.
Show resolved Hide resolved
{
Object.keys(block.details).map((key) => (
luukbrauckmann marked this conversation as resolved.
Show resolved Hide resolved
<>
<dt>{key}</dt>
{hasMultipleValues(block.details[key]) ? (
<div>
luukbrauckmann marked this conversation as resolved.
Show resolved Hide resolved
{splitValues(block.details[key]).map((value) => (
<dd>{value}</dd>
))}
</div>
) : (
<dd>{block.details[key]}</dd>
)}
</>
))
}
</dl>

<style>
.details-block {
display: grid;
}

.details-block--vertical {
grid-template-columns: 1fr;
}

.details-block--horizontal {
grid-template-columns: max-content 1fr;
}
</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
display
}
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