Search documentation

Search pages, components, blocks, styles and colours.

Get started
Skip to content

Density

PreviousNext

DensityProvider sets compact, default or spacious for everything inside it, including the overlays it opens.

Density on iOS

Installation

bunx --bun fabricator-ui@latest add density

Usage

import { Button } from "@/components/ui/button"
import { DensityProvider } from "@/components/ui/density"
import { Input } from "@/components/ui/input"
<DensityProvider density={density}>
  <Button>Control</Button>
  <Input placeholder="Text field" />
</DensityProvider>

Composition

  • Density
  • DensityProvider
  • DensityScope

Examples

density-example.tsx
 
import { Button } from "@/components/ui/button"
import { DensityProvider } from "@/components/ui/density"
import { Input } from "@/components/ui/input"
 
const DENSITIES = ["compact", "default", "spacious"] as const
 
function DensityExample() {
  return (
    <ExampleWrapper>
      {DENSITIES.map((density) => (
        <Example key={density} title={density}>
          <DensityProvider density={density}>
            <Button>Control</Button>
            <Input placeholder="Text field" />
          </DensityProvider>
        </Example>
      ))}
    </ExampleWrapper>
  )
}
 
export { DensityExample }

API reference

Props it adds to what it wraps: density.

Differences from web

Same. DensityProvider sets scoped variables, with no wrapper view. FabricatorRoot sizes each density for the device from the window's width, since the website's are sized for a pointer: Default is a phone's 44pt controls with 15pt text and a tablet's 40pt, Compact a step down (40pt on a phone, 34pt on a tablet) and Spacious a step up (52pt on a phone, 44pt on a tablet). At a phone's Default a control's size="sm" is a step down, 36pt, and size="lg" a step up, 52pt.

Accessibility

Text is read as it appears. Give a control with no text an accessibilityLabel.