Vue feedback widget

Installation

npm install @happyreact/vue 

Usage

First, you need to create a Happy React project. You will get a token to connect the widget with Happy React. There you can change project settings, add domains to the whitelist, or see statistics.

Displaying widget with basic styling

This code lets you add the widget to your website with the basic styling that comes with the package.

<script setup>
import { Widget } from '@happyreact/vue';
import '@happyreact/vue/theme.css';
</script>
 
<template>
  <Widget token="[token]" resource="users-happiness" />
</template>
  • [token] - project token, find it in project settings
  • users-happiness - unique identifier of a resource

Custom styles using Global CSS

Use this if your application allows importing global styles. You can use default classes to style widget elements. Please see Happy React styling guide for more about styling.

<script setup>
import { Widget } from '@happyreact/vue';
</script>
 
<template>
  <Widget token="[token]" resource="users-happiness" />
</template>
 
<style>
.hr-container {
}
 
.hr-reaction {
}
</style>
💡

Remember to replace token and resource with your project's token and proper resource

Custom styles using classes

Use this with Module CSS. Import styles as a variable and assign them using classes property. This can let you add class to different elements of the widget. Please see Happy React styling guide for more about styling.

<script setup>
import { Widget } from '@happyreact/vue';
import '@happyreact/vue/theme.css';
</script>
 
<template>
  <Widget
    token="[token]"
    resource="users-happiness"
    :classes="{
      container: $style.container,
      reaction: $style.reaction
    }"
  />
</template>
 
<style module>
.container {
}
 
.reaction {
}
</style>
💡

Remember to replace token and resource with your project's token and proper resource

Reacting to user events

Right now you can use two events:

  • onReaction - fire after user reaction
  • onReactionsLimitReached - fire after the user reach the limit of reactions
<script setup>
import { Widget } from '@happyreact/vue';
import '@happyreact/vue/theme.css';
 
function handleReaction(data) {
  console.log('Reaction clicked with data', data);
}
 
function handleReactionsLimitReached() {
  console.log('Reactions limit reached');
}
</script>
 
<template>
  <Widget
    token="[token]"
    resource="users-happiness"
    :onReaction="handleReaction"
    :onReactionsLimitReached="handleReactionsLimitReached"
  />
</template>
💡

Remember to replace token and resource with your project's token and proper resource

API

The Widget component lets you display a feedback widget with reactions and settings. Control these settings on Happy React dashboard (opens in a new tab).

Required props

PropTypeDescription
tokenstringToken of your project
resourcestring
Unique identifier of resource

Optional props

PropDefaultTypeDescription
classesstring |
{ root?: string; container?: string; grid?: string; cell?: string; reaction?: string; reactionActive?: string; reactionIcon?: string; reactionText?: string; }
Classes applied to widget elements. You can find them on Happy React styling guide
urlhttps://app.happyreact.comstringUrl where should widget get data. Used when you have own Happy React instance
onReaction(data: { id: string; icon: string; }) => voidEvent fired when user click reaction
onReactionsLimitReached() => voidEvent fired when user reach reactions limit
Was this page helpful?