Skip to content

Commit 64c44ab

Browse files
Shreyas281299Rankush Kumar
andauthored
docs(cc-widgets): add AI documentation - AGENTS.md and ARCHITECTURE.md (#597)
Co-authored-by: Rankush Kumar <rankkuma+cisco@cisco.com>
1 parent c16dc06 commit 64c44ab

2 files changed

Lines changed: 796 additions & 0 deletions

File tree

Lines changed: 341 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,341 @@
1+
# CC Widgets - Widget Aggregator & Web Components
2+
3+
## Overview
4+
5+
CC Widgets is an aggregator package that bundles all contact center widgets and exports them in two formats: React components for React applications, and Web Components for framework-agnostic use. It uses the r2wc library to convert React widgets into standards-compliant Web Components that can be used in any web application.
6+
7+
**Package:** `@webex/cc-widgets`
8+
9+
**Version:** See [package.json](../package.json)
10+
11+
---
12+
13+
## Why and What is This Package Used For?
14+
15+
### Purpose
16+
17+
CC Widgets serves as the main entry point for contact center widgets. It:
18+
19+
- **Single package, no dependency sprawl** - Install one package (`@webex/cc-widgets`) instead of multiple widget packages; no need to track versions, peer dependencies, or compatibility across `@webex/cc-station-login`, `@webex/cc-user-state`, `@webex/cc-task`, etc.
20+
- **Provides complete widget suite** - All widgets (StationLogin, UserState, TaskList, CallControl, OutdialCall, etc.) are bundled and ready to use
21+
- **Delivers production-ready bundles** - Pre-built, optimized webpack bundles with all dependencies included
22+
- **Reduces integration effort** - One installation, one import, immediate access to all widgets
23+
24+
### Key Capabilities
25+
26+
- **Dual Export System**:
27+
28+
- Import as React components for React applications
29+
- Use as Web Components (`<widget-cc-*>`) for framework-agnostic integration
30+
- Both formats available from the same package
31+
32+
- **Automatic Web Component Registration**:
33+
34+
- Web Components auto-register in the browser when bundle is loaded
35+
- No manual `customElements.define()` required
36+
- Ready to use immediately in HTML
37+
38+
- **Single Package Management**:
39+
40+
- All widgets bundled in one npm package
41+
- Guaranteed compatibility between widgets
42+
- Simplified version management and updates
43+
44+
- **Production Optimized**:
45+
46+
- Webpack-bundled with code splitting
47+
- React and dependencies included in Web Component bundle
48+
- Minimal bundle size for React component exports (re-exports only)
49+
50+
- **Event System**:
51+
52+
- React components use standard props and callbacks
53+
- Web Components emit CustomEvents for framework-agnostic communication
54+
- Consistent event handling across both formats
55+
56+
- **Shared Store Access**:
57+
- Global MobX store accessible from both React and Web Components
58+
- Single source of truth for agent state, tasks, and SDK interactions
59+
- No store duplication or synchronization needed
60+
61+
---
62+
63+
## Dependencies
64+
65+
**Note:** For exact versions, see [package.json](../package.json)
66+
67+
### Runtime Dependencies
68+
69+
| Package | Purpose |
70+
| ------------------------------ | -------------------------------------------------------- |
71+
| `@r2wc/react-to-web-component` | React to Web Component conversion |
72+
| `@webex/cc-station-login` | Station Login widget |
73+
| `@webex/cc-user-state` | User State widget |
74+
| `@webex/cc-task` | Task widgets (TaskList, IncomingTask, CallControl, etc.) |
75+
| `@webex/cc-store` | MobX singleton store |
76+
77+
### Peer Dependencies
78+
79+
| Package | Purpose |
80+
| ---------------------------------- | -------------------------------------------- |
81+
| `@momentum-ui/react-collaboration` | Momentum UI components (required by widgets) |
82+
83+
### Note on React Dependencies
84+
85+
React and ReactDOM are **not** listed as dependencies because:
86+
87+
- React components expect the host app to provide React
88+
- Web Components bundle includes React internally
89+
- This prevents duplicate React instances
90+
91+
---
92+
93+
## Available Widgets
94+
95+
### React Component Exports
96+
97+
```typescript
98+
import {
99+
StationLogin, // Agent station login
100+
UserState, // Agent state management
101+
IncomingTask, // Incoming task notifications
102+
TaskList, // Active tasks list
103+
CallControl, // Call control buttons
104+
CallControlCAD, // CAD-enabled call control
105+
OutdialCall, // Outbound dialing
106+
store, // MobX store singleton
107+
} from '@webex/cc-widgets';
108+
```
109+
110+
---
111+
112+
## Examples and Use Cases
113+
114+
### Getting Started
115+
116+
#### React Component Usage
117+
118+
```typescript
119+
import { StationLogin, UserState, TaskList } from '@webex/cc-widgets';
120+
import store from '@webex/cc-widgets';
121+
import React from 'react';
122+
123+
function MyApp() {
124+
return (
125+
<div>
126+
<StationLogin
127+
onLogin={() => console.log('Logged in')}
128+
profileMode={false}
129+
/>
130+
<UserState
131+
onStateChange={(state) => console.log('State:', state)}
132+
/>
133+
<TaskList
134+
onTaskSelected={(id) => console.log('Task:', id)}
135+
/>
136+
</div>
137+
);
138+
}
139+
```
140+
141+
#### Web Component Usage (HTML)
142+
143+
```html
144+
<!DOCTYPE html>
145+
<html>
146+
<head>
147+
<title>Contact Center Widgets</title>
148+
<!-- Import Momentum UI CSS -->
149+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@momentum-ui/core/css/momentum-ui.min.css" />
150+
</head>
151+
<body>
152+
<!-- Use Web Components -->
153+
<widget-cc-station-login></widget-cc-station-login>
154+
<widget-cc-user-state></widget-cc-user-state>
155+
<widget-cc-task-list></widget-cc-task-list>
156+
157+
<!-- Import the Web Components bundle -->
158+
<script src="path/to/cc-widgets/dist/wc.js"></script>
159+
160+
<script>
161+
// Initialize the widget store and set your access token BEFORE using any widgets
162+
const store = window['ccWidgetStore'];
163+
store.init({
164+
access_token: '<YOUR_ACCESS_TOKEN>',
165+
webexConfig: {
166+
// Optionally configure Webex SDK here
167+
},
168+
});
169+
</script>
170+
</body>
171+
</html>
172+
```
173+
174+
### Common Use Cases
175+
176+
#### 1. Embedding in Non-React Applications
177+
178+
```html
179+
<!-- Angular, Vue, or vanilla JS app -->
180+
<!DOCTYPE html>
181+
<html>
182+
<body>
183+
<div id="app">
184+
<!-- Web Components work anywhere -->
185+
<widget-cc-user-state></widget-cc-user-state>
186+
<widget-cc-call-control></widget-cc-call-control>
187+
</div>
188+
189+
<script src="cc-widgets/dist/wc.js"></script>
190+
<script>
191+
// Initialize the widget store and set Webex configuration and access token
192+
store.init({
193+
webexConfig,
194+
access_token: '<YOUR_ACCESS_TOKEN>',
195+
});
196+
</script>
197+
</body>
198+
</html>
199+
```
200+
201+
#### 3. Micro-Frontend Architecture
202+
203+
```typescript
204+
// Host application
205+
import { StationLogin, UserState } from '@webex/cc-widgets';
206+
import store from '@webex/cc-widgets';
207+
208+
// Initialize the store before using it and before sharing across micro-frontends
209+
store.init({
210+
access_token: '<YOUR_ACCESS_TOKEN>',
211+
// Add any other necessary configuration here
212+
});
213+
214+
// Share store across micro-frontends
215+
window.ccStore = store;
216+
217+
function HostApp() {
218+
return (
219+
<div>
220+
<StationLogin profileMode={false} />
221+
{/* Other micro-frontends can access window.ccStore */}
222+
</div>
223+
);
224+
}
225+
```
226+
227+
### Integration Patterns
228+
229+
#### Initializing Store Before Widget Use
230+
231+
```typescript
232+
import {store} from '@webex/cc-widgets';
233+
234+
async function initialize() {
235+
await store.init({
236+
webexConfig,
237+
access_token: <ACCESS_TOKEN>,
238+
});
239+
240+
// 4. Now widgets are ready to use
241+
renderWidgets();
242+
}
243+
```
244+
245+
#### Event Handling with Web Components
246+
247+
Web Components use **property assignment** for event handlers (not `addEventListener`). Assign callback functions directly to event properties:
248+
249+
```javascript
250+
// Create or get references to Web Components
251+
const ccStationLogin = document.createElement('widget-cc-station-login');
252+
const ccUserState = document.createElement('widget-cc-user-state');
253+
const ccIncomingTask = document.createElement('widget-cc-incoming-task');
254+
const ccTaskList = document.createElement('widget-cc-task-list');
255+
const ccCallControl = document.createElement('widget-cc-call-control');
256+
const ccOutdial = document.createElement('widget-cc-outdial-call');
257+
258+
// Assign event handler callbacks directly to properties
259+
ccStationLogin.onLogin = () => {
260+
console.log('Login successful');
261+
showAgentDashboard();
262+
};
263+
264+
ccStationLogin.onLogout = () => {
265+
console.log('Logout successful');
266+
showLoginScreen();
267+
};
268+
269+
ccUserState.onStateChange = (status) => {
270+
console.log('Agent state changed:', status);
271+
updateStatusIndicator(status);
272+
};
273+
274+
ccIncomingTask.onAccepted = () => {
275+
console.log('Task accepted');
276+
};
277+
278+
ccIncomingTask.onDeclined = () => {
279+
console.log('Task declined');
280+
};
281+
282+
ccTaskList.onTaskAccepted = () => {
283+
console.log('Task accepted from task list');
284+
};
285+
286+
ccTaskList.onTaskDeclined = () => {
287+
console.log('Task declined from task list');
288+
};
289+
290+
ccCallControl.onHoldResume = () => {
291+
console.log('Hold/Resume toggled');
292+
};
293+
294+
ccCallControl.onEnd = () => {
295+
console.log('Call ended');
296+
};
297+
298+
ccCallControl.onWrapUp = (params) => {
299+
console.log('Wrap-up completed', params);
300+
};
301+
302+
// Append widgets to DOM after assigning event handlers
303+
document.body.appendChild(ccStationLogin);
304+
document.body.appendChild(ccUserState);
305+
document.body.appendChild(ccTaskList);
306+
document.body.appendChild(ccCallControl);
307+
```
308+
309+
---
310+
311+
## Installation
312+
313+
```bash
314+
# Install the widgets bundle
315+
yarn add @webex/cc-widgets
316+
317+
```
318+
319+
---
320+
321+
## Build Outputs
322+
323+
The package produces two bundles:
324+
325+
### 1. React Bundle (`dist/index.js`)
326+
327+
Used with: import { StationLogin } from '@webex/cc-widgets'. Contains: Re-exports of React widgets + store. Size: Small (just re-exports, no bundled code)
328+
329+
### 2. Web Components Bundle (`dist/wc.js`)
330+
331+
Used with: <script src="dist/wc.js"></script>. Contains: All widgets + React + dependencies bundled.Size: Large (self-contained bundle).Includes: r2wc wrappers + custom element registration
332+
333+
---
334+
335+
## Additional Resources
336+
337+
For detailed architecture, r2wc integration patterns, and troubleshooting, see [architecture.md](./architecture.md).
338+
339+
---
340+
341+
_Last Updated: 2025-11-26_

0 commit comments

Comments
 (0)