0.0.7 • Published 5 years ago

react-native-faq v0.0.7

Weekly downloads
8
License
MIT
Repository
github
Last release
5 years ago

Build Status

react-native-faq

React Native F.A.Q.

Installation

Run npm install react-native-faq or yarn add react-native-faq

See it in action!

react-native-faq SNACK example

COMPONENTS

FAQ

It renders and array of questions each question should be defined according the Question Component.

e.g.

//Define some questions
const questions = [{
  question: "How can I help you?",
       reply: "You have several options to choose:",
       bullets: bullets,
       actionText: "I'm ready to help!",
       onClick: action_example
}]

// Render a FAQ component

<FAQ questions=questions />
proptypedefaultdescription
containerStyleobject"{}"Style for the main View Component of the F.A.Q. This view contains the title and questions container
titleContainerStyleobject"{}"Style for the View component title container
titleStyleobject"{ fontSize: 30, textAlign: 'center'}"Style for the Text component containing the title
titlestring | A string for the title of the FAQ
questionsarray | An array containing the Questions to be rendered.
questionContainerStyleobject"{}"styles for the View component questions container.

Question

Ideally to be render as an array inside the F.A.Q. component, but can be render alone just.

Here you have an example for the definition of a simple Question:

//First define some bullets
  const bullets = [
    "you could say hello",
    "Open an issue",
    "making a pull request",
    "or give me more ideas to improve this component"]
//Then definy an action (WebBroser is a method from ["expo"](https://docs.expo.io/versions/latest/))

const action_example = () => {
   WebBrowser.openBrowserAsync(
       "https://github.com/Olcina/react-native-faq"
   )};

//Wrap up everything in your quesstion props
const  props  = {
       question: "How can I help you?",
       reply: "You have several options to choose:",
       bullets: bullets,
       actionText: "I'm ready to help!",
       onClick: action_example}

//Finally render your question 

<Question  {...props} />
   
proptypedefaultdescription
bulletsarray"null"An array of strings containing the aditional bullets for the Questions.
bulletStyleobject"{ marginLeft: \"10%\"}"Each bullet is made of a Text component, use this props to style all bullets.
actionTextstring | An string inside a Text component for the title.
containerStyleobject"{ backgroundColor: \"lightgrey\", margin: 2, borderRadius: 5}"Main Question View component style.
actionStyleobject"{ backgroundColor: \"black\", borderRadius: 5, margin: 5}"Question action button style container It's a Touchable Opacity component containing a Text component
actionTextStyleobject"{ fontSize: 30, textAlign: \"center\"}"Text component style for the Question title
replyStyleobject"{ fontSize: 15}"Question reply container style
titleStyleobject"{ fontSize: 20}"Question title container style
onClickfunc"null"onClick prop: Can be any function you want to trigger.

EXPO EXAMPLE

A working example for an expo project

import * as React from 'react';
import { Text, View, StyleSheet } from 'react-native';
import { Constants, WebBrowser } from 'expo';
import { FAQ, Question } from './components/Question'

// define some bullets
const bullets = [
    'you could say hello',
    'Open an issue',
    'making a pull request',
    'or give me more ideas to improve this component'
]
// define an action
const action_example = () => {
    WebBrowser.openBrowserAsync(
        'https://github.com/Olcina/react-native-faq'
    );
}

const goTo = (link) => {
    WebBrowser.openBrowserAsync(
        link
    );
}

const questions = [
    {
        question: "How can I help you?",
        reply: "You have several options to choose:",
        bullets: bullets,
        actionText: "I'm ready to help!",
        onClick: action_example
    },
    {
        question: "Don't you know how to start?",
        reply: "Open a GitHub account and chat whit me",
        actionText: "Sure! Take me there!",
        onClick: () => goTo('https://github.com/'),
    }
]

// or any pure javascript modules available in npm
import { Card } from 'react-native-paper';

export default class App extends React.Component {
    render() {
        return (
            <View style={styles.container}>

                <View>
                    <Text style={{ textAlign: 'center' }}>You can load a complete F.A.Q.</Text>

                    <FAQ
                        title='F.A.Q.'
                        questions={questions}
                    />

                </View>

                <View>
                    <Text style={{ textAlign: 'center' }}>Or add your questions one by one</Text>
                    <Question
                        question="Is it possible to add just one question?"
                        reply="Of course, here you have an example"
                        actionText="Sure! Take me there!"
                        onClick={() => goTo('https://github.com/')}
                    />
                </View>

            </View>
        );
    }
}

const styles = StyleSheet.create({
    container: {
        flex: 1,
        justifyContent: 'space-evenly',
        paddingTop: Constants.statusBarHeight,
        backgroundColor: '#ecf0f1',
        padding: 8,
    }
});