Open this example in the interactive library
Live preview
Source code
// components/AlphaChannelMixer.tsx
import { useState } from "react";
export default function AlphaChannelMixer({ hex = "#bc805a" }: { hex?: string } = {}) {
const [a, set] = useState(65);
return (
<label>
Opacity {a}%
<input type="range" value={a} onChange={(e) => set(+e.target.value)} />
<span
style={{
display: "block",
padding: 16,
background:
hex +
Math.round(a * 2.55)
.toString(16)
.padStart(2, "0"),
}}
>
Sample
</span>
</label>
);
}
