Skip to content

Commit

Permalink
fix(kcard): deprecate body slot instead of removing [KHCP-8971]
Browse files Browse the repository at this point in the history
  • Loading branch information
portikM committed Oct 31, 2023
1 parent b1daa27 commit 871c149
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 20 deletions.
8 changes: 4 additions & 4 deletions docs/components/collapse.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,9 @@ To set the default state (collapsed or expanded) without binding to v-model you
</div>
</template>
<template #visible-content>
<KCard body="I am content that is always visible" />
<KCard content="I am content that is always visible" />
</template>
<KCard body="I am only visible when expanded" />
<KCard content="I am only visible when expanded" />
</KCollapse>
</template>
</KCard>
Expand All @@ -182,10 +182,10 @@ To set the default state (collapsed or expanded) without binding to v-model you
</div>
</template>
<template #visible-content>
<KCard body="I am content that is always visible" />
<KCard content="I am content that is always visible" />
</template>

<KCard body="I am only visible when expanded" />
<KCard content="I am only visible when expanded" />
</KCollapse>
```

Expand Down
2 changes: 1 addition & 1 deletion docs/guide/migrating-to-version-9.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ Kongponents styles are no longer designed to be utilized standalone, separately
#### Slots

* `statusHat` slot has been removed
* `body` slot has been removed. Use `default` slot instead
* `body` slot has been deprecated in favor of `default` slot
* `notifications` slot has been removed

#### Events
Expand Down
19 changes: 19 additions & 0 deletions sandbox/pages/SandboxCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,25 @@
</KCard>
</div>
</SandboxSectionComponent>

<!-- Legacy -->
<SandboxTitleComponent
is-subtitle
title="Legacy"
/>
<SandboxSectionComponent title="body slot (deprecated)">
<KCard>
When both `default` and `body` slots are present, `default` slot will be used.
<template #body>
And `body` slot will be ignored.
</template>
</KCard>
<KCard>
<template #body>
But when only the `body` slot is present, it will be treated as `default`.
</template>
</KCard>
</SandboxSectionComponent>
</div>
</template>

Expand Down
20 changes: 18 additions & 2 deletions src/components/KCard/KCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@
</div>
</div>
<div
v-if="$slots.default || content"
v-if="$slots.default || $slots.body || content"
class="card-content"
>
<slot><p>{{ content }}</p></slot>
<slot :name="contentSlotName">
<p>{{ content }}</p>
</slot>
</div>
<div
v-if="$slots.footer"
Expand All @@ -37,6 +39,8 @@
</template>

<script setup lang="ts">
import { useSlots, computed } from 'vue'
defineProps({
title: {
type: String,
Expand All @@ -47,6 +51,18 @@ defineProps({
default: '',
},
})
const slots = useSlots()
const contentSlotName = computed((): 'body' | 'default' => { // TODO: remove this when body slot is removed
if (slots.body && !slots.default) {
console.warn('KCard: `body` slot has been deprecated in favor of `default` slot. See the migration guide for more details: https://alpha--kongponents.netlify.app/guide/migrating-to-version-9.html#kcard')
return 'body'
}
return 'default'
})
</script>

<style lang="scss" scoped>
Expand Down
14 changes: 5 additions & 9 deletions src/components/KCatalog/KCatalogItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@
<KCard
class="k-card-catalog-item"
:data-testid="item && item.title ? `${item.title.replace(/[^0-9a-z]/gi, '-')}-catalog-item` : 'catalog-item'"
has-hover
role="button"
tabindex="0"
:test-mode="!!testMode || undefined"
@click="($event: any) => handleCardClick($event, item)"
>
<template #title>
Expand All @@ -18,13 +16,11 @@
<slot name="cardActions" />
</template>

<template #body>
<div :class="{ 'multi-line-truncate': truncate }">
<slot name="cardBody">
{{ item ? item.description : '' }}
</slot>
</div>
</template>
<div :class="{ 'multi-line-truncate': truncate }">
<slot name="cardBody">
{{ item ? item.description : '' }}
</slot>
</div>
</KCard>
</template>

Expand Down
6 changes: 2 additions & 4 deletions src/components/KSlideout/KSlideout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,8 @@
</button>

<div class="content">
<KCard border-variant="noBorder">
<template #body>
<slot />
</template>
<KCard>
<slot />
</KCard>
</div>
</div>
Expand Down

0 comments on commit 871c149

Please sign in to comment.