@present-day/reveal-row 0.1.4 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +88 -9
- package/dist/index.d.mts +27 -2
- package/dist/index.d.ts +27 -2
- package/dist/index.js +229 -81
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +230 -82
- package/dist/index.mjs.map +1 -1
- package/package.json +10 -6
package/README.md
CHANGED
|
@@ -1,19 +1,39 @@
|
|
|
1
|
-
#
|
|
1
|
+
# RevealRow
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
**Buttery swipe-to-reveal actions for React lists — powered by native scroll physics, not JavaScript animation.**
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
[](https://www.npmjs.com/package/@present-day/reveal-row)
|
|
6
|
+
[](https://github.com/present-day/reveal-row/actions/workflows/ci.yml)
|
|
7
|
+
[](https://bundlephobia.com/package/@present-day/reveal-row)
|
|
8
|
+
[](https://www.npmjs.com/package/@present-day/reveal-row)
|
|
9
|
+
[](./LICENSE)
|
|
6
10
|
|
|
11
|
+
The swipe-to-delete pattern everyone knows from iOS Mail — as a headless React component. Swipe (or drag, or scroll) a row horizontally to reveal action buttons on the **right**, the **left**, or **both** sides, with three crisp snap positions: left · center · right.
|
|
12
|
+
|
|
13
|
+
**[▶ Try the live playground](https://present-day.github.io/reveal-row/)**
|
|
14
|
+
|
|
15
|
+
<img width="295" height="640" alt="RevealRow demo — swiping a list row to reveal actions" src="https://github.com/user-attachments/assets/932021d4-5224-479f-9df9-c7045bf12afb" />
|
|
16
|
+
|
|
17
|
+
## Why RevealRow?
|
|
18
|
+
|
|
19
|
+
- 🍦 **Native scroll physics** — momentum, rubber-banding, and snap come from the browser's own scroll engine (CSS scroll-snap), not a JS animation loop. It feels right because it *is* the real thing.
|
|
20
|
+
- 🎨 **Headless & unstyled** — no bundled CSS. Every sub-element takes your class names, so it drops into Tailwind, CSS Modules, or plain CSS without a fight.
|
|
21
|
+
- 📱 **Touch, trackpad, and mouse** — one component, every input. Works inside vertically scrolling lists without gesture conflicts.
|
|
22
|
+
- 🪶 **Tiny & dependency-free** — just `react` and `react-dom` as peers. Tree-shakeable, `sideEffects: false`, ESM + CJS + types.
|
|
23
|
+
- ♿ **Accessible by default** — focus-driven reveal for keyboard users, `prefers-reduced-motion` support, configurable ARIA labels, and a click-guard so a swipe never fires an accidental row activation.
|
|
24
|
+
- 🎛️ **Fully controllable** — imperative ref API (`reveal('left')`, `close()`), settled-position callbacks, and a `disabled`/`isActive` protocol for coordinating whole lists.
|
|
7
25
|
|
|
8
26
|
## Install
|
|
9
27
|
|
|
10
28
|
```bash
|
|
29
|
+
bun add @present-day/reveal-row
|
|
30
|
+
# or
|
|
11
31
|
npm i @present-day/reveal-row
|
|
12
32
|
```
|
|
13
33
|
|
|
14
34
|
Peer dependencies: `react`, `react-dom` (v18 or v19).
|
|
15
35
|
|
|
16
|
-
##
|
|
36
|
+
## Quick start
|
|
17
37
|
|
|
18
38
|
```tsx
|
|
19
39
|
import { RevealRow } from '@present-day/reveal-row'
|
|
@@ -37,6 +57,34 @@ import { RevealRow } from '@present-day/reveal-row'
|
|
|
37
57
|
</RevealRow>
|
|
38
58
|
```
|
|
39
59
|
|
|
60
|
+
## Multiple actions per side
|
|
61
|
+
|
|
62
|
+
A side slot is a single column that **auto-sizes to its content** (with an 88px floor) — to show several buttons (iOS Mail-style Delete + Pin), lay them out with flex and give each button its own width. No math required:
|
|
63
|
+
|
|
64
|
+
```tsx
|
|
65
|
+
<RevealRow
|
|
66
|
+
right={
|
|
67
|
+
<div style={{ display: 'flex', height: '100%' }}>
|
|
68
|
+
<button style={{ width: 88 }} onClick={handleDelete}>Delete</button>
|
|
69
|
+
<button style={{ width: 88 }} onClick={handlePin}>Pin</button>
|
|
70
|
+
</div>
|
|
71
|
+
}
|
|
72
|
+
>
|
|
73
|
+
<MyRowContent />
|
|
74
|
+
</RevealRow>
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
Passing `actionWidthLeft`/`actionWidthRight` a number still gives you a fixed-width column, exactly as before.
|
|
78
|
+
|
|
79
|
+
**[▶ See it live in the playground](https://present-day.github.io/reveal-row/)** under "Multiple actions".
|
|
80
|
+
|
|
81
|
+
## Accessibility
|
|
82
|
+
|
|
83
|
+
- **Focus-driven reveal** — tabbing into an off-screen action button snaps that side cleanly into view (instead of the browser's un-snapped scroll-into-view). When focus leaves the row, a focus-initiated reveal closes again — so keyboard users never leave rows stuck open. Swipe-opened rows are not affected by focus loss.
|
|
84
|
+
- **Reduced motion** — preset animations become instant under `prefers-reduced-motion: reduce`. An explicit `animationConfig` is treated as an intentional override and left untouched.
|
|
85
|
+
- **State hooks for styling and testing** — the root carries `data-reveal-position="left | center | right"` (settled position) alongside `data-reveal-mode`.
|
|
86
|
+
- **Screen readers** — the drag handle is decorative (`aria-hidden`) with a configurable sr-only description (`handleAriaLabel`).
|
|
87
|
+
|
|
40
88
|
## Modes
|
|
41
89
|
|
|
42
90
|
| `mode` | Slots used | Resting ("closed") scroll |
|
|
@@ -55,8 +103,8 @@ Omit `mode` and it's inferred: both slots → `both`, only `left` → `left`, ot
|
|
|
55
103
|
| `left` | `ReactNode` | — | Leading action column |
|
|
56
104
|
| `right` | `ReactNode` | — | Trailing action column |
|
|
57
105
|
| `mode` | `'left' \| 'right' \| 'both'` | inferred | Override mode detection |
|
|
58
|
-
| `actionWidthLeft` | `number` |
|
|
59
|
-
| `actionWidthRight` | `number` |
|
|
106
|
+
| `actionWidthLeft` | `number` | auto (min 88px) | Fixed width (px) of the left column; omit to size to content |
|
|
107
|
+
| `actionWidthRight` | `number` | auto (min 88px) | Fixed width (px) of the right column; omit to size to content |
|
|
60
108
|
| `classNames` | `RevealRowClassNames` | `{}` | Class names for each sub-element |
|
|
61
109
|
| `showHandle` | `boolean` | `true` | Render the default 6-dot drag affordance |
|
|
62
110
|
| `handle` | `ReactNode` | — | Replace the default handle with custom content |
|
|
@@ -87,9 +135,9 @@ ref.current?.reveal('right') // snap to right action
|
|
|
87
135
|
ref.current?.reveal('center') // alias for close
|
|
88
136
|
```
|
|
89
137
|
|
|
90
|
-
## classNames
|
|
138
|
+
## Styling with classNames
|
|
91
139
|
|
|
92
|
-
All sub-elements accept class names
|
|
140
|
+
All sub-elements accept class names, so styling is entirely yours:
|
|
93
141
|
|
|
94
142
|
```tsx
|
|
95
143
|
<RevealRow
|
|
@@ -113,6 +161,37 @@ All sub-elements accept class names for styling:
|
|
|
113
161
|
|
|
114
162
|
**Preventing row activation on swipe** — the component guards against triggering a click after a horizontal drag. If you wrap the row in a command palette item or similar, keep the built-in `onClickCapture` behaviour intact, or replicate it.
|
|
115
163
|
|
|
116
|
-
|
|
164
|
+
**Focus styles** — the row root is a scroll container, and CSS clips anything drawn outside the scrollport, including focus outlines (on both axes). Draw focus rings *inward* on action buttons and row content: `outline-offset: -2px`, or Tailwind's `focus-visible:ring-2 focus-visible:ring-inset`.
|
|
165
|
+
|
|
166
|
+
**Single-axis scrolling** — the root pins `overflow-y: hidden` so rows only ever scroll horizontally; vertical overflow clips instead of scrolling.
|
|
167
|
+
|
|
168
|
+
**Rounded list corners** — don't rely on a parent's `overflow: hidden` + `border-radius` to clip action buttons: scroll containers are composited on their own layers, and browsers can skip ancestor rounded clipping mid-scroll, exposing square button corners. Instead, put the matching radius on the buttons that touch the container's edges — the outermost button of the group, on the first and last rows only. Drive it from a token so the radius stays in one place:
|
|
169
|
+
|
|
170
|
+
```css
|
|
171
|
+
:root { --row-radius: 12px; }
|
|
172
|
+
.list { border-radius: var(--row-radius); }
|
|
173
|
+
.list > :first-child [data-reveal-row-right] button:last-child { border-top-right-radius: var(--row-radius); }
|
|
174
|
+
.list > :last-child [data-reveal-row-right] button:last-child { border-bottom-right-radius: var(--row-radius); }
|
|
175
|
+
.list > :first-child [data-reveal-row-left] button:first-child { border-top-left-radius: var(--row-radius); }
|
|
176
|
+
.list > :last-child [data-reveal-row-left] button:first-child { border-bottom-left-radius: var(--row-radius); }
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
The playground implements the same idea with an index-aware helper (`edgeCorners` in `playground/src/PlaygroundApp.tsx`).
|
|
180
|
+
|
|
181
|
+
## CSS tokens
|
|
182
|
+
|
|
183
|
+
The component is headless, but its one built-in dimension is themeable via a CSS custom property:
|
|
184
|
+
|
|
185
|
+
| Token | Default | Effect |
|
|
186
|
+
| ----- | ------- | ------ |
|
|
187
|
+
| `--reveal-row-action-min-width` | `88px` | Minimum width of an auto-sized action column (the floor under content-based sizing) |
|
|
188
|
+
|
|
189
|
+
Set it on `:root` or any ancestor: `[data-reveal-mode] { --reveal-row-action-min-width: 72px; }`. Explicit `actionWidthLeft`/`actionWidthRight` props bypass the token. The playground layers its own tokens on top (`--row-radius`, `--action-width`) in `playground/index.html` — retheme everything from one place.
|
|
190
|
+
|
|
191
|
+
## Publishing (maintainers)
|
|
117
192
|
|
|
118
193
|
Run `bun run build` to produce `dist/`. The `exports` field in `package.json` points to `dist/index.{js,mjs,d.ts}`. Push a tag to trigger the GitHub Actions publish workflow (OIDC trusted publishing — no npm token needed in secrets).
|
|
194
|
+
|
|
195
|
+
## License
|
|
196
|
+
|
|
197
|
+
[MIT](./LICENSE) © [Present Day](https://presentday.io)
|
package/dist/index.d.mts
CHANGED
|
@@ -18,6 +18,18 @@ declare const REVEAL_HANDLE_POSITION: {
|
|
|
18
18
|
readonly end: "end";
|
|
19
19
|
};
|
|
20
20
|
type RevealHandlePosition = (typeof REVEAL_HANDLE_POSITION)[keyof typeof REVEAL_HANDLE_POSITION];
|
|
21
|
+
declare const REVEAL_ROW_ELEMENTS: {
|
|
22
|
+
readonly div: "div";
|
|
23
|
+
readonly section: "section";
|
|
24
|
+
readonly article: "article";
|
|
25
|
+
readonly main: "main";
|
|
26
|
+
readonly aside: "aside";
|
|
27
|
+
readonly header: "header";
|
|
28
|
+
readonly footer: "footer";
|
|
29
|
+
readonly nav: "nav";
|
|
30
|
+
readonly li: "li";
|
|
31
|
+
};
|
|
32
|
+
type RevealRowElement = (typeof REVEAL_ROW_ELEMENTS)[keyof typeof REVEAL_ROW_ELEMENTS];
|
|
21
33
|
declare const ANIMATION_PRESET: {
|
|
22
34
|
readonly none: "none";
|
|
23
35
|
readonly quick: "quick";
|
|
@@ -51,12 +63,25 @@ type RevealRowProps = {
|
|
|
51
63
|
* Trailing action column (e.g. add). Omitted in `left` mode.
|
|
52
64
|
*/
|
|
53
65
|
right?: ReactNode;
|
|
66
|
+
/**
|
|
67
|
+
* The HTML element to use for the root container.
|
|
68
|
+
* @default 'div'
|
|
69
|
+
*/
|
|
70
|
+
as?: RevealRowElement;
|
|
54
71
|
/**
|
|
55
72
|
* If both `left` and `right` are set, defaults to `both`. If only one side,
|
|
56
73
|
* mode is derived unless overridden.
|
|
57
74
|
*/
|
|
58
75
|
mode?: RevealMode;
|
|
76
|
+
/**
|
|
77
|
+
* Fixed width (px) of the left action column. Omit to size the column to
|
|
78
|
+
* its content with an 88px floor (`minmax(88px, max-content)`).
|
|
79
|
+
*/
|
|
59
80
|
actionWidthLeft?: number;
|
|
81
|
+
/**
|
|
82
|
+
* Fixed width (px) of the right action column. Omit to size the column to
|
|
83
|
+
* its content with an 88px floor (`minmax(88px, max-content)`).
|
|
84
|
+
*/
|
|
60
85
|
actionWidthRight?: number;
|
|
61
86
|
classNames?: RevealRowClassNames;
|
|
62
87
|
/** @default true */
|
|
@@ -73,7 +98,7 @@ type RevealRowProps = {
|
|
|
73
98
|
handleAriaLabel?: string;
|
|
74
99
|
/** Fires when the settled position changes. */
|
|
75
100
|
onRevealChange?: (position: RevealPosition) => void;
|
|
76
|
-
onScroll?: (event: UIEvent<
|
|
101
|
+
onScroll?: (event: UIEvent<HTMLElement>) => void;
|
|
77
102
|
/** Resets to closed; default true. */
|
|
78
103
|
resetWhenDisabled?: boolean;
|
|
79
104
|
disabled?: boolean;
|
|
@@ -106,4 +131,4 @@ declare function getScrollClosed(wL: number, _wR: number, _maxScroll: number, mo
|
|
|
106
131
|
|
|
107
132
|
declare const RevealRow: react.ForwardRefExoticComponent<RevealRowProps & react.RefAttributes<RevealRowHandle>>;
|
|
108
133
|
|
|
109
|
-
export { ANIMATION_PRESET, ANIMATION_PRESETS, type AnimationConfig, type AnimationPreset, REVEAL_HANDLE_POSITION, REVEAL_MODE, REVEAL_POSITION, type RevealHandlePosition, type RevealMode, type RevealPosition, RevealRow, type RevealRowClassNames, type RevealRowHandle, type RevealRowProps, getRevealFromScroll, getScrollClosed };
|
|
134
|
+
export { ANIMATION_PRESET, ANIMATION_PRESETS, type AnimationConfig, type AnimationPreset, REVEAL_HANDLE_POSITION, REVEAL_MODE, REVEAL_POSITION, REVEAL_ROW_ELEMENTS, type RevealHandlePosition, type RevealMode, type RevealPosition, RevealRow, type RevealRowClassNames, type RevealRowElement, type RevealRowHandle, type RevealRowProps, getRevealFromScroll, getScrollClosed };
|
package/dist/index.d.ts
CHANGED
|
@@ -18,6 +18,18 @@ declare const REVEAL_HANDLE_POSITION: {
|
|
|
18
18
|
readonly end: "end";
|
|
19
19
|
};
|
|
20
20
|
type RevealHandlePosition = (typeof REVEAL_HANDLE_POSITION)[keyof typeof REVEAL_HANDLE_POSITION];
|
|
21
|
+
declare const REVEAL_ROW_ELEMENTS: {
|
|
22
|
+
readonly div: "div";
|
|
23
|
+
readonly section: "section";
|
|
24
|
+
readonly article: "article";
|
|
25
|
+
readonly main: "main";
|
|
26
|
+
readonly aside: "aside";
|
|
27
|
+
readonly header: "header";
|
|
28
|
+
readonly footer: "footer";
|
|
29
|
+
readonly nav: "nav";
|
|
30
|
+
readonly li: "li";
|
|
31
|
+
};
|
|
32
|
+
type RevealRowElement = (typeof REVEAL_ROW_ELEMENTS)[keyof typeof REVEAL_ROW_ELEMENTS];
|
|
21
33
|
declare const ANIMATION_PRESET: {
|
|
22
34
|
readonly none: "none";
|
|
23
35
|
readonly quick: "quick";
|
|
@@ -51,12 +63,25 @@ type RevealRowProps = {
|
|
|
51
63
|
* Trailing action column (e.g. add). Omitted in `left` mode.
|
|
52
64
|
*/
|
|
53
65
|
right?: ReactNode;
|
|
66
|
+
/**
|
|
67
|
+
* The HTML element to use for the root container.
|
|
68
|
+
* @default 'div'
|
|
69
|
+
*/
|
|
70
|
+
as?: RevealRowElement;
|
|
54
71
|
/**
|
|
55
72
|
* If both `left` and `right` are set, defaults to `both`. If only one side,
|
|
56
73
|
* mode is derived unless overridden.
|
|
57
74
|
*/
|
|
58
75
|
mode?: RevealMode;
|
|
76
|
+
/**
|
|
77
|
+
* Fixed width (px) of the left action column. Omit to size the column to
|
|
78
|
+
* its content with an 88px floor (`minmax(88px, max-content)`).
|
|
79
|
+
*/
|
|
59
80
|
actionWidthLeft?: number;
|
|
81
|
+
/**
|
|
82
|
+
* Fixed width (px) of the right action column. Omit to size the column to
|
|
83
|
+
* its content with an 88px floor (`minmax(88px, max-content)`).
|
|
84
|
+
*/
|
|
60
85
|
actionWidthRight?: number;
|
|
61
86
|
classNames?: RevealRowClassNames;
|
|
62
87
|
/** @default true */
|
|
@@ -73,7 +98,7 @@ type RevealRowProps = {
|
|
|
73
98
|
handleAriaLabel?: string;
|
|
74
99
|
/** Fires when the settled position changes. */
|
|
75
100
|
onRevealChange?: (position: RevealPosition) => void;
|
|
76
|
-
onScroll?: (event: UIEvent<
|
|
101
|
+
onScroll?: (event: UIEvent<HTMLElement>) => void;
|
|
77
102
|
/** Resets to closed; default true. */
|
|
78
103
|
resetWhenDisabled?: boolean;
|
|
79
104
|
disabled?: boolean;
|
|
@@ -106,4 +131,4 @@ declare function getScrollClosed(wL: number, _wR: number, _maxScroll: number, mo
|
|
|
106
131
|
|
|
107
132
|
declare const RevealRow: react.ForwardRefExoticComponent<RevealRowProps & react.RefAttributes<RevealRowHandle>>;
|
|
108
133
|
|
|
109
|
-
export { ANIMATION_PRESET, ANIMATION_PRESETS, type AnimationConfig, type AnimationPreset, REVEAL_HANDLE_POSITION, REVEAL_MODE, REVEAL_POSITION, type RevealHandlePosition, type RevealMode, type RevealPosition, RevealRow, type RevealRowClassNames, type RevealRowHandle, type RevealRowProps, getRevealFromScroll, getScrollClosed };
|
|
134
|
+
export { ANIMATION_PRESET, ANIMATION_PRESETS, type AnimationConfig, type AnimationPreset, REVEAL_HANDLE_POSITION, REVEAL_MODE, REVEAL_POSITION, REVEAL_ROW_ELEMENTS, type RevealHandlePosition, type RevealMode, type RevealPosition, RevealRow, type RevealRowClassNames, type RevealRowElement, type RevealRowHandle, type RevealRowProps, getRevealFromScroll, getScrollClosed };
|