# IdleManager

**When to use:** Show something only once the user has stopped interacting — a screen saver, a session-timeout warning, an "are you still there?" prompt, an idle dashboard view. It renders its children after a period of inactivity and hides them again the moment the user does anything.

**Keywords:** auto logout, inactivity timer, timeout, away, afk, screensaver, session expiry

**Import:** `import { IdleManager } from '@ahrowe/ui'`
**Types:** `import type { IdleManagerProps } from '@ahrowe/ui'`

```tsx
import { IdleManager } from '@ahrowe/ui';

// Nothing is rendered until the user has been idle for 14 minutes.
<IdleManager idleAfterSeconds={14 * 60}>
  <SessionWarning onStaySignedIn={keepAlive} />
</IdleManager>

// Only arm it where it makes sense — here, only while signed in.
<IdleManager idleAfterSeconds={60} renderCondition={isSignedIn}>
  <ScreenSaver />
</IdleManager>
```

**Key props:**

| Prop | Type | Description |
|------|------|-------------|
| `children` | `ReactNode` | Rendered only while the user is idle |
| `idleAfterSeconds` | `number` | Seconds of inactivity before the children appear. Default `600` |
| `renderCondition` | `boolean` | Children appear only when this is `true` **and** the user is idle. Default `true` |

**How idle is decided:** a `click`, `mousemove`, `keydown`, `scroll` or `touchstart` anywhere in the document counts as activity. Any of them restarts the countdown and hides the children again at once.

There is no callback. The component tells you nothing and renders instead, so whatever should happen on idle goes in the children: put the side effect in their own `useEffect`, which runs when they mount.

```tsx
function AutoLogout() {
  useEffect(() => {
    signOut();
  }, []);
  return <p>Signed out for inactivity.</p>;
}

<IdleManager idleAfterSeconds={15 * 60}>
  <AutoLogout />
</IdleManager>
```

Changing `idleAfterSeconds` restarts the countdown without hiding what is already on screen; only real activity does that. The pending timer is cleared on unmount, so it never fires afterwards.
