@bigandy/sibling-count
v0.2.0
Published
A web component that allows you to put --sibling-count on the parent item, as well as --sibling-index on each child item. This allows cool things such as https://nerdy.dev/cyclical-radio-group-with-trig-functions-and-grid but without the hard-work of hand
Downloads
19
Readme
Sibling-count Web Component
A web component that allows you to put --sibling-count on the parent item, as well as --sibling-index on each child item. This allows cool things such as https://nerdy.dev/cyclical-radio-group-with-trig-functions-and-grid but without the hard-work of hand-coding the css variables.
Scripts
npm run dev
- runs the vite dev environmentnpm run build
- builds the project with vite buildnpm run npm:publish
- publishes the package to npm (needs One Time Password)
Examples
- https://codepen.io/bigandy/pen/OJovxRW
Notes
You can import with unpkg https://unpkg.com/@bigandy/sibling-count@latest
and then use in your HTML
<sibling-count>
<ul>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
</sibling-count>
<ul style="--sibling-count: 10;">
<li style="--sibling-index: 1;"></li>
<li style="--sibling-index: 2;"></li>
<li style="--sibling-index: 3;"></li>
<li style="--sibling-index: 4;"></li>
<li style="--sibling-index: 5;"></li>
<li style="--sibling-index: 6;"></li>
<li style="--sibling-index: 7;"></li>
<li style="--sibling-index: 8;"></li>
<li style="--sibling-index: 9;"></li>
<li style="--sibling-index: 10;"></li>
</ul>
and use the following CSS
ul {
list-style: none;
padding-left: 0;
transform: rotate(-90deg);
width: 500px;
aspect-ratio: 1;
& li {
height: 3em;
background: hsl(
calc(var(--sibling-index) * calc(360 / var(--sibling-count) * 1deg)) 100% 50%
);
}
}
Resulting in this: