Ballmac UI home

In View

A wrapper that knows when it is on screen: it sets a data attribute for CSS, offers a render function and callbacks, and can run a simple entrance.

effect

fade

effect

slide-up

effect

slide-down

effect

scale

effect

blur

Installation

$ pnpm dlx shadcn@latest add @ballmac/in-view

Usage

import { InView } from "@/components/ballmac/in-view"

The full example is in the Code tab above.

Examples

Render function and callback

Off screen

Style it with data-in-view, or read the state in a function child.

0 changes

API reference

PropTypeDefault
children*

Content, or a function that receives whether the element is in view.

React.ReactNode | ((inView: boolean) => React.ReactNode)—
effect

Built-in entrance. "none" only reports the state and leaves styling to you.

InViewEffect"fade"
amount

Fraction of the element that must be visible: 0 to 1, or "some" / "all".

number | "some" | "all"0.25
margin

Shrinks or grows the viewport used for the check, like CSS margins: "0px 0px -20% 0px".

string—
once

Stay revealed after the first time.

booleantrue
delay

Seconds before the entrance starts.

number0
duration

Seconds the entrance takes.

number0.55
onInViewChange

Called whenever the element enters or leaves the view.

(inView: boolean) => void—
as

Element to render.

"div" | "section" | "article" | "li" | "span""div"

Also accepts the standard attributes of its root element.

Accessibility

KeyAction
Screen readersContent is always in the DOM; only presentation changes
Reduced motionContent is shown with no entrance

Use with AI

<InView effect='fade|slide-up|slide-down|scale|blur|none' amount margin once onInViewChange>{content or (inView)=>content}</InView>. data-in-view is true or false for Tailwind's data-[in-view=true] variants. With the shadcn MCP server set up (guide), ask your agent:

Add the Ballmac UI In View (@ballmac/in-view) to this project with the shadcn MCP, then use it where it fits.

Use it for

  • Starting a video, counter or animation only when seen
  • Custom reveal styling driven by data-in-view

Not for

  • Staggered groups (blur-fade or stagger-list)

Registry JSON: https://ui.ballmac.com/r/in-view.json

Credits

Free to use in personal and commercial projects.

Registry
shadcn/utils