mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-14 18:01:06 +00:00
Fixes https://github.com/carbon-design-system/carbon-icons-svelte/issues/207 `carbon-icons-svelte@13` and `carbon-pictograms-svelte@13` now only support TypeScript for Svelte 4/5. The new `Component` type is incompatible with the `icon` prop in `carbon-components-svelte`, causing a type error with Svelte 5, as `typeof SvelteComponent` doesn't match the new `Component` type. Since `Component` isn't available in Svelte 3/4, this PR changes the `icon` prop type to `any` for compatibility across Svelte 3, 4, and 5.
89 lines
2.1 KiB
Svelte
89 lines
2.1 KiB
Svelte
<script>
|
|
/**
|
|
* Specify the size of the link
|
|
* @type {"sm" | "lg"}
|
|
*/
|
|
export let size = undefined;
|
|
|
|
/**
|
|
* Specify the href value
|
|
* @type {string}
|
|
*/
|
|
export let href = undefined;
|
|
|
|
/** Set to `true` to use the inline variant */
|
|
export let inline = false;
|
|
|
|
/**
|
|
* Specify the icon to render
|
|
* `inline` must be `false`
|
|
* @type {any}
|
|
*/
|
|
export let icon = undefined;
|
|
|
|
/** Set to `true` to disable the checkbox */
|
|
export let disabled = false;
|
|
|
|
/** Set to `true` to allow visited styles */
|
|
export let visited = false;
|
|
|
|
/** Obtain a reference to the top-level HTML element */
|
|
export let ref = null;
|
|
</script>
|
|
|
|
<!-- svelte-ignore a11y-mouse-events-have-key-events -->
|
|
<!-- svelte-ignore a11y-missing-attribute -->
|
|
<!-- svelte-ignore a11y-no-redundant-roles -->
|
|
<!-- svelte-ignore a11y-interactive-supports-focus -->
|
|
{#if disabled}
|
|
<!-- svelte-ignore a11y-no-noninteractive-element-interactions -->
|
|
<a
|
|
bind:this={ref}
|
|
role="link"
|
|
aria-disabled="true"
|
|
class:bx--link={true}
|
|
class:bx--link--disabled={disabled}
|
|
class:bx--link--inline={inline}
|
|
class:bx--link--visited={visited}
|
|
{...$$restProps}
|
|
on:click
|
|
on:mouseover
|
|
on:mouseenter
|
|
on:mouseleave
|
|
>
|
|
<slot />
|
|
{#if !inline && ($$slots.icon || icon)}
|
|
<div class:bx--link__icon={true}>
|
|
<slot name="icon">
|
|
<svelte:component this={icon} />
|
|
</slot>
|
|
</div>
|
|
{/if}
|
|
</a>
|
|
{:else}
|
|
<a
|
|
bind:this={ref}
|
|
class:bx--link={true}
|
|
class:bx--link--disabled={disabled}
|
|
class:bx--link--inline={inline}
|
|
class:bx--link--visited={visited}
|
|
class:bx--link--sm={size === "sm"}
|
|
class:bx--link--lg={size === "lg"}
|
|
rel={$$restProps.target === "_blank" ? "noopener noreferrer" : undefined}
|
|
{href}
|
|
{...$$restProps}
|
|
on:click
|
|
on:mouseover
|
|
on:mouseenter
|
|
on:mouseleave
|
|
>
|
|
<slot />
|
|
{#if !inline && ($$slots.icon || icon)}
|
|
<div class:bx--link__icon={true}>
|
|
<slot name="icon">
|
|
<svelte:component this={icon} />
|
|
</slot>
|
|
</div>
|
|
{/if}
|
|
</a>
|
|
{/if}
|