DataSaverToggle
SM · 950B gzip budgetA manual override for the library's constrained-connection behaviour.
- Category
- Accessibility & preferences
- Budget
- sm, single-purpose control
- External runtime
- React / React DOM only
axe fixtureSSR rendersource scanbundle budget
Preview
Live fixtureTry the component here. Locale-aware formatting and direction follow the selected language; example content and labels are not automatically translated. Overlay demos use interactive launchers.
Install
npx shadcn@latest add https://gear5-ui.vercel.app/r/data-saver-toggle.jsonCopies the source into your project. Pulls in 3 shared registry items: switch, cn, use-stored-value.
New here? Set up Tailwind and import aliases first →Source & props
Edit on GitHub ↗Prop types and inline documentation are included below. This is repository source; the installer rewrites shared imports for your project.
"use client";
import { useStoredValue } from "../lib/use-stored-value";
import { Switch } from "./switch";
const STORAGE_KEY = "gear5-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
Quality contract- 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