Openverse is a search engine for openly-licensed media. This monorepo includes all application code.
<script setup lang="ts">
/**
* Display a banner that can indicate one of four semantics in one of two color
* variants.
*/
import { computed } from "vue"
import type { BannerNature, BannerVariant } from "#shared/constants/banners"
import type { BannerId } from "#shared/types/banners"
import VIcon from "~/components/VIcon/VIcon.vue"
import VIconButton from "~/components/VIconButton/VIconButton.vue"
const props = withDefaults(
defineProps<{
/**
* the semantic meaning of the banner; This can carry a positive, neutral
* or negative connotation.
*/
nature?: BannerNature
/**
* the color variant of the banner; The dark variant is intended for use on
* bg-complementary pages.
*/
variant?: BannerVariant
/**
* the unique ID of the banner
*/
id: BannerId
/**
* the label to apply to the close button
*/
closeButtonLabel?: string
}>(),
{
nature: "info",
variant: "regular",
}
)
defineEmits<{
close: []
}>()
const classNames = computed(() =>
props.variant === "dark"
? "bg-tertiary text-over-dark"
: {
info: "bg-info",
warning: "bg-warning",
success: "bg-success",
error: "bg-error",
}[props.nature]
)
const iconClassNames = computed(() =>
props.variant === "dark"
? ""
: {
info: "text-info-8",
warning: "text-warning-8",
success: "text-success-8",
error: "text-error-8",
}[props.nature]
)
const closeButtonClassNames = computed(() =>
props.variant === "dark"
? "focus-visible:focus-slim-tx hover:bg-tertiary-hover"
: {
info: "hover:bg-info-3!",
warning: "hover:bg-warning-3!",
success: "hover:bg-success-3!",
error: "hover:bg-error-3!",
}[props.nature]
)
</script>
<template>
<section
class="flex flex-row items-center gap-2 rounded-xs p-2 lg:p-3"
:class="classNames"
:data-testid="`banner-${id}`"
>
<slot name="start">
<VIcon :name="nature" :class="iconClassNames" />
</slot>
<p class="grow caption-regular lg:paragraph-small">
<slot />
</p>
<slot name="end">
<VIconButton
:variant="variant === 'dark' ? 'transparent-tx' : 'transparent-gray'"
:icon-props="{ name: 'close-small' }"
size="small"
:label="closeButtonLabel || $t('modal.closeBanner')"
:class="closeButtonClassNames"
@click="$emit('close')"
/>
</slot>
</section>
</template>