From dd314d975550144d3a6cae33dac374d43b1dc65f Mon Sep 17 00:00:00 2001 From: Daniel Morse Date: Fri, 25 Oct 2019 16:12:29 -0400 Subject: [PATCH] feat: rework button slotted content so that empty spans are not output, remove 'is-empty' CSS --- packages/components/bolt-button/src/button.js | 98 ++++++++++--------- .../components/bolt-button/src/button.scss | 16 +-- .../components/bolt-button/src/button.twig | 2 - 3 files changed, 58 insertions(+), 58 deletions(-) diff --git a/packages/components/bolt-button/src/button.js b/packages/components/bolt-button/src/button.js index ce2edc3599..ed8ffa55fa 100644 --- a/packages/components/bolt-button/src/button.js +++ b/packages/components/bolt-button/src/button.js @@ -71,57 +71,65 @@ class BoltButton extends BoltAction { let buttonElement = null; const innerSlots = () => { - const itemClasses = cx('c-bolt-button__item', { - 'is-empty': 'default' in this.slots === false, - }); - const beforeIconClasses = cx('c-bolt-button__icon', { - 'is-empty': 'before' in this.slots === false, - }); - const afterIconClasses = cx('c-bolt-button__icon', { - 'is-empty': 'after' in this.slots === false, - }); + const itemClasses = cx('c-bolt-button__item'); + const iconClasses = cx('c-bolt-button__icon'); + const sizerClasses = cx('c-bolt-button__icon-sizer'); if (bolt.isServer) { return html` - ${'before' in this.slots ? this.slot('before') : ''}${'default' in this.slots - ? this.slot('default') - : ''}${'after' in this.slots ? this.slot('after') : ''} + ${'before' in this.slots + ? html` + ${this.slot('before')} + ` + : ''}${'default' in this.slots + ? html` + ${this.slot('default')} + ` + : ''}${'after' in this.slots + ? html` + ${this.slot('after')} + ` + : ''} `; } else { return html` - ${'before' in this.slots - ? this.slot('before') - : html` - - `}${'default' in this.slots - ? this.slot('default') - : html` - - `}${'after' in this.slots - ? this.slot('after') - : html` - - `} + ${'before' in this.slots + ? html` + ${this.slot('before')} + ` + : html` + + `}${'default' in this.slots + ? html` + ${this.slot('default')} + ` + : html` + + `}${'after' in this.slots + ? html` + ${this.slot('after')} + ` + : html` + + `} `; } }; diff --git a/packages/components/bolt-button/src/button.scss b/packages/components/bolt-button/src/button.scss index ad16f595b0..54bef608a1 100644 --- a/packages/components/bolt-button/src/button.scss +++ b/packages/components/bolt-button/src/button.scss @@ -245,11 +245,7 @@ bolt-button[width='full@small'], /** * Icon and text spacing and display */ -.c-bolt-button__icon.is-empty { - display: none; -} - -.c-bolt-button__icon:not(.is-empty) { +.c-bolt-button__icon { display: flex; } @@ -259,19 +255,17 @@ bolt-button[width='full@small'], text-align: start; } -.c-bolt-button__icon:not(.is-empty) { - .c-bolt-button__icon-sizer { - display: flex; // This fixes the spacing issue caused by bolt-icon defined as inline-block. - } +.c-bolt-button__icon-sizer { + display: flex; // This fixes the spacing issue caused by bolt-icon defined as inline-block. } // Spacing only applies when there are BOTH text and icon .c-bolt-button:not(.c-bolt-button--icon-only) { - .c-bolt-button__item + .c-bolt-button__icon:not(.is-empty) { + .c-bolt-button__item + .c-bolt-button__icon { @include bolt-margin-left(xxsmall); } - .c-bolt-button__icon:not(.is-empty) + .c-bolt-button__item { + .c-bolt-button__icon + .c-bolt-button__item { @include bolt-margin-left(xxsmall); } } diff --git a/packages/components/bolt-button/src/button.twig b/packages/components/bolt-button/src/button.twig index aa46bb7cc7..0a294fab4b 100644 --- a/packages/components/bolt-button/src/button.twig +++ b/packages/components/bolt-button/src/button.twig @@ -130,8 +130,6 @@ Sort classes passed in via attributes into two groups: }) %} {% include "@bolt-components-icon/icon.twig" with icon only %} - {% else %} - {% endif %} {% endmacro %}