Skip to Content

Privacy Mask

A one-tap hide-values mask for showing a screen to someone else.

Checking balance

$48,250

import {
  MASKED_VALUE,
  MaskToggle,
  PrivacyMaskProvider,
  usePrivacyMask,
} from "@dapplelight/signet-ui/components/privacy-mask"

function Balance({ amount }: { amount: number }) {
  const { masked } = usePrivacyMask()
  return <span>{masked ? MASKED_VALUE : `$${amount.toLocaleString()}`}</span>
}

export function Demo() {
  return (
    <PrivacyMaskProvider>
      <MaskToggle />
      <p className="text-2xl font-semibold">
        <Balance amount={48250} />
      </p>
    </PrivacyMaskProvider>
  )
}

Installation

npm i @dapplelight/signet-ui

Usage

import {
  MaskToggle,
  PrivacyMaskProvider,
  RatioFill,
  RatioProgress,
  RatioText,
  usePrivacyMask,
} from "@dapplelight/signet-ui/components/privacy-mask"
import { YourScreen } from "./your-screen"

<PrivacyMaskProvider>
  <MaskToggle />
  <YourScreen />
</PrivacyMaskProvider>

This is a display preference, not a security boundary: the data is still in memory.

Examples

Ratios

••% of the travel budget used

x
import {
  MaskToggle,
  PrivacyMaskProvider,
  RatioFill,
  RatioProgress,
  RatioText,
} from "@dapplelight/signet-ui/components/privacy-mask"

<PrivacyMaskProvider defaultMasked>
  <MaskToggle />
  <RatioText>92% of the travel budget used</RatioText>
  <RatioProgress value={92} aria-label="Travel budget used" />
  <div className="h-1 w-full rounded-full bg-bg-elevated">
    <RatioFill pct={92} className="h-full rounded-full bg-primary" />
  </div>
</PrivacyMaskProvider>

Controlled

$12,400

import { useState } from "react"
import { PrivacyMaskProvider } from "@dapplelight/signet-ui/components/privacy-mask"
import { Button } from "@dapplelight/signet-ui/components/button"
import { Balance } from "./balance"

const [masked, setMasked] = useState(false)

<PrivacyMaskProvider masked={masked} onMaskedChange={setMasked}>
  <Button variant="outline" onClick={() => setMasked(!masked)}>
    {masked ? "Show balances" : "Hide balances"}
  </Button>
  <Balance amount={12400} />
</PrivacyMaskProvider>

Toggle labels

import { MaskToggle } from "@dapplelight/signet-ui/components/privacy-mask"

<MaskToggle hideLabel="Hide revenue" showLabel="Show revenue" shortcut="H" />

API Reference

PrivacyMaskProvider

PropTypeDefaultDescription
maskedboolean-Controlled state. Makes storageKey and defaultMasked inert.
onMaskedChange(masked: boolean) => void-Called when the mask changes.
defaultMaskedbooleanfalseStarting value when nothing is stored.
storageKeystring | false"signet-privacy-mask"localStorage key for the choice. false keeps it for this tab only.

MaskToggle

PropTypeDefaultDescription
disabledboolean-Disable the button.
hideLabelstring"Hide values"Accessible name while values show.
showLabelstring"Show values"Accessible name while masked.
shortcutstring-Key shown in the tooltip. The app binds it.
classNamestring-Class on the button.

RatioText / RatioProgress / RatioFill

PropTypeDefaultDescription
RatioText childrenstring-Text whose percentages become ••% while masked.
RatioProgress valuenumber-A Progress that sits at 0 while masked.
RatioFill pctnumber-A bar fill that is 0% wide while masked.
RatioFill as"div" | "span""div"Element to render.

usePrivacyMask / useMaskedRatio

PropTypeDefaultDescription
usePrivacyMask(){ masked, setMasked, toggle }-Outside a provider: never masked.
useMaskedRatio(){ masked, text, node, value, width }-Helpers that mask ratios of hidden values.