This commit is contained in:
+27
@@ -0,0 +1,27 @@
|
||||
<script lang="ts">
|
||||
import type { ButtonRootProps } from "../types.js";
|
||||
|
||||
let {
|
||||
href,
|
||||
type,
|
||||
children,
|
||||
disabled = false,
|
||||
ref = $bindable(null),
|
||||
...restProps
|
||||
}: ButtonRootProps = $props();
|
||||
</script>
|
||||
|
||||
<svelte:element
|
||||
this={href ? "a" : "button"}
|
||||
data-button-root
|
||||
type={href ? undefined : type}
|
||||
href={href && !disabled ? href : undefined}
|
||||
disabled={href ? undefined : disabled}
|
||||
aria-disabled={href ? disabled : undefined}
|
||||
role={href && disabled ? "link" : undefined}
|
||||
tabindex={href && disabled ? -1 : 0}
|
||||
bind:this={ref}
|
||||
{...restProps}
|
||||
>
|
||||
{@render children?.()}
|
||||
</svelte:element>
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
import type { ButtonRootProps } from "../types.js";
|
||||
declare const Button: import("svelte").Component<ButtonRootProps, {}, "ref">;
|
||||
type Button = ReturnType<typeof Button>;
|
||||
export default Button;
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
export { default as Root } from "./components/button.svelte";
|
||||
export type { ButtonRootProps as RootProps } from "./types.js";
|
||||
+1
@@ -0,0 +1 @@
|
||||
export { default as Root } from "./components/button.svelte";
|
||||
+1
@@ -0,0 +1 @@
|
||||
export * as Button from "./exports.js";
|
||||
+1
@@ -0,0 +1 @@
|
||||
export * as Button from "./exports.js";
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
import type { HTMLAnchorAttributes, HTMLButtonAttributes } from "svelte/elements";
|
||||
import type { WithoutChildren } from "svelte-toolbelt";
|
||||
import type { WithChildren } from "../../shared/index.js";
|
||||
export type ButtonRootPropsWithoutHTML = WithChildren<{
|
||||
ref?: HTMLElement | null;
|
||||
}>;
|
||||
type AnchorElement = ButtonRootPropsWithoutHTML & WithoutChildren<Omit<HTMLAnchorAttributes, "href" | "type">> & {
|
||||
href: HTMLAnchorAttributes["href"];
|
||||
type?: never;
|
||||
disabled?: HTMLButtonAttributes["disabled"];
|
||||
};
|
||||
type ButtonElement = ButtonRootPropsWithoutHTML & WithoutChildren<Omit<HTMLButtonAttributes, "type" | "href">> & {
|
||||
type?: HTMLButtonAttributes["type"];
|
||||
href?: never;
|
||||
disabled?: HTMLButtonAttributes["disabled"];
|
||||
};
|
||||
export type ButtonRootProps = AnchorElement | ButtonElement;
|
||||
export {};
|
||||
+1
@@ -0,0 +1 @@
|
||||
export {};
|
||||
Reference in New Issue
Block a user