Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
87 changes: 87 additions & 0 deletions src/apps/pages/sections/Tabs.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
---
import _ from "underscore";
import MultiColumn from "./MultiColumn.astro";
import clsx from "clsx";

const {
tabs
} = Astro.props;
---

<div class="border-b border-gray-200">
<nav aria-label="Tabs" class="-mb-px flex space-x-8">
{
_.map(tabs, (tab, idx) => (
<h2
class={clsx(
'tab-label whitespace-nowrap border-b-2 px-1 py-4 text-sm font-medium',
{ 'border-transparent text-gray-500 hover:border-secondary/60 hover:text-secondary/60 cursor-pointer': idx !== 0 },
{ 'border-secondary text-secondary': idx === 0 }
)}
id={tab.label}
>
{ tab.label }
</h2>
))
}
</nav>
</div>

{
_.map(tabs, (tab, idx) => (
<div class={clsx(
'tab-content py-6 flex-col',
{ 'flex': idx === 0 },
{ 'hidden': idx !== 0 }
)} id={`${tab.label}--content`} >
{
_.map(tab.content, (section) => (
<MultiColumn
textAlignment={section.text_alignment}
content={section.columns}
gap={section.gap}
/>
))
}
</div>
))
}

<script is:inline>
window.document.addEventListener('DOMContentLoaded', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

What are you thoughts on using a React component with client:load vs. inline Javascript? Is the performance savings worth the readability/maintainability penalty?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did it this way because of the annoying restrictions on including Astro components inside React components; I want to be able to use the other page builder components as tab content and those are (mostly) Astro components. If we're happy restricting the tab content to, say, a couple of columns of rich text, or even to the specific name/title format of the team member tab designs, then it would make sense to do it as a React component, but my initial thought was to make the component a more flexible container for other content.

Copy link
Contributor

Choose a reason for hiding this comment

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

That's a fair point. After doing some brain storming about it, I don't have a great solution. But I do wonder if we'll run into any side effects of spreading the interactivity logic between React and vanilla JS.

Do we want to opt out of script processing by using the is:inline directive? What happens if multiple Tabs sections are inserted into a page?

If we're allowing other page builder components to be added as tab content, will this require us to duplicate the page builder config options in Tina multiple times?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah good questions. It's definitely not ideal. I was envisioning perhaps eventually separating out some of the pages Tina schema into like, layout templates and content templates, and then the content templates list can more easily be included in multiple places. (This is how e.g. Storyblok, which we used for NBU, organizes its content blocks; when you create a block you can specify it as like page, layout, content, or some combination, and that affects where it can be inserted.) Definitely something to think about once we have the full complement of components.

Hmm, I think the script could be modified to handle the possibility of multiple tab components on one page; that's a good catch.

const tabLabels = document.querySelectorAll('.tab-label');
for (const tab of tabLabels) {
console.log(tab);
tab.addEventListener('click', () => {
const tabContent = document.querySelectorAll('.tab-content');
tab.classList.remove('border-transparent');
tab.classList.remove('text-gray-500');
tab.classList.remove('hover:border-secondary/60');
tab.classList.remove('hover:text-secondary/60');
tab.classList.remove('cursor-pointer');
tab.classList.add('border-secondary');
tab.classList.add('text-secondary');
for (const otherTab of tabLabels) {
if (otherTab.id !== tab.id) {
otherTab.classList.add('border-transparent');
otherTab.classList.add('text-gray-500');
otherTab.classList.add('hover:border-secondary/60');
otherTab.classList.add('hover:text-secondary/60');
otherTab.classList.add('cursor-pointer');
otherTab.classList.remove('border-secondary');
otherTab.classList.remove('text-secondary');
}
}
for (const content of tabContent) {
if (content.id?.slice(0, -9) === tab.id) {
content.classList.remove('hidden');
content.classList.add('flex');
} else {
content.classList.remove('flex');
content.classList.add('hidden');
}
}
})
}
})
</script>
9 changes: 9 additions & 0 deletions src/layouts/Page.astro
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import FreeText from '@apps/pages/sections/FreeText.astro';
import Images from '@apps/pages/sections/Images.astro';
import MultiColumn from '@apps/pages/sections/MultiColumn.astro';
import Spacer from '@apps/pages/sections/Spacer.astro';
import Tabs from '@apps/pages/sections/Tabs.astro';
import TextImage from '@apps/pages/sections/TextImage';
import { getTranslations } from '@backend/i18n';
import { fetchPage } from '@backend/tina';
Expand All @@ -26,6 +27,7 @@ const SectionTypes = {
images: 'PagesSectionsImages',
multiColumn: 'PagesSectionsMulti_column',
spacer: 'PagesSectionsSpacer',
tabs: 'PagesSectionsTabs',
textImage: 'PagesSectionsText_image',
};

Expand Down Expand Up @@ -120,6 +122,13 @@ const SectionTypes = {
url={section.url}
/>
)}
{ section.__typename === SectionTypes.tabs && (
<Container>
<Tabs
tabs={section.tabs}
/>
</Container>
)}
</section>
))}
</Layout>
152 changes: 152 additions & 0 deletions tina/content/pages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,158 @@ const Pages: Collection = {
label: 'Darken Background?',
type: 'boolean'
}]
}, {
name: 'tabs',
label: 'Tabbed Content',
fields: [{
name: 'tabs',
label: 'Tabs',
type: 'object',
list: true,
fields: [{
name: 'label',
label: 'Tab Label',
type: 'string'
}, {
name: 'content',
label: 'Tab Content',
type: 'object',
list: true,
fields: [{
name: 'text_alignment',
label: 'Text Alignment',
type: 'string',
options: [{
label: 'Left',
value: 'left'
}, {
label: 'Center',
value: 'center'
}]
}, {
name: 'gap',
label: 'Column Gap',
type: 'string',
options: [{
label: 'Large',
value: 'large'
}, {
label: 'Small',
value: 'small'
}]
}, {
name: 'columns',
label: 'Columns',
type: 'object',
list: true,
ui: {
min: 1,
max: 4
},
fields: [{
name: 'width',
label: 'Column width (percent)',
type: 'string',
options: [{
label: '25%',
value: 'col-span-3'
}, {
label: '33%',
value: 'col-span-4'
}, {
label: '50%',
value: 'col-span-6'
}, {
label: '67%',
value: 'col-span-8'
}, {
label: '75%',
value: 'col-span-9'
}, {
label: '100%',
value: 'col-span-12'
}]
}, {
name: 'content',
label: 'Content',
type: 'object',
list: true,
templates: [{
name: 'richtext',
label: 'Rich Text',
fields: [{
name: 'text',
label: 'Text',
type: 'rich-text',
templates: richTextTemplates
}]
}, {
name: 'image',
label: 'Image',
fields: [{
name: 'image',
label: 'Image',
type: 'image'
}]
}, {
name: 'basic',
label: 'Title and Description (plain text)',
fields: [{
name: 'title',
label: 'Title',
type: 'string'
}, {
name: 'description',
label: 'Description',
type: 'string',
ui: {
component: 'textarea'
}
}]
}, {
name: 'card',
label: 'Card Link',
fields: [{
name: 'slug',
label: 'Link',
type: 'string'
}, {
name: 'title',
label: 'Title',
type: 'string'
}, {
name: 'author',
label: 'Author',
type: 'string'
}, {
name: 'date',
label: 'Date',
type: 'datetime'
}, {
name: 'category',
label: 'Category',
type: 'string'
}, {
name: 'image',
label: 'Image',
type: 'image',
}, {
name: 'alt',
label: 'Image Alt Text',
type: 'string'
}, {
name: 'blurb',
label: 'Blurb',
type: 'string',
ui: {
component: 'textarea'
}
}]
}]
}]
}]
}]
}]
}]
}]
};
Expand Down
2 changes: 1 addition & 1 deletion tina/tina-lock.json

Large diffs are not rendered by default.