Files
chatwoot/app/javascript/shared/components/CardButton.vue
Sivin Varghese 3a693947b5 feat: Add RTL Support to Widget (#11022)
This PR adds RTL support to the web widget for improved right-to-left language compatibility, updates colors, and cleans up code.

Fixes https://linear.app/chatwoot/issue/CW-4089/rtl-issues-on-widget

https://github.com/chatwoot/chatwoot/issues/9791

Other PR: https://github.com/chatwoot/chatwoot/pull/11016
2025-03-21 09:39:03 -07:00

73 lines
1.5 KiB
Vue

<script>
import { mapGetters } from 'vuex';
import { getContrastingTextColor } from '@chatwoot/utils';
import { IFrameHelper } from 'widget/helpers/utils';
export default {
components: {},
props: {
action: {
type: Object,
default: () => {},
},
},
computed: {
...mapGetters({
widgetColor: 'appConfig/getWidgetColor',
}),
textColor() {
return getContrastingTextColor(this.widgetColor);
},
isLink() {
return this.action.type === 'link';
},
},
methods: {
onClick() {
if (this.action.type === 'postback') {
// Send message to parent iframe
if (IFrameHelper.isIFrame()) {
IFrameHelper.sendMessage({
event: 'postback',
data: { payload: this.action.payload },
});
}
}
},
},
};
</script>
<template>
<a
v-if="isLink"
:key="action.uri"
class="action-button button"
:href="action.uri"
:style="{
background: widgetColor,
borderColor: widgetColor,
color: textColor,
}"
target="_blank"
rel="noopener nofollow noreferrer"
>
{{ action.text }}
</a>
<button
v-else
:key="action.payload"
class="action-button button !bg-n-background dark:!bg-n-alpha-black1 text-n-brand"
:style="{ borderColor: widgetColor, color: widgetColor }"
@click="onClick"
>
{{ action.text }}
</button>
</template>
<style scoped lang="scss">
.action-button {
@apply items-center rounded-lg flex font-medium justify-center mt-1 p-0 w-full;
}
</style>