70 lines
2 KiB
Svelte
70 lines
2 KiB
Svelte
<script>
|
|
// Ref: https://svelte.dev/repl/a5f4d395b15a44d48a6b2239ef705fc4?version=3.35.0
|
|
// based on suggestions from:
|
|
// Inclusive Components by Heydon Pickering https://inclusive-components.design/collapsible-sections/
|
|
export let headerText;
|
|
|
|
let expanded = false;
|
|
</script>
|
|
|
|
<div class="collapsible">
|
|
<h3>
|
|
<button aria-expanded={expanded} on:click={() => expanded = !expanded}>{headerText}
|
|
<svg class="indicator" viewBox="0 0 20 20" fill="none" >
|
|
<path class="vert" d="M10 1V19" stroke="black" stroke-width="2"/>
|
|
<path d="M1 10L19 10" stroke="black" stroke-width="2"/>
|
|
</svg>
|
|
</button>
|
|
</h3>
|
|
<!-- <div class='tree' hidden={!expanded}>
|
|
<svg viewBox="0 0 60 60" fill="#ccc">
|
|
<path class="open" d="M40 1 V69" stroke="#444" stroke-width="4" />
|
|
</svg>
|
|
</div> -->
|
|
<div class='contents' hidden={!expanded}>
|
|
<slot></slot>
|
|
</div>
|
|
</div>
|
|
|
|
<style>
|
|
.collapsible {
|
|
margin: 8px 0 4px 0;
|
|
}
|
|
.collapsible .collapsible h3 button {
|
|
padding-left: 20px;
|
|
}
|
|
.tree { float: left; }
|
|
.contents {
|
|
float: left;
|
|
clear: both;
|
|
width: 100%;
|
|
border-bottom: dashed #aaa 1px;
|
|
padding-bottom: 1em;
|
|
margin-bottom: 1em;
|
|
}
|
|
h3 {
|
|
margin: 0;
|
|
}
|
|
button {
|
|
background-color: var(--background, #fff);
|
|
color: var(--gray-darkest, #282828);
|
|
display: flex;
|
|
justify-content: space-between;
|
|
border: 1px #aaa solid;
|
|
margin-left: 0px;
|
|
padding: 0.7em 0.7em;
|
|
}
|
|
button[aria-expanded="true"] { border-bottom: 2px solid var(--gray-light, #eee); }
|
|
button[aria-expanded="true"] .vert { display: none; }
|
|
button:focus svg { outline: 1firtpx solid; }
|
|
button[aria-expanded="true"] rect { fill: currentColor; }
|
|
svg.indicator {
|
|
height: 1.0em;
|
|
width: 1.0em;
|
|
margin-left: 6px;
|
|
margin-right: 6px;
|
|
margin-top: 4px;;
|
|
}
|
|
.tree:hover svg { outline: 1firtpx solid; }
|
|
|
|
</style>
|