Skip to content

Commit

Permalink
feat(plugin): improve names of token types and added missing closing …
Browse files Browse the repository at this point in the history
…token for label
  • Loading branch information
d3m1d0v committed Sep 25, 2024
1 parent 48fbc21 commit 74237f8
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 13 deletions.
22 changes: 15 additions & 7 deletions src/plugin/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,9 @@ function insertTabs(
const tabPanelOpen = new state.Token('tab-panel_open', 'div', 1);
const tabPanelClose = new state.Token('tab-panel_close', 'div', -1);

const verticalTabOpen = new state.Token('tab_open', 'input', 0);
const verticalTabLabelOpen = new state.Token('label_open', 'label', 1);
const verticalTabInput = new state.Token('tab-input', 'input', 0);
const verticalTabLabelOpen = new state.Token('tab-label_open', 'label', 1);
const verticalTabLabelClose = new state.Token('tab-label_close', 'label', -1);

tabOpen.map = tabs[i].listItem.map;
tabOpen.markup = tabs[i].listItem.markup;
Expand All @@ -216,10 +217,10 @@ function insertTabs(

const tabPanelId = generateID();

verticalTabOpen.block = true;
verticalTabInput.block = true;

verticalTabOpen.attrJoin('class', 'radio');
verticalTabOpen.attrSet('type', 'radio');
verticalTabInput.attrJoin('class', 'radio');
verticalTabInput.attrSet('type', 'radio');

tabOpen.map = tabs[i].listItem.map;
tabOpen.markup = tabs[i].listItem.markup;
Expand Down Expand Up @@ -252,7 +253,7 @@ function insertTabs(
if (isTabActive) {
if (align === 'radio') {
tabOpen.attrSet(VERTICAL_TAB_FORCED_OPEN, 'true');
verticalTabOpen.attrSet('checked', 'true');
verticalTabInput.attrSet('checked', 'true');
tabPanelOpen.attrJoin('class', ACTIVE_CLASSNAME);
} else {
tabOpen.attrSet(TAB_ACTIVE_KEY, i === 0 ? 'true' : 'false');
Expand All @@ -263,7 +264,14 @@ function insertTabs(
}

if (align === 'radio') {
tabsTokens.push(tabOpen, verticalTabOpen, verticalTabLabelOpen, tabInline, tabClose);
tabsTokens.push(
tabOpen,
verticalTabInput,
verticalTabLabelOpen,
tabInline,
verticalTabLabelClose,
tabClose,
);
tabsTokens.push(tabPanelOpen, ...tabs[i].tokens, tabPanelClose);
} else {
tabListTokens.push(tabOpen, tabInline, tabClose);
Expand Down
54 changes: 48 additions & 6 deletions test/data/tabs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1238,7 +1238,7 @@ export const vertical = [
hidden: false,
},
{
type: 'tab_open',
type: 'tab-input',
tag: 'input',
map: null,
nesting: 0,
Expand All @@ -1252,7 +1252,7 @@ export const vertical = [
hidden: false,
},
{
type: 'label_open',
type: 'tab-label_open',
tag: 'label',
map: null,
nesting: 1,
Expand Down Expand Up @@ -1295,6 +1295,20 @@ export const vertical = [
block: false,
hidden: false,
},
{
type: 'tab-label_close',
tag: 'label',
map: null,
nesting: -1,
level: 0,
children: null,
content: '',
markup: '',
info: '',
meta: null,
block: false,
hidden: false,
},
{
type: 'tab_close',
tag: 'div',
Expand Down Expand Up @@ -1410,7 +1424,7 @@ export const vertical = [
hidden: false,
},
{
type: 'tab_open',
type: 'tab-input',
tag: 'input',
map: null,
nesting: 0,
Expand All @@ -1424,7 +1438,7 @@ export const vertical = [
hidden: false,
},
{
type: 'label_open',
type: 'tab-label_open',
tag: 'label',
map: null,
nesting: 1,
Expand Down Expand Up @@ -1467,6 +1481,20 @@ export const vertical = [
block: false,
hidden: false,
},
{
type: 'tab-label_close',
tag: 'label',
map: null,
nesting: -1,
level: 0,
children: null,
content: '',
markup: '',
info: '',
meta: null,
block: false,
hidden: false,
},
{
type: 'tab_close',
tag: 'div',
Expand Down Expand Up @@ -1724,7 +1752,7 @@ export const vertical = [
hidden: false,
},
{
type: 'tab_open',
type: 'tab-input',
tag: 'input',
map: null,
nesting: 0,
Expand All @@ -1738,7 +1766,7 @@ export const vertical = [
hidden: false,
},
{
type: 'label_open',
type: 'tab-label_open',
tag: 'label',
map: null,
nesting: 1,
Expand Down Expand Up @@ -1781,6 +1809,20 @@ export const vertical = [
block: false,
hidden: false,
},
{
type: 'tab-label_close',
tag: 'label',
map: null,
nesting: -1,
level: 0,
children: null,
content: '',
markup: '',
info: '',
meta: null,
block: false,
hidden: false,
},
{
type: 'tab_close',
tag: 'div',
Expand Down

0 comments on commit 74237f8

Please sign in to comment.