feat(button): infer hasIconOnly using $$slots API

- requires Svelte version >=3.25
This commit is contained in:
Eric Liu 2021-01-22 16:13:22 -08:00
commit 74d48e78cd
2 changed files with 2 additions and 5 deletions

View file

@ -1,7 +1,3 @@
---
description: High-level description
---
<script> <script>
import { Button } from "carbon-components-svelte"; import { Button } from "carbon-components-svelte";
import Add16 from "carbon-icons-svelte/lib/Add16"; import Add16 from "carbon-icons-svelte/lib/Add16";
@ -48,7 +44,7 @@ Set `hasIconOnly` to `true` to use the icon-only button variant.
The tooltip position and alignment can be controlled by the `tooltipPosition`, `tooltipAlignment` props, respectively. The tooltip position and alignment can be controlled by the `tooltipPosition`, `tooltipAlignment` props, respectively.
<Button hasIconOnly tooltipPosition="bottom" tooltipAlignment="center" iconDescription="Tooltip text" icon={Add16} /> <Button tooltipPosition="bottom" tooltipAlignment="center" iconDescription="Tooltip text" icon={Add16} />
### Link button ### Link button

View file

@ -80,6 +80,7 @@
$: if (ctx && ref) { $: if (ctx && ref) {
ctx.declareRef(ref); ctx.declareRef(ref);
} }
$: hasIconOnly = icon && !$$slots.default;
$: buttonProps = { $: buttonProps = {
role: "button", role: "button",
type: href && !disabled ? undefined : type, type: href && !disabled ? undefined : type,