Mysterious_Dev 67f77d027a
Use Typescript for Card component (#128)
* Use Typescript for Card component

* Update Card.vue
2023-11-13 13:05:43 -07:00

60 lines
1.1 KiB
Vue

<script setup lang="ts">
import { Button, DropdownIcon } from '@'
import { reactive } from 'vue'
const props = withDefaults(
defineProps<{
collapsible: boolean
defaultCollapsed: boolean
noAutoBody: boolean
}>(),
{
collapsible: false,
defaultCollapsed: false,
noAutoBody: false,
}
)
const state = reactive({
collapsed: props.defaultCollapsed,
})
function toggleCollapsed() {
state.collapsed = !state.collapsed
}
</script>
<template>
<div class="card">
<div v-if="!!$slots.header || collapsible" class="header">
<slot name="header"></slot>
<div v-if="collapsible" class="btn-group">
<Button :action="toggleCollapsed">
<DropdownIcon :style="{ transform: `rotate(${state.collapsed ? 0 : 180}deg)` }" />
</Button>
</div>
</div>
<slot v-if="!state.collapsed" />
</div>
</template>
<style lang="scss" scoped>
.header {
display: flex;
:deep(h1, h2, h3, h4) {
margin-block: 0;
}
&:not(:last-child) {
margin-bottom: var(--gap-lg);
}
}
.btn-group {
margin-left: auto;
margin-right: 0;
}
</style>