Skip to content

Commit e9350c2

Browse files
authored
✨ 369 show icons on the left side of the button (#370)
* 369: add iconShownLeft to button * 369: format code * 369: pr feedback
1 parent 0a20e99 commit e9350c2

File tree

2 files changed

+36
-5
lines changed

2 files changed

+36
-5
lines changed

src/components/Button/MucButton.stories.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,11 @@ export const IconAnimated = {
6060
iconAnimated: true,
6161
},
6262
};
63+
64+
export const IconShownLeft = {
65+
args: {
66+
default: "With Icon",
67+
icon: "arrow-left",
68+
iconShownLeft: true,
69+
},
70+
};

src/components/Button/MucButton.vue

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@
66
:class="[buttonVariantClass, iconAnimatedClass, disabledClass]"
77
>
88
<span>
9-
<slot />
9+
<slot v-if="!iconShownLeft" />
1010
<muc-icon
1111
v-if="icon"
1212
:icon="icon"
1313
class="m-button__icon"
14-
:class="{ 'no-left-margin': !slots.default }"
14+
:class="iconPositionClass"
1515
/>
16+
<slot v-if="iconShownLeft" />
1617
</span>
1718
</button>
1819
</template>
@@ -30,6 +31,7 @@ const {
3031
variant = "primary",
3132
disabled = false,
3233
iconAnimated = false,
34+
iconShownLeft = false,
3335
} = defineProps<{
3436
/**
3537
* The variant prop gives you easy access to several different button styles.
@@ -51,6 +53,12 @@ const {
5153
* Default is `false`
5254
*/
5355
iconAnimated?: boolean;
56+
/**
57+
* Whether the Icon should be shown on the left side of the button (slide-right) or not.
58+
*
59+
* Default is `false`
60+
*/
61+
iconShownLeft?: boolean;
5462
}>();
5563
5664
defineSlots<{
@@ -79,9 +87,20 @@ const buttonVariantClass = computed(() => {
7987
}
8088
});
8189
82-
const iconAnimatedClass = computed(() =>
83-
iconAnimated ? "m-button--animated-right" : ""
84-
);
90+
const iconAnimatedClass = computed(() => {
91+
if (iconAnimated && iconShownLeft) {
92+
return "m-button--animated-left";
93+
} else if (iconAnimated) {
94+
return "m-button--animated-right";
95+
} else {
96+
return "";
97+
}
98+
});
99+
100+
const iconPositionClass = computed(() => ({
101+
"set-right-margin": iconShownLeft,
102+
"no-left-margin": !iconShownLeft ? !slots.default : !iconAnimated,
103+
}));
85104
86105
/**
87106
* Emit a click event if not in disabled state.
@@ -101,6 +120,10 @@ const disabledClass = computed(() => (disabled ? "disabled" : ""));
101120
margin-left: 0;
102121
}
103122
123+
.set-right-margin {
124+
margin-right: 0.75rem;
125+
}
126+
104127
[aria-disabled="true"] {
105128
pointer-events: none;
106129
}

0 commit comments

Comments
 (0)