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

Add tabbed widget JS and CSS to build #2180

Merged
merged 9 commits into from
Aug 24, 2021
74 changes: 74 additions & 0 deletions resources/web/style/tab_widget.pcss
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
.tabs {
width: 100%;
}
[role="tablist"] {
margin: 0 0 -0.1em;
overflow: visible;
}
[role="tab"] {
position: relative;
padding: 0.3em 0.5em 0.4em;
border: 1px solid hsl(219, 1%, 72%);
border-radius: 0.2em 0.2em 0 0;
overflow: visible;
font-family: inherit;
font-size: inherit;
background: hsl(220, 20%, 94%);
}
[role="tab"]:hover::before,
[role="tab"]:focus::before,
[role="tab"][aria-selected="true"]::before {
position: absolute;
bottom: 100%;
right: -1px;
left: -1px;
border-radius: 0.2em 0.2em 0 0;
border-top: 3px solid hsl(219, 1%, 72%);
content: '';
}
[role="tab"][aria-selected="true"] {
border-radius: 0;
background: hsl(220, 43%, 99%);
outline: 0;
}
[role="tab"][aria-selected="true"]:not(:focus):not(:hover)::before {
border-top: 5px solid hsl(218, 96%, 48%);
}
[role="tab"][aria-selected="true"]::after {
position: absolute;
z-index: 3;
bottom: -1px;
right: 0;
left: 0;
height: 0.3em;
background: hsl(220, 43%, 99%);
box-shadow: none;
content: '';
}
[role="tab"]:hover,
[role="tab"]:focus,
[role="tab"]:active {
outline: 0;
border-radius: 0;
color: inherit;
}
[role="tab"]:hover::before,
[role="tab"]:focus::before {
border-color: hsl(218, 96%, 48%);
}
[role="tabpanel"] {
position: relative;
z-index: 2;
padding: 1em;
border: 1px solid hsl(219, 1%, 72%);
border-radius: 0 0.2em 0.2em 0.2em;
box-shadow: 0 0 0.2em hsl(219, 1%, 72%);
background: hsl(220, 43%, 99%);
margin-bottom: 1em;
}
[role="tabpanel"] p {
margin: 0;
}
[role="tabpanel"] * + p {
margin-top: 1em;
}
1 change: 1 addition & 0 deletions resources/web/styles.pcss
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
@import './style/settings_modal.pcss';
@import './style/sidebar.pcss';
@import './style/table.pcss';
@import './style/tab_widget.pcss';
@import './style/this_page.pcss';
@import './style/toc.pcss';
@import './style/util.pcss';
Expand Down
7 changes: 6 additions & 1 deletion resources/web/template.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
<script>dataLayer = [];</script><noscript><iframe src="//www.googletagmanager.com/ns.html?id=GTM-58RLH5" height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start': new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0], j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src= '//www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f); })(window,document,'script','dataLayer','GTM-58RLH5');</script>
<!-- End Google Tag Manager -->

<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-12395217-16"></script>
<script>
Expand Down Expand Up @@ -133,6 +133,11 @@ <h3>Most Popular</h3>
<script src="/static/js/swiftype_app_search.umd.min.js"></script>
<script src="/guide/static/jquery.js"></script>
<script type="text/javascript" src="/guide/static/docs.js"></script>
<!--BEGIN TABBED WIDGET JAVASCRIPT-->
<script type='text/javascript'>
function setActiveTab(e){const t=e.parentNode,r=t.parentNode;t.querySelectorAll('[aria-selected="true"]').forEach(e=>e.setAttribute("aria-selected",!1)),e.setAttribute("aria-selected",!0),r.querySelectorAll('[role="tabpanel"]').forEach(e=>e.setAttribute("hidden",!0)),r.parentNode.querySelector(`#${e.getAttribute("aria-controls")}`).removeAttribute("hidden")}function changeTabs(e){const t=e.target.parentNode,r=Array.apply(null,t.querySelectorAll("button")),{index:n}=r.reduce(({found:t,index:n},o)=>t||r[n]!==e.target?t?{found:t,index:n}:{found:t,index:n+1}:{found:!0,index:n},{found:!1,index:0}),o=t.parentNode,{tabGroup:d}=o.dataset;document.querySelectorAll("[data-tab-group="+d+"]").forEach(e=>{setActiveTab(e.querySelectorAll("button")[n])})}window.addEventListener("DOMContentLoaded",()=>{const e=document.querySelectorAll('[role="tab"]'),t=document.querySelector('[role="tablist"]');e.forEach(e=>{e.addEventListener("click",changeTabs)});let r=0;t.addEventListener("keydown",t=>{39!==t.keyCode&&37!==t.keyCode||(e[r].setAttribute("tabindex",-1),39===t.keyCode?++r>=e.length&&(r=0):37===t.keyCode&&--r<0&&(r=e.length-1),e[r].setAttribute("tabindex",0),e[r].focus())})});
</script>
<!--END TABBED WIDGET JAVASCRIPT-->
<!-- DOCS FINAL -->
</body>
</html>