📢 Use this project, contribute to it or open issues to help evolve it using Store Discussion.
The Tab Layout app provides you the needed structure to create different layouts within the store's main one from the use of tabs.
Example of a storefront with tabs (Perfumes até 40%off , Presentes , and Best Sellers ) displaying different content for users. |
- Add the Tab Layout app to your theme's dependencies in the
manifest.json
file:
{
"dependencies": {
"vtex.tab-layout": "0.x"
}
}
Now, you are able to use all the blocks exported by the tab-layout
app. Check out the full list below:
- In the desired page template (e.g.,
store.home
), add thetab-layout
block:
{
"store.home": {
"blocks": [
"tab-layout#home"
]
},
- Declare the
tab-list
and thetab-content
blocks astab-layout
's children. Do not forget to use thetab-layout
's props, for example:
{
"store.home": {
"blocks": [
"tab-layout#home"
]
},
"tab-layout#home": {
"children": [
"tab-list#home",
"tab-content#home"
],
"props": {
"blockClass": "home",
"defaultActiveTabId": "home1"
}
}
}
- Add and then declare the desired
tab-list.item
blocks astab-list
's children:
{
"store.home": {
"blocks": [
"tab-layout#home"
]
},
"tab-layout#home": {
"children": [
"tab-list#home",
"tab-content#home"
],
"props": {
"blockClass": "home",
"defaultActiveTabId": "home1"
}
},
"tab-list#home": {
"children": [
"tab-list.item#home1",
"tab-list.item#home2"
]
},
"tab-list.item#home1": {
"props": {
"tabId": "home1",
"label": "Home 1",
"defaultActiveTab": true
}
},
"tab-list.item#home2": {
"props": {
"tabId": "home2",
"label": "Home 2"
}
}
}
- Add and then declare the desired
tab-content.item
blocks astab-content
's children:
{
"store.home": {
"blocks": [
"tab-layout#home"
]
},
"tab-layout#home": {
"children": [
"tab-list#home",
"tab-content#home"
],
"props": {
"blockClass": "home",
"defaultActiveTabId": "home1"
}
},
"tab-list#home": {
"children": [
"tab-list.item#home1",
"tab-list.item#home2"
]
},
"tab-list.item#home1": {
"props": {
"tabId": "home1",
"label": "Home 1",
"defaultActiveTab": true
}
},
"tab-list.item#home2": {
"props": {
"tabId": "home2",
"label": "Home 2"
}
},
"tab-content#home": {
"children": [
"tab-content.item#home1",
"tab-content.item#home2"
]
},
"tab-content.item#home1": {
"children": [
"carousel#home"
],
"props": {
"tabId": "home1"
}
},
"tab-content.item#home2": {
"children": [
"shelf#home",
"info-card#home",
"rich-text#question",
"rich-text#link",
"newsletter"
],
"props": {
"tabId": "home2"
}
}
}
⚠️ Make sure to declare thetab-content.item
's children blocks in order to properly render the tab content.
Prop name | Type | Description | Default value |
---|---|---|---|
defaultActiveTabId |
string |
ID of the desired tab to be rendered as the default one. If no value is provided, the first tab declared in the theme will be used as default. | undefined |
blockClass |
string |
Block ID of your choosing to be used in CSS customization. | undefined |
Prop name | Type | Description | Default value |
---|---|---|---|
blockClass |
string |
Block ID of your choosing to be used in CSS customization. | undefined |
Prop name | Type | Description | Default value |
---|---|---|---|
blockClass |
string |
Block ID of your choosing to be used in CSS customization. | undefined |
tabId |
string |
Tab ID of your choosing. It will be used to match the tab to its content (defined by the tab-content.item block). |
undefined |
label |
string |
Defines the tab's text label. | undefined |
defaultActiveTab |
boolean |
Defines the item as the default active tab. | false |
Prop name | Type | Description | Default value |
---|---|---|---|
blockClass |
string |
Block ID of your choosing to be used in CSS customization. | undefined |
tabId |
string |
Tab ID of your choosing. It will be used to match the tab to a given content (defined by the tab-content.item block). |
undefined |
Prop name | Type | Description | Default value |
---|---|---|---|
blockClass |
string |
Block ID of your choosing to be used in CSS customization. | undefined |
Prop name | Type | Description | Default value |
---|---|---|---|
blockClass |
string |
Block ID of your choosing to be used in CSS customization. | undefined |
tabId |
string |
Tab ID of your choosing. It will be used to match the content to a given tab (defined by the tab-list.item / tab-list.item.children blocks). |
undefined |
⚠️ Be mindful of thetabID
specified in bothtab-list.item
andtab-content.item
blocks, as this parameter couples a tab and its corresponding content.
In order to apply CSS customizations in this and other blocks, follow the instructions given in the recipe on Using CSS Handles for store customization.
CSS Handle |
---|
container |
contentContainer |
contentItem |
listContainer |
listItem |
listItemActive |
listItemChildren |
listItemChildrenActive |
Thanks goes to these wonderful people:
Jean Nussenzveig 💻 |
Lucas Yamamoto 💻 |
weslybrandao 💻 |
This project follows the all-contributors specification. Contributions of any kind welcome!