Skip to content

Early previewhamur is not on npm yet. The components are being built in the open, follow along on GitHub.

DisplayReact

Presence

An element that stays on screen while it animates out.

Rendered by React 19.3.1

import * as React from 'react'
import { Presence } from '@hamur/react/presence'

export default function PresenceExample() {
  const [present, setPresent] = React.useState(false)
  return (
    <div className="stack">
      <div className="actions">
        <button
          className="button"
          type="button"
          aria-expanded={present}
          onClick={() => setPresent((value) => !value)}
        >
          {present ? 'Hide panel' : 'Show panel'}
        </button>
      </div>
      <Presence className="presence-panel" present={present}>
        <p>Your changes are saved as a draft.</p>
      </Presence>
    </div>
  )
}
Not measured yetTests passing in React
10.2 KiBSize
Not measured yetMemory
Not measured yetSpeed
[N] commits

Installation

npm i @hamur/react

Not on npm yet. The package goes out under the chosen name.

Anatomy

Import the component and assemble its parts:

<Presence />

Examples

Keep Mounted

The same panel with keepMounted, so it stays in the document, hidden, and a status line reads what onPresentChangeComplete reported.

PresenceKeepMounted.tsx
import * as React from 'react'
import { Presence } from '@hamur/react/presence'

export default function PresenceKeepMountedExample() {
  const [present, setPresent] = React.useState(false)
  const [status, setStatus] = React.useState('No change yet')
  return (
    <div className="stack">
      <div className="actions">
        <button className="button" type="button" onClick={() => setPresent((value) => !value)}>
          {present ? 'Hide panel' : 'Show panel'}
        </button>
      </div>
      <Presence
        className="presence-panel"
        present={present}
        keepMounted
        onPresentChangeComplete={(next: boolean) => setStatus(next ? 'Shown, animation finished' : 'Hidden, animation finished')}
      >
        <p>Your changes are saved as a draft.</p>
      </Presence>
      <p className="muted">{status}</p>
    </div>
  )
}

API reference

3 props across 1 parts, in React syntax. className, style, render are listed once, under Shared props.

PresencePresence

Renders the app's element while present is true, plays its enter animation, and keeps it through its exit animation when present turns false. Renders a <div>.

Presence props
PropTypeDefault
presentrequiredWhether the element is shown.boolean—
keepMountedWhether the element stays in the document, hidden, while not present.booleanfalse
onPresentChangeCompleteCalled once the enter or exit animation of a change of present has finished.((present: boolean) => void)—
Presence data attributes
Data attributeDescription
data-openPresent while present is true.
data-closedPresent while present is false: during the exit and while keepMounted keeps it hidden.
data-starting-stylePresent when the element begins animating in.
data-ending-stylePresent while the element is animating out.

Shared props

Every part that renders an element takes these.

Shared props
PropType
classNameCSS class applied to the element, or a function that returns a class based on the component's state.string | ((state: State) => string | undefined)
styleStyle applied to the element, or a function that returns a style object based on the component's state.React.CSSProperties | ((state: State) => React.CSSProperties | undefined)
renderAllows you to replace the component's HTML element with a different tag, or compose it with another component.React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, State>

Keyboard and accessibility

Keyboard

Presence takes no focus and has no keys. The buttons in the examples are plain buttons: Enter and Space press them.

Accessibility

What the parts set
PartSetsSo that
Presenceno role or ARIA; an open or closed mark; inert from the start of an exit; hidden with keepMounteda leaving element cannot be reached while it fades, and a hidden one is not read

Focus order

  1. Presence is not focusable; its focusable children are tab stops while it is present.
  2. A leaving element is inert: focus passes over it, and an element that held focus when the exit started loses it to the document body.
  3. A keepMounted element that is hidden has no tab stops.