-
-
Notifications
You must be signed in to change notification settings - Fork 182
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
151 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 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,34 @@ | ||
'use strict' | ||
|
||
module.exports = (ctx) => | ||
function (args, content = '') { | ||
const tabsId = `keep-tabs-${Date.now()}` | ||
let activeTabIdx = Number(args[0]) || 1 | ||
|
||
const tabBlock = /<!--\s*tab (.*?)\s*-->\n([\w\W\s\S]*?)<!--\s*endtab\s*-->/g | ||
const matches = content.matchAll(tabBlock) | ||
|
||
let tabIdx = 1 | ||
let tabsNav = '' | ||
let tabsContent = '' | ||
|
||
for (const match of matches) { | ||
let tabName = match[1] | ||
const href = `${tabsId}-${tabIdx}` | ||
const isActive = tabIdx === activeTabIdx ? ' active' : '' | ||
tabIdx += 1 | ||
|
||
tabsNav += `<div class="tab${isActive}" data-href="${href}">${tabName}</div>` | ||
|
||
let tabContent = match[2] | ||
tabContent = ctx.render.renderSync({ text: tabContent, engine: 'markdown' }).trim() | ||
tabsContent += `<div class="tab-pane${isActive}" id="${href}">${tabContent}</div>` | ||
} | ||
|
||
tabsNav = `<div class="tabs-nav">${tabsNav}</div>` | ||
tabsContent = `<div class="tabs-content">${tabsContent}</div>` | ||
|
||
return `<div class="keep-tabs" id="${tabsId}"> | ||
${tabsNav + tabsContent} | ||
</div>` | ||
} |
This file contains 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,76 @@ | ||
$border-height = 2px | ||
|
||
.keep-tabs { | ||
position relative | ||
box-sizing border-box | ||
width 100% | ||
height auto | ||
background var(--background-color) | ||
border-radius 0.4rem | ||
box-shadow 0.1rem 0.1rem 0.5rem var(--shadow-color) | ||
|
||
.tabs-nav { | ||
position relative | ||
display flex | ||
justify-content flex-start | ||
box-sizing border-box | ||
list-style none | ||
|
||
&::before { | ||
position absolute | ||
bottom 0 | ||
left 0 | ||
box-sizing border-box | ||
width 100% | ||
height $border-height | ||
background var(--border-color) | ||
content '' | ||
} | ||
|
||
.tab { | ||
position relative | ||
box-sizing border-box | ||
margin-right 0.8rem | ||
padding 1rem 0.6rem | ||
overflow hidden | ||
color var(--text-color-3) | ||
cursor pointer | ||
|
||
&.active { | ||
font-weight 600 | ||
|
||
&::before { | ||
position absolute | ||
bottom 0 | ||
left 50% | ||
box-sizing border-box | ||
width 100% | ||
height $border-height | ||
background var(--primary-color) | ||
border-radius 0.2rem | ||
transform translateX(-50%) | ||
content '' | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
||
.tabs-content { | ||
position relative | ||
box-sizing border-box | ||
|
||
.tab-pane { | ||
position relative | ||
box-sizing border-box | ||
width 100% | ||
height auto | ||
min-height 12rem | ||
padding 0.6rem 0.8rem | ||
|
||
&:not(.active) { | ||
display none | ||
} | ||
} | ||
} | ||
} |
This file contains 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 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