|
| 1 | +--- |
| 2 | +import Checklist from "~icons/material-symbols/checklist"; |
| 3 | +--- |
| 4 | + |
| 5 | +<script> |
| 6 | +document.addEventListener("DOMContentLoaded", () => { |
| 7 | + const checkpointElems = document.querySelectorAll<HTMLElement>(".comp-checkpoint"); |
| 8 | + |
| 9 | + checkpointElems.forEach((elem, elemIdx) => { |
| 10 | + const listItems = elem.querySelectorAll<HTMLLIElement>("ul > li"); |
| 11 | + |
| 12 | + listItems.forEach((item, itemIdx) => { |
| 13 | + const checkbox = item.querySelector<HTMLInputElement>("input[type=\"checkbox\"]"); |
| 14 | + if (checkbox == null) { |
| 15 | + return; |
| 16 | + } |
| 17 | + |
| 18 | + checkbox.disabled = false; |
| 19 | + const uniqueId = `checkpoint-${elemIdx}-${itemIdx}`; |
| 20 | + checkbox.id = uniqueId; |
| 21 | + |
| 22 | + const label = document.createElement("label"); |
| 23 | + label.htmlFor = uniqueId; |
| 24 | + |
| 25 | + const nodesToWrap: ChildNode[] = [checkbox]; |
| 26 | + let next = checkbox.nextSibling; |
| 27 | + |
| 28 | + // 後続のノードがテキストか、インライン要素である限り収集を続ける |
| 29 | + while (next != null && next.nodeName !== 'UL' && next.nodeName !== 'P' && next.nodeName !== 'DIV') { |
| 30 | + nodesToWrap.push(next); |
| 31 | + next = next.nextSibling; |
| 32 | + } |
| 33 | + |
| 34 | + nodesToWrap.forEach(node => label.appendChild(node)); |
| 35 | + item.prepend(label); |
| 36 | + }); |
| 37 | + }); |
| 38 | +}); |
| 39 | +</script> |
| 40 | + |
| 41 | +<div class="container comp-checkpoint"> |
| 42 | + <div class="title"> |
| 43 | + <Checklist height="100%" width="100%" /> |
| 44 | + <p>チェックポイント!</p> |
| 45 | + </div> |
| 46 | + <slot /> |
| 47 | +</div> |
| 48 | + |
| 49 | +<style> |
| 50 | +.container { |
| 51 | + padding: 1rem; |
| 52 | + border-radius: 10px; |
| 53 | + background-color: var(--sl-color-green-low); |
| 54 | + display: flex; |
| 55 | + flex-direction: column; |
| 56 | + gap: 1rem; |
| 57 | + |
| 58 | + & .title { |
| 59 | + display: grid; |
| 60 | + grid-template-columns: 2rem 1fr; |
| 61 | + align-items: center; |
| 62 | + gap: 0.5rem; |
| 63 | + |
| 64 | + & > p { |
| 65 | + font-size: var(--sl-text-3xl); |
| 66 | + font-weight: bold; |
| 67 | + margin: 0; |
| 68 | + } |
| 69 | + } |
| 70 | +} |
| 71 | + |
| 72 | +:global(.comp-checkpoint ul) { |
| 73 | + margin-top: 0 !important; /* comes from star-light */ |
| 74 | +} |
| 75 | + |
| 76 | +:global(.comp-checkpoint > ul) { |
| 77 | + list-style: none; |
| 78 | + padding-inline: 1rem; |
| 79 | + padding-block-end: 1rem; |
| 80 | + |
| 81 | + & :global(> li > label) { |
| 82 | + margin-bottom: 0 !important; /* comes from star-light */ |
| 83 | + cursor: pointer; |
| 84 | + display: grid; |
| 85 | + grid-template-columns: 1.5rem 1fr; |
| 86 | + align-items: start; |
| 87 | + gap: 1rem; |
| 88 | + |
| 89 | + & :global(> input[type="checkbox"]) { |
| 90 | + accent-color: var(--sl-color-green); |
| 91 | + height: 1.5rem; |
| 92 | + width: 1.5rem; |
| 93 | + border: 1px solid #8b98a5; |
| 94 | + border-radius: 4px; |
| 95 | + |
| 96 | + & :checked { |
| 97 | + border: 1px solid #8b98a5; |
| 98 | + background-color: var(--sl-color-green); |
| 99 | + } |
| 100 | + } |
| 101 | + |
| 102 | + @media (width <= 30rem) { |
| 103 | + grid-template-columns: 1rem 1fr; |
| 104 | + gap: 0.5rem; |
| 105 | + |
| 106 | + & :global(> input[type="checkbox"]) { |
| 107 | + height: 1rem; |
| 108 | + width: 1rem; |
| 109 | + margin-top: 0.25rem; |
| 110 | + } |
| 111 | + } |
| 112 | + } |
| 113 | +} |
| 114 | + |
| 115 | +</style> |
0 commit comments