Skip to content

Commit

Permalink
Merge branch 'main' into refactor-progress-bar
Browse files Browse the repository at this point in the history
  • Loading branch information
Haberkamp authored Sep 25, 2024
2 parents b3fed4d + dd42b3b commit 4e7d63d
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 175 deletions.
5 changes: 5 additions & 0 deletions .changeset/tender-llamas-sleep.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@shopware-ag/meteor-component-library": patch
---

Remove default margin from base field, hidden by future flag
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
<template>
<div class="mt-field" :class="classes">
<div
class="mt-field"
:class="[
{
'has--error': hasError,
'is--disabled': disabled,
'is--inherited': isInherited,
'has--focus': hasFocus,
'mt-field--future-remove-default-margin': future.removeDefaultMargin,
},
mtBlockSize,
]"
>
<div class="mt-field__label">
<mt-inheritance-switch
v-if="isInheritanceField"
Expand Down Expand Up @@ -59,6 +71,7 @@ import useEmptySlotCheck from "../../../../composables/useEmptySlotCheck";
import MtValidationMixin from "../../../../mixins/validation.mixin";
import MtFormFieldMixin from "../../../../mixins/form-field.mixin";
import { createId } from "../../../../utils/id";
import { useFutureFlags } from "@/composables/useFutureFlags";
export default defineComponent({
name: "MtBaseField",
Expand Down Expand Up @@ -209,19 +222,6 @@ export default defineComponent({
};
},
// eslint-disable-next-line @typescript-eslint/no-explicit-any
classes(): any[] {
return [
{
"has--error": this.hasError,
"is--disabled": this.disabled,
"is--inherited": this.isInherited,
"has--focus": this.hasFocus,
},
this.mtBlockSize,
];
},
mtBlockSize(): string {
return `mt-field--${this.size}`;
},
Expand All @@ -233,9 +233,11 @@ export default defineComponent({
setup() {
const { hasSlotContent } = useEmptySlotCheck();
const future = useFutureFlags();
return {
hasSlotContent,
future,
};
},
});
Expand Down Expand Up @@ -471,4 +473,8 @@ $mt-field-transition:
}
}
}
.mt-field--future-remove-default-margin {
margin-bottom: 0;
}
</style>
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { within } from "@storybook/test";
import { expect } from "@storybook/test";
import { expect, userEvent, within } from "@storybook/test";

import meta, { type MtLinkMeta, type MtLinkStory } from "./mt-link.stories";

Expand Down Expand Up @@ -27,11 +26,11 @@ export const VisualTestRenderExternalLinkDisabled: MtLinkStory = {
args: {
disabled: true,
},
play: async ({ canvasElement }) => {
play: async ({ canvasElement, args }) => {
const canvas = within(canvasElement);

const link = canvas.getByText("Link");
await userEvent.click(canvas.getByRole("link"));

expect(getComputedStyle(link).pointerEvents).toEqual("none");
expect(args.click).not.toHaveBeenCalled();
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import { fn } from "@storybook/test";
import MtLink from "./mt-link.vue";
import type { SlottedMeta } from "@/_internal/story-helper";

export type MtLinkMeta = SlottedMeta<typeof MtLink, "default" | "close">;
export type MtLinkMeta = SlottedMeta<typeof MtLink, "default" | "close" | "click">;

export default {
title: "Components/Navigation/mt-link",
component: MtLink,
args: {
as: "router-link",
as: "a",
default: "Link",
to: "/",
variant: "primary",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,88 +1,41 @@
<template>
<component
:is="as"
class="mt-link"
:class="linkClasses"
:class="[
'mt-link',
`mt-link--${variant}`,
{
'mt-link--disabled': disabled,
},
]"
:aria-disabled="disabled"
role="link"
:tabindex="disabled ? -1 : 0"
v-bind="to ? { ...$attrs, to } : $attrs"
@click="onClick"
@click="disabled ? undefined : $emit('click', $event)"
>
<slot />
</component>
</template>

<script lang="ts">
import { defineComponent } from "vue";
import type { PropType } from "vue";
export default defineComponent({
name: "MtLink",
props: {
/**
* Set the element type of the link
*/
as: {
type: String,
required: false,
default: "router-link",
},
/**
* Set the to prop of the router/nuxt-link
*/
to: {
type: String,
required: false,
default: undefined,
},
/**
* Render the link in various styles
*/
variant: {
type: String as PropType<"primary" | "critical">,
required: false,
default: "primary",
validator(value: string) {
if (!value.length) {
return true;
}
return ["primary", "critical"].includes(value);
},
},
/**
* Make the link unclickable
*/
disabled: {
type: Boolean,
required: false,
default: false,
},
},
computed: {
linkClasses() {
return {
[`mt-link--${this.variant}`]: !!this.variant,
"mt-link--disabled": this.disabled,
};
},
<script setup lang="ts">
withDefaults(
defineProps<{
to?: string;
as?: string;
variant?: "primary" | "critical";
disabled?: boolean;
}>(),
{
as: "router-link",
variant: "primary",
disabled: false,
},
);
methods: {
onClick(event: MouseEvent) {
if (this.disabled) {
event.preventDefault();
event.stopImmediatePropagation();
return;
}
this.$emit("click", event);
},
},
});
defineEmits<{
(e: "click", event: MouseEvent): void;
}>();
</script>

<style scoped>
Expand All @@ -99,7 +52,6 @@ export default defineComponent({
.mt-link:is(:disabled, .mt-link--disabled) {
cursor: not-allowed;
pointer-events: none;
}
.mt-link--primary {
Expand Down
Loading

0 comments on commit 4e7d63d

Please sign in to comment.