@enigmax/primitives 0.11.0 → 0.11.1
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/dist/{chunk-L4KA342C.js → chunk-KTW4GO43.js} +3 -2
- package/dist/next/index.js +2 -2
- package/dist/react/index.d.ts +11 -1
- package/dist/react/index.js +1 -1
- package/dist/react-router/index.js +2 -2
- package/package.json +1 -1
- package/src/react/button.tsx +13 -1
- package/src/react/use-button.ts +4 -2
|
@@ -172,7 +172,7 @@ function useButton(options = {}) {
|
|
|
172
172
|
event.preventDefault();
|
|
173
173
|
return;
|
|
174
174
|
}
|
|
175
|
-
void instance.press();
|
|
175
|
+
void instance.press(event);
|
|
176
176
|
},
|
|
177
177
|
"aria-disabled": !state.available,
|
|
178
178
|
"aria-busy": state.loading,
|
|
@@ -202,11 +202,12 @@ var Button = forwardRef(function Button2({
|
|
|
202
202
|
cooldown,
|
|
203
203
|
shortcut,
|
|
204
204
|
onPress,
|
|
205
|
+
onClick,
|
|
205
206
|
onChange,
|
|
206
207
|
type = "button",
|
|
207
208
|
...rest
|
|
208
209
|
}, ref) {
|
|
209
|
-
const button = useButton({ href, disabled, loading, cooldown, shortcut, onPress, onChange });
|
|
210
|
+
const button = useButton({ href, disabled, loading, cooldown, shortcut, onPress: onPress ?? onClick, onChange });
|
|
210
211
|
const state = button;
|
|
211
212
|
const Tag = as ?? (state.element === "a" ? getLinkComponent() : "button");
|
|
212
213
|
const native = Tag === "button" ? { type } : {};
|
package/dist/next/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { Button } from '../chunk-
|
|
3
|
-
export { Input, PasswordStrength, getLinkComponent, setLinkComponent, useButton, useInput, useMarquee, useSearch } from '../chunk-
|
|
2
|
+
import { Button } from '../chunk-KTW4GO43.js';
|
|
3
|
+
export { Input, PasswordStrength, getLinkComponent, setLinkComponent, useButton, useInput, useMarquee, useSearch } from '../chunk-KTW4GO43.js';
|
|
4
4
|
export { estimatePasswordStrength, generatePassword } from '../chunk-42Y7OOJM.js';
|
|
5
5
|
import '../chunk-UZFEEFMF.js';
|
|
6
6
|
import Link from 'next/link';
|
package/dist/react/index.d.ts
CHANGED
|
@@ -18,6 +18,16 @@ export { F as FuseConstructor } from '../search-CsO3L1Lw.js';
|
|
|
18
18
|
* ordinary one means writing the same six lines at every call site, which is how they drift.
|
|
19
19
|
*/
|
|
20
20
|
interface ButtonProps extends ButtonOptions, Omit<ComponentPropsWithoutRef<"button">, "onClick" | "onChange" | "children" | "type"> {
|
|
21
|
+
/**
|
|
22
|
+
* What to run when it is pressed. The same thing as `onPress`, under the name React
|
|
23
|
+
* already uses - write whichever reads better.
|
|
24
|
+
*
|
|
25
|
+
* It is an ALIAS, not a second handler: the component owns the element's real onClick,
|
|
26
|
+
* because that is where a press is refused while the button is loading, disabled or
|
|
27
|
+
* cooling down. Passing one through would replace that and silently take the behaviour
|
|
28
|
+
* with it. Returning a promise drives `loading` for its duration, same as `onPress`.
|
|
29
|
+
*/
|
|
30
|
+
onClick?: ButtonOptions["onPress"];
|
|
21
31
|
/**
|
|
22
32
|
* Override what to render. You rarely need it: an href already renders whatever
|
|
23
33
|
* `setLinkComponent` registered - your router's Link - and a button otherwise.
|
|
@@ -133,7 +143,7 @@ declare function useSearch<T>(options?: SearchOptions<T>): UseSearchResult<T>;
|
|
|
133
143
|
interface UseButtonResult extends ButtonState {
|
|
134
144
|
/** Spread onto the element named by `element`. */
|
|
135
145
|
props: {
|
|
136
|
-
onClick: (event: {
|
|
146
|
+
onClick: (event: Event | {
|
|
137
147
|
preventDefault(): void;
|
|
138
148
|
}) => void;
|
|
139
149
|
"aria-disabled": boolean;
|
package/dist/react/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
export { Button, Input, PasswordStrength, getLinkComponent, setLinkComponent, useButton, useInput, useMarquee, useSearch } from '../chunk-
|
|
2
|
+
export { Button, Input, PasswordStrength, getLinkComponent, setLinkComponent, useButton, useInput, useMarquee, useSearch } from '../chunk-KTW4GO43.js';
|
|
3
3
|
export { estimatePasswordStrength, generatePassword } from '../chunk-42Y7OOJM.js';
|
|
4
4
|
import '../chunk-UZFEEFMF.js';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { Button } from '../chunk-
|
|
3
|
-
export { Input, PasswordStrength, getLinkComponent, setLinkComponent, useButton, useInput, useMarquee, useSearch } from '../chunk-
|
|
2
|
+
import { Button } from '../chunk-KTW4GO43.js';
|
|
3
|
+
export { Input, PasswordStrength, getLinkComponent, setLinkComponent, useButton, useInput, useMarquee, useSearch } from '../chunk-KTW4GO43.js';
|
|
4
4
|
export { estimatePasswordStrength, generatePassword } from '../chunk-42Y7OOJM.js';
|
|
5
5
|
import '../chunk-UZFEEFMF.js';
|
|
6
6
|
import { Link } from 'react-router';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@enigmax/primitives",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.1",
|
|
4
4
|
"description": "Headless interaction primitives: the behaviour, the timing and the accessibility of components like a draggable infinite marquee, with no styles of their own. Framework-agnostic core plus thin adapters.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
package/src/react/button.tsx
CHANGED
|
@@ -20,7 +20,18 @@ import { createElement, forwardRef, type ComponentPropsWithoutRef, type ElementT
|
|
|
20
20
|
|
|
21
21
|
// `onChange` is omitted from the DOM side because the primitive's own onChange - which
|
|
22
22
|
// reports the button's state - would otherwise clash with the form event of the same name.
|
|
23
|
+
// `onClick` is omitted and re-declared below, as an alias rather than a second handler.
|
|
23
24
|
export interface ButtonProps extends ButtonOptions, Omit<ComponentPropsWithoutRef<"button">, "onClick" | "onChange" | "children" | "type"> {
|
|
25
|
+
/**
|
|
26
|
+
* What to run when it is pressed. The same thing as `onPress`, under the name React
|
|
27
|
+
* already uses - write whichever reads better.
|
|
28
|
+
*
|
|
29
|
+
* It is an ALIAS, not a second handler: the component owns the element's real onClick,
|
|
30
|
+
* because that is where a press is refused while the button is loading, disabled or
|
|
31
|
+
* cooling down. Passing one through would replace that and silently take the behaviour
|
|
32
|
+
* with it. Returning a promise drives `loading` for its duration, same as `onPress`.
|
|
33
|
+
*/
|
|
34
|
+
onClick?: ButtonOptions["onPress"];
|
|
24
35
|
/**
|
|
25
36
|
* Override what to render. You rarely need it: an href already renders whatever
|
|
26
37
|
* `setLinkComponent` registered - your router's Link - and a button otherwise.
|
|
@@ -52,11 +63,12 @@ export const Button = forwardRef<HTMLElement, ButtonProps>(function Button({
|
|
|
52
63
|
cooldown,
|
|
53
64
|
shortcut,
|
|
54
65
|
onPress,
|
|
66
|
+
onClick,
|
|
55
67
|
onChange,
|
|
56
68
|
type = "button",
|
|
57
69
|
...rest
|
|
58
70
|
}, ref) {
|
|
59
|
-
const button = useButton({ href, disabled, loading, cooldown, shortcut, onPress, onChange });
|
|
71
|
+
const button = useButton({ href, disabled, loading, cooldown, shortcut, onPress: onPress ?? onClick, onChange });
|
|
60
72
|
const state: ButtonState = button;
|
|
61
73
|
|
|
62
74
|
// An href renders the registered link - next/link, react-router's, whatever was passed
|
package/src/react/use-button.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { createButton, type ButtonOptions, type ButtonState } from "@/core/butto
|
|
|
4
4
|
export interface UseButtonResult extends ButtonState {
|
|
5
5
|
/** Spread onto the element named by `element`. */
|
|
6
6
|
props: {
|
|
7
|
-
onClick: (event: { preventDefault(): void; }) => void;
|
|
7
|
+
onClick: (event: Event | { preventDefault(): void; }) => void;
|
|
8
8
|
"aria-disabled": boolean;
|
|
9
9
|
"aria-busy": boolean;
|
|
10
10
|
"data-loading"?: "";
|
|
@@ -76,7 +76,9 @@ export function useButton(options: ButtonOptions = {}): UseButtonResult {
|
|
|
76
76
|
// An unavailable link still receives clicks - aria-disabled is advisory -
|
|
77
77
|
// so the press is refused here rather than relying on the attribute.
|
|
78
78
|
if (!state.available) { event.preventDefault(); return; }
|
|
79
|
-
|
|
79
|
+
// Passed through: a handler that wants to stop propagation or read the
|
|
80
|
+
// target had no way to get at it while press() was called bare.
|
|
81
|
+
void instance.press(event as Event);
|
|
80
82
|
},
|
|
81
83
|
"aria-disabled": !state.available,
|
|
82
84
|
"aria-busy": state.loading,
|