Skip to content

Commit

Permalink
fix: handle dynamic content in empathize
Browse files Browse the repository at this point in the history
  • Loading branch information
diegopf committed May 28, 2024
1 parent 1bffd7c commit 5b683fa
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,25 +1,39 @@
<template>
<SearchInput />
<Empathize :animation="CollapseHeight" class="empathize">
<h1>It is a Empathize</h1>
<h2>It is a Empathize</h2>
<h3>It is a Empathize</h3>
<p>
Component containing the empathize. It has a required slot to define its content and two props
to define when to open and close it: `eventsToOpenEmpathize` and `eventsToCloseEmpathize`.
</p>
<div v-if="showContent">
<h1>It is a Empathize</h1>
<h2>It is a Empathize</h2>
<h3>It is a Empathize</h3>
<p>
Component containing the empathize. It has a required slot to define its content and two
props to define when to open and close it: `eventsToOpenEmpathize` and
`eventsToCloseEmpathize`.
</p>
</div>
</Empathize>
<Empathize :animation="CollapseHeight" class="empathize" />
<button @click="toggleContent">
{{ showContent ? 'hide empathize content' : 'show empathize content' }}
</button>
</template>

<script setup lang="ts">
import { ref } from 'vue';
import CollapseHeight from '../../../../x-components/src/components/animations/collapse-height.vue';
import Empathize from '../../../../x-components/src/x-modules/empathize/components/empathize.vue';
import SearchInput from '../../../../x-components/src/x-modules/search-box/components/search-input.vue';
const showContent = ref(true);
const toggleContent = () => {
showContent.value = !showContent.value;
};
</script>

<style scoped>
.empathize {
border: 3px solid red;
padding-top: 16px;
padding-bottom: 16px;
}
</style>
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</template>

<script lang="ts">
import { computed, defineComponent, PropType, ref } from 'vue';
import { defineComponent, PropType, ref } from 'vue';
import { NoElement } from '../../../components/no-element';
import { useDebounce } from '../../../composables/use-debounce';
import { useRegisterXModule } from '../../../composables/use-register-x-module';
Expand Down Expand Up @@ -64,7 +64,7 @@
const empathizeRef = ref<HTMLDivElement>();
const isOpen = ref(false);
const hasContent = computed(() => !!empathizeRef.value?.children.length);
const hasContent = ref(!!empathizeRef.value?.children.length);
/**
* Changes the state of {@link Empathize.isOpen} assigning to it the value of `newOpen`
Expand All @@ -87,6 +87,7 @@
* element.
*/
function open() {
hasContent.value = !!empathizeRef.value?.children.length;
if (hasContent.value) {
changeOpen(true);
}
Expand Down

0 comments on commit 5b683fa

Please sign in to comment.