-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f2d82a6
commit 62f2720
Showing
10 changed files
with
2,535 additions
and
753 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { Children, cloneElement } from '@wordpress/element'; | ||
|
||
/** | ||
* Utility component for the chatbot. | ||
* | ||
* @since n.e.x.t | ||
* | ||
* @param {Object} props Component props. | ||
* @param {Function} props.createChatBotMessage Function to create a chat message. | ||
* @param {Function} props.setState Function to set the state of the component. | ||
* @param {Element} props.children The children of the component. | ||
* @return {Component} The component to be rendered. | ||
*/ | ||
export default function ActionProvider( { | ||
createChatBotMessage, | ||
setState, | ||
children, | ||
} ) { | ||
return ( | ||
<div> | ||
{ Children.map( children, ( child ) => { | ||
return cloneElement( child, { | ||
actions: {}, | ||
} ); | ||
} ) } | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import Chatbot from 'react-chatbot-kit'; | ||
import 'react-chatbot-kit/build/main.css'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { useState } from '@wordpress/element'; | ||
import { Button } from '@wordpress/components'; | ||
import { __ } from '@wordpress/i18n'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import config from '../../config'; | ||
import MessageParser from '../MessageParser'; | ||
import ActionProvider from '../ActionProvider'; | ||
import './style.scss'; | ||
|
||
/** | ||
* Renders the chatbot. | ||
* | ||
* @since n.e.x.t | ||
* | ||
* @return {Component} The component to be rendered. | ||
*/ | ||
export default function ChatbotApp() { | ||
const [ isVisible, setIsVisible ] = useState( false ); | ||
const toggleVisibility = () => setIsVisible( ! isVisible ); | ||
|
||
return ( | ||
<> | ||
{ isVisible && ( | ||
<div | ||
id="wp-starter-plugin-chatbot-container" | ||
className="chatbot-container" | ||
> | ||
<Chatbot | ||
config={ config } | ||
messageParser={ MessageParser } | ||
actionProvider={ ActionProvider } | ||
/> | ||
</div> | ||
) } | ||
<Button | ||
variant="primary" | ||
onClick={ toggleVisibility } | ||
className="chatbot-button" | ||
aria-controls="wp-starter-plugin-chatbot-container" | ||
aria-expanded={ isVisible } | ||
> | ||
{ __( 'Need help?', 'wp-starter-plugin' ) } | ||
</Button> | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
.chatbot-container { | ||
position: fixed; | ||
bottom: 2rem; | ||
right: 2rem; | ||
z-index: 1000; | ||
border-radius: 5px; | ||
margin-bottom: 3rem; | ||
} | ||
|
||
.chatbot-button { | ||
position: fixed; | ||
bottom: 2rem; | ||
right: 2rem; | ||
z-index: 100; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { Children, cloneElement } from '@wordpress/element'; | ||
|
||
/** | ||
* Utility component for the chatbot. | ||
* | ||
* @since n.e.x.t | ||
* | ||
* @param {Object} props Component props. | ||
* @param {Element} props.children The children of the component. | ||
* @param {Object} props.actions Actions to be passed to the children. | ||
* @return {Component} The component to be rendered. | ||
*/ | ||
export default function MessageParser( { children, actions } ) { | ||
const parse = ( message ) => { | ||
console.log( message ); // eslint-disable-line no-console | ||
}; | ||
|
||
return ( | ||
<div> | ||
{ Children.map( children, ( child ) => { | ||
return cloneElement( child, { | ||
parse, | ||
actions: {}, | ||
} ); | ||
} ) } | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { createChatBotMessage } from 'react-chatbot-kit'; | ||
|
||
const config = { | ||
initialMessages: [ createChatBotMessage( `Hello world` ) ], | ||
}; | ||
|
||
export default config; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.