Files
Modrinth-plus/lib/components/base/Card.vue

63 lines
1.2 KiB
Vue
Raw Normal View History

2023-02-16 14:02:39 -08:00
<script setup>
2023-02-18 11:43:12 -07:00
import { Button, DropdownIcon } from '@/components'
2023-02-16 14:02:39 -08:00
2023-02-18 11:43:12 -07:00
import { reactive } from 'vue'
2023-02-16 14:02:39 -08:00
const props = defineProps({
collapsible: {
type: Boolean,
default: false,
},
defaultCollapsed: {
type: Boolean,
default: false,
},
noAutoBody: {
type: Boolean,
default: false,
},
2023-02-18 11:43:12 -07:00
})
2023-02-16 14:02:39 -08:00
const state = reactive({
collapsed: props.defaultCollapsed,
2023-02-18 11:43:12 -07:00
})
2023-02-16 14:02:39 -08:00
function toggleCollapsed() {
2023-02-18 11:43:12 -07:00
state.collapsed = !state.collapsed
2023-02-16 14:02:39 -08:00
}
</script>
<template>
<div
class="omorphia__card standard-body padding-xl bg-raised radius-lg margin-bottom-md"
:class="{ 'auto-body': !noAutoBody }"
>
<div v-if="!!$slots.header || collapsible" class="header">
<slot name="header"></slot>
2023-02-18 11:43:12 -07:00
<div v-if="collapsible" class="button-group margin-left-auto margin-right-0">
2023-02-16 14:02:39 -08:00
<Button :action="toggleCollapsed">
2023-02-18 11:43:12 -07:00
<DropdownIcon :style="{ transform: `rotate(${state.collapsed ? 0 : 180}deg)` }" />
2023-02-16 14:02:39 -08:00
</Button>
</div>
</div>
<slot v-if="!state.collapsed" />
</div>
</template>
<style lang="scss" scoped>
.omorphia__card {
}
.header {
display: flex;
:deep(h1, h2, h3, h4) {
margin-block: 0;
}
&:not(:last-child) {
margin-bottom: var(--gap-lg);
}
}
</style>