Skip to content

Presence

Keeps a thing on the page while it leaves, so it can fade out, then removes it.

import { Presence } from '@sypnia/ui/react'

On this page
  1. A note that fades out
  2. When to use it
  3. For everyone
  4. Props

A note that fades out

Saved 3 minutes ago.

Code
import { useState } from 'react';
import { Button, Presence } from '@sypnia/ui/react';

// The note fades out before it leaves the page (its exit has keyframes of its own).
export default function Fade() {
  const [on, setOn] = useState(true);
  return (
    <div className="sy-stack" style={{ '--gap': 'var(--s-3)' } as React.CSSProperties}>
      <div><Button onClick={() => setOn(!on)}>{on ? 'Hide' : 'Show'}</Button></div>
      <style>{'@keyframes g-out { to { opacity: 0; translate: 0 -0.25rem; } } .g-note[data-exiting] { animation: g-out var(--dur-2) var(--ease-in) both; }'}</style>
      <Presence present={on}>{({ exiting, ref }) => <p ref={ref} className="g-note" data-exiting={exiting ? '' : undefined} data-enter="">Saved 3 minutes ago.</p>}</Presence>
    </div>
  );
}

When to use it

Use it when

  • Anything of your own with an exit animation.

Do not use it when

  • Reusing the entry keyframes in reverse for the exit: the exit never ends. Give it keyframes of its own.

For everyone

  • With reduced motion the exit is instant.

Props

PresenceTypeDefault
presentrequired boolean
  1. A note that fades out
  2. When to use it
  3. For everyone
  4. Props

    Search pages, sections and terms