-
Notifications
You must be signed in to change notification settings - Fork 328
Expand file tree
/
Copy pathButton.svelte
More file actions
74 lines (66 loc) · 2.03 KB
/
Copy pathButton.svelte
File metadata and controls
74 lines (66 loc) · 2.03 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<script lang="ts">
import clsx from "clsx";
import { Spinner } from "$lib";
import type { ButtonProps } from "$lib";
import { getTheme } from "$lib/theme/themeUtils";
import { button } from "./theme";
import { getButtonGroupContext } from "$lib/context";
const groupCtx = getButtonGroupContext();
const group = groupCtx?.size;
const ctxDisabled = groupCtx?.disabled;
let {
children,
pill,
outline = false,
size = "md",
color,
shadow = false,
tag = "button",
disabled,
loading = false,
spinnerProps = { size: "4" },
class: className,
...restProps
}: ButtonProps = $props();
const theme = $derived(getTheme("button"));
let actualSize = $derived(group ? "sm" : size);
let actualColor = $derived(color ?? (group ? (outline ? "dark" : "alternative") : "primary"));
let isDisabled = $derived(Boolean(ctxDisabled) || Boolean(disabled) || loading);
const { base, outline: outline_, shadow: shadow_, spinner } = $derived(button({ color: actualColor, size: actualSize, disabled: isDisabled, pill, group: !!group }));
let btnCls = $derived(base({ class: clsx(outline && outline_(), shadow && shadow_(), theme?.base, className) }));
</script>
{#if restProps.href !== undefined}
<a {...restProps} class={btnCls}>
{@render children?.()}
</a>
{:else if tag === "button"}
<button type="button" {...restProps} class={btnCls} disabled={isDisabled}>
{@render children?.()}
{#if loading}
<Spinner {...spinnerProps} class={spinner()} />
{/if}
</button>
{:else}
<svelte:element this={tag} {...restProps} class={btnCls}>
{@render children?.()}
</svelte:element>
{/if}
<!--
@component
[Go to docs](https://flowbite-svelte.com/)
## Type
[ButtonProps](https://github.com/themesberg/flowbite-svelte/blob/main/src/lib/types.ts#L344)
## Props
@prop children
@prop pill
@prop outline = false
@prop size = "md"
@prop color
@prop shadow = false
@prop tag = "button"
@prop disabled
@prop loading = false
@prop spinnerProps = { size: "4" }
@prop class: className
@prop ...restProps
-->