Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/adding additional props #6

Merged
merged 20 commits into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion example/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ function App() {
return (
<>
<h1>Demo website</h1>
<Stack project="https://www.stack-ai.com/embed/46bf5b6a-9b4d-48f6-8a13-cdfc4fe58520/11da0c81-afe2-4ccd-b498-807bbde8e7f1/653fefcfcc37c0093d55e6a9" />
<Stack project="https://www.stack-ai.com/embed/stack[testt]/c9a85553-64aa-45d1-923d-d125825c2b2b/656cf12c16dd780760afde33" />
houmland marked this conversation as resolved.
Show resolved Hide resolved
</>
);
}
Expand Down
23 changes: 20 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
"react": ">=17.0.0",
"react-dom": ">=17.0.0",
"react-iframe": "^1.8.5",
"react-merge-refs": "^2.1.1"
"react-merge-refs": "^2.1.1",
"react-stackai": "^0.1.6"
houmland marked this conversation as resolved.
Show resolved Hide resolved
},
"peerDependencies": {
"react": ">=17.0.0",
Expand Down
41 changes: 22 additions & 19 deletions src/Stack.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,40 @@ import { forwardRef, useEffect, LegacyRef } from 'react';
type StackProps = {
houmland marked this conversation as resolved.
Show resolved Hide resolved
project: string;
innerRef?: LegacyRef<HTMLIFrameElement> | undefined;
width?: string;
height?: string;
fixed?: boolean;
};

// We are forwarding the ref to the iframe so that the user has access to it.
const Stack = forwardRef(function Stack({ project, innerRef }: StackProps) {
const Stack = forwardRef(function Stack({
project,
innerRef,
width = '35rem', // Default width value
height = '38.5rem', // Default height value
houmland marked this conversation as resolved.
Show resolved Hide resolved
fixed = true // Default fixed value
houmland marked this conversation as resolved.
Show resolved Hide resolved
}: StackProps) {

// Resizes based on the open/close state of the chatbot
useEffect(() => {
const iframe = document.getElementById('responsiveIframe');
if (iframe) {
iframe.style.width = '90px';
iframe.style.height = '90px';
iframe.style.width = width;
iframe.style.height = height;
}

const handleMessage = (event: MessageEvent) => {
const iframe = document.getElementById('responsiveIframe');
if (iframe && event.data.type === 'chatbotStateChange') {
if (iframe && event.data.isClosed) {
setTimeout(() => {
iframe.style.width = '90px';
iframe.style.height = '90px';
}, 300);
const isMobile = window.innerWidth < 1000;
if (isMobile) {
// Mobile
iframe.style.width = '100vw';
iframe.style.height = '38.5rem';
} else {
const isMobile = window.innerWidth < 1000;
if (isMobile) {
// Mobile
iframe.style.width = '100vw';
iframe.style.height = '38.5rem';
} else {
// Desktop
iframe.style.width = '35rem';
iframe.style.height = '38.5rem';
}
// Desktop
iframe.style.width = width;
iframe.style.height = height;
}
}
};
Expand All @@ -52,7 +55,7 @@ const Stack = forwardRef(function Stack({ project, innerRef }: StackProps) {
className="chatbot-container"
allow="microphone"
style={{
position: 'fixed',
position: fixed? 'fixed' : 'relative',
houmland marked this conversation as resolved.
Show resolved Hide resolved
zIndex: '100',
overflow: 'hidden',
bottom: '0',
Expand Down
Loading