Command Palette

Search for a command to run...

54
Blog
PreviousNext

Slide to Unlock

An iOS 26-inspired liquid glass slide-to-unlock switch with real-time SVG refraction effects.

Browser Compatibility

MDN Source
Chrome...
Full
Edge...
Full
Safari...
Full
Firefox...
Partial
Opera...
Full

Compatibility Note for Liquid Glass Refraction:

Firefox supports backdrop-filter but currently lacks support for referring to SVG filters via url(#filterId). This results in the surface appearing as a simple semi-transparent blur without the refractive liquid effect.

"use client";
 
import { SlideToUnlock } from "@/components/jyotirmoydas/slide-to-unlock";
 
export function SlideToUnlockDemo1() {
  return <SlideToUnlock />;
}

Installation

bunx --bun shadcn@latest add @jyotirmoydas/slide-to-unlock

Usage

import { SlideToUnlock } from "@/components/jyotirmoydas/slide-to-unlock";
<SlideToUnlock onUnlock={() => console.log("Unlocked!")} />

API Reference

Callbacks

Event handlers triggered during state transitions.

PropTypeDescription
onUnlock() => voidCallback triggered when the slider reaches ON position.
onLock() => voidCallback triggered when the slider reaches OFF position.

Behavior

Control the switch's initial state and feedback mechanisms.

PropTypeDefaultDescription
defaultCheckedbooleanfalseInitial state of the switch.
soundEnabledbooleantrueWhether to play the unlock sound effect.
toastEnabledbooleantrueWhether to show a toast notification on unlock.
toastMessagestring"Unlocked"Custom message to display in the unlock toast.
disabledbooleanfalseWhether the switch is disabled.

Appearance

Customize the visual appearance of the switch.

PropTypeDefaultDescription
classNamestringAdditional CSS classes to apply.
thumbColorstring"rgba(255, 255, 255, 1)"Color of the thumb/handle.
trackColorOffstring"#94949F77"Background color of the track when OFF.
trackColorOnstring"#3BBF4EEE"Background color of the track when ON.

Optical Parameters

Fine-tune the liquid glass refraction effect. These parameters control the SVG filter that creates the glass-like appearance.

PropTypeDefaultDescription
blurnumber0.2Blur level for the glass refraction effect.
specularOpacitynumber0.5Opacity of the specular highlight.
specularSaturationnumber6Saturation multiplier for the specular highlight.
refractionLevelnumber1Base refraction level (magnification intensity).

Examples

Default

The default configuration with unlock sound and toast notification enabled.

"use client";
 
import { SlideToUnlock } from "@/components/jyotirmoydas/slide-to-unlock";
 
export function SlideToUnlockDemo1() {
  return <SlideToUnlock />;
}

Custom Colors

Customize the thumb and track colors to match your design system.

"use client";
 
import { SlideToUnlock } from "@/components/jyotirmoydas/slide-to-unlock";
 
export function SlideToUnlockDemo2() {
  return (
    <SlideToUnlock
      thumbColor="rgba(59, 130, 246, 0.95)"
      trackColorOff="#e7e5e4"
      trackColorOn="#173462"
      toastMessage="Color Changed"
    />
  );
}

Custom Optical Parameters

Fine-tune the glass refraction effect by adjusting the optical parameters. Try different values to achieve your desired look.

"use client";
 
import { SlideToUnlock } from "@/components/jyotirmoydas/slide-to-unlock";
 
export function SlideToUnlockDemo3() {
  // Customize the optical parameters to fine-tune the glass effect
  // Try adjusting these values to see how they affect the refraction!
  return (
    <SlideToUnlock
      blur={0.3}
      specularOpacity={0.7}
      specularSaturation={8}
      refractionLevel={1.2}
      toastEnabled={false}
      soundEnabled={false}
    />
  );
}

Disabled State

A disabled switch that doesn't respond to interactions.

"use client";
 
import { SlideToUnlock } from "@/components/jyotirmoydas/slide-to-unlock";
 
export function SlideToUnlockDemo4() {
  return (
    <SlideToUnlock
      disabled
      defaultChecked={false}
      soundEnabled={false}
      toastEnabled={false}
    />
  );
}