Files
WRNexusJS/packages/ui/components/button.wrn
T
2026-08-01 01:09:58 +05:30

168 lines
5.5 KiB
Plaintext

component Button {
outputs {
click(payload: { sourceEvent?: Event; [key: string]: string | number | boolean | null | object })
focus(payload: { sourceEvent?: Event; [key: string]: string | number | boolean | null | object })
blur(payload: { sourceEvent?: Event; [key: string]: string | number | boolean | null | object })
}
props {
label: string = "Button"
loadingLabel: string = "Loading…"
description: string = ""
as: string = ""
href: string = ""
target: string = ""
rel: string = ""
type: string = "button"
variant: string = "default"
color: string = "primary"
size: string = "default"
disabled: boolean = false
loading: boolean = false
pill: boolean = false
fullWidth: boolean = false
icon: string = ""
iconPosition: string = "start"
ariaLabel: string = ""
ariaPressed: string = ""
ariaExpanded: string = ""
ariaControls: string = ""
title: string = ""
autofocus: boolean = false
controlClass: string = ""
class: string = ""
}
view {
<span
class="wire-action {fullWidth ? 'w-full' : ''} {class}"
>
{#if as === "a" || (as === "" && href)}
<a
{...attrs}
href="{disabled || loading ? '' : href}"
target="{target}"
rel="{rel}"
title="{title}"
aria-label="{ariaLabel || ((size === 'icon' || size === 'icon-xs' || size === 'icon-sm' || size === 'icon-lg') ? label : '')}"
aria-disabled="{disabled || loading}"
aria-busy="{loading}"
aria-pressed="{ariaPressed}"
aria-expanded="{ariaExpanded}"
aria-controls="{ariaControls}"
tabindex="{disabled || loading ? '-1' : '0'}"
class="wire-btn wire-btn--variant-{variant} wire-btn--color-{color} wire-btn--size-{size} {pill ? 'wire-btn--pill' : ''} {description ? 'wire-btn--with-description' : ''} {fullWidth ? 'w-full' : ''} {controlClass}"
>
{#if loading}
<span
class="wire-spinner wire-spinner--inline"
aria-hidden="true"
>
</span>
{/if}
{#if icon && !loading && iconPosition === "start"}
<span
class="wire-btn__icon {icon}"
aria-hidden="true"
>
</span>
{/if}
<span
class="wire-btn__copy {(size === 'icon' || size === 'icon-xs' || size === 'icon-sm' || size === 'icon-lg') ? 'wire-visually-hidden' : ''}"
>
<span
class="wire-btn__label"
>
<slot>{loading ? loadingLabel : label}</slot>
</span>
{#if description && !loading}
<span
class="wire-btn__description"
>
{description}
</span>
{/if}
</span>
{#if icon && !loading && iconPosition === "end"}
<span
class="wire-btn__icon {icon}"
aria-hidden="true"
>
</span>
{/if}
{#if (size === "icon" || size === "icon-xs" || size === "icon-sm" || size === "icon-lg") && (ariaLabel || label)}
<span
class="wire-btn__tooltip"
role="tooltip"
aria-hidden="true"
>
{ariaLabel || label}
</span>
{/if}
</a>
{:else}
<button
{...attrs}
type="{type}"
title="{title}"
autofocus="{autofocus}"
disabled="{disabled || loading}"
aria-label="{ariaLabel || ((size === 'icon' || size === 'icon-xs' || size === 'icon-sm' || size === 'icon-lg') ? label : '')}"
aria-busy="{loading}"
aria-pressed="{ariaPressed}"
aria-expanded="{ariaExpanded}"
aria-controls="{ariaControls}"
class="wire-btn wire-btn--variant-{variant} wire-btn--color-{color} wire-btn--size-{size} {pill ? 'wire-btn--pill' : ''} {description ? 'wire-btn--with-description' : ''} {fullWidth ? 'w-full' : ''} {controlClass}"
>
{#if loading}
<span
class="wire-spinner wire-spinner--inline"
aria-hidden="true"
>
</span>
{/if}
{#if icon && !loading && iconPosition === "start"}
<span
class="wire-btn__icon {icon}"
aria-hidden="true"
>
</span>
{/if}
<span
class="wire-btn__copy {(size === 'icon' || size === 'icon-xs' || size === 'icon-sm' || size === 'icon-lg') ? 'wire-visually-hidden' : ''}"
>
<span
class="wire-btn__label"
>
<slot>{loading ? loadingLabel : label}</slot>
</span>
{#if description && !loading}
<span
class="wire-btn__description"
>
{description}
</span>
{/if}
</span>
{#if icon && !loading && iconPosition === "end"}
<span
class="wire-btn__icon {icon}"
aria-hidden="true"
>
</span>
{/if}
{#if (size === "icon" || size === "icon-xs" || size === "icon-sm" || size === "icon-lg") && (ariaLabel || label)}
<span
class="wire-btn__tooltip"
role="tooltip"
aria-hidden="true"
>
{ariaLabel || label}
</span>
{/if}
</button>
{/if}
</span>
}
}