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

Basic wireframe for a new tab type #7290

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
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
117 changes: 117 additions & 0 deletions _plugins/sdktabs.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
module Tags
class SdkTabsBlock < Liquid::Block
def initialize(tag_name, tabonly = 'false', tokens)
super
@tabclass = 'sdk-tab_toggle'
@tabid = 'sdk-tab_' + (0...12).map { (97 + rand(26)).chr }.join
if tabonly.downcase.strip == 'local'
@tabclass = 'sdk-tab_toggle_only'
end
end
def render(context)
tabs = super.scan(/data\-sdk\-tab=\"sdk\-(.*?)\"/)
tabslist = '<ul class="sdk-ab-nav sdk-ab-nav-tabs ' + @tabclass + '_ul" id="' + @tabid + '_nav">' + "\n"
if tabs.length > 0
tabs.each_with_index do |tab, ind|
# scan returns array of results, only care about first match
tabslist += ' <li class="sdkrow ' + tab[0].gsub(' ', '-').gsub(/[^\w-]/, '')
if ind == 0
tabslist += ' active'
end
tabslist += '"><a class="' + @tabclass + '" data-sdk-tab-target="' + @tabid + '" data-sdk-tab="' + tab[0].gsub(' ', '-').gsub(/[^\w-]/, '') + '">' + tab[0] + '</a></li>' + "\n"
end
end
tabslist += '</ul>' + "\n"
tabslist + '<div id="' + @tabid + '" class="sdk-tab-content ' + @tabclass + '_div">' + "\n" + super + "\n</div>\n"
end
end

class SdkTabBlock < Liquid::Block
def initialize(tag_name, tab, tokens)
super
@tab = tab.strip.downcase
end

def render(context)
return "" if @tab.empty?

site = context.registers[:site]
converter = site.find_converter_instance(Jekyll::Converters::Markdown)

lines = super.rstrip.split(/\r\n|\r|\n/).select { |line| line.size > 0 }
indentation = lines.map do |line|
match = line.match(/^(\s+)[^\s]+/)
match ? match[1].size : 0
end
indentation = indentation.min

content = indentation ? super.gsub(/^#{' |\t' * indentation}/, '') : super
content = converter.convert(content)
content = content.strip # Strip again to avoid "\n"
tabslug = @tab.gsub(' ', '-').gsub(/[^\w-]/, '')

return '<div class="sdk-ab-tab-pane ' + tabslug + '_tab " data-sdk-tab="sdk-' + @tab + '">' + content + "</div>"
end
end

class SdkSubTabsBlock < Liquid::Block
def initialize(tag_name, tabonly = 'false', tokens)
super
@tabclass = 'sub_sdk-tab_toggle'
@tabid = 'sub_sdk-tab_' + (0...12).map { (97 + rand(26)).chr }.join
if tabonly.downcase.strip != 'global'
@tabclass = 'sub_sdk-tab_toggle_only'
end
end
def render(context)
tabs = super.scan(/data\-sdk\-sub\_tab=\"(.*?)\"/)
tabslist = '<ul class="sdk-ab-sub_nav sdk-ab-sub_nav-sub_tabs ' + @tabclass + '_ul" id="' + @tabid + '_nav">' + "\n"

if tabs.length > 0
tabs.each_with_index do |tab, ind|
# scan returns array of results, only care about first match
tabslist += ' <li class="coderow ' + tab[0].gsub(' ', '-') + '_sub_sdk_tab'
if ind == 0
tabslist += ' sub_active'
end
tabslist += '"><a class="' + @tabclass + '" data-sdk-sub_tab-target="' + @tabid + '" data-sdk-sub_tab="' + tab[0].gsub(' ', '-') + '_sub_sdk_tab">' + tab[0] + '</a></li>' + "\n"
end
end
tabslist += '</ul>' + "\n"
tabslist + '<div id="' + @tabid + '" class="sdk-ab-sub_tab-content ' + @tabclass + '_sdk_div">' + "\n" + super + "\n</div>\n"
end
end

class SdkSubTabBlock < Liquid::Block
def initialize(tag_name, tab, tokens)
super
@tab = tab.strip.downcase
end

def render(context)
return "" if @tab.empty?

site = context.registers[:site]
converter = site.find_converter_instance(Jekyll::Converters::Markdown)

lines = super.rstrip.split(/\r\n|\r|\n/).select { |line| line.size > 0 }
indentation = lines.map do |line|
match = line.match(/^(\s+)[^\s]+/)
match ? match[1].size : 0
end
indentation = indentation.min

content = indentation ? super.gsub(/^#{' |\t' * indentation}/, '') : super
content = converter.convert(content)
content = content.strip # Strip again to avoid "\n"
tabslug = @tab.gsub(' ', '-')

return '<div class="sdk-ab-sub_tab-pane ' + tabslug + '_sub_sdk_tab " data-sdk-sub_tab="' + @tab + '">' + content + "</div>"
end
end
end

Liquid::Template.register_tag("sdktabs", Tags::SdkTabsBlock)
Liquid::Template.register_tag("sdktab", Tags::SdkTabBlock)
Liquid::Template.register_tag("sdksubtabs", Tags::SdkSubTabsBlock)
Liquid::Template.register_tag("sdksubtab", Tags::SdkSubTabBlock)
4 changes: 2 additions & 2 deletions _plugins/tabs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def render(context)
content = content.strip # Strip again to avoid "\n"
tabslug = @tab.gsub(' ', '-')

'<div class="ab-tab-pane ' + tabslug + '_tab " data-tab="' + @tab + '">' + content + "</div>"
return '<div class="ab-tab-pane ' + tabslug + '_tab " data-tab="' + @tab + '">' + content + "</div>"
end
end

Expand Down Expand Up @@ -106,7 +106,7 @@ def render(context)
content = content.strip # Strip again to avoid "\n"
tabslug = @tab.gsub(' ', '-')

'<div class="ab-sub_tab-pane ' + tabslug + '_sub_tab " data-sub_tab="' + @tab + '">' + content + "</div>"
return '<div class="ab-sub_tab-pane ' + tabslug + '_sub_tab " data-sub_tab="' + @tab + '">' + content + "</div>"
end
end
end
Expand Down
173 changes: 148 additions & 25 deletions assets/css/_tabs.scss
Original file line number Diff line number Diff line change
Expand Up @@ -120,31 +120,154 @@
}
}

.ab-tab-content,
.ab-sub_tab-content {
margin-bottom: 30px;
padding: 20px 20px 0 20px;
p {
padding: 0;
}
border: 1px solid $grey-ghost;
}
.ab-tab-content {
overflow-x: auto;
> .ab-tab-pane {
display: none;
}
> .active {
display: block;
}
}
.ab-sub_tab-content {
> .ab-sub_tab-pane {
display: none;
}
> .sub_active {
display: block;
.ab-tab-content, .ab-sub_tab-content {
margin-bottom: 30px;
padding: 20px 20px 0 20px;
p {
padding: 0;
}
border: 1px solid $grey-ghost;
}
.ab-tab-content {
> .ab-tab-pane {
display: none;
}
> .active {
display: block;
}
}
.ab-sub_tab-content {
> .ab-sub_tab-pane {
display: none;
}
> .sub_active {
display: block;
}
}
// Sdk tabs css
.sdkrow {
margin-left: 0;
}

ul.sdk-ab-nav,
ul.sdk-ab-sub_nav {
margin-bottom: 10px;
margin-left: 0 !important;
padding-left: 0;
list-style: none;

> li {
position: relative;
display: block;
&::before {
content: none !important;
font-size: 12px;
vertical-align: middle;
}
> a {
position: relative !important;
display: block !important;
padding: 5px 15px;
cursor: pointer;
font-size: 14px;

border: 1px solid $blue-ice !important;
border-radius: 5px !important;
&:hover,
&:focus {
text-decoration: none;
background-color: $white;
}
}
}

&::before,
&::after {
content: " ";
display: table;
}
&::after {
clear: both;
}
}

ul.sdk-ab-nav-tabs,
ul.sdk-ab-sub_nav-sub_tabs{

> li {
float: left;
margin-bottom: 10px;
margin-right: 10px;
> a {
color: $black-shark;
margin-right: 2px;
line-height: 25px;
text-transform: uppercase;
&:hover {
color: $blue-scooter;
background-color: $white;
}
}
}

> li {
&.active {
color: $blue-scooter;
background-color: $white ;
border-radius: 5px;
border-color: $navy-bay;
cursor: default;
a {
color: $navy-bay;

&:hover {
color: $blue-scooter;
background-color: $white;
}
}
}
}
}
ul.sdk-ab-sub_nav-sub_tabs {
> li {
&.sub_active {
color: $blue-scooter;
background-color: $white ;
border-radius: 5px;
border-color: $navy-bay;
cursor: default;
a {
color: $navy-bay;

&:hover {
color: $blue-scooter;
background-color: $white;
}
}
}
}
}
}
.sdk-tab-content, .sdk-ab_sub_tab-content {
padding: 20px 20px 0 20px;
p {
padding: 0;
}

> .sdk-ab-tab-pane {
display: none;
}
> .active {
display: block;
}
}

.sdk-ab-sub_tab-content {
> .sdk-ab-sub_tab-pane {
display: none;
}
> .sub_active {
display: block;
}
}
}
}
Loading