Material

A content-layer material from ultra-thin to thick that blurs what is behind it.

foundation

Apple: Materials

· Base UI: element

Thicknesses

ultra-thin

thin

regular

thick

import { Material } from "@applecn/ui/components/material"
import { Text } from "@applecn/ui/components/text"

export default function MaterialBasic() {
  return (
    <div className="grid grid-cols-2 gap-4 rounded-4xl bg-[linear-gradient(135deg,var(--system-pink),var(--system-orange),var(--system-teal))] p-4 sm:grid-cols-4">
      {(["ultra-thin", "thin", "regular", "thick"] as const).map(
        (thickness) => (
          <Material
            key={thickness}
            thickness={thickness}
            className="flex h-24 items-center justify-center rounded-3xl"
          >
            <Text variant="subheadline" emphasized>
              {thickness}
            </Text>
          </Material>
        )
      )}
    </div>
  )
}

Install

From the registry this site publishes, with dependencies resolved by the CLI.

npx shadcn@latest add https://applecn.vercel.app/r/material.json

Source

packages/ui/src/components/material.tsx

import { cva, type VariantProps } from "class-variance-authority"
import { cn } from "cn"
import type { ComponentProps } from "react"

/**
 * A content-layer material: a translucent surface that blurs what is behind it. Thicker
 * materials give text more contrast; thinner ones keep the background present. For bars,
 * sheets and menus use `Glass` instead.
 */
const materialVariants = cva("", {
  variants: {
    thickness: {
      "ultra-thin": "material-ultra-thin",
      thin: "material-thin",
      regular: "material-regular",
      thick: "material-thick",
    },
  },
  defaultVariants: {
    thickness: "regular",
  },
})

type MaterialProps = ComponentProps<"div"> &
  VariantProps<typeof materialVariants>

function Material({
  className,
  thickness = "regular",
  ...props
}: MaterialProps) {
  return (
    <div
      data-slot="material"
      data-thickness={thickness}
      className={cn(materialVariants({ thickness }), className)}
      {...props}
    />
  )
}

export { Material, materialVariants }
export type { MaterialProps }