-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Button.mjs
50 lines (42 loc) · 1.31 KB
/
Button.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// @ts-check
import classNameProp from "class-name-prop";
import React from "react";
/** CSS dependency URLs for the React component {@linkcode Button}. */
export const css = new Set([new URL("./Button.css", import.meta.url).href]);
/**
* React component for a {@link HTMLButtonElement button}.
*
* It automatically has the
* [`disabled`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button#attr-disabled)
* attribute until mounted, to prevent a default action from happening if the
* user clicks quickly after SSR.
*
* For an on-page interaction, typically in a form.
*
* Links are semantically different and have separate, distinctly styled
* components.
*/
const Button = React.forwardRef(
(
/**
* @type {React.ComponentPropsWithoutRef<"button">
* & { [dataAttribute: `data-${string}`]: unknown }}
*/
{ disabled, className, ...props },
/** @type {React.ForwardedRef<HTMLButtonElement>} */
ref
) => {
const [isMounted, setIsMounted] = React.useState(false);
React.useEffect(() => {
setIsMounted(true);
}, []);
return React.createElement("button", {
className: classNameProp("daui-Button", className),
disabled: disabled || !isMounted,
...props,
ref,
});
}
);
Button.displayName = "Button";
export default Button;