Dither button
A button whose far end breaks into a grid of dots, the way the designs.here sky does. Point at it and the dots sweep back across it while the arrow steps forward.
Options
Code
import "./dither-button.css";
/* quiet gives the raised white version. Its colour can be set with the
--dh-dbutton-colour variable. */
export function DitherButton({ children, quiet = false, arrow = true, ...props }) {
return (
<button className="dh-dbutton" type="button" data-quiet={quiet ? "" : undefined} {...props}>
{children}
{arrow && (
<svg viewBox="0 0 16 16" width="14" height="14" fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true">
<path d="M3 8h9.500M8.500 4l4 4-4 4" />
</svg>
)}
</button>
);
}/* Where the dots begin, as a share of the button's width. Registered so it can be animated. */
@property --dh-dbutton-from {
syntax: "<percentage>";
inherits: true;
initial-value: 58%;
}
.dh-dbutton {
--dh-dbutton-colour: var(--dh-accent, #2563ff);
--dh-dbutton-dots: color-mix(in oklab, var(--dh-dbutton-colour) 62%, #000);
--dh-dbutton-from: 58%;
position: relative;
isolation: isolate;
display: inline-flex;
align-items: center;
gap: 0.6em;
height: 2.6em;
padding: 0 1em 0 1.15em;
overflow: hidden;
border: 0;
border-radius: 0.65em;
background: var(--dh-dbutton-colour);
box-shadow:
inset 0 0 0 1px color-mix(in srgb, var(--dh-dbutton-dots) 55%, transparent),
0 1px 2px rgb(0 0 0 / 0.2);
color: var(--dh-on-accent, #fff);
font: inherit;
font-weight: 500;
letter-spacing: -0.01em;
cursor: pointer;
transition:
--dh-dbutton-from 700ms cubic-bezier(0.23, 1, 0.32, 1),
transform 150ms cubic-bezier(0.23, 1, 0.32, 1);
}
/* The dots: a darker shade of the colour, shown only through a grid of round holes that
fades in from left to right. */
.dh-dbutton::before {
content: "";
position: absolute;
inset: 0;
z-index: -1;
background: var(--dh-dbutton-dots);
-webkit-mask-image: radial-gradient(circle, #000 0.085em, transparent 0.11em), linear-gradient(90deg, transparent var(--dh-dbutton-from), #000 calc(var(--dh-dbutton-from) + 55%));
mask-image: radial-gradient(circle, #000 0.085em, transparent 0.11em), linear-gradient(90deg, transparent var(--dh-dbutton-from), #000 calc(var(--dh-dbutton-from) + 55%));
-webkit-mask-size: 0.3em 0.3em, auto;
mask-size: 0.3em 0.3em, auto;
-webkit-mask-composite: source-in;
mask-composite: intersect;
}
.dh-dbutton svg {
transition: transform 350ms cubic-bezier(0.23, 1, 0.32, 1);
}
.dh-dbutton:active {
transform: scale(0.97);
}
.dh-dbutton:focus-visible {
outline: 2px solid var(--dh-faint, #8a8a8a);
outline-offset: 2px;
}
@media (hover: hover) {
.dh-dbutton:hover {
--dh-dbutton-from: 8%;
}
.dh-dbutton:hover svg {
transform: translateX(0.2em);
}
}
/* The quiet one: a raised white button whose dots are your colour. */
.dh-dbutton[data-quiet] {
--dh-dbutton-dots: color-mix(in srgb, var(--dh-dbutton-colour) 34%, transparent);
background: var(--dh-raised, #fff);
box-shadow:
0 0 0 0.5px var(--dh-edge, #d6d6d2),
0 1px 2px rgb(0 0 0 / 0.12);
color: var(--dh-fg, #171717);
}
@media (prefers-reduced-motion: reduce) {
.dh-dbutton,
.dh-dbutton svg {
transition: none;
}
}
/* The preview's layout. */
.dh-dbutton-row {
display: flex;
flex-wrap: wrap;
justify-content: center;
gap: 0.75em;
}<div class="dh-dbutton-row">
<button class="dh-dbutton" type="button">Get started<svg viewBox="0 0 16 16" width="14" height="14" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M3 8h9.500M8.500 4l4 4-4 4" /></svg></button>
<button class="dh-dbutton" type="button" data-quiet>Read the docs<svg viewBox="0 0 16 16" width="14" height="14" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M3 8h9.500M8.500 4l4 4-4 4" /></svg></button>
</div>/* Where the dots begin, as a share of the button's width. Registered so it can be animated. */
@property --dh-dbutton-from {
syntax: "<percentage>";
inherits: true;
initial-value: 58%;
}
.dh-dbutton {
--dh-dbutton-colour: var(--dh-accent, #2563ff);
--dh-dbutton-dots: color-mix(in oklab, var(--dh-dbutton-colour) 62%, #000);
--dh-dbutton-from: 58%;
position: relative;
isolation: isolate;
display: inline-flex;
align-items: center;
gap: 0.6em;
height: 2.6em;
padding: 0 1em 0 1.15em;
overflow: hidden;
border: 0;
border-radius: 0.65em;
background: var(--dh-dbutton-colour);
box-shadow:
inset 0 0 0 1px color-mix(in srgb, var(--dh-dbutton-dots) 55%, transparent),
0 1px 2px rgb(0 0 0 / 0.2);
color: var(--dh-on-accent, #fff);
font: inherit;
font-weight: 500;
letter-spacing: -0.01em;
cursor: pointer;
transition:
--dh-dbutton-from 700ms cubic-bezier(0.23, 1, 0.32, 1),
transform 150ms cubic-bezier(0.23, 1, 0.32, 1);
}
/* The dots: a darker shade of the colour, shown only through a grid of round holes that
fades in from left to right. */
.dh-dbutton::before {
content: "";
position: absolute;
inset: 0;
z-index: -1;
background: var(--dh-dbutton-dots);
-webkit-mask-image: radial-gradient(circle, #000 0.085em, transparent 0.11em), linear-gradient(90deg, transparent var(--dh-dbutton-from), #000 calc(var(--dh-dbutton-from) + 55%));
mask-image: radial-gradient(circle, #000 0.085em, transparent 0.11em), linear-gradient(90deg, transparent var(--dh-dbutton-from), #000 calc(var(--dh-dbutton-from) + 55%));
-webkit-mask-size: 0.3em 0.3em, auto;
mask-size: 0.3em 0.3em, auto;
-webkit-mask-composite: source-in;
mask-composite: intersect;
}
.dh-dbutton svg {
transition: transform 350ms cubic-bezier(0.23, 1, 0.32, 1);
}
.dh-dbutton:active {
transform: scale(0.97);
}
.dh-dbutton:focus-visible {
outline: 2px solid var(--dh-faint, #8a8a8a);
outline-offset: 2px;
}
@media (hover: hover) {
.dh-dbutton:hover {
--dh-dbutton-from: 8%;
}
.dh-dbutton:hover svg {
transform: translateX(0.2em);
}
}
/* The quiet one: a raised white button whose dots are your colour. */
.dh-dbutton[data-quiet] {
--dh-dbutton-dots: color-mix(in srgb, var(--dh-dbutton-colour) 34%, transparent);
background: var(--dh-raised, #fff);
box-shadow:
0 0 0 0.5px var(--dh-edge, #d6d6d2),
0 1px 2px rgb(0 0 0 / 0.12);
color: var(--dh-fg, #171717);
}
@media (prefers-reduced-motion: reduce) {
.dh-dbutton,
.dh-dbutton svg {
transition: none;
}
}
/* The preview's layout. */
.dh-dbutton-row {
display: flex;
flex-wrap: wrap;
justify-content: center;
gap: 0.75em;
}Dither button is not in the Figma file yet.
Use the React or HTML code for now.