Skip to content

Instantly share code, notes, and snippets.

@AvocadoVenom
Created June 19, 2022 15:47
Show Gist options
  • Select an option

  • Save AvocadoVenom/711f088e3f9313cde4934c61874b5d91 to your computer and use it in GitHub Desktop.

Select an option

Save AvocadoVenom/711f088e3f9313cde4934c61874b5d91 to your computer and use it in GitHub Desktop.
<template>
<div class="block-content">
<button
type="button"
class="block-content__button"
aria-label="Toggle button"
@click="isExpanded = !isExpanded"
>
{{ toggleCtaLabel }}
</button>
<p v-show="isExpanded" class="block-content__paragraph" v-html="content" />
</div>
</template>
<script lang="ts">
import { computed, defineComponent, ref } from "vue";
export default defineComponent({
name: "ExpandableBlockContent",
props: {
content: { type: String },
},
setup() {
const isExpanded = ref(true);
const toggleCtaLabel = computed(() =>
isExpanded.value ? "Collapse" : "Expand"
);
return {
isExpanded,
toggleCtaLabel,
};
},
});
</script>
<style scoped>
.block-content {
display: flex;
flex-direction: column;
align-items: flex-start;
gap: 8px;
padding: 24px 20px;
background-color: skyblue;
border-radius: 8px;
}
.block-content__paragraph {
color: white;
}
.block-content__button {
color: white;
text-decoration: underline;
}
</style>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment