ovdashboard/ui/src/components/TickerBar.vue

89 lines
1.8 KiB
Vue
Raw Normal View History

2022-09-12 13:01:58 +00:00
<template>
2022-09-13 01:56:45 +00:00
<v-footer :color="color" :dark="is_dark" fixed>
2022-09-13 02:24:23 +00:00
<span ref="marquee" class="text-h6">
<div ref="content" v-html="content" />
2022-09-12 13:01:58 +00:00
</span>
</v-footer>
</template>
<script lang="ts">
2022-09-13 02:24:23 +00:00
import { Component, Prop, Ref, Vue, Watch } from "vue-property-decorator";
2022-09-13 01:50:59 +00:00
import Color from "color";
2022-09-12 13:01:58 +00:00
@Component
export default class TickerBar extends Vue {
2022-09-12 22:37:55 +00:00
@Prop({ required: true })
private readonly content!: string;
2022-09-12 13:01:58 +00:00
2022-09-13 01:50:59 +00:00
@Prop({ default: "primary" })
2022-09-13 01:56:45 +00:00
private readonly color!: string;
2022-09-13 01:50:59 +00:00
2022-09-13 02:24:23 +00:00
@Ref("content")
private readonly _content!: HTMLDivElement;
@Ref("marquee")
private readonly _marquee!: HTMLSpanElement;
2022-09-13 01:50:59 +00:00
private get is_dark(): boolean {
2022-09-13 02:24:23 +00:00
return this.footer_color.isDark();
2022-09-13 01:50:59 +00:00
}
2022-09-13 02:24:23 +00:00
private get footer_color(): Color {
2022-09-13 01:50:59 +00:00
// try getting from vuetify theme
2022-09-13 01:56:45 +00:00
let color = this.$vuetify.theme.themes.light[this.color];
2022-09-13 01:50:59 +00:00
if (typeof color === "string") {
return Color(color);
}
// fallback: parse color directly
2022-09-13 01:56:45 +00:00
return Color(this.color);
2022-09-13 01:50:59 +00:00
}
2022-09-13 02:24:23 +00:00
@Watch("content", { immediate: true })
private set_marquee_duration(): void {
this.$nextTick((): void => {
const width = parseFloat(
window.getComputedStyle(this._content).getPropertyValue("width")
);
// 10 seconds + another second per 40px
const duration = 10 + Math.round(width / 40);
2022-09-19 09:17:53 +00:00
this._marquee.style.setProperty("animation-duration", `${duration}s`);
2022-09-13 02:24:23 +00:00
});
2022-09-12 13:01:58 +00:00
}
}
</script>
2022-09-12 21:05:41 +00:00
<style lang="scss" scoped>
2022-09-12 13:01:58 +00:00
@keyframes marquee {
0% {
transform: translate(0, 0);
}
100% {
transform: translate(-100%, 0);
}
}
.v-footer {
white-space: nowrap;
overflow: hidden;
> span {
display: inline-block;
padding-left: 100%;
text-indent: 0;
animation: marquee 30s linear infinite;
&:hover {
animation-play-state: paused;
}
}
2022-09-15 18:01:57 +00:00
:deep() * {
2022-09-12 21:05:41 +00:00
margin: 0 !important;
}
2022-09-12 13:01:58 +00:00
}
2022-09-12 22:35:58 +00:00
</style>