72 lines
2.3 KiB
Vue
72 lines
2.3 KiB
Vue
<script setup lang="ts">
|
|
import { nextTick, onBeforeUnmount, ref, watch } from "vue";
|
|
|
|
/**
|
|
* The mark stands in for the A of the name. Closed, only the mark shows; open,
|
|
* the rest of the name slides out from behind it and, with `cycle`, steps
|
|
* through the product family.
|
|
*/
|
|
const props = withDefaults(defineProps<{ open?: boolean; cycle?: boolean }>(), {
|
|
open: true,
|
|
cycle: false,
|
|
});
|
|
|
|
const NAMES = ["rchie", "rchitect", "rchimedes", "rchipelago"];
|
|
|
|
const index = ref(0);
|
|
const swapping = ref(false);
|
|
const width = ref("0px");
|
|
const text = ref<HTMLElement>();
|
|
let timer: ReturnType<typeof setInterval> | undefined;
|
|
|
|
async function fit(): Promise<void> {
|
|
await nextTick();
|
|
width.value = props.open && text.value ? `${Math.ceil(text.value.getBoundingClientRect().width)}px` : "0px";
|
|
}
|
|
|
|
function next(): void {
|
|
swapping.value = true;
|
|
setTimeout(() => {
|
|
index.value = (index.value + 1) % NAMES.length;
|
|
swapping.value = false;
|
|
void fit();
|
|
}, 200);
|
|
}
|
|
|
|
watch(
|
|
() => props.open,
|
|
(open) => {
|
|
clearInterval(timer);
|
|
if (open && props.cycle) timer = setInterval(next, 1800);
|
|
// Reset to Archie once the name has folded away, not while it is visible.
|
|
if (!open) setTimeout(() => !props.open && (index.value = 0), 460);
|
|
void fit();
|
|
},
|
|
{ immediate: true },
|
|
);
|
|
onBeforeUnmount(() => clearInterval(timer));
|
|
</script>
|
|
|
|
<template>
|
|
<span class="text-foreground inline-flex items-baseline text-lg leading-none font-semibold tracking-tight whitespace-nowrap">
|
|
<svg viewBox="2 3 20 18" aria-hidden="true" class="text-brand h-[0.698em] w-[0.776em] shrink-0 self-baseline overflow-visible">
|
|
<path d="M2 21h4l8-18h-4z" fill="currentColor" />
|
|
<path d="M14.9 5.03 22 21h-4l-5.1-11.47z" fill="currentColor" />
|
|
<path d="M10.47 15h3.06l1.11 2.5H9.36z" fill="currentColor" />
|
|
</svg>
|
|
<span class="sr-only">Archie</span>
|
|
<span
|
|
aria-hidden="true"
|
|
class="-mb-[0.25em] inline-block overflow-hidden pb-[0.25em] transition-[max-width] duration-[460ms] ease-[cubic-bezier(0.2,0.7,0.2,1)]"
|
|
:style="{ maxWidth: width }"
|
|
>
|
|
<span
|
|
ref="text"
|
|
class="inline-block w-max pl-[0.02em] transition-[opacity,translate] duration-200"
|
|
:class="swapping && 'translate-y-[0.18em] opacity-0'"
|
|
>{{ NAMES[index] }}</span
|
|
>
|
|
</span>
|
|
</span>
|
|
</template>
|