Files
mkdocs-material/src/assets/stylesheets/main/extensions/pymdownx/_tabbed.scss
2021-11-21 23:19:42 +01:00

238 lines
6.4 KiB
SCSS

////
/// Copyright (c) 2016-2021 Martin Donath <martin.donath@squidfunk.com>
///
/// Permission is hereby granted, free of charge, to any person obtaining a
/// copy of this software and associated documentation files (the "Software"),
/// to deal in the Software without restriction, including without limitation
/// the rights to use, copy, modify, merge, publish, distribute, sublicense,
/// and/or sell copies of the Software, and to permit persons to whom the
/// Software is furnished to do so, subject to the following conditions:
///
/// The above copyright notice and this permission notice shall be included in
/// all copies or substantial portions of the Software.
///
/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
/// FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
/// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
/// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
/// DEALINGS
////
// ----------------------------------------------------------------------------
// Rules
// ----------------------------------------------------------------------------
// Scoped in typesetted content to match specificity of regular content
.md-typeset {
// Tabbed container
.tabbed-set {
position: relative;
display: flex;
flex-flow: column wrap;
margin: 1em 0;
border-radius: px2rem(2px);
// Tab radio button - the Tabbed extension will generate radio buttons with
// labels, so tabs can be triggered without the necessity for JavaScript.
// This is pretty cool, as it has great accessibility out-of-the box, so
// we just hide the radio button and toggle the label color for indication.
> input {
position: absolute;
width: 0;
height: 0;
opacity: 0;
// Tab label states
@for $i from 20 through 1 {
&:nth-child(#{$i}) {
// Tab is active
&:checked {
// Tab label
~ .tabbed-labels > :nth-child(#{$i}) {
@extend %tabbed-label;
}
// Tab content
~ .tabbed-content > :nth-child(#{$i}) {
@extend %tabbed-content;
}
}
// Tab label on keyboard focus
&.focus-visible ~ .tabbed-labels > :nth-child(#{$i}) {
@extend %tabbed-label-focus-visible;
}
}
}
}
}
// Tabbed labels
.tabbed-labels {
display: flex;
max-width: 100%;
overflow: auto;
box-shadow: 0 px2rem(-1px) var(--md-default-fg-color--lightest) inset;
scroll-snap-type: x proximity;
-ms-overflow-style: none; // IE, Edge
scrollbar-width: none; // Firefox
// [print]: Move one layer up for ordering
@media print {
display: contents;
}
// Webkit scrollbar
&::-webkit-scrollbar {
display: none; // Chrome, Safari
}
// Tab label
> label {
z-index: 1;
flex-shrink: 0;
width: auto;
padding: px2em(10px, 12.8px) 1.25em px2em(8px, 12.8px);
color: var(--md-default-fg-color--light);
font-weight: 700;
font-size: px2rem(12.8px);
white-space: nowrap;
border-bottom: px2rem(2px) solid transparent;
scroll-snap-align: start;
border-radius: px2rem(2px) px2rem(2px) 0 0;
cursor: pointer;
transition:
background-color 250ms,
color 250ms;
// [print]: Intersperse labels with containers
@media print {
// Ensure correct order of labels
@for $i from 1 through 20 {
&:nth-child(#{$i}) {
order: $i;
}
}
}
// Tab label on hover
&:hover {
color: var(--md-accent-fg-color);
}
}
}
// Tabbed content
.tabbed-content {
width: 100%;
// [print]: Move one layer up for ordering
@media print {
display: contents;
}
}
// Tabbed block
.tabbed-block {
display: none;
// [print]: Intersperse labels with containers
@media print {
display: block;
// Ensure correct order of containers
@for $i from 1 through 20 {
&:nth-child(#{$i}) {
order: $i;
}
}
}
// Code block is the first child of a tab - remove margin and mirror
// previous (now deprecated) SuperFences code block grouping behavior
> pre:first-child,
> .highlight:first-child pre,
> .highlighttable:first-child {
margin: 0;
// Omit rounded borders
> code {
border-top-left-radius: 0;
border-top-right-radius: 0;
}
}
// Adjust spacing for nested tabbed container
> .tabbed-set {
margin: 0;
}
}
}
// ----------------------------------------------------------------------------
// Rules: top-level
// ----------------------------------------------------------------------------
// [mobile -]: Align with body copy
@include break-to-device(mobile) {
// Top-level tabbed labels
.md-content__inner > .tabbed-set .tabbed-labels {
max-width: 100vw;
margin: 0 px2rem(-16px);
padding-left: px2rem(16px);
scroll-padding-left: px2rem(16px);
// Adjust for right-to-left languages
[dir="rtl"] & {
padding-right: px2rem(16px);
padding-left: initial;
scroll-padding-right: px2rem(16px);
scroll-padding-left: initial;
}
// Hack: some browsers ignore the right padding on flex containers,
// see https://bit.ly/3lsPS3S
&::after {
padding-right: px2rem(16px);
content: "";
// Adjust for right-to-left languages
[dir="rtl"] & {
padding-right: initial;
padding-left: px2rem(16px);
}
}
}
}
// ----------------------------------------------------------------------------
// Placeholders: improve colocation for better compression
// ----------------------------------------------------------------------------
// Tab label placeholder
%tabbed-label {
// [screen]: Show active state
@media screen {
color: var(--md-accent-fg-color);
border-color: var(--md-accent-fg-color);
}
}
// Tab label on keyboard focus placeholder
%tabbed-label-focus-visible {
background-color: var(--md-accent-fg-color--transparent);
}
// Tab content placeholder
%tabbed-content {
display: block;
}