-
Notifications
You must be signed in to change notification settings - Fork 1
Adding tab component #340
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
Open
ajolipa
wants to merge
1
commit into
develop
Choose a base branch
from
RB-tab-section
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Adding tab component #340
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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', () => { | ||
| 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> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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:loadvs. inline Javascript? Is the performance savings worth the readability/maintainability penalty?There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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:inlinedirective? 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?
There was a problem hiding this comment.
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
pagesTina 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.