Loading…
← All components

Buttons · Filter

3D Checkbox Filter

Checkboxes drawn as cubes on a tilted glass panel: checked, a cube rolls onto its glowing face. Vertical or horizontal, any options, any color.

<CheckboxFilter3D />Live

Customize

Direction
Tilt axis
Checked#7630FF
Panel#14111c
Text#ffffff

Installation

Use it in your project

Or skip the copy-paste

One command: writes the file and installs the dependencies.

$ npx deepui-cli add checkbox-filter
01

Install

The 3D packages this component is built on.

Nothing to install: React is all it needs.

02

Add the component

One self-contained file: create components/CheckboxFilter3D.tsx and paste it in.

components/CheckboxFilter3D.tsx
1"use client";
2
3import { memo, useCallback, useRef, useState, type CSSProperties, type PointerEvent } from "react";
4
5/**
6 * The shared props API of DeepUI's individual 3D components (not the full-page templates, which keep
7 * their own tailored scenes).
8 *
9 * The props are grouped by concern. A component extends ONLY the groups it really applies, so its
10 * type never advertises a knob that does nothing (a card has no particles, a background has no tilt):
11 *
12 * interface MyCardProps extends CursorProps, TiltProps, MaterialProps, PerformanceProps { … }
13 *
14 * `Base3DComponentProps` is every group at once, for tooling that handles any component. Same name,
15 * same unit and same meaning everywhere; the default values live in DEFAULT_3D_PROPS. These files are
16 * inlined into each component's single-file bundle (lib/bundle-source.mjs), only what it uses.
17 */
18
19/** Which rotation axes follow the pointer. "x-only": the object nods (up / down); "y-only": it turns (left / right). */
20export type TiltAxis = "both" | "x-only" | "y-only" | "none";
21
22/** 1. Cursor: how the pointer pulls, pushes and drags the object. */
23interface CursorProps {
24 /** Reach of the pointer's influence, in the component's own space: CSS pixels for pixel-laid-out widgets, world units for 3D scenes (each component says which). Default 220 (px). */
25 cursorRadius?: number;
26 /** Positive pulls things towards the pointer, negative pushes them away (repulsion, shockwave). Default 1. */
27 cursorForce?: number;
28 /** How far the object slides towards the pointer, 0 (stays put) to 1 (follows closely). Default 0. */
29 magneticStrength?: number;
30 /** Share of the remaining distance the motion closes each frame (at 60 fps), 0.01 (heavy, slow) to 1 (instant). Default 0.1. */
31 cursorDamping?: number;
32}
33
34/** 2. Tilt and parallax: the object leans towards the pointer, its layers slide against each other. */
35interface TiltProps {
36 /** Largest lean towards the pointer, in degrees. Default 15. */
37 maxTiltAngle?: number;
38 /** Axes that follow the pointer. Default "both". */
39 tiltAxis?: TiltAxis;
40 /** Lean away from the pointer instead of towards it. Default false. */
41 invertTilt?: boolean;
42 /** How far apart the depth layers slide when the object tilts, 0 (flat) to 2. Default 1. */
43 parallaxOffset?: number;
44}
45
46/** 3. Text and 3D typography, for components that draw a label. */
47interface Text3DProps {
48 /** The label drawn by the component. */
49 text?: string;
50 /** Scale of the lettering. Default 1. */
51 fontSize?: number;
52 /** Extrusion depth of 3D letters. Default 0.2. */
53 textDepth?: number;
54 /** Bevelled, light-catching edges on 3D letters. Default true. */
55 bevelEnabled?: boolean;
56 /** Custom font: a .woff / .ttf (flat text) or a typeface .json (extruded text). */
57 fontUrl?: string;
58}
59
60/** 4. Rendering, materials and glow. */
61interface MaterialProps {
62 /** Main color of the object. Default "#6366f1". */
63 primaryColor?: string;
64 /** Color of the glow. Default "#00f0ff". */
65 emissiveColor?: string;
66 /** Strength of the glow, 0 (none) to 3. Default 1. */
67 emissiveIntensity?: number;
68 /** 0 (mirror, glass) to 1 (matte). Default 0.3. */
69 roughness?: number;
70 /** 0 (plastic, organic) to 1 (metal). Default 0.5. */
71 metalness?: number;
72 /** 0 (opaque) to 1 (clear glass): see-through, refracting surfaces. Default 0. */
73 transmission?: number;
74 /** Technical wireframe rendering. Default false. */
75 wireframe?: boolean;
76}
77
78/** 5. Particles, idle motion and shader animation. */
79interface MotionProps {
80 /** Number of instanced elements. Default depends on the component. */
81 particleCount?: number;
82 /** Spin on its own, in radians per second (negative: the other way; 0.5 ≈ one turn in 12 s). Default 0. */
83 autoRotateSpeed?: number;
84 /** Pulses or ripples per second. Default 1. */
85 pulseRate?: number;
86 /** Amplitude of the noise deformation, 0 (none) to 2. Default 1. */
87 displacementScale?: number;
88}
89
90/** 6. Environment and camera. */
91interface EnvironmentProps {
92 /** Camera field of view, in degrees. Default depends on the component. */
93 cameraFov?: number;
94 /** Color of the depth fog. Default "#0a0a0a". */
95 fogColor?: string;
96 /** Thickness of the fog, 0 (none) to 0.2. Default 0. */
97 fogDensity?: number;
98}
99
100/** 7. Performance and accessibility. */
101interface PerformanceProps {
102 /** Lighter rendering for weak devices: pixel ratio 1, fewer instances, smaller environment maps. Default false. */
103 lowPowerMode?: boolean;
104 /** Under the OS "reduce motion" setting, stop idle spin, pulses and deformation (pointer feedback stays). Default true. */
105 respectReducedMotion?: boolean;
106 /** Stop the render loop while the component is scrolled out of view. Default true. */
107 pauseWhenOffscreen?: boolean;
108}
109
110/** Every group at once. Components extend only the groups they apply (see the top of this file). */
111interface Base3DComponentProps
112 extends CursorProps,
113 TiltProps,
114 Text3DProps,
115 MaterialProps,
116 MotionProps,
117 EnvironmentProps,
118 PerformanceProps {}
119
120type Defaults = Required<Omit<Base3DComponentProps, "text" | "fontUrl" | "particleCount" | "cameraFov">>;
121
122/** The values a prop takes when it is left out. A component may override one, and then documents it. */
123const DEFAULT_3D_PROPS: Defaults = {
124 cursorRadius: 220,
125 cursorForce: 1,
126 magneticStrength: 0,
127 cursorDamping: 0.1,
128 maxTiltAngle: 15,
129 tiltAxis: "both",
130 invertTilt: false,
131 parallaxOffset: 1,
132 fontSize: 1,
133 textDepth: 0.2,
134 bevelEnabled: true,
135 primaryColor: "#6366f1",
136 emissiveColor: "#00f0ff",
137 emissiveIntensity: 1,
138 roughness: 0.3,
139 metalness: 0.5,
140 transmission: 0,
141 wireframe: false,
142 autoRotateSpeed: 0,
143 pulseRate: 1,
144 displacementScale: 1,
145 fogColor: "#0a0a0a",
146 fogDensity: 0,
147 lowPowerMode: false,
148 respectReducedMotion: true,
149 pauseWhenOffscreen: true,
150};
151
152export interface CheckboxFilterOption {
153 /** Value reported by onChange. Defaults to the label. */
154 id?: string;
155 label: string;
156 /** Small line under the label, e.g. a number of results. */
157 count?: number | string;
158}
159
160export interface CheckboxFilter3DProps extends Pick<MaterialProps, "primaryColor" | "emissiveColor">, TiltProps {
161 /** The boxes to check: labels, or { id, label, count }. Default ["Free", "Pro"]. */
162 options?: (string | CheckboxFilterOption)[];
163 /** Checked ids, for a controlled filter (pair it with onChange). */
164 value?: string[];
165 /** Checked ids at first render when uncontrolled. Default: all of them. */
166 defaultValue?: string[];
167 /** Called with the checked ids, in the order of `options`. */
168 onChange?: (ids: string[]) => void;
169 /** Small caption at the top of the panel. Empty string hides it. Default "Access". */
170 title?: string;
171 /** Accessible name of the group (screen readers). Default "Filter". */
172 legend?: string;
173 /** "vertical": a column, labels under the cubes. "horizontal": a row, labels beside them. */
174 direction?: "vertical" | "horizontal";
175 /** Color of the checked face and of the glow. Default "#7630FF". */
176 emissiveColor?: string;
177 /** @deprecated Use `emissiveColor`. */
178 accentColor?: string;
179 /** Tint of the glass panel and of the unchecked faces. Default "#14111c". */
180 primaryColor?: string;
181 /** @deprecated Use `primaryColor`. */
182 panelColor?: string;
183 /** Labels and caption. Default "#ffffff". */
184 textColor?: string;
185 /** Edge of a cube, in px. Default 40. */
186 cubeSize?: number;
187 /** Draw the tilted glass panel behind the options. Default true. */
188 panel?: boolean;
189 /** Largest lean of the panel towards the pointer, in degrees. Default 13. */
190 maxTiltAngle?: number;
191 /** @deprecated Use `tiltAxis="none"` to turn the lean off. */
192 tilt?: boolean;
193 /** Resting turn of the panel around its vertical axis, in degrees (e.g. 16 to face a list on its right). Default 0. */
194 angle?: number;
195 className?: string;
196 style?: CSSProperties;
197}
198
199// Styles scoped under .cbf3d, colors and sizes read from CSS variables set on the root
200const CSS = `
201.cbf3d{--cbf-accent:#7630ff;--cbf-panel:#14111c;--cbf-text:#fff;--cbf-cube:40px;--cbf-angle:0deg;--cbf-depth:1;perspective:900px;margin:0;padding:0;border:0;min-width:0;color:var(--cbf-text);font-family:inherit}
202.cbf3d__panel{--rx:0deg;--ry:0deg;position:relative;display:flex;align-items:center;transform-style:preserve-3d;transform:rotateX(var(--rx)) rotateY(calc(var(--cbf-angle) + var(--ry)));transition:transform .6s cubic-bezier(.22,1,.36,1)}
203.cbf3d--vertical .cbf3d__panel{flex-direction:column;gap:calc(var(--cbf-cube)*.55)}
204.cbf3d--horizontal .cbf3d__panel{flex-direction:row;gap:calc(var(--cbf-cube)*.5)}
205.cbf3d--glass .cbf3d__panel{padding:calc(var(--cbf-cube)*.5) calc(var(--cbf-cube)*.55);border-radius:calc(var(--cbf-cube)*.6);background:radial-gradient(120% 70% at 50% 0%,color-mix(in srgb,var(--cbf-accent) 24%,transparent),transparent 70%),linear-gradient(180deg,color-mix(in srgb,var(--cbf-panel) 70%,rgba(255,255,255,.08)),color-mix(in srgb,var(--cbf-panel) 85%,transparent));box-shadow:inset 0 0 0 1px rgba(255,255,255,.12),0 30px 60px -25px rgba(0,0,0,.9),0 0 50px -25px var(--cbf-accent);backdrop-filter:blur(18px);-webkit-backdrop-filter:blur(18px)}
206.cbf3d--glass .cbf3d__panel::before{content:"";position:absolute;inset:0;border-radius:inherit;background:color-mix(in srgb,var(--cbf-accent) 18%,transparent);box-shadow:inset 0 0 0 1px color-mix(in srgb,var(--cbf-accent) 35%,transparent);transform:translateZ(-14px);pointer-events:none}
207.cbf3d__title{font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-size:10px;letter-spacing:.25em;text-transform:uppercase;opacity:.5;transform:translateZ(calc(18px * var(--cbf-depth)));white-space:nowrap}
208.cbf3d__option{position:relative;display:flex;align-items:center;cursor:pointer;transform-style:preserve-3d;transform:translateZ(calc(26px * var(--cbf-depth)));-webkit-tap-highlight-color:transparent}
209.cbf3d--vertical .cbf3d__option{flex-direction:column;gap:calc(var(--cbf-cube)*.25);text-align:center}
210.cbf3d--horizontal .cbf3d__option{flex-direction:row;gap:calc(var(--cbf-cube)*.3)}
211.cbf3d__input{position:absolute;width:1px;height:1px;margin:-1px;padding:0;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap;border:0}
212.cbf3d__text{display:flex;flex-direction:column;line-height:1.15}
213.cbf3d--vertical .cbf3d__text{align-items:center}
214.cbf3d__label{font-size:calc(var(--cbf-cube)*.32 + 1px);font-weight:600;white-space:nowrap}
215.cbf3d__count{font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-size:10px;opacity:.45}
216.cbf3d__cube{position:relative;flex:none;width:var(--cbf-cube);height:var(--cbf-cube);transform-style:preserve-3d;transition:transform .7s cubic-bezier(.22,1,.36,1)}
217.cbf3d__option:hover .cbf3d__cube{transform:rotateX(-14deg) rotateY(14deg)}
218.cbf3d__input:checked+.cbf3d__cube{transform:rotateX(-90deg)}
219.cbf3d__option:hover .cbf3d__input:checked+.cbf3d__cube{transform:rotateX(-76deg) rotateY(-14deg)}
220.cbf3d__input:focus-visible+.cbf3d__cube .cbf3d__face--front,.cbf3d__input:focus-visible+.cbf3d__cube .cbf3d__face--top{outline:2px solid var(--cbf-accent);outline-offset:3px}
221.cbf3d__face{position:absolute;inset:0;display:grid;place-items:center;border-radius:calc(var(--cbf-cube)*.22);backface-visibility:hidden;-webkit-backface-visibility:hidden;background:linear-gradient(145deg,color-mix(in srgb,var(--cbf-panel) 80%,#fff 12%),color-mix(in srgb,var(--cbf-panel) 85%,#000));box-shadow:inset 0 0 0 1px rgba(255,255,255,.16)}
222.cbf3d__face--front{transform:translateZ(calc(var(--cbf-cube)/2))}
223.cbf3d__face--front::after{content:"";width:34%;height:34%;border-radius:20%;box-shadow:inset 0 0 0 1.5px rgba(255,255,255,.3)}
224.cbf3d__face--back{transform:rotateY(180deg) translateZ(calc(var(--cbf-cube)/2))}
225.cbf3d__face--left{transform:rotateY(-90deg) translateZ(calc(var(--cbf-cube)/2));filter:brightness(.7)}
226.cbf3d__face--right{transform:rotateY(90deg) translateZ(calc(var(--cbf-cube)/2));filter:brightness(.7)}
227.cbf3d__face--bottom{transform:rotateX(-90deg) translateZ(calc(var(--cbf-cube)/2));filter:brightness(.55)}
228.cbf3d__face--top{transform:rotateX(90deg) translateZ(calc(var(--cbf-cube)/2));background:linear-gradient(145deg,color-mix(in srgb,var(--cbf-accent) 70%,#fff),color-mix(in srgb,var(--cbf-accent) 80%,#000));box-shadow:inset 0 0 0 1px rgba(255,255,255,.35),0 0 28px color-mix(in srgb,var(--cbf-accent) 85%,transparent);color:#fff}
229.cbf3d__face--top svg{width:55%;height:55%}
230@media (prefers-reduced-motion:reduce){.cbf3d__panel,.cbf3d__cube{transition:none}}
231`;
232
233const DEFAULT_OPTIONS = ["Free", "Pro"];
234
235const normalize = (option: string | CheckboxFilterOption): Required<Pick<CheckboxFilterOption, "id" | "label">> & CheckboxFilterOption =>
236 typeof option === "string" ? { id: option, label: option } : { ...option, id: option.id ?? option.label };
237
238/**
239 * A set of checkboxes drawn as CSS 3D cubes on a tilted glass panel: checked, a cube rolls forward onto
240 * its glowing face. Real <input type="checkbox"> under the hood (keyboard, screen readers, forms), no
241 * WebGL. Controlled with `value` + `onChange`, or uncontrolled with `defaultValue`. Position it yourself,
242 * e.g. fixed on the left of a list: className="fixed left-5 top-1/2 -translate-y-1/2".
243 */
244function CheckboxFilter3D({
245 options = DEFAULT_OPTIONS,
246 value,
247 defaultValue,
248 onChange,
249 title = "Access",
250 legend = "Filter",
251 direction = "vertical",
252 emissiveColor,
253 accentColor = emissiveColor ?? "#7630FF",
254 primaryColor,
255 panelColor = primaryColor ?? "#14111c",
256 textColor = "#ffffff",
257 cubeSize = 40,
258 panel = true,
259 tilt = true,
260 maxTiltAngle = 13,
261 tiltAxis = tilt ? DEFAULT_3D_PROPS.tiltAxis : "none",
262 invertTilt = DEFAULT_3D_PROPS.invertTilt,
263 parallaxOffset = DEFAULT_3D_PROPS.parallaxOffset,
264 angle = 0,
265 className = "",
266 style,
267}: CheckboxFilter3DProps) {
268 const items = options.map(normalize);
269 const [inner, setInner] = useState<string[]>(() => defaultValue ?? items.map((item) => item.id));
270 const checked = value ?? inner;
271 const panelRef = useRef<HTMLDivElement>(null);
272
273 const toggle = (id: string) => {
274 const set = new Set(checked);
275 if (set.has(id)) set.delete(id);
276 else set.add(id);
277 // Keep the order of the options
278 const next = items.map((item) => item.id).filter((itemId) => set.has(itemId));
279 if (value === undefined) setInner(next);
280 onChange?.(next);
281 };
282
283 // The panel leans towards the pointer (CSS variables, no re-render), back to rest when it leaves
284 const lean = useCallback(
285 (event: PointerEvent<HTMLFieldSetElement>) => {
286 const el = panelRef.current;
287 if (!el || tiltAxis === "none") return;
288 const rect = el.getBoundingClientRect();
289 const x = (event.clientX - rect.left) / rect.width - 0.5;
290 const y = (event.clientY - rect.top) / rect.height - 0.5;
291 // x, y in -0.5…0.5: the edges of the panel reach maxTiltAngle (a little less on the vertical axis)
292 const sign = invertTilt ? -1 : 1;
293 if (tiltAxis !== "x-only") el.style.setProperty("--ry", `${x * 2 * maxTiltAngle * sign}deg`);
294 if (tiltAxis !== "y-only") el.style.setProperty("--rx", `${-y * 1.4 * maxTiltAngle * sign}deg`);
295 },
296 [tiltAxis, maxTiltAngle, invertTilt]
297 );
298 const rest = useCallback(() => {
299 panelRef.current?.style.removeProperty("--ry");
300 panelRef.current?.style.removeProperty("--rx");
301 }, []);
302
303 const vars = {
304 "--cbf-accent": accentColor,
305 "--cbf-panel": panelColor,
306 "--cbf-text": textColor,
307 "--cbf-cube": `${cubeSize}px`,
308 "--cbf-angle": `${angle}deg`,
309 "--cbf-depth": parallaxOffset,
310 ...style,
311 } as CSSProperties;
312
313 return (
314 <fieldset className={`cbf3d cbf3d--${direction} ${panel ? "cbf3d--glass" : ""} ${className}`} style={vars} onPointerMove={lean} onPointerLeave={rest}>
315 <style>{CSS}</style>
316 <legend className="cbf3d__input">{legend}</legend>
317 <div ref={panelRef} className="cbf3d__panel">
318 {title && (
319 <span className="cbf3d__title" aria-hidden="true">
320 {title}
321 </span>
322 )}
323 {items.map((item) => (
324 <label key={item.id} className="cbf3d__option">
325 <input type="checkbox" className="cbf3d__input" checked={checked.includes(item.id)} onChange={() => toggle(item.id)} />
326 <span className="cbf3d__cube" aria-hidden="true">
327 <span className="cbf3d__face cbf3d__face--front" />
328 <span className="cbf3d__face cbf3d__face--back" />
329 <span className="cbf3d__face cbf3d__face--left" />
330 <span className="cbf3d__face cbf3d__face--right" />
331 <span className="cbf3d__face cbf3d__face--bottom" />
332 <span className="cbf3d__face cbf3d__face--top">
333 <svg viewBox="0 0 24 24">
334 <path d="M5 12.5l4.5 4.5L19 7.5" fill="none" stroke="currentColor" strokeWidth="3" strokeLinecap="round" strokeLinejoin="round" />
335 </svg>
336 </span>
337 </span>
338 <span className="cbf3d__text">
339 <span className="cbf3d__label">{item.label}</span>
340 {item.count !== undefined && <span className="cbf3d__count">{item.count}</span>}
341 </span>
342 </label>
343 ))}
344 </div>
345 </fieldset>
346 );
347}
348
349export default memo(CheckboxFilter3D);
03

Drop it in a page

Updated live with the settings above.

app/page.tsx
1"use client";
2
3import { useState } from "react";
4import CheckboxFilter3D from "@/components/CheckboxFilter3D";
5
6export default function Section() {
7 const [checked, setChecked] = useState(["Free", "Pro", "New"]);
8
9 return (
10 // The component fills this box: give it a position and a height
11 <div style={{ position: "relative", width: "100%", height: "420px" }}>
12 <CheckboxFilter3D
13 title="Access"
14 direction="vertical"
15 tiltAxis="both"
16 cubeSize={40}
17 maxTiltAngle={13}
18 angle={12}
19 emissiveColor="#7630FF"
20 primaryColor="#14111c"
21 textColor="#ffffff"
22 options={["Free", "Pro", "New"]}
23 panel
24 value={checked}
25 onChange={setChecked}
26 />
27 </div>
28 );
29}
Next componentQuantum Monolith→