<script type="module" src="https://spicy-sections.glitch.me/SpicySections.js"></script>
<h1>
Showing off Spicy Sections
</h1>
<p>
This demo shows different designed affordances at different screen sizes (resize your viewport and view the source too)…
</p>
<ul>
<li><code>0-30em</code>: collapsable sections</li>
<li><code>30-60em</code>: structured content</li>
<li><code>60em+</code>: tab-bar</li>
</ul>
<spicy-sections id="demos">
<h2>Tabs</h2>
<div>
<p>
The <code>tab-bar</code> affordance
can use shadow-dom to establish
a styleable tab-bar and panels.
The required parts can be exposed for styling
with consistent pseudo-elements.
</p>
<p>
In a tab state, we likely want to style:
</p>
<ul>
<li>The outer box</li>
<li>The tab bar</li>
<li>The tabs themselves</li>
<li>The selected tab</li>
<li>The tab panel area</li>
</ul>
</div>
<h2>Collapse</h2>
<div>
<p>
The accordion-like <code>collapse</code> affordance
also uses shadow-dom to establish
summary-details like behavior for each section,
with an option to make the toggle-states
<code>exclusive-collapse</code>.
</p>
<p>
In an accordion state, we likely want to style:
</p>
<ul>
<li>The outer box</li>
<li>The section headings/buttons</li>
<li>The open/closed marker</li>
<li>Open and closed heading styles</li>
<li>Open and closed content styles</li>
</ul>
</div>
<h2>Structured Content</h2>
<div>
<p>
The fallback state is simply structured HTML,
without any show/hide affordances.
This does not require any special styling.
</p>
</div>
</spicy-sections>
spicy-sections {
/* Big hand-wave over how we'd ultimately express this, but for this custom element, this is how you inform when you'd like to emply which affodances 'collapse', 'tab-bar' and 'exclusive-collapse' are the available affordances. Anything else is, effectively "plain" or "none". It is only read once.
*/
--const-mq-affordances: [screen and (max-width: 40em) ] collapse | [screen and
(min-width: 60em) ] tab-bar;
display: block;
border: thick var(--demo-border, solid black);
border-width: thick 0;
padding: 1em;
}
/* just normal css/dom any heading works */
h2 {
font-size: var(--heading-size, 1.2em);
margin: 0;
}
/* you can tell there are none employed */
h2:not([affordance] *) {
margin-bottom: 0.5em;
}
/* content panels when plain */
h2:not([affordance] *):not(:first-child) {
margin-top: 1.5em;
}
/* content panels, always */
spicy-sections h2 + * {
margin-top: 0;
}
/* accordion buttons */
[affordance="collapse"] {
--heading-size: 1em;
--demo-border: dotted tomato;
}
/* structured content */
spicy-sections:not([affordance]) {
--demo-border: dashed teal;
}
/* tabs */
[affordance="tab-bar"] {
--demo-border: solid mediumvioletred;
}
/* the pseudo element created around the tabs, when it exists */
::part(tab-list) {
display: flex;
}
/* only when they're tabs */
[affordance="tab-bar"] h2 {
padding: 0.125em 0.5em;
cursor: pointer;
}
/* Only when they're tabs and selected */
[affordance="tab-bar"] h2[tabindex="0"] {
background: papayawhip;
border: 0;
}
/* Tabs that aren't selected */
[affordance="tab-bar"] h2:not([tabindex="0"]) {
color: gray;
}
/* content, when it's tabs */
[affordance="tab-bar"] [role="tabpanel"] {
background: papayawhip;
padding: 1em;
}
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.