Skip to content

Commit

Permalink
migrate mt-label to custom built i18n
Browse files Browse the repository at this point in the history
  • Loading branch information
Haberkamp committed Oct 22, 2024
1 parent 3b50452 commit 07d54ff
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 84 deletions.
5 changes: 5 additions & 0 deletions .changeset/twenty-coins-fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@shopware-ag/meteor-component-library": patch
---

Migrate mt-label to custom built i18n composable
125 changes: 41 additions & 84 deletions packages/component-library/src/components/_internal/mt-label.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<button
v-if="showDismissable"
class="mt-label__dismiss"
:title="$tc('mt-label.remove')"
:title="t('remove')"
@click.prevent.stop="$emit('dismiss')"
>
<slot name="dismiss-icon">
Expand All @@ -20,98 +20,55 @@
</span>
</template>

<script lang="ts">
import type { PropType } from "vue";
import { defineComponent } from "vue";
<script setup lang="ts">
import { computed, useAttrs } from "vue";
import MtIcon from "../icons-media/mt-icon/mt-icon.vue";
import MtColorBadge from "../feedback-indicator/mt-color-badge/mt-color-badge.vue";
export default defineComponent({
name: "MtLabel",
i18n: {
messages: {
en: {
"mt-label": {
remove: "Remove",
},
},
de: {
"mt-label": {
remove: "Entfernen",
},
},
},
import { useI18n } from "@/composables/useI18n";
const props = withDefaults(
defineProps<{
variant?: "info" | "danger" | "success" | "warning" | "neutral" | "primary";
size?: "small" | "medium" | "default";
appearance?: "default" | "pill" | "circle" | "badged";
ghost?: boolean;
caps?: boolean;
dismissable?: boolean;
}>(),
{
variant: "neutral",
size: "default",
appearance: "default",
ghost: false,
caps: false,
},
);
components: {
"mt-icon": MtIcon,
"mt-color-badge": MtColorBadge,
},
props: {
variant: {
type: String as PropType<"info" | "danger" | "success" | "warning" | "neutral" | "primary">,
required: false,
default: "",
validator(value: string) {
if (!value.length) {
return true;
}
return ["info", "danger", "success", "warning", "neutral", "primary"].includes(value);
},
},
size: {
type: String as PropType<"small" | "medium" | "default">,
required: false,
default: "default",
validator(value: string) {
return ["small", "medium", "default"].includes(value);
},
const { t } = useI18n({
messages: {
en: {
remove: "Remove",
},
appearance: {
type: String as PropType<"default" | "pill" | "circle" | "badged">,
required: false,
default: "default",
validator(value: string) {
return ["default", "pill", "circle", "badged"].includes(value);
},
},
ghost: {
type: Boolean,
required: false,
default: false,
},
caps: {
type: Boolean,
required: false,
default: false,
},
dismissable: {
type: Boolean,
required: false,
default: true,
de: {
remove: "Entfernen",
},
},
});
computed: {
labelClasses() {
return [
`mt-label--appearance-${this.appearance}`,
`mt-label--size-${this.size}`,
{
[`mt-label--${this.variant}`]: !!this.variant,
"mt-label--dismissable": this.showDismissable,
"mt-label--ghost": this.ghost,
"mt-label--caps": this.caps,
},
];
},
showDismissable(): boolean {
return !!this.$attrs.onDismiss && this.dismissable;
const attrs = useAttrs();
const showDismissable = computed(() => !!attrs.onDismiss && props.dismissable);
const labelClasses = computed(() => {
return [
`mt-label--appearance-${props.appearance}`,
`mt-label--size-${props.size}`,
{
[`mt-label--${props.variant}`]: !!props.variant,
"mt-label--dismissable": showDismissable,
"mt-label--ghost": props.ghost,
"mt-label--caps": props.caps,
},
},
];
});
</script>

Expand Down

0 comments on commit 07d54ff

Please sign in to comment.