DataSaverToggle
SM, under 950B gzippedA manual override for the library's constrained-connection behaviour.
- Category
- Accessibility & preferences
- Budget
- sm, single-purpose control
- Runtime deps
- None
Preview
This is the exact fixture the conformance suite renders in CI. Switch the language to see the component mirror and reformat.
Install
npx shadcn@latest add https://kata-ui-rho.vercel.app/r/data-saver-toggle.jsonCopies the source into your project. Pulls in 3 primitives: switch, cn, use-stored-value.
Source
"use client";
import { useStoredValue } from "../lib/use-stored-value";
import { Switch } from "./switch";
const STORAGE_KEY = "anywhere-ui:force-data-saver";
/**
* Lets someone opt into the library's constrained-connection behaviour
* manually — useful on an unmetered fast connection where the person still
* wants to save data by choice, which `useNetwork`'s automatic detection has
* no way to know about. Setting this overrides `useNetwork().constrained`
* to `true` regardless of the measured connection; see its docs for wiring.
*/
export function DataSaverToggle({ label = "Data saver" }: { label?: string }) {
const [stored, setStored] = useStoredValue(STORAGE_KEY, "false");
const forced = stored === "true";
return <Switch checked={forced} onCheckedChange={(v) => setStored(String(v))} label={label} />;
}
What CI checks
- Bundled, minified and gzipped against its tier budget
- Audited by axe in the state previewed above
- Rendered through react-dom/server with no browser globals
- Scanned for network calls, dangerous sinks, and unguarded animation