Skip to content

Commit

Permalink
Fix slot content detection
Browse files Browse the repository at this point in the history
  • Loading branch information
José Ortiz committed Dec 29, 2021
1 parent fd37752 commit 20f63ff
Show file tree
Hide file tree
Showing 12 changed files with 38 additions and 12 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@lana/b2c-mapp-ui",
"version": "9.4.1",
"version": "9.4.2",
"description": "Shared custom libraries for building µapps.",
"bugs": {
"url": "https://github.com/lana/b2c-mapp-ui/issues"
Expand Down
6 changes: 6 additions & 0 deletions src/components/ActionItem/ActionItem.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Comment } from 'vue';

import TextParagraph from '../TextParagraph/TextParagraph.vue';

const errorStatuses = [
Expand Down Expand Up @@ -32,6 +34,10 @@ const props = {
const emits = ['click'];

const computed = {
hasDefaultSlot() {
const result = this.$slots.default && this.$slots.default().findIndex((node) => (node.type !== Comment)) !== -1;
return result;
},
hasErrorStatus() {
if (!this.status) { return; }
const result = errorStatuses.includes(this.status.toLowerCase());
Expand Down
10 changes: 9 additions & 1 deletion src/components/ActionItem/ActionItem.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const defaultExample = (args, { argTypes }) => ({
:status="status"
@click="onClick"
>
<RenderString :string="defaultSlot" />
<RenderString v-if="defaultSlot" :string="defaultSlot" />
</ActionItem>
</ul>
`,
Expand Down Expand Up @@ -137,6 +137,14 @@ const fullExample = (args, { argTypes }) => ({
<DocumentFilledIcon/>
</div>
</ActionItem>
<ActionItem :title="title"
:description="description"
:highlight="highlight"
:status="status"
@click="onClick"
>
<div v-if="false"/>
</ActionItem>
</ul>
`,
});
Expand Down
2 changes: 1 addition & 1 deletion src/components/ActionItem/ActionItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
class="item"
@click="onClick"
>
<div v-if="$slots.default"
<div v-if="hasDefaultSlot"
class="media"
:data-testid="`${dataTestId}-mediacolor`"
>
Expand Down
6 changes: 5 additions & 1 deletion src/components/BoxContentItem/BoxContentItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,16 @@ const data = function () {
};

const computed = {
hasDefaultSlot() {
const result = this.$slots.default && this.$slots.default().findIndex((node) => (node.type !== Comment)) !== -1;
return result;
},
hasIcon() {
const result = (this.success);
return result;
},
hasMetaText() {
const result = (this.metaText || this.$slots.customMetaText);
const result = (this.metaText || this.$slots.customMetaText());
return result;
},
};
Expand Down
2 changes: 1 addition & 1 deletion src/components/BoxContentItem/BoxContentItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
@touchStart="toggleIsPressed"
@touchEnd="toggleIsPressed"
>
<div v-if="$slots.default"
<div v-if="hasDefaultSlot"
class="media"
:data-testid="`${dataTestId}-media-icon`"
>
Expand Down
4 changes: 2 additions & 2 deletions src/components/Carousel/Carousel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
@click="debouncedChangeRenderedItem(-1)"
>
<slot v-if="arrowIcons" name="leftArrowIcon">
<ChevronLeftIcon v-if="!$slots.leftArrowIcon" class="icon"/>
<ChevronLeftIcon class="icon"/>
</slot>
</button>
<button v-show="isNextAvailable"
Expand All @@ -38,7 +38,7 @@
@click="debouncedChangeRenderedItem(1)"
>
<slot v-if="arrowIcons" name="rightArrowIcon">
<ChevronRightIcon v-if="!$slots.rightArrowIcon" class="icon"/>
<ChevronRightIcon class="icon"/>
</slot>
</button>
</slot>
Expand Down
6 changes: 5 additions & 1 deletion src/components/ContentItem/ContentItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,16 @@ const data = function () {
};

const computed = {
hasDefaultSlot() {
const result = this.$slots.default && this.$slots.default().findIndex((node) => (node.type !== Comment)) !== -1;
return result;
},
hasIcon() {
const result = (this.success || this.hasForwardButton);
return result;
},
hasMetaText() {
const result = (this.metaText || this.$slots.customMetaText);
const result = (this.metaText || (this.$slots.customMetaText && this.$slots.customMetaText().findIndex((node) => (node.type !== Comment)) !== -1));
return result;
},
iconName() {
Expand Down
2 changes: 1 addition & 1 deletion src/components/ContentItem/ContentItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
@touchStart="toggleIsPressed"
@touchEnd="toggleIsPressed"
>
<div v-if="$slots.default"
<div v-if="hasDefaultSlot"
class="media"
:class="{ 'no-border': noBorder }"
:data-testid="`${dataTestId}-media-icon`"
Expand Down
4 changes: 4 additions & 0 deletions src/components/ListItem/ListItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ const watch = {
};

const computed = {
hasDefaultSlot() {
const result = this.$slots.default && this.$slots.default().findIndex((node) => (node.type !== Comment)) !== -1;
return result;
},
isRightLabelShowing() {
const result = (!this.hasToggle && this.rightLabel);
return result;
Expand Down
2 changes: 1 addition & 1 deletion src/components/ListItem/ListItem.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<li class="list-item" :data-testid="dataTestId">
<div v-if="$slots.default"
<div v-if="hasDefaultSlot"
class="media"
:data-testid="`${dataTestId}-icon`"
>
Expand Down

0 comments on commit 20f63ff

Please sign in to comment.