|
| 1 | +<template> |
| 2 | + <div :class="[ui.wrapper, to && ui.to]" v-bind="attrs" :style="{ '--color-light': colorLight, '--color-dark': colorDark }"> |
| 3 | + <NuxtLink v-if="to" :to="to" :target="target" class="focus:outline-none" tabindex="-1"> |
| 4 | + <span class="absolute inset-0" aria-hidden="true" /> |
| 5 | + </NuxtLink> |
| 6 | + |
| 7 | + <UIcon v-if="icon" :name="icon" :class="ui.icon.base" /> |
| 8 | + |
| 9 | + <UIcon v-if="!!to && target === '_blank'" :name="ui.externalIcon.name" :class="ui.externalIcon.base" /> |
| 10 | + |
| 11 | + <slot mdc-unwrap="p" /> |
| 12 | + </div> |
| 13 | +</template> |
| 14 | + |
| 15 | +<script setup lang="ts"> |
| 16 | +import type { PropType } from 'vue' |
| 17 | +import colors from '#tailwind-config/theme/colors' |
| 18 | +import type uiColors from '#ui-colors' |
| 19 | +
|
| 20 | +const appConfig = useAppConfig() |
| 21 | +
|
| 22 | +const config = computed(() => ({ |
| 23 | + wrapper: 'block pl-4 pr-6 py-3 rounded-md border border-gray-200 dark:border-gray-700 bg-gray-50 dark:bg-gray-800 text-gray-700 dark:text-gray-300 text-sm/6 my-5 last:mb-0 font-normal group relative prose-code:bg-white dark:prose-code:bg-gray-900', |
| 24 | + to: 'hover:border-[--color-light] dark:hover:border-[--color-dark] hover:text-[--color-light] dark:hover:text-[--color-dark] border-dashed hover:border-solid hover:text-gray-800 dark:hover:text-gray-200', |
| 25 | + icon: { |
| 26 | + base: 'w-4 h-4 mr-2 inline-flex items-center align-sub text-[--color-light] dark:text-[--color-dark]', |
| 27 | + }, |
| 28 | + externalIcon: { |
| 29 | + name: appConfig.ui.icons.external, |
| 30 | + base: 'w-4 h-4 absolute right-2 top-2 text-gray-400 dark:text-gray-500 group-hover:text-[--color-light] dark:group-hover:text-[--color-dark]', |
| 31 | + }, |
| 32 | +})) |
| 33 | +
|
| 34 | +defineOptions({ |
| 35 | + inheritAttrs: false, |
| 36 | +}) |
| 37 | +
|
| 38 | +const props = defineProps({ |
| 39 | + icon: { |
| 40 | + type: String, |
| 41 | + default: undefined, |
| 42 | + }, |
| 43 | + color: { |
| 44 | + type: String as PropType<typeof uiColors[number]>, |
| 45 | + default: 'primary', |
| 46 | + }, |
| 47 | + to: { |
| 48 | + type: String, |
| 49 | + default: undefined, |
| 50 | + }, |
| 51 | + target: { |
| 52 | + type: String, |
| 53 | + default: undefined, |
| 54 | + }, |
| 55 | + class: { |
| 56 | + type: [String, Object, Array] as PropType<any>, |
| 57 | + default: undefined, |
| 58 | + }, |
| 59 | + ui: { |
| 60 | + type: Object as PropType<Partial<typeof config.value>>, |
| 61 | + default: () => ({}), |
| 62 | + }, |
| 63 | +}) |
| 64 | +
|
| 65 | +const { ui, attrs } = useUI('content.callout', toRef(props, 'ui'), config, toRef(props, 'class'), true) |
| 66 | +
|
| 67 | +const colorLight = computed(() => { |
| 68 | + if (props.color === 'primary') { |
| 69 | + return 'rgb(var(--color-primary-DEFAULT))' |
| 70 | + } |
| 71 | + // @ts-expect-error untyped |
| 72 | + return colors[props.color]?.['500'] || (colors[props.color] as string) || props.color |
| 73 | +}) |
| 74 | +const colorDark = computed(() => { |
| 75 | + if (props.color === 'primary') { |
| 76 | + return 'rgb(var(--color-primary-DEFAULT))' |
| 77 | + } |
| 78 | + // @ts-expect-error untyped |
| 79 | + return colors[props.color]?.['400'] || (colors[props.color] as string) || props.color |
| 80 | +}) |
| 81 | +
|
| 82 | +const target = computed(() => props.target || (props.to && props.to.startsWith('http') ? '_blank' : undefined)) |
| 83 | +</script> |
0 commit comments