Skip to content

Commit

Permalink
fix(sbb-button): remove gap for hidden icons in icon slot (#2526)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeripeierSBB authored Mar 27, 2024
1 parent 6fbf085 commit 433c57c
Show file tree
Hide file tree
Showing 27 changed files with 86 additions and 107 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,8 @@ snapshots["sbb-button-link renders a sbb-button-link without icon ShadowDom"] =
tabindex="-1"
target="_blank"
>
<span class="sbb-button__icon">
<slot name="icon">
</slot>
</span>
<slot name="icon">
</slot>
<span class="sbb-button__label">
<slot>
</slot>
Expand Down Expand Up @@ -101,10 +99,8 @@ snapshots["sbb-button-link renders a disabled sbb-button-link with slotted icon
role="presentation"
tabindex="-1"
>
<span class="sbb-button__icon">
<slot name="icon">
</slot>
</span>
<slot name="icon">
</slot>
<span class="sbb-button__label">
<slot>
</slot>
Expand Down
2 changes: 2 additions & 0 deletions src/components/button/button-link/button-link.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
primaryNegativeActive,
primaryNegativeDisabled,
sizeM,
withHiddenSlottedIcon,
withSlottedIcon,
} from '../common/common-stories';

Expand Down Expand Up @@ -49,6 +50,7 @@ export const Active: StoryObj = primaryActive;
export const NegativeActive: StoryObj = primaryNegativeActive;
export const FocusVisible: StoryObj = primaryFocusVisible;
export const LoadingIndicator: StoryObj = loadingIndicator;
export const WithHiddenSlottedIcon: StoryObj = withHiddenSlottedIcon;

const meta: Meta = {
args: defaultArgs,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@ snapshots["sbb-button-static renders a sbb-button-static without icon Dom"] =

snapshots["sbb-button-static renders a sbb-button-static without icon ShadowDom"] =
`<span class="sbb-action-base sbb-button-static">
<span class="sbb-button__icon">
<slot name="icon">
</slot>
</span>
<slot name="icon">
</slot>
<span class="sbb-button__label">
<slot>
</slot>
Expand Down Expand Up @@ -53,10 +51,8 @@ snapshots["sbb-button-static renders a sbb-button-static with slotted icon Dom"]

snapshots["sbb-button-static renders a sbb-button-static with slotted icon ShadowDom"] =
`<span class="sbb-action-base sbb-button-static">
<span class="sbb-button__icon">
<slot name="icon">
</slot>
</span>
<slot name="icon">
</slot>
<span class="sbb-button__label">
<slot>
</slot>
Expand Down
2 changes: 2 additions & 0 deletions src/components/button/button-static/button-static.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
primaryNegativeDisabled,
sizeM,
withSlottedIcon,
withHiddenSlottedIcon,
} from '../common/common-stories';

import readme from './readme.md?raw';
Expand Down Expand Up @@ -61,6 +62,7 @@ export const Active: StoryObj = primaryActive;
export const NegativeActive: StoryObj = primaryNegativeActive;
export const FocusVisible: StoryObj = primaryFocusVisible;
export const LoadingIndicator: StoryObj = loadingIndicator;
export const WithHiddenSlottedIcon: StoryObj = withHiddenSlottedIcon;

const meta: Meta = {
args: defaultArgs,
Expand Down
12 changes: 4 additions & 8 deletions src/components/button/button/__snapshots__/button.spec.snap.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,8 @@ snapshots["sbb-button renders a sbb-button without icon Dom"] =

snapshots["sbb-button renders a sbb-button without icon ShadowDom"] =
`<span class="sbb-action-base sbb-button">
<span class="sbb-button__icon">
<slot name="icon">
</slot>
</span>
<slot name="icon">
</slot>
<span class="sbb-button__label">
<slot>
</slot>
Expand Down Expand Up @@ -63,10 +61,8 @@ snapshots["sbb-button renders a sbb-button with slotted icon Dom"] =

snapshots["sbb-button renders a sbb-button with slotted icon ShadowDom"] =
`<span class="sbb-action-base sbb-button">
<span class="sbb-button__icon">
<slot name="icon">
</slot>
</span>
<slot name="icon">
</slot>
<span class="sbb-button__label">
<slot>
</slot>
Expand Down
2 changes: 2 additions & 0 deletions src/components/button/button/button.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
primaryNegativeActive,
primaryNegativeDisabled,
sizeM,
withHiddenSlottedIcon,
withSlottedIcon,
} from '../common/common-stories';

Expand Down Expand Up @@ -51,6 +52,7 @@ export const NegativeActive: StoryObj = primaryNegativeActive;
export const FocusVisible: StoryObj = primaryFocusVisible;
export const LoadingIndicator: StoryObj = loadingIndicator;
export const RequestSubmit: StoryObj = requestSubmit;
export const WithHiddenSlottedIcon: StoryObj = withHiddenSlottedIcon;

const meta: Meta = {
args: defaultArgs,
Expand Down
11 changes: 2 additions & 9 deletions src/components/button/common/button-common.scss
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,8 @@ $icon-only: ':where([data-slot-names~=icon], [icon-name]):not([data-slot-names~=
}

.sbb-button__label,
.sbb-button__icon {
::slotted([slot='icon']),
sbb-icon {
transition: transform var(--sbb-button-transition-duration)
var(--sbb-button-transition-easing-function);
transform: translateY(var(--sbb-button-translate-y-content-hover, #{sbb.px-to-rem-build(0)}));
Expand All @@ -210,11 +211,3 @@ $icon-only: ':where([data-slot-names~=icon], [icon-name]):not([data-slot-names~=
display: none;
}
}

.sbb-button__icon {
display: flex;

:host(:not([data-slot-names~='icon'], [icon-name])) & {
display: none;
}
}
2 changes: 1 addition & 1 deletion src/components/button/common/button-common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export const SbbButtonCommonElementMixin = <T extends AbstractConstructor<SbbAct

protected override renderTemplate(): TemplateResult {
return html`
<span class="sbb-button__icon"> ${super.renderIconSlot()} </span>
${super.renderIconSlot()}
<span class="sbb-button__label">
<slot></slot>
</span>
Expand Down
11 changes: 10 additions & 1 deletion src/components/button/common/common-stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,12 @@ const IconSlotTemplate = ({
tag,
text,
'icon-name': iconName,
hiddenIcon,
...args
}: Args): TemplateResult => html`
<${unsafeStatic(tag)} ${sbbSpread(args)}>
${text}
<sbb-icon slot="icon" name=${iconName}></sbb-icon>
<sbb-icon slot="icon" name=${iconName} style=${hiddenIcon ? 'display: none;' : ''} ></sbb-icon>
</${unsafeStatic(tag)}>
`;

Expand Down Expand Up @@ -226,6 +227,14 @@ export const loadingIndicator: StoryObj = {
args: { disabled: true },
};

export const withHiddenSlottedIcon: StoryObj = {
render: IconSlotTemplate,
args: {
hiddenIcon: true,
'icon-name': 'chevron-small-right-small',
},
};

export const commonDecorators = [
(story: () => WebComponentsRenderer['storyResult'], context: StoryContext) => html`
<div
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,8 @@ snapshots["sbb-secondary-button-link renders a sbb-secondary-button-link without
tabindex="-1"
target="_blank"
>
<span class="sbb-button__icon">
<slot name="icon">
</slot>
</span>
<slot name="icon">
</slot>
<span class="sbb-button__label">
<slot>
</slot>
Expand Down Expand Up @@ -101,10 +99,8 @@ snapshots["sbb-secondary-button-link renders a disabled sbb-secondary-button-lin
role="presentation"
tabindex="-1"
>
<span class="sbb-button__icon">
<slot name="icon">
</slot>
</span>
<slot name="icon">
</slot>
<span class="sbb-button__label">
<slot>
</slot>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
primaryNegativeActive,
primaryNegativeDisabled,
sizeM,
withHiddenSlottedIcon,
withSlottedIcon,
} from '../common/common-stories';

Expand Down Expand Up @@ -49,6 +50,7 @@ export const Active: StoryObj = primaryActive;
export const NegativeActive: StoryObj = primaryNegativeActive;
export const FocusVisible: StoryObj = primaryFocusVisible;
export const LoadingIndicator: StoryObj = loadingIndicator;
export const WithHiddenSlottedIcon: StoryObj = withHiddenSlottedIcon;

const meta: Meta = {
args: defaultArgs,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@ snapshots["sbb-secondary-button-static renders a sbb-secondary-button-static wit

snapshots["sbb-secondary-button-static renders a sbb-secondary-button-static without icon ShadowDom"] =
`<span class="sbb-action-base sbb-secondary-button-static">
<span class="sbb-button__icon">
<slot name="icon">
</slot>
</span>
<slot name="icon">
</slot>
<span class="sbb-button__label">
<slot>
</slot>
Expand Down Expand Up @@ -53,10 +51,8 @@ snapshots["sbb-secondary-button-static renders a sbb-secondary-button-static wit

snapshots["sbb-secondary-button-static renders a sbb-secondary-button-static with slotted icon ShadowDom"] =
`<span class="sbb-action-base sbb-secondary-button-static">
<span class="sbb-button__icon">
<slot name="icon">
</slot>
</span>
<slot name="icon">
</slot>
<span class="sbb-button__label">
<slot>
</slot>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
primaryNegativeDisabled,
sizeM,
withSlottedIcon,
withHiddenSlottedIcon,
} from '../common/common-stories';

import readme from './readme.md?raw';
Expand Down Expand Up @@ -61,6 +62,7 @@ export const Active: StoryObj = primaryActive;
export const NegativeActive: StoryObj = primaryNegativeActive;
export const FocusVisible: StoryObj = primaryFocusVisible;
export const LoadingIndicator: StoryObj = loadingIndicator;
export const WithHiddenSlottedIcon: StoryObj = withHiddenSlottedIcon;

const meta: Meta = {
args: defaultArgs,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,8 @@ snapshots["sbb-secondary-button renders a sbb-secondary-button without icon Dom"

snapshots["sbb-secondary-button renders a sbb-secondary-button without icon ShadowDom"] =
`<span class="sbb-action-base sbb-secondary-button">
<span class="sbb-button__icon">
<slot name="icon">
</slot>
</span>
<slot name="icon">
</slot>
<span class="sbb-button__label">
<slot>
</slot>
Expand Down Expand Up @@ -63,10 +61,8 @@ snapshots["sbb-secondary-button renders a sbb-secondary-button with slotted icon

snapshots["sbb-secondary-button renders a sbb-secondary-button with slotted icon ShadowDom"] =
`<span class="sbb-action-base sbb-secondary-button">
<span class="sbb-button__icon">
<slot name="icon">
</slot>
</span>
<slot name="icon">
</slot>
<span class="sbb-button__label">
<slot>
</slot>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
primaryNegativeActive,
primaryNegativeDisabled,
sizeM,
withHiddenSlottedIcon,
withSlottedIcon,
} from '../common/common-stories';

Expand Down Expand Up @@ -52,6 +53,8 @@ export const FocusVisible: StoryObj = primaryFocusVisible;
export const LoadingIndicator: StoryObj = loadingIndicator;
export const RequestSubmit: StoryObj = requestSubmit;

export const WithHiddenSlottedIcon: StoryObj = withHiddenSlottedIcon;

const meta: Meta = {
args: defaultArgs,
argTypes: defaultArgTypes,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,8 @@ snapshots["sbb-tertiary-button-link renders a sbb-tertiary-button-link without i
tabindex="-1"
target="_blank"
>
<span class="sbb-button__icon">
<slot name="icon">
</slot>
</span>
<slot name="icon">
</slot>
<span class="sbb-button__label">
<slot>
</slot>
Expand Down Expand Up @@ -101,10 +99,8 @@ snapshots["sbb-tertiary-button-link renders a disabled sbb-tertiary-button-link
role="presentation"
tabindex="-1"
>
<span class="sbb-button__icon">
<slot name="icon">
</slot>
</span>
<slot name="icon">
</slot>
<span class="sbb-button__label">
<slot>
</slot>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
primaryNegativeActive,
primaryNegativeDisabled,
sizeM,
withHiddenSlottedIcon,
withSlottedIcon,
} from '../common/common-stories';

Expand Down Expand Up @@ -49,6 +50,7 @@ export const Active: StoryObj = primaryActive;
export const NegativeActive: StoryObj = primaryNegativeActive;
export const FocusVisible: StoryObj = primaryFocusVisible;
export const LoadingIndicator: StoryObj = loadingIndicator;
export const WithHiddenSlottedIcon: StoryObj = withHiddenSlottedIcon;

const meta: Meta = {
args: defaultArgs,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@ snapshots["sbb-tertiary-button-static renders a sbb-secondary-button-static with

snapshots["sbb-tertiary-button-static renders a sbb-secondary-button-static without icon ShadowDom"] =
`<span class="sbb-action-base sbb-tertiary-button-static">
<span class="sbb-button__icon">
<slot name="icon">
</slot>
</span>
<slot name="icon">
</slot>
<span class="sbb-button__label">
<slot>
</slot>
Expand Down Expand Up @@ -53,10 +51,8 @@ snapshots["sbb-tertiary-button-static renders a sbb-tertiary-button-static with

snapshots["sbb-tertiary-button-static renders a sbb-tertiary-button-static with slotted icon ShadowDom"] =
`<span class="sbb-action-base sbb-tertiary-button-static">
<span class="sbb-button__icon">
<slot name="icon">
</slot>
</span>
<slot name="icon">
</slot>
<span class="sbb-button__label">
<slot>
</slot>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
primaryNegativeDisabled,
sizeM,
withSlottedIcon,
withHiddenSlottedIcon,
} from '../common/common-stories';

import readme from './readme.md?raw';
Expand Down Expand Up @@ -61,6 +62,7 @@ export const Active: StoryObj = primaryActive;
export const NegativeActive: StoryObj = primaryNegativeActive;
export const FocusVisible: StoryObj = primaryFocusVisible;
export const LoadingIndicator: StoryObj = loadingIndicator;
export const WithHiddenSlottedIcon: StoryObj = withHiddenSlottedIcon;

const meta: Meta = {
args: defaultArgs,
Expand Down
Loading

0 comments on commit 433c57c

Please sign in to comment.