@latte-macchiat-io/latte-vanilla-components 0.0.335 → 0.0.336
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/package.json
CHANGED
@@ -1,9 +1,12 @@
|
|
1
1
|
import { clsx } from 'clsx';
|
2
2
|
|
3
3
|
import { buttonRecipe, type ButtonVariants } from './styles.css';
|
4
|
+
import { AllowedButton } from './types';
|
4
5
|
|
5
|
-
export type ButtonProps = React.HTMLAttributes<HTMLButtonElement> &
|
6
|
+
export type ButtonProps = React.HTMLAttributes<HTMLButtonElement | HTMLAnchorElement> &
|
6
7
|
ButtonVariants & {
|
8
|
+
href?: string;
|
9
|
+
as: AllowedButton;
|
7
10
|
isPending?: boolean;
|
8
11
|
isDisabled?: boolean;
|
9
12
|
translation?: {
|
@@ -16,14 +19,26 @@ export const Button = ({
|
|
16
19
|
style,
|
17
20
|
variant,
|
18
21
|
onClick,
|
22
|
+
as = 'a',
|
23
|
+
href = '',
|
19
24
|
children,
|
20
25
|
fullWidth,
|
21
26
|
className,
|
22
27
|
isPending = false,
|
23
28
|
isDisabled = false,
|
24
29
|
translation = { isPendingLabel: 'Loading...' },
|
25
|
-
}: ButtonProps) =>
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
+
}: ButtonProps) => {
|
31
|
+
if (as === 'a') {
|
32
|
+
return (
|
33
|
+
<a href={href} className={clsx(buttonRecipe({ variant, style, size, fullWidth }), className)}>
|
34
|
+
{children}
|
35
|
+
</a>
|
36
|
+
);
|
37
|
+
}
|
38
|
+
|
39
|
+
return (
|
40
|
+
<button onClick={onClick} disabled={isDisabled || isPending} className={clsx(buttonRecipe({ variant, style, size, fullWidth }), className)}>
|
41
|
+
{isPending ? translation.isPendingLabel : children}
|
42
|
+
</button>
|
43
|
+
);
|
44
|
+
};
|
@@ -0,0 +1 @@
|
|
1
|
+
export type AllowedButton = 'button' | 'a';
|