Skip to content

fredjens/react-conversational-ui

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

7 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿค– React Conversational UI

A react component for conversational UI. Define your question and get the users input in return.

How to use

Define the questions

The questions supports these field.

  • text - the text for your question (string) (required)
  • image - url to a image (string)
  • buttons - if you want to have answer alternatives (array)
  • key - the key that will be returned with the questions. If not key defined the question will not be returned.

The React component

The component take these props:

  • questions - an array of questions.
  • onEnded - function to return the user input when session ends.
  • theme - styles and settings (optional)
import Conversation from '../containers/Conversation';

const App = (props) => {
  function getUserAnswers(answers) {
    console.log('answers', answers);
  }

  return (
    <div>
      <Conversation
        questions={questions}
        onEnded={getUserAnswers}
        theme={theme}
      />
    </div>
  );
}

๐Ÿ’… Themeing

You can customize the size, colors, fonts and avatars.

const theme = {
  blobColor: 'cyan',
  userBlobColor: 'deeppink',
  user: '๐Ÿ‘€',
  bot: '๐Ÿ˜พ',
  baseColor: '#ccc',
  font: "'courier', monotype",
  height: '500px',
  width: '500px',
};

Example questions

Questions:

const questions = [{
    text: 'Hello!',
  }, {
    text: 'What is your first name?',
    key: 'firstName',
  }, {
    text: 'How are you?',
    key: 'emotion',
    buttons: [{
      text: 'Awesome!',
      value: 'great',
    }, {
      text: 'Good',
      value: 'good',
    }, {
      text: 'Could be better',
      value: 'medium',
    }, {
      text: 'Not so good...',
      value: 'bad',
    }]
  }, {
    text: 'Do you like this image?',
    key: 'imageLike',
    image: 'https://unsplash.it/400/300/?random',
    buttons: [{
      text: 'Yes, looks great!',
      value: 'yes',
    }, {
      text: 'No really...',
      value: 'no',
    }]
}];

๐Ÿ“ฆ Dependencies

  • Create React App <3
  • Styled Components
  • Flexbox

About

๐Ÿค– React conversational UI

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published