Skip to content

Commit

Permalink
[KOptionalText] Refactor component
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexVelezLl committed Jan 10, 2023
1 parent b169b5c commit d0ec826
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions lib/KOptionalText.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>

<span v-if="!textEmpty" :style="textStyle">
<span v-if="!textEmpty" :style="appearanceOverrides">
<template v-if="text">
{{ text }}
</template>
Expand Down Expand Up @@ -34,7 +34,7 @@
/**
* If provided, sets the styles of the text
*/
textStyle: {
appearanceOverrides: {
type: Object,
default: null,
},
Expand All @@ -55,13 +55,16 @@
return '';
}
return this.$slots.default
return this.getNodesText(this.$slots.default);
},
getNodesText(nodes) {
return nodes
.map(node => {
if (node.text) {
return node.text;
}
if (node.children) {
return node.children.map(child => child.text).join('');
return this.getNodesText(node.children);
}
return '';
})
Expand Down

0 comments on commit d0ec826

Please sign in to comment.