Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@bruit/component

Package Overview
Dependencies
Maintainers
1
Versions
162
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@bruit/component

send your feedbacks with bruit.io

  • 0.2.18
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
241
decreased by-6.23%
Maintainers
1
Weekly downloads
 
Created
Source

Bruit.io

BRuit is a User Issues Tool

NPM Version License License Built With Stencil

Bruit.io is a WebComponent built on Stencil.js

Available on all frameworks that support WebComponents such as

Angular React Ember Vue Stencil Polymer Ionic Meteor Backbone Aurelia


Bruit.io is a tool to get your users feedbacks, designed to be as simple to use as possible, following the Web Component 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

Table of Contents

Installation
Usage
Configuration
    BrtConfig
    BrtField
    BrtLabels
    BrtColors
    BrtLogLevels
    BrtData
    BrtError
Add data in feedbacks
Handle errors
Frameworks integration
Contributing
Having troubles?

Install

In command line

npm install @bruit/component --save

Or by directly modifying your index.html file

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

Usage

Simply add the following tag wherever you want in your project

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

with properties :

integration code examples :

Javascript      Angular      React      Vue

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;
  logLevels?: BrtLogLevels;
  maxLogLines?: number;
  colors?: BrtColors;
  closeModalOnSubmit?: boolean;
  apiUrl?: string;
}
AttributeTypeDescriptionMandatoryDefault value
apiKeystringyour personal api key (create an api key)yes-
formarray<BrtField>inputs list for the generated formyes-
labelsBrtLabelsdescribes the labels of the modal (title / button / ...)nosee
logLevelsBrtLogLevelsUsed to filter the logs to send by their level (debug, warn, error, etc)nosee
maxLogLinesnumberDefines the number of log lines to send in the feedbackno100
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 processingnohttps://api.bruit.io/feedback
  • 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: string;
  required?: boolean;
  value?: any;
}
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

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';

BrtLogLevels

By default, all log levels (log, warn, errors, ...) are sent in the feedback. BrtLogLevels allows to disable specific ones.

To disable a type, just set with the related type to false in the logLevels section:

{
  "apiKey": "xxxxxxxxxx",
  "form": ["..."],
  "logLevels": {
    "log": false,
    ...
  }
}
interface BrtLogLevels {
  log?: boolean;
  debug?: boolean;
  info?: boolean;
  warn?: boolean;
  error?: boolean;
  network?: boolean;
  click?: boolean;
  url?: boolean;
}
  • special types:

    • network type is for your fetch and xmlHttpRequest calls.
    • click type is for mouse click event.
    • url type log all url changing
  • Typescript import:

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

Automatically add data in 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.

If you have data that can be retrieved synchronously, you can use data.

For asynchronous data, you can use dataFn.

data

data property is used for send synchronous data.

Just give him an BrtData array.

dataFn

dataFn property is used for send asynchronous data.

Give him an Promise of BrtData array. Your promise will be called upon to submit the feedback.

BrtData

  • Format :
interface BrtData {
  label: string;
  type?: string;
  value: any;
  id?: string;
}
  • import if using Typescript :
import { BrtData } from '@bruit/component';

Handle errors

event

bruit-io emit onError event when an error occured.

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

more information about errors

BrtError

  • Format :
interface BrtError {
  code: number;
  text: string;
}
  • import if using Typescript :
import { BrtError } from '@bruit/component';

Framework integrations

JavaScript

Integrating bruit-io component to a project without a JavaScript framework is straight forward. If you're using a simple HTML page, you can add bruit component via a script tag.

<!DOCTYPE html>
<html lang="en">
<head>
  <script src="https://unpkg.com/@bruit/component/dist/test-components.js"></script>
</head>
<body>
  <bruit-io></bruit-io>
  <script>
    var bruitCmp = document.querySelector('bruit-io');
    bruitCmp.config = {
      apiKey: 'xxxxxxxxxxxxxxxxx',
      form: [...]
    };
  </script>
</body>
</html>

from stencil documentation

Angular

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

  1. Include the CUSTOM_ELEMENTS_SCHEMA in the modules that use the components
  2. Call defineCustomElements(window) 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 the web components in the HTML markup without the compiler producing errors. 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 custom elements.

Calling defineCustomElements

Bruit component include a main function that is used to load the components in the collection. That function is called defineCustomElements() and it needs to be called once during the bootstrapping of your application. One convenient place to do this is in main.ts as such:

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

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

import { defineCustomElements } from '@bruit/component/dist/loader';

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

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

Using bruit-io in your 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 the create-react-app script the easiest way to include the bruit-io component is to call defineCustomElements(window) from 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 { defineCustomElements } from '@bruit/component/dist/loader';

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

from stencil documentation

Vue

In order to use the bruit-io component within the Vue app, the application must 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. For example:

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

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

defineCustomElements(window);

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

from stencil documentation

Contributing

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!

Having troubles ?

FAQs

Package last updated on 13 Nov 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc