advent22/ui/src/components/calendar/SVGRect.vue

77 lines
1.6 KiB
Vue
Raw Normal View History

2023-01-17 18:25:56 +00:00
<template>
2023-09-22 19:02:51 +00:00
<foreignObject
:x="Math.round(get_bg_aspect_ratio() * rectangle.left)"
2023-09-22 19:02:51 +00:00
:y="rectangle.top"
:width="Math.round(get_bg_aspect_ratio() * rectangle.width)"
2023-09-22 19:02:51 +00:00
:height="rectangle.height"
:style="`transform: scaleX(${1 / get_bg_aspect_ratio()})`"
2023-09-22 19:02:51 +00:00
>
<div
xmlns="http://www.w3.org/1999/xhtml"
:class="`px-2 is-flex is-align-items-center is-justify-content-center is-size-2 has-text-weight-bold ${variant} ${
visible ? 'visible' : ''
}`"
2023-10-27 15:09:44 +00:00
style="height: inherit"
v-bind="$attrs"
2023-09-22 19:02:51 +00:00
>
<slot name="default" />
</div>
</foreignObject>
2023-01-17 18:25:56 +00:00
</template>
<script setup lang="ts">
import { loading_success } from "@/lib/helpers";
2024-08-23 16:38:04 +00:00
import { Rectangle } from "@/lib/rects/rectangle";
import { advent22Store } from "@/lib/store";
const store = advent22Store();
2023-01-17 18:25:56 +00:00
2023-09-22 19:02:51 +00:00
type BulmaVariant =
| "primary"
| "link"
| "info"
| "success"
| "warning"
| "danger";
2023-09-20 16:16:45 +00:00
withDefaults(
defineProps<{
variant: BulmaVariant;
visible?: boolean;
rectangle: Rectangle;
}>(),
{
visible: true,
2023-01-17 18:25:56 +00:00
},
);
2023-09-22 19:02:51 +00:00
function get_bg_aspect_ratio(): number {
if (!loading_success(store.background_image)) return 1;
return store.background_image.height / store.background_image.width;
2023-01-17 18:25:56 +00:00
}
</script>
<style lang="scss" scoped>
@use "@/bulma-scheme" as scheme;
foreignObject > div {
2023-11-06 00:32:56 +00:00
&:not(.visible, :hover):deep() > * {
display: none;
}
&.visible,
&:hover {
2023-11-24 00:53:52 +00:00
border-width: 2px;
border-style: solid;
2023-01-17 18:25:56 +00:00
@each $name, $color in scheme.$colors {
2023-11-06 00:32:56 +00:00
&.#{$name} {
background-color: rgba($color, 0.3);
border-color: rgba($color, 0.9);
}
}
2023-01-17 18:25:56 +00:00
}
}
2023-09-07 01:17:14 +00:00
</style>