Color Wheel Examples
The examples below assume that you have imported the component and set up the theme.
Basic
Let the user pick the hue and saturation of a color on a wheel. value holds the hue and the saturation, separated by a space, and the valuechange event writes the new value to an output.
The controls pick the angle and radius channels in each color-space.
--active
<div class="color-wheel-basic"> <sv-color-wheel style="--sv-polar-slider-marker-clr: transparent" aria-label="Color" value="217 76" ></sv-color-wheel> <output></output></div>
<script type="application/x-typescript" module> const colorWheel = document.querySelector<ColorWheel>(".color-wheel-basic sv-color-wheel")!; const valueOutput = document.querySelector<HTMLOutputElement>(".color-wheel-basic output")!;
updateValueOutput(); colorWheel.addEventListener("valuechange", updateValueOutput);
function updateValueOutput() { valueOutput.value = `value="${colorWheel.value}"`; }</script>
<style> .color-wheel-basic { display: grid; gap: 0.75em; justify-items: center;
sv-color-wheel { --sv-polar-slider-marker-clr: transparent; }
output { font-variant-numeric: tabular-nums; } }</style>Ring
Let the user pick a single channel of a color, like the hue, on a ring. ring makes the wheel edit the angle channel alone, value holds that one number, and the valuechange event writes it to an output.
The controls show the channels of each color-space.
<div class="color-wheel-ring"> <sv-color-wheel style="--sv-polar-slider-marker-clr: transparent" aria-label="Hue" ring value="350" ></sv-color-wheel> <output></output></div>
<script type="application/x-typescript" module> const colorWheel = document.querySelector<ColorWheel>(".color-wheel-ring sv-color-wheel")!; const valueOutput = document.querySelector<HTMLOutputElement>(".color-wheel-ring output")!;
updateValueOutput(); colorWheel.addEventListener("valuechange", updateValueOutput);
function updateValueOutput() { valueOutput.value = `value="${colorWheel.value}"`; }</script>
<style> .color-wheel-ring { display: grid; gap: 0.75em; justify-items: center;
sv-color-wheel { --sv-polar-slider-marker-clr: transparent; }
output { font-variant-numeric: tabular-nums; } }</style>