Created
June 19, 2022 15:47
-
-
Save AvocadoVenom/711f088e3f9313cde4934c61874b5d91 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <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