diff --git a/src/components/Button/Button.svelte b/src/components/Button/Button.svelte index 1756e32b..d82fa35a 100644 --- a/src/components/Button/Button.svelte +++ b/src/components/Button/Button.svelte @@ -4,7 +4,6 @@ export let as = undefined; export let disabled = false; export let size = 'default'; - export let small = false; export let kind = 'primary'; export let href = undefined; export let tabindex = '0'; @@ -18,79 +17,66 @@ import { getContext } from 'svelte'; import { cx } from '../../lib'; - const hasIconOnly = !!icon && !$$props.$$slots; const ctx = getContext('ComposedModal'); let buttonRef = undefined; $: if (ctx && buttonRef) { - ctx.declareRef({ name: 'buttonRef', ref: buttonRef }); + ctx.declareRef(buttonRef); } - $: _class = cx( - '--btn', - size === 'field' && '--btn--field', - (size === 'small' || small) && '--btn--sm', - kind === 'primary' && '--btn--primary', - kind === 'danger' && '--btn--danger', - kind === 'secondary' && '--btn--secondary', - kind === 'ghost' && '--btn--ghost', - kind === 'danger--primary' && '--btn--danger--primary', - kind === 'tertiary' && '--btn--tertiary', - disabled && '--btn--disabled', - hasIconOnly && '--btn--icon-only', - hasIconOnly && '--tooltip__trigger', - hasIconOnly && '--tooltip--a11y', - hasIconOnly && tooltipPosition && `--tooltip--${tooltipPosition}`, - hasIconOnly && tooltipAlignment && `--tooltip--align-${tooltipAlignment}`, - className - ); + $: hasIconOnly = !!icon && !$$props.$$slots; $: buttonProps = { role: 'button', type: href && !disabled ? undefined : type, tabindex, - class: _class, disabled, href, - style + style, + class: cx( + '--btn', + size === 'field' && '--btn--field', + size === 'small' && '--btn--sm', + kind && `--btn--${kind}`, + disabled && '--btn--disabled', + hasIconOnly && '--btn--icon-only', + hasIconOnly && '--tooltip__trigger', + hasIconOnly && '--tooltip--a11y', + hasIconOnly && tooltipPosition && `--tooltip--${tooltipPosition}`, + hasIconOnly && tooltipAlignment && `--tooltip--align-${tooltipAlignment}`, + className + ) }; {#if as} +{:else if href && !disabled} + + + {#if hasIconOnly} + {iconDescription} + {/if} + + {#if icon} + {:else} - {#if href && !disabled} - - {#if hasIconOnly} - {iconDescription} - {/if} - - {#if icon} - - {:else} - - {/if} + {/if} diff --git a/src/components/ComposedModal/ComposedModal.svelte b/src/components/ComposedModal/ComposedModal.svelte index d6a0f9c5..ad30981e 100644 --- a/src/components/ComposedModal/ComposedModal.svelte +++ b/src/components/ComposedModal/ComposedModal.svelte @@ -13,7 +13,8 @@ import { cx } from '../../lib'; const dispatch = createEventDispatcher(); - const refs = {}; + + let buttonRef = undefined; let outerModal = undefined; let innerModal = undefined; @@ -24,8 +25,8 @@ submit: () => { dispatch('submit'); }, - declareRef: ({ name, ref }) => { - refs[name] = ref; + declareRef: ref => { + buttonRef = ref; } }); @@ -38,22 +39,17 @@ return focusElement.focus(); } - if (refs.buttonRef) { - refs.buttonRef.focus(); + if (buttonRef) { + buttonRef.focus(); } } - const _containerClass = cx( - '--modal-container', - size && `--modal-container--${size}`, - containerClass - ); $: didOpen = open; - $: _class = cx('--modal', open && 'is-visible', danger && '--modal--danger', className); - $: if (innerModal) { - focus(innerModal); - } $: { + if (innerModal) { + focus(innerModal); + } + if (open) { document.body.classList.add(cx('--body--with-modal-open')); } else { @@ -64,10 +60,10 @@