2.0.44 • Published 5 years ago

the-chat v2.0.44

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

the-chat

Build Status npm Version JS Standard

Chat UI of the-components

Installation

$ npm install the-chat --save

Usage

'use strict'

import React from 'react'
import { TheChat, TheChatStyle } from 'the-chat'
import { TheImageStyle } from 'the-image'
import { TheInputStyle } from 'the-input'
import { TheButtonStyle } from 'the-button'
import { TheVideoStyle } from 'the-video'
import { TheSpinStyle } from 'the-spin'
import { TheFormStyle } from 'the-form'

const images = [
  'https://raw.githubusercontent.com/apeman-asset-labo/apeman-asset-images/master/dist/dummy/01.jpg',
  'https://raw.githubusercontent.com/apeman-asset-labo/apeman-asset-images/master/dist/dummy/02.jpg',
  'https://raw.githubusercontent.com/apeman-asset-labo/apeman-asset-images/master/dist/dummy/03.jpg'
]

const videos = [
  './mov_bbb.mp4'
]

class ExampleComponent extends React.Component {
  constructor (props) {
    super(props)
    this._timer = null
    this.state = {
      form: {},
      items: [
        {
          at: new Date('2017/10/01 12:34'),
          text: 'This is the first post from John',
          who: {
            name: 'John',
            image: images[0]
          }
        },
        {
          at: new Date('2017/10/02 12:34'),
          text: 'This is the second post from John',
          who: {
            name: 'John',
            image: images[0]
          }
        },
        {
          at: new Date('2017/10/03 12:34'),
          node: <span>This is the third post from John</span>,
          who: {
            name: 'John',
            image: images[0]
          }
        },
        {
          at: new Date('2017/10/08 12:38'),
          video: videos[0],
          who: {
            name: 'John The Video',
            image: images[1],
          }
        },
        {
          at: new Date('2017/10/08 14:38'),
          image: images[2],
          align: 'right',
          text: `This is an text\n hoge fuge fuge`,
          status: 'Read',
          who: {
            name: 'hoge',
          }
        },
        {
          raw: true,
          at: new Date('2017/10/08 14:44'),
          node: <h3>this is some raw data</h3>,
        },
        {
          at: new Date('2017/10/08 14:38'),
          image: images[2],
          align: 'right',
          who: {
            name: 'hoge',
            image: images[0]
          }
        },
      ]
    }
  }

  render () {
    const { items } = this.state
    return (
      <div>
        <TheVideoStyle/>
        <TheButtonStyle/>
        <TheInputStyle/>
        <TheImageStyle/>
        <TheSpinStyle/>
        <TheFormStyle/>
        <TheChatStyle/>
        <TheChat>
          <TheChat.TimeLine style={{
            height: '300px',
            border: '4px solid #333'
          }}
                            items={items}
                            onWho={(who) => console.log('who selected', who)}
                            onScrollReachTop={() => console.log('reached to top')}
                            onScrollReachBottom={() => console.log('reached to bottom')}
          />
          <TheChat.Form onUpdate={(form) => this.setState({ form })}
                        values={this.state.form}
                        onSubmit={() => this.setState({
                          form: {},
                          items: [...this.state.items, {
                            at: new Date(),
                            text: this.state.form.text,
                            align: 'right',
                            who: {
                              name: 'Me',
                              color: '#33A'
                            }
                          }]
                        })}
          />
        </TheChat>

        <hr/>

        <TheChat>
          <TheChat.TimeLine alt='Not chat yet'
                            empty={true}
          />
        </TheChat>
      </div>

    )
  }

  componentDidMount () {
    this._timer = setInterval(() => {
      const { items } = this.state
      if (window.DISABLE_THE_CHAT_PUSH) {
        return
      }
      this.setState({
        items: [...items, {
          at: new Date(),
          text: 'Say hoo!',
          align: this.state.items.length % 2 ? 'left' : 'right',
          who: {
            name: 'hoge',
            initial: 'H'
          }
        }]
      })
      console.log('item added')
    }, 5000)
  }

  componentWillUnmount () {
    clearInterval(this._timer)
  }
}

export default ExampleComponent

Components

TheChat

Chat UI of the-components

TheChatForm

Chat UI of the-components

Props

NameTypeDescriptionDefault
disabledboolDisabled attributefalse
maxRowsnumberMax rows5
minLengthnumberMinimum text length1
minRowsnumberMin rows2
onSubmitfuncHandler for value submit() => null
onUpdatefuncHandler for value update() => null
spinningboolfalse
submitTextstringText for submit'Send'
valuesobjectForm values{}
autoExpandtrue

TheChatStyle

Style for TheChat

Props

NameTypeDescriptionDefault
optionsobjectStyle options{}

TheChatTimeLine

Chat Time line

Props

NameTypeDescriptionDefault
altstringAlt text'No chat yet'
itemsarrayOf objectItem data[]
langstringLang'en'
onScrollReachBottomfuncHandler when scroll reaches bottomnull
onScrollReachTopfuncHandler when scroll reaches topnull
onWhofuncHandler for who tapnull
spinningboolShows spinfalse
whoBaseColorstringBase color of whoTheChatTimeLineItem.DEFAULT_WHO_BASE_COLOR
whoImageSizenumberSize of who imageTheChatTimeLineItem.DEFAULT_WHO_IMAGE_SIZE

TheChatTimeLineItem

Chat Time line item

Props

NameTypeDescriptionDefault
alignenumContent align'left'
atinstanceOfnull
imageunionImage Urlnull
onWhofuncHandler for click who() => null
statusstringStatus textnull
textstringTextnull
videounionVideo urlnull
whoobjectWho posts{}
whoBaseColorstringBase color of whoTheChatTimeLineItem.DEFAULT_WHO_BASE_COLOR
whoImageSizenumberImage size of whoTheChatTimeLineItem.DEFAULT_WHO_IMAGE_SIZE

License

This software is released under the MIT License.

Links

2.0.44

5 years ago

2.0.43

5 years ago

2.0.42

5 years ago

2.0.40

5 years ago

2.0.39

5 years ago

2.0.38

5 years ago

2.0.37

5 years ago

2.0.36

5 years ago

2.0.35

6 years ago

2.0.34

6 years ago

2.0.33

6 years ago

2.0.32

6 years ago

2.0.31

6 years ago

2.0.30

6 years ago

2.0.29

6 years ago

2.0.28

6 years ago

2.0.27

6 years ago

2.0.26

6 years ago

2.0.25

6 years ago

2.0.24

6 years ago

2.0.23

6 years ago

2.0.22

6 years ago

2.0.21

6 years ago

2.0.20

6 years ago

2.0.19

6 years ago

2.0.18

6 years ago

2.0.17

6 years ago

2.0.15

6 years ago

2.0.14

6 years ago

2.0.13

6 years ago

2.0.12

6 years ago

2.0.11

6 years ago

2.0.10

6 years ago

2.0.9

6 years ago

2.0.8

6 years ago

2.0.7

6 years ago

2.0.6

6 years ago

2.0.5

6 years ago

2.0.4

6 years ago

2.0.3

6 years ago

2.0.2

6 years ago

2.0.0

6 years ago

1.0.26

6 years ago

1.0.25

6 years ago

1.0.24

6 years ago

1.0.23

6 years ago

1.0.22

6 years ago

1.0.21

6 years ago

1.0.20

6 years ago

1.0.19

6 years ago

1.0.18

6 years ago

1.0.17

6 years ago

1.0.16

6 years ago

1.0.15

7 years ago

1.0.14

7 years ago

1.0.13

7 years ago

1.0.12

7 years ago

1.0.11

7 years ago

1.0.10

7 years ago

1.0.9

7 years ago

1.0.8

7 years ago

1.0.7

7 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago