Skip to content

Commit

Permalink
refactor: migrate to props destructure
Browse files Browse the repository at this point in the history
Signed-off-by: ZTL-UwU <zhangtianli2006@163.com>
  • Loading branch information
ZTL-UwU committed Oct 14, 2024
1 parent 6a5bf03 commit 4ed5a92
Show file tree
Hide file tree
Showing 25 changed files with 104 additions and 109 deletions.
10 changes: 4 additions & 6 deletions components/content/Accordion.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<UiAccordion
:type="type"
:collapsible="collapsible"
:type
:collapsible
:default-value="defaultValue"
class="[&:not(:first-child)]:mt-5"
>
Expand All @@ -10,11 +10,9 @@
</template>

<script setup lang="ts">
withDefaults(defineProps<{
const { type = 'single' } = defineProps<{
type?: 'single' | 'multiple';
collapsible?: boolean;
defaultValue: string | string[];
}>(), {
type: 'single',
});
}>();
</script>
30 changes: 16 additions & 14 deletions components/content/Alert.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,21 @@
</template>

<script setup lang="ts">
const props = withDefaults(defineProps<{
const {
to,
target,
type = 'default',
external = undefined,
inStack = false,
} = defineProps<{
title?: string;
icon?: string;
type?: 'default' | 'info' | 'warning' | 'success' | 'danger';
to?: string;
target?: string;
target?: Target;
external?: boolean;
inStack?: boolean;
}>(), {
type: 'default',
external: undefined,
inStack: false,
});
}>();
const typeTwClass = {
default: '',
Expand All @@ -48,15 +50,15 @@ const typeTwClass = {
};
async function alertClick() {
if (props.to) {
if (props.target) {
await navigateTo(props.to, {
external: props.external ?? props.to.startsWith('http'),
open: { target: props.target },
if (to) {
if (target) {
await navigateTo(to, {
external: external ?? to.startsWith('http'),
open: { target },
});
} else {
await navigateTo(props.to, {
external: props.external ?? props.to.startsWith('http'),
await navigateTo(to, {
external: external ?? to.startsWith('http'),
});
}
}
Expand Down
24 changes: 12 additions & 12 deletions components/content/Badge.vue
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
<template>
<NuxtLink :to="to" :target="target" class="mx-0.5">
<UiBadge :variant="variant" :class="typeTwClass[type]">
<NuxtLink :to :target class="mx-0.5">
<UiBadge :variant :class="typeTwClass[type]">
<ContentSlot unwrap="p" />
</UiBadge>
</NuxtLink>
</template>

<script setup lang="ts">
const props = withDefaults(defineProps<{
const {
type = 'default',
variant = 'default',
} = defineProps<{
type?: 'default' | 'info' | 'warning' | 'success' | 'danger';
to?: string;
target?: string;
target?: Target;
variant?: 'default' | 'secondary' | 'destructive' | 'outline';
}>(), {
type: 'default',
variant: 'default',
});
}>();
const typeTwClass = {
default: '',
info: `${props.variant !== 'outline' && 'bg-sky-500 hover:bg-sky-400'} ${props.variant === 'outline' && 'border-sky-500 text-sky-500'}`,
warning: `${props.variant !== 'outline' && 'bg-amber-500 hover:bg-amber-400'} ${props.variant === 'outline' && 'border-amber-500 text-amber-500'}`,
success: `${props.variant !== 'outline' && 'bg-green-500 hover:bg-green-400'} ${props.variant === 'outline' && 'border-green-500 text-green-500'}`,
danger: `${props.variant !== 'outline' && 'bg-red-500 hover:bg-red-400'} ${props.variant === 'outline' && 'border-red-500 text-red-500'}`,
info: `${variant !== 'outline' && 'bg-sky-500 hover:bg-sky-400'} ${variant === 'outline' && 'border-sky-500 text-sky-500'}`,
warning: `${variant !== 'outline' && 'bg-amber-500 hover:bg-amber-400'} ${variant === 'outline' && 'border-amber-500 text-amber-500'}`,
success: `${variant !== 'outline' && 'bg-green-500 hover:bg-green-400'} ${variant === 'outline' && 'border-green-500 text-green-500'}`,
danger: `${variant !== 'outline' && 'bg-red-500 hover:bg-red-400'} ${variant === 'outline' && 'border-red-500 text-red-500'}`,
};
</script>
4 changes: 2 additions & 2 deletions components/content/Callout.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<Alert :icon="icon" :to="to" :target="target">
<Alert :icon :to :target>
<slot />
</Alert>
</template>
Expand All @@ -8,6 +8,6 @@
defineProps<{
icon?: string;
to?: string;
target?: string;
target?: Target;
}>();
</script>
4 changes: 2 additions & 2 deletions components/content/Card.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<div class="group-has-[div]:mt-0 [&:not(:first-child)]:mt-5">
<NuxtLink :to="to" :target="target">
<NuxtLink :to :target>
<UiCard
class="relative h-full transition-all"
:class="[
Expand Down Expand Up @@ -40,7 +40,7 @@ defineProps<{
footer?: string;
content?: string;
to?: string;
target?: string;
target?: Target;
icon?: string;
inStack?: boolean;
}>();
Expand Down
6 changes: 3 additions & 3 deletions components/content/CodeCopy.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@
<script setup lang="ts">
import { useToast } from '@/components/ui/toast/use-toast';
const props = defineProps<{
const { code } = defineProps<{
code: string;
}>();
const { toast } = useToast();
const { copy } = useClipboard({ source: props.code });
const { copy } = useClipboard({ source: code });
const copied = ref(false);
async function handleClick() {
await copy(props.code);
await copy(code);
copied.value = true;
if (useConfig().value.main.codeCopyToast) {
Expand Down
4 changes: 2 additions & 2 deletions components/content/Hero.vue
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
defineProps<{
announcement?: {
to?: string;
target?: string;
target?: Target;
icon?: string;
title: string;
};
Expand All @@ -55,7 +55,7 @@ defineProps<{
rightIcon?: string;
variant?: 'default' | 'link' | 'destructive' | 'outline' | 'secondary' | 'ghost';
to: string;
target?: string;
target?: Target;
}];
}>();
</script>
4 changes: 2 additions & 2 deletions components/content/HeroAlt.vue
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
defineProps<{
announcement?: {
to?: string;
target?: string;
target?: Target;
icon?: string;
title: string;
};
Expand All @@ -52,7 +52,7 @@ defineProps<{
rightIcon?: string;
variant?: 'default' | 'link' | 'destructive' | 'outline' | 'secondary' | 'ghost';
to: string;
target?: string;
target?: Target;
}];
}>();
</script>
6 changes: 2 additions & 4 deletions components/content/Kbd.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@
</template>

<script setup lang="ts">
withDefaults(defineProps<{
const { size = 'sm' } = defineProps<{
size?: 'xs' | 'sm' | 'md';
}>(), {
size: 'sm',
});
}>();
const sizeClasses = {
xs: 'min-h-4 text-[10px] h-4 px-1',
Expand Down
26 changes: 8 additions & 18 deletions components/content/ProseA.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,12 @@
</template>

<script setup lang="ts">
import type { PropType } from 'vue';
defineProps({
href: {
type: String,
default: '',
},
target: {
type: String as PropType<'_blank' | '_parent' | '_self' | '_top' | (string & object) | null | undefined>,
default: undefined,
required: false,
},
external: {
type: Boolean,
default: undefined,
required: false,
},
});
const {
href = '',
external = false,
} = defineProps<{
href?: string;
target?: Target;
external?: boolean;
}>();
</script>
4 changes: 2 additions & 2 deletions components/content/ProseCode.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
<div v-if="!inGroup && filename" class="flex border-b p-3 font-mono text-sm">
<SmartIcon v-if="icon" :name="icon" class="mr-1.5 self-center" />
{{ filename }}
<CodeCopy :code="code" class="ml-auto mr-1" />
<CodeCopy :code class="ml-auto mr-1" />
</div>

<span v-if="!filename" class="absolute right-3 top-3 z-10">
<CodeCopy :code="code" />
<CodeCopy :code />
</span>
<div class="bg-muted/30">
<UiScrollArea>
Expand Down
6 changes: 3 additions & 3 deletions components/content/ProseH1.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<h1 :id="id" class="scroll-m-20 text-4xl font-extrabold tracking-tight lg:text-5xl">
<h1 :id class="scroll-m-20 text-4xl font-extrabold tracking-tight lg:text-5xl">
<NuxtLink
v-if="generate"
:href="`#${id}`"
Expand All @@ -11,8 +11,8 @@
</template>

<script setup lang="ts">
const props = defineProps<{ id?: string }>();
const { id } = defineProps<{ id?: string }>();
const { headings } = useRuntimeConfig().public.mdc;
const generate = computed(() => props.id && headings?.anchorLinks?.h1);
const generate = computed(() => id && headings?.anchorLinks?.h1);
</script>
6 changes: 3 additions & 3 deletions components/content/ProseH2.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<h2 :id="id" class="scroll-m-20 border-b pb-2 text-3xl font-semibold tracking-tight transition-colors [&:not(:first-child)]:mt-10">
<h2 :id class="scroll-m-20 border-b pb-2 text-3xl font-semibold tracking-tight transition-colors [&:not(:first-child)]:mt-10">
<NuxtLink
v-if="id && generate"
:href="`#${id}`"
Expand All @@ -11,8 +11,8 @@
</template>

<script setup lang="ts">
const props = defineProps<{ id?: string }>();
const { id } = defineProps<{ id?: string }>();
const { headings } = useRuntimeConfig().public.mdc;
const generate = computed(() => props.id && headings?.anchorLinks?.h2);
const generate = computed(() => id && headings?.anchorLinks?.h2);
</script>
6 changes: 3 additions & 3 deletions components/content/ProseH3.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<h3 :id="id" class="scroll-m-20 text-2xl font-semibold tracking-tight [&:not(:first-child)]:mt-8">
<h3 :id class="scroll-m-20 text-2xl font-semibold tracking-tight [&:not(:first-child)]:mt-8">
<NuxtLink
v-if="id && generate"
:href="`#${id}`"
Expand All @@ -11,8 +11,8 @@
</template>

<script setup lang="ts">
const props = defineProps<{ id?: string }>();
const { id } = defineProps<{ id?: string }>();
const { headings } = useRuntimeConfig().public.mdc;
const generate = computed(() => props.id && headings?.anchorLinks?.h3);
const generate = computed(() => id && headings?.anchorLinks?.h3);
</script>
6 changes: 3 additions & 3 deletions components/content/ProseH4.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<h4 :id="id" class="scroll-m-20 text-xl font-semibold tracking-tight [&:not(:first-child)]:mt-6">
<h4 :id class="scroll-m-20 text-xl font-semibold tracking-tight [&:not(:first-child)]:mt-6">
<NuxtLink
v-if="id && generate"
:href="`#${id}`"
Expand All @@ -11,8 +11,8 @@
</template>

<script setup lang="ts">
const props = defineProps<{ id?: string }>();
const { id } = defineProps<{ id?: string }>();
const { headings } = useRuntimeConfig().public.mdc;
const generate = computed(() => props.id && headings?.anchorLinks?.h4);
const generate = computed(() => id && headings?.anchorLinks?.h4);
</script>
6 changes: 3 additions & 3 deletions components/content/ProseH5.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<h5 :id="id" class="scroll-m-20 text-lg font-semibold tracking-tight [&:not(:first-child)]:mt-6">
<h5 :id class="scroll-m-20 text-lg font-semibold tracking-tight [&:not(:first-child)]:mt-6">
<NuxtLink
v-if="id && generate"
:href="`#${id}`"
Expand All @@ -11,8 +11,8 @@
</template>

<script setup lang="ts">
const props = defineProps<{ id?: string }>();
const { id } = defineProps<{ id?: string }>();
const { headings } = useRuntimeConfig().public.mdc;
const generate = computed(() => props.id && headings?.anchorLinks?.h4);
const generate = computed(() => id && headings?.anchorLinks?.h4);
</script>
6 changes: 3 additions & 3 deletions components/content/ProseH6.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<h6 :id="id" class="scroll-m-20 text-lg font-semibold tracking-tight [&:not(:first-child)]:mt-6">
<h6 :id class="scroll-m-20 text-lg font-semibold tracking-tight [&:not(:first-child)]:mt-6">
<NuxtLink
v-if="id && generate"
:href="`#${id}`"
Expand All @@ -11,8 +11,8 @@
</template>

<script setup lang="ts">
const props = defineProps<{ id?: string }>();
const { id } = defineProps<{ id?: string }>();
const { headings } = useRuntimeConfig().public.mdc;
const generate = computed(() => props.id && headings?.anchorLinks?.h4);
const generate = computed(() => id && headings?.anchorLinks?.h4);
</script>
6 changes: 3 additions & 3 deletions components/content/ProseImg.vue
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<template>
<NuxtImg
:src="refinedSrc"
:alt="alt"
:width="width"
:height="height"
:alt
:width
:height
class="rounded-md [&:not(:first-child)]:mt-8 [&:not(:last-child)]:mb-8"
/>
</template>
Expand Down
5 changes: 4 additions & 1 deletion components/content/ProsePre.vue
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,8 @@ defineProps({
</script>

<style>
pre code .line{display:block;min-height:1rem}
pre code .line{
display: block;
min-height: 1rem
}
</style>
Loading

0 comments on commit 4ed5a92

Please sign in to comment.