Code Monkey home page Code Monkey logo

talquei's Introduction


๐Ÿง Why?

Forget the boring and non-intuitive forms. With talquei you can quickly build fantastic forms as in the image above.

๐Ÿ’ป Install

Install using your package manager:

$ yarn add talquei

Add into your app:

import Vue from 'vue'
import Talquei from 'talquei'

// import the styles 
import 'talquei/dist/talquei.min.css'

Vue.use(Talquei)

Or import into your component:

import { Talquei, TalqueiMessage } from 'talquei'

export default {
  components: {
    Talquei,
    TalqueiMessage
  }
}

โš™๏ธ Usage

The Talquei component should wrapper any TalqueiMessage:

<template>
  <Talquei>
    <TalqueiMessage text="Hi! My name is Talquei!" />
    <TalqueiMessage text="I'm a plugin to help you." />
  </Talquei>
</template>

Request user input

You can request a user entry by prop or slot. The prop will basically inject your tag into a form and fill the entry in the v-model.

Example
<template>
  <Talquei>
    <TalqueiMessage text="What's your name?" />
    <TalqueiMessage
      v-model="name"
      :input="{ tag: 'text', placeholder: 'Enter your name' }"
      is-user
    />
  </Talquei>
</template>

<script>
export default {
  data: () => ({
    name: ''
  })
}
</script>

Format user input

When the user enters the text, you can format it using the prop template:

Example
<template>
  <Talquei>
    <TalqueiMessage
      :input="{ tag: 'text', placeholder: 'Enter your name' }"
      template="My name is {text}"
      is-user
    />
  </Talquei>
</template>

Predefined answers

If you need predefined answers (such as the select or radio tag) you can set input.type = 'select' and pass your object in the options field:

Example
<template>
  <Talquei>
    <TalqueiMessage text="Which front-end framework do you prefer?" />
    <TalqueiMessage
      v-model="name"
      :input="{ tag: 'select', options: frameworks }"
      is-user
    />
  </Talquei>
</template>

<script>
export default {
  data: () => ({
    frameworks: {
      vue: 'Vue.js',
      angular: 'AngularJS',
      ember: 'Ember.js'
    }
  })
}
</script>

Conditional messages

Use when you want the v-if attribute to display conditional messages:

Example
<template>
  <Talquei>
    <TalqueiMessage text="Which front-end framework do you prefer?" />
    <TalqueiMessage
      v-model="name"
      :input="{ tag: 'select', options: frameworks }"
      is-user
    />
    <TalqueiMessage text="What plugins do you usually use in your projects?" />
    <TalqueiMessage
      v-if="answer === 'vue'"
      v-model="plugin"
      :input="{ tag: 'text', placeholder: 'talquei' }"
      is-user
    />
  </Talquei>
</template>
</script>

Using slots

If you need to build more complex input (like validations, custom components) you can use slots. After the completion remeber to call the next() method from the Talquei component.

Example
<template>
  <Talquei ref="talquei">
    <TalqueiMessage text="Hello">
      <form @submit.stop="onSubmit">
        <input ref="input" type="text">
        <button>Ok</button>
      </form>
    </TalqueiMessage>
  </Talquei>
</template>

<script>
export default {
  methods: {
    onSubmit () {
      this.name = this.$refs.input.value
      this.$refs.talquei.next()
    }
  }
}
</script>

๐Ÿ”Ž API

Talquei component

Props

Name Description Type Default
autoRun Starts the conversation when mounted Boolean true

Slots

Name Description
default Insert your TalqueiMessage here. Don't need a root element

Methods

init(): void

Use this method to start the conversation if you set autoRun to false.

next(): void

Search the next message. Nested messages will inject this method to call when finalizing typing.

TalqueiMessage component

Props

Name Description Type Default
input Request a user input See details Object undefined
isUser Define as a message written by the user Boolean false
text Text to be displayed, if isUser will not be typed String undefined
value Useful only for use in v-model String undefined
template Formats user input String {text}
input object

Will create a basic form from the tag informed, should not be defined if you prefer to use the slot.

  • tag: Valid tags are currently text or select.
  • options (select): Use this field to define an object with the available options.
  • placeholder (text): Set the placeholder of your input field.
  • type (text): Set the type of your input field. Default is text.

Slots

Name Description
default Use this if you need more complex or personalized user input
avatar Change the element used as avatar. Default is "๐Ÿค–"

๐Ÿค Contribute

If you want to contribute to this project, please see our Contributing Guide.

talquei's People

Contributors

luciorubeens avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.