1.4.2 • Published 2 years ago

@bruit/component v1.4.2

Weekly downloads
151
License
MIT
Repository
github
Last release
2 years ago

bruit.io is a tool to get your users feedbacks, designed to be as simple to use as possible, following the Web Components standards. Users' feedbacks are sent directly to your favorite project management tools 🎉 .

bruit.io is built around an open source Web Component and a backend reciving the users feedback.

And we do no data retention at all about those feedbacks 👏


Getting started

start on bruit.io

By default, bruit.io component posts feedbacks to bruit.io api. If you wish, It can be connected with your own.

The free bruit.io api allows to pass feedbacks on to tools such as

Table of Contents

Installation Usage Configuration     BrtConfig     BrtField     BrtLabels     BrtColors Add data in feedbacks Handle errors Frameworks integration Contributing Known issues Having troubles?

Installation

bruit.io can be installed either with a command line

npm install @bruit/component --save

Or by directly modifying your index.html file

    <script type="module" src="https://unpkg.com/@bruit/component/dist/bruit/bruit.esm.js"></script>
    <script nomodule src="https://unpkg.com/@bruit/component/dist/bruit/bruit.js"></script>

Usage

Simply add this tag wherever you want in your project:

<bruit-io> ... optional element to click ... </bruit-io>

These properties are available on the component:

Integration code examples are available for these platforms:

Configuration

bruit-io Web Component has a config attribute, which takes a value of BrtConfig type.

BrtConfig

Describes the options for the bruit-io component

interface BrtConfig {
  apiKey?: string;
  form: Array<BrtField>;
  labels?: BrtLabels;
  colors?: BrtColors;
  closeModalOnSubmit?: boolean;
  apiUrl?: string;
  durationBeforeClosing?: number;
  elementToRenderSelector?: string;
  screenshot?: {
    maxWidth?: number,
    maxHeight?: number,
    imageType?: string,
    compression?: number
  }
}
AttributeTypeDescriptionMandatoryDefault value
apiKeystringyour personal api key (create an api key)no-
formarray<BrtField>inputs list for the generated formyes-
labelsBrtLabelsdescribes the labels of the modal (title / button / ...)nosee
colorsBrtColorsAllows to pick your colors in the modal themingnosee
closeModalOnSubmitbooleantrue to have modal closed automatically on submit (feedback is sent in background)nofalse
apiUrlstringAllows to use some third party backend for feedback processingnosee
durationBeforeClosingnumberAllows to define a number of milliseconds before the popup gets closedno-
elementToRenderSelectorstringsets the css selector of the element to use as the root of the rendering for the screenshotnodocument.body
screenshot.maxWidthnumberthe maximum width of the generated screenshot. Set it to have the screenshot resized when it's too largeno-
screenshot.maxHeightnumberthe maximum height of the generated screenshot. Set it to have the screenshot resized when it's too tallno-
screenshot.imageTypeimage/png ; image/jpegthe type of image to generatenoimage/png
screenshot.compressionnumberthe compression to apply to the screenshot between 1 (no compression) and 0 (fully compressed) ; only applies to image/jpeg typeno0.9

Typescript import :

import { BrtConfig } from '@bruit/component';

BrtField

Describes both the fields displayed in the popup form and the users' answers.

interface BrtField {
  id?: string;
  label: string;
  type: BrtFieldType;
  required?: boolean;
  value?: any;
  max?: number;
}
AttributeTypeDescriptionMandatory
idstringUnique identifier for the fieldno
labelstringPlaceholder / label for the fieldyes
typeBrtFieldTypeThe input type of the fieldyes
requiredbooleantrue to make the field required to send the feedbackno
valueanyThe value typed by the userno
maxnumbermax number for rating typeno

BrtConfig.form must contain one BrtField with id="agreement" and type="checkbox", used to check whether personal data should be sent with the feedback.

There are special values for the id attribute:

  • agreement: sets the field to use to check whether user agrees to send his personal data
  • title: sets the field used to display the title of feedback

Typescript import:

import { BrtField } from '@bruit/component';

BrtLabels

Used to describe the texts displayed in the modal.

interface BrtLabels {
  title?: string;
  introduction?: string;
  button?: string;
}
AttributeDescriptionDefault value
titleDefines the title of the modalbruit.io
introductionDefines the description textsend a feedback
buttonDefines the text of the submit buttonsend

Typescript import:

import { BrtLabels } from '@bruit/component';

BrtColors

If you feel like an artist 🎨 , you may use BrtColors to change the theme of the modal.

This gives the possiblity to change the header, body, background, errors and focus colors.

Only hexadecimal values are allowed here.

interface BrtColors {
  header?: string;
  body?: string;
  background?: string;
  errors?: string;
  focus?: string;
}
AttributeDescriptionDefault value
headerthe modal's header color#2D8297
bodythe color for the background of the modal#eee
backgroundthe color used to dim what's behind the modal#444444ee
errorsthe text color to use for errors#c31313
focusthe color to use on focused field#1f5a6

Typescript import:

import { BrtColors } from '@bruit/component';

BrtFeedback

By default, bruit.io component posts a feedback to bruit.io API (https://api.bruit.io/feedback).

If you wish, it can be connected with your own API.

To do it, you must provide a API endpoint, to be passed to BrtConfig as apiUrl.

bruit.io component posts a BrtFeedback to your API endpoint.

interface BrtFeedback {
  apiKey?: string;
  canvas?: string;
  url?: string;
  cookies?: BrtCookies;
  navigator?: BrtNavigatorInfo;
  display?: BrtScreenInfo;
  logs?: Array<BrtLog>;
  data: Array<BrtData>;
}

Typescript import:

import { BrtFeedback } from '@bruit/types';

Add data to the feedback

It is possible to automatically had technical data in the feedback, for example the version number of your application, the identifier of the user sending the feedback, etc.

This is done by using either the brt-data or brt-data-fn property on the component.

data

brt-data property is used to send an array of objects to add to the feedback to the component.

The property takes a BrtData array as a value.

dataFn

brt-data-fn property takes a function as a value. The function should return either an array of BrtData or a promise of an array of BrtData.

BrtData

Used to pass additional data to the feedback (ie the application version number)

interface BrtData {
  label: string;
  type?: string;
  value: any;
  id?: string;
}
AttributeTypeDescriptionMandatory
labelstringa label for the datayes
typestringthe type of the datano
valueanythe value to sendyes
idstringan identifier for the datano

Typescript import:

import { BrtData } from '@bruit/component';

Handle errors

event

bruit-io emits onError events when an error occurs.

An error is of type BrtError, composed by a code and a text.

more information about errors

BrtError

Format of the errors which may be sent by the component.

interface BrtError {
  code: number;
  text: string;
}

Typescript import:

import { BrtError } from '@bruit/component';

Framework integrations

JavaScript

Integrating bruit-io component to a project without a JavaScript framework is pretty straight forward. When using a simple HTML page, bruit.io can be added from a CDN as follows:

<!DOCTYPE html>
<html lang="en">
  <head>
    <script type="module" src="https://unpkg.com/@bruit/component/dist/bruit/bruit.esm.js"></script>
    <script nomodule src="https://unpkg.com/@bruit/component/dist/bruit/bruit.js"></script>
  </head>
  ...
</html>

Then, you may add the bruit-io component directly:

<body>
  <bruit-io></bruit-io>
  ...
  <script>
    var bruitCmp = document.querySelector('bruit-io');


    bruitCmp.config = {
      // whatever your config is
    };
  </script>
</body>

from stencil documentation

Angular

Using bruit-io component within an Angular project is a two-step process. You need to:

  1. Include the CUSTOM_ELEMENTS_SCHEMA in the modules that use the components
  2. Call defineCustomElements() from main.ts (or some other appropriate place)

Including the Custom Elements Schema

Including the CUSTOM_ELEMENTS_SCHEMA in the module allows the use of Web Components in the HTML files. Here is an example of adding it to AppModule:

import { BrowserModule } from '@angular/platform-browser';
import { CUSTOM_ELEMENTS_SCHEMA, NgModule } from '@angular/core';
import { AppComponent } from './app.component';

@NgModule({
  declarations: [AppComponent],
  imports: [BrowserModule],
  bootstrap: [AppComponent],
  schemas: [CUSTOM_ELEMENTS_SCHEMA]
})
export class AppModule {}

The CUSTOM_ELEMENTS_SCHEMA needs to be included in any module that uses bruit.io.

Calling defineCustomElements

bruit.io component includes a function used to load itself in the application window object. That function is called defineCustomElements() and needs to be executed once during the bootstrapping of your application. One convenient place to add it is in the main.ts file as follows:

import { enableProdMode } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';

import { AppModule } from './app/app.module';
import { environment } from './environments/environment';

import { applyPolyfills, defineCustomElements } from '@bruit/component/loader';
// if you want set bruit config :
// import BruitCoreConfig from '@bruit/component/dist/collection/start';

if (environment.production) {
  enableProdMode();
}

platformBrowserDynamic()
  .bootstrapModule(AppModule)
  .catch(err => console.log(err));
applyPolyfills().then(() => {
  defineCustomElements(window)

    // if you want set bruit config :
  // defineCustomElements(window).then(() => {
  //   BruitCore({
  //     logCacheLength: {
  //       click: 5
  //     }
  //   });
  // });
})

Using bruit.io in an Angular component

<bruit-io
  [config]="bruitConfig"
  [data]="bruitData"
  [dataFn]="bruitDataPromise()"
  (onError)="handleBruitError($event)"
></bruit-io>
public bruitConfig: BrtConfig = {
  apiKey:"xxxxxxxxxxx",
  form:[...]
};

public bruitData: Array<BrtData> = [
  {
    label:"version",
    value: environment.version
  }
];

constructor(private api : ApiService){}

bruitDataPromise(): Promise<Array<BrtData>>{
  return this.api.getUser().then( user =>
    [
      {
        label: "user id",
        value: user.id
      },
      {
        label: "user email",
        value: user.email
      }
    ]
  );
}

handleBruitError(error: BrtError){
  ...
}

from stencil documentation

React

With an application built using React CLI (namely create-react-app), the easiest way is to include the bruit-io component by calling the defineCustomElements() method in the index.js file.

import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import registerServiceWorker from './registerServiceWorker';

import { applyPolyfills, defineCustomElements } from '@bruit/component/loader';
// if you want set bruit config :
// import BruitCoreConfig from '@bruit/component/dist/collection/start';


ReactDOM.render(<App />, document.getElementById('root'));
registerServiceWorker();
applyPolyfills().then(() => {
  defineCustomElements(window);

  // if you want set bruit config :
  // defineCustomElements(window).then(() => {
  //   BruitCore({
  //     logCacheLength: {
  //       click: 5
  //     }
  //   });
  // });
});

from stencil documentation

Vue

In order to use the bruit-io Web Component inside of a Vue application, it should be modified to define the custom elements and to inform the Vue compiler which elements to ignore during compilation. This can all be done within the main.js file as follows:

import Vue from 'vue';
import App from './App.vue';
import { applyPolyfills, defineCustomElements } from '@bruit/component/loader';

Vue.config.productionTip = false;
Vue.config.ignoredElements = [/bruit-\w*/];

applyPolyfills().then(() => {
  defineCustomElements(window);
});

new Vue({
  render: h => h(App)
}).$mount('#app');

from stencil documentation

Contributing

Bruit.io web component is 100% free and open source. Contributing to bruit.io may involve writing TypeScript, TSX, Stencil, SCSS or Markdown depending on the component you are working on. We are looking for help in any of these areas!

Known issues

Having troubles ?

1.4.2

2 years ago

1.4.1

2 years ago

1.4.0

2 years ago

1.3.15

3 years ago

1.3.14

3 years ago

1.3.13

4 years ago

1.3.12

4 years ago

1.3.12-beta1

4 years ago

1.3.12-beta2

4 years ago

1.3.11

4 years ago

1.3.10

4 years ago

1.3.9

4 years ago

1.3.8

4 years ago

1.3.7

4 years ago

1.3.6

4 years ago

1.3.5

4 years ago

1.3.4

4 years ago

1.3.3

4 years ago

1.3.2

4 years ago

1.3.1

4 years ago

1.3.0-beta2

4 years ago

1.3.0-beta1

4 years ago

1.3.0

4 years ago

1.2.4-1

4 years ago

1.2.5

4 years ago

1.2.4

4 years ago

1.2.3

4 years ago

1.2.2

4 years ago

1.2.1

4 years ago

1.2.0

4 years ago

1.0.7

5 years ago

1.0.7-9

5 years ago

1.0.7-8

5 years ago

1.0.7-7

5 years ago

1.0.7-6

5 years ago

1.0.7-5

5 years ago

1.0.7-4

5 years ago

1.0.7-3

5 years ago

1.0.7-2

5 years ago

1.0.7-1

5 years ago

2.0.14-plop

5 years ago

1.0.8-3

5 years ago

2.0.13-plop

5 years ago

2.0.12-plop

5 years ago

2.0.11-plop

5 years ago

2.0.10-plop

5 years ago

2.0.9-plop

5 years ago

2.0.4-plop

5 years ago

1.1.0-22

5 years ago

1.1.0-21

5 years ago

1.1.0-20

5 years ago

1.1.0-19

5 years ago

1.1.0-18

5 years ago

1.1.0-17

5 years ago

1.1.0-16

5 years ago

1.1.0-15

5 years ago

1.1.0-14

5 years ago

1.1.0-13

5 years ago

1.1.0-12

5 years ago

1.1.0-11

5 years ago

1.1.0-10

5 years ago

1.0.8-2

5 years ago

1.1.0-9

5 years ago

1.0.8-1

5 years ago

1.1.0-8

5 years ago

1.1.0-7

5 years ago

1.1.0-6

5 years ago

1.1.0-5

5 years ago

1.1.0-4

5 years ago

1.1.0-3

5 years ago

1.1.0-2

5 years ago

1.1.0-1

5 years ago

1.0.7-beta1

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.5-3

5 years ago

1.0.5-2

5 years ago

1.0.5-1

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago

0.7.19-1

5 years ago

0.7.17

5 years ago

0.7.16

5 years ago

0.7.15

5 years ago

0.7.15-1

5 years ago

0.7.14

5 years ago

0.7.13

5 years ago

0.7.13-7

5 years ago

0.7.13-6

5 years ago

0.7.13-5

5 years ago

0.7.13-4

5 years ago

0.7.13-3

5 years ago

0.7.13-2

5 years ago

0.7.13-1

5 years ago

0.7.12

5 years ago

0.7.11

5 years ago

0.7.10

5 years ago

0.7.10-1

5 years ago

0.7.9

5 years ago

0.7.8-3

5 years ago

0.7.8-2

5 years ago

0.7.8-1

5 years ago

0.7.8

5 years ago

0.7.7

5 years ago

0.7.7-4

5 years ago

0.7.7-3

5 years ago

0.7.7-2

5 years ago

0.7.7-1

5 years ago

0.7.6

5 years ago

0.8.0-1

5 years ago

0.7.5

5 years ago

0.7.5-2

5 years ago

0.7.5-1

5 years ago

0.7.4

5 years ago

0.7.3

5 years ago

0.7.2

5 years ago

0.7.1

5 years ago

0.7.0

5 years ago

0.7.0-3

5 years ago

0.7.0-2

5 years ago

0.7.0-1

5 years ago

0.6.5

5 years ago

0.6.5-1

5 years ago

0.6.4

5 years ago

0.6.3-1

5 years ago

0.6.2

5 years ago

0.6.1

5 years ago

0.6.0

5 years ago

0.5.2

5 years ago

0.5.1

5 years ago

0.5.0

5 years ago

0.5.0-6

5 years ago

0.5.0-5

5 years ago

0.5.0-4

5 years ago

0.5.0-3

5 years ago

0.5.0-2

5 years ago

0.5.0-1

5 years ago

0.4.11

5 years ago

0.4.10

5 years ago

0.4.9-1

5 years ago

0.4.8

5 years ago

0.4.7

5 years ago

0.4.6

5 years ago

0.4.5

5 years ago

0.4.4

5 years ago

0.4.3

5 years ago

0.4.2

5 years ago

0.4.1

5 years ago

0.4.0

5 years ago

0.3.3

5 years ago

0.3.2

5 years ago

0.3.1

5 years ago

0.2.19

5 years ago

0.2.18

5 years ago

0.2.17

5 years ago

0.2.16

5 years ago

0.2.15

5 years ago

0.2.14

5 years ago

0.2.12

5 years ago

0.2.11

5 years ago