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

feat(plugin): improve names of token types and added missing closing token for label #63

Merged
merged 1 commit into from
Sep 25, 2024
Merged
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
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
Loading