Skip to content

Commit 8e73836

Browse files
authored
Merge pull request #24 from necyberteam/simplifications
remove web-component option, consolidate CSS, pare down props, add ratings, add query/session headers
2 parents 6e35159 + f26128c commit 8e73836

32 files changed

+881
-1363
lines changed

README.md

Lines changed: 86 additions & 248 deletions
Large diffs are not rendered by default.

build/static/css/main.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/static/css/main.css.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/static/js/main.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/static/js/main.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.d.ts

Lines changed: 15 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
interface QABotProps {
22
apiKey?: string;
3-
/** Whether the chat window is open by default (floating mode only, ignored for embedded) */
4-
defaultOpen?: boolean;
3+
/** Whether the chat window is open (floating mode only, ignored for embedded) */
4+
open?: boolean;
5+
/** Callback when chat window open state changes */
6+
onOpenChange?: (open: boolean) => void;
57
/** Whether the bot is embedded in the page (always open when embedded) */
68
embedded?: boolean;
79
isLoggedIn?: boolean;
@@ -10,35 +12,29 @@ interface QABotProps {
1012
[key: string]: any; // Allow additional props
1113
}
1214

13-
// Note: To control the chat window externally, use the useChatWindow hook from react-chatbotify:
14-
// import { useChatWindow } from 'react-chatbotify';
15-
// const { toggleChatWindow } = useChatWindow();
15+
// Note: The React component uses controlled mode - manage state in your parent component:
16+
//
17+
// const [isOpen, setIsOpen] = useState(false);
18+
// const [userLoggedIn, setUserLoggedIn] = useState(false);
19+
// <QABot open={isOpen} onOpenChange={setIsOpen} isLoggedIn={userLoggedIn} />
20+
//
21+
// To send messages programmatically, use the ref:
22+
// const botRef = useRef();
23+
// botRef.current?.addMessage("Hello World!");
1624

1725
// React component
1826
export const QABot: React.ForwardRefExoticComponent<
1927
QABotProps & React.RefAttributes<{
2028
addMessage: (message: string) => void;
21-
setBotIsLoggedIn: (status: boolean) => void;
22-
openChat: () => void;
23-
closeChat: () => void;
24-
toggleChat: () => void;
2529
}>
2630
>;
2731

28-
// Web Component class (available in the standalone build)
29-
export class WebComponentQABot extends HTMLElement {
30-
static observedAttributes: string[];
31-
attributeChangedCallback(name: string, oldValue: string, newValue: string): void;
32-
connectedCallback(): void;
33-
disconnectedCallback(): void;
34-
}
35-
36-
// Function for non-React integration
32+
// Function for non-React integration (now React-backed for everything)
3733
interface QABotConfig extends QABotProps {
3834
target: HTMLElement;
3935
}
4036

41-
// Main function for programmatic usage (works with React or Web Component)
37+
// Main function for programmatic usage (now React-backed for all usage)
4238
export function qaBot(config: QABotConfig): {
4339
addMessage: (message: string) => void;
4440
setBotIsLoggedIn: (status: boolean) => void;
@@ -48,23 +44,5 @@ export function qaBot(config: QABotConfig): {
4844
destroy: () => void;
4945
};
5046

51-
// Web Component specific function (exposed in the standalone bundle)
52-
export function webComponentQABot(config: QABotConfig): () => void;
53-
5447
// Default export (React component)
5548
export default QABot;
56-
57-
// Augment the HTMLElementTagNameMap to include our custom element
58-
declare global {
59-
interface HTMLElementTagNameMap {
60-
'qa-bot': WebComponentQABot;
61-
}
62-
63-
// Global object for standalone usage
64-
interface Window {
65-
qaBot?: typeof webComponentQABot;
66-
}
67-
68-
// Global function available without window prefix
69-
var qaBot: typeof webComponentQABot;
70-
}

local-demo.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,11 @@ function updateBotLoginStatus(isLoggedIn) {
5656
function setupLoginCheckbox() {
5757
const loginCheckbox = document.getElementById('user-logged-in');
5858
if (loginCheckbox) {
59-
// Initialize checkbox state based on current cookie
6059
loginCheckbox.checked = isUserLoggedIn();
6160

6261
loginCheckbox.addEventListener('change', (e) => {
6362
setAuthCookie(e.target.checked);
6463
updateBotLoginStatus(e.target.checked);
65-
console.log('| user logged in:', e.target.checked);
6664
});
6765
}
6866
}

package-lock.json

Lines changed: 23 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
22
"name": "@snf/access-qa-bot",
3-
"version": "2.0.0",
3+
"version": "2.1.0-rc.7",
44
"private": false,
55
"homepage": ".",
6-
"description": "ACCESS Q&A Bot React Component and Web Component",
6+
"description": "ACCESS Q&A Bot React Component",
77
"main": "./dist/access-qa-bot.umd.cjs",
88
"module": "./dist/access-qa-bot.js",
99
"exports": {
@@ -21,7 +21,8 @@
2121
"index.d.ts"
2222
],
2323
"dependencies": {
24-
"react-chatbotify": "^2.0.0-beta.38"
24+
"react-chatbotify": "^2.0.0-beta.38",
25+
"uuid": "^11.1.0"
2526
},
2627
"peerDependencies": {
2728
"preact": "^10.0.0",

rollup.config.mjs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,28 +51,21 @@ export default [
5151
external: Object.keys(pkg.peerDependencies || {})
5252
},
5353

54-
// UMD build with React bundled for standalone use
54+
// UMD build with React bundled for standalone use - now React-backed
5555
{
56-
input: 'src/web-component.js',
56+
input: 'src/standalone.js',
5757
output: {
5858
file: './dist/access-qa-bot.standalone.js',
5959
format: 'umd',
6060
name: 'qaBot',
6161
sourcemap: true,
62-
exports: 'named',
63-
globals: {
64-
// We don't need globals since React is bundled
65-
}
62+
exports: 'default',
63+
globals: {}
6664
},
6765
plugins: [
6866
postcss({
6967
extensions: ['.css'],
7068
minimize: true,
71-
// For web components, extract the CSS to inject it in shadow DOM
72-
extract: false,
73-
modules: false,
74-
autoModules: false,
75-
// This ensures the CSS is injected into JS properly for shadow DOM
7669
inject: {
7770
insertAt: 'top',
7871
},

0 commit comments

Comments
 (0)