Skip to content

Commit

Permalink
fix: Fix type-safety of the Link component
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisGV04 committed Aug 8, 2023
1 parent f7d4992 commit a91cb09
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 21 deletions.
35 changes: 17 additions & 18 deletions src/runtime/components/elements/Button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,24 @@ import buildAppConfig from "#build/app.config";

type ParentLinkProps = InstanceType<typeof UiLink>["$props"];
type ButtonUiConfig = Partial<UiButtonConfig>;
type Props = ParentLinkProps & {
label?: string;
leadingIcon?: string;
trailingIcon?: string;
type?: HTMLButtonElement["type"];
loading?: boolean;
disabled?: boolean;
truncate?: boolean;
block?: boolean;
padded?: boolean;
size?: UiButtonSizes;
color?: UiButtonColors;
variant?: UiButtonVariants;
loadingIcon?: string;
ui?: ButtonUiConfig;
};

export default defineComponent<
ParentLinkProps & {
label?: string;
leadingIcon?: string;
trailingIcon?: string;
type?: HTMLButtonElement["type"];
loading?: boolean;
disabled?: boolean;
truncate?: boolean;
block?: boolean;
padded?: boolean;
size?: UiButtonSizes;
color?: UiButtonColors;
variant?: UiButtonVariants;
loadingIcon?: string;
ui?: ButtonUiConfig;
}
>({
export default defineComponent<Props>({
components: { UiLink, UiIcon },

props: {
Expand Down
21 changes: 18 additions & 3 deletions src/runtime/components/elements/Link.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,26 @@
import { NuxtLink } from "#components";
import { useRoute } from "#imports";
import { defineComponent, h, type PropType } from "vue";
import type { RouteLocationNormalized } from "vue-router";
import type { RouteLocationNormalized, RouteLocationRaw } from "vue-router";
import { classNames, isDeepEqual } from "../../utils";

type NuxtLinkProps = InstanceType<typeof NuxtLink>["$props"];
type Props = NuxtLinkProps & {
type Props = {
// NuxtLink props
to?: RouteLocationRaw;
href?: RouteLocationRaw;
external?: boolean;
replace?: boolean;
custom?: boolean;
target?: "_blank" | "_parent" | "_self" | "_top" | (string & {}) | null;
rel?: string | null;
noRel?: boolean;
prefetch?: boolean;
noPrefetch?: boolean;
activeClass?: string;
exactActiveClass?: string;
ariaCurrentValue?: string;

// UiLink props
type?: HTMLButtonElement["type"];
disabled?: boolean;
exact?: boolean;
Expand Down

0 comments on commit a91cb09

Please sign in to comment.