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
5664defineSlots <{
@@ -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