titaned-frontend-library 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (77) hide show
  1. package/CHANGELOG.md +43 -0
  2. package/MEILISEARCH_INTEGRATION.md +261 -0
  3. package/README.md +236 -0
  4. package/SEARCH_INTEGRATION_README.md +208 -0
  5. package/dist/App.d.ts +3 -0
  6. package/dist/components/ButtonComponent.scss +3 -0
  7. package/dist/components/Footer.scss +87 -0
  8. package/dist/components/MainHeader.scss +915 -0
  9. package/dist/components/Sidebar.scss +170 -0
  10. package/dist/components/UserMenu.scss +0 -0
  11. package/dist/components/common/Button/ButtonComponent.d.ts +4 -0
  12. package/dist/components/common/Footer/Footer.d.ts +4 -0
  13. package/dist/components/common/Header/MainHeader.d.ts +4 -0
  14. package/dist/components/common/Header/SimpleSearchContext.d.ts +36 -0
  15. package/dist/components/common/NavDropdownMenu/NavDropdownMenu.d.ts +11 -0
  16. package/dist/components/common/SearchHighlight.d.ts +11 -0
  17. package/dist/components/common/SearchResultItem.d.ts +12 -0
  18. package/dist/components/common/Sidebar/Sidebar.d.ts +12 -0
  19. package/dist/components/common/UserMenu/UserMenu.d.ts +15 -0
  20. package/dist/components/common/menu/MenuComponent.d.ts +4 -0
  21. package/dist/contexts/SidebarContext.d.ts +6 -0
  22. package/dist/examples/MeiliSearchUsageExample.d.ts +3 -0
  23. package/dist/hooks/useIsMobileSize.d.ts +2 -0
  24. package/dist/hooks/useSidebar.d.ts +1 -0
  25. package/dist/index.cjs +27 -0
  26. package/dist/index.css +1 -0
  27. package/dist/index.d.ts +8 -0
  28. package/dist/index.js +1867 -0
  29. package/dist/interfaces/components.d.ts +181 -0
  30. package/dist/main.d.ts +0 -0
  31. package/dist/providers/SidebarProvider.d.ts +4 -0
  32. package/dist/services/meiliSearchService.d.ts +47 -0
  33. package/dist/utils/searchNavigation.d.ts +43 -0
  34. package/dist/vite.svg +1 -0
  35. package/eslint.config.js +28 -0
  36. package/index.html +13 -0
  37. package/next.config.ts +35 -0
  38. package/package.json +53 -0
  39. package/public/vite.svg +1 -0
  40. package/src/@edx-frontend-platform-i18n.d.ts +1 -0
  41. package/src/App.css +66 -0
  42. package/src/App.tsx +54 -0
  43. package/src/assets/react.svg +1 -0
  44. package/src/components/common/Button/ButtonComponent.scss +3 -0
  45. package/src/components/common/Button/ButtonComponent.tsx +34 -0
  46. package/src/components/common/Footer/Footer.scss +87 -0
  47. package/src/components/common/Footer/Footer.tsx +53 -0
  48. package/src/components/common/Header/MainHeader.scss +915 -0
  49. package/src/components/common/Header/MainHeader.tsx +701 -0
  50. package/src/components/common/Header/SimpleSearchContext.tsx +194 -0
  51. package/src/components/common/NavDropdownMenu/NavDropdownMenu.tsx +58 -0
  52. package/src/components/common/SearchHighlight.tsx +64 -0
  53. package/src/components/common/SearchResultItem.tsx +162 -0
  54. package/src/components/common/Sidebar/Sidebar.scss +170 -0
  55. package/src/components/common/Sidebar/Sidebar.tsx +137 -0
  56. package/src/components/common/UserMenu/UserMenu.scss +0 -0
  57. package/src/components/common/UserMenu/UserMenu.tsx +73 -0
  58. package/src/components/common/menu/MenuComponent.module.css +12 -0
  59. package/src/components/common/menu/MenuComponent.tsx +37 -0
  60. package/src/contexts/SidebarContext.tsx +9 -0
  61. package/src/declarations.d.ts +10 -0
  62. package/src/examples/MeiliSearchUsageExample.tsx +102 -0
  63. package/src/hooks/useIsMobileSize.ts +19 -0
  64. package/src/hooks/useSidebar.ts +10 -0
  65. package/src/index.css +68 -0
  66. package/src/index.ts +21 -0
  67. package/src/interfaces/components.ts +172 -0
  68. package/src/main.tsx +11 -0
  69. package/src/providers/SidebarProvider.tsx +20 -0
  70. package/src/services/meiliSearchService.ts +233 -0
  71. package/src/styles/global-overrides.scss +1131 -0
  72. package/src/utils/searchNavigation.ts +140 -0
  73. package/src/vite-env.d.ts +1 -0
  74. package/tsconfig.app.json +26 -0
  75. package/tsconfig.json +17 -0
  76. package/tsconfig.node.json +24 -0
  77. package/vite.config.ts +34 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,43 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [Unreleased]
9
+
10
+ ### Added
11
+ - Initial release of TitanEd Library
12
+ - MainHeader component with search functionality
13
+ - Sidebar component with responsive design
14
+ - Footer component
15
+ - SidebarProvider and useSidebar hook
16
+ - SimpleSearchProvider and useSimpleSearch hook
17
+ - MeiliSearch integration
18
+ - TypeScript support with full type definitions
19
+ - SCSS styling support
20
+ - Global style overrides
21
+
22
+ ### Changed
23
+ - Nothing yet
24
+
25
+ ### Deprecated
26
+ - Nothing yet
27
+
28
+ ### Removed
29
+ - Nothing yet
30
+
31
+ ### Fixed
32
+ - Nothing yet
33
+
34
+ ### Security
35
+ - Nothing yet
36
+
37
+ ## [0.0.134] - 2024-01-XX
38
+
39
+ ### Added
40
+ - Initial version with core components
41
+ - Basic TypeScript setup
42
+ - Vite build configuration
43
+ - SCSS support with static copying
@@ -0,0 +1,261 @@
1
+ # MeiliSearch Integration for TitanEd Library
2
+
3
+ This document explains how to use the MeiliSearch integration in the TitanEd library's MainHeader component.
4
+
5
+ ## Overview
6
+
7
+ The MainHeader component now supports MeiliSearch integration for content searching. It uses the exact API payload structure from your Open edX authoring console logs, making it compatible with your existing MeiliSearch setup.
8
+
9
+ ## Features
10
+
11
+ - **Real-time Search**: Search as you type with MeiliSearch API
12
+ - **Search Results Display**: Shows search results in a dropdown with highlighting
13
+ - **Mobile Support**: Full mobile search modal with results
14
+ - **Error Handling**: Proper error states and loading indicators
15
+ - **Faceted Search**: Supports MeiliSearch facets for advanced filtering
16
+ - **Highlighting**: Search term highlighting in results
17
+
18
+ ## Configuration
19
+
20
+ ### Required Props
21
+
22
+ The MainHeader component now requires a `meiliSearchConfig` prop:
23
+
24
+ ```typescript
25
+ interface MeiliSearchConfig {
26
+ host: string; // MeiliSearch server URL
27
+ apiKey: string; // MeiliSearch API key
28
+ indexName: string; // Index name (e.g., 'tutor_studio_content')
29
+ }
30
+ ```
31
+
32
+ ### Example Usage
33
+
34
+ ```tsx
35
+ import MainHeader from 'titaned-lib';
36
+ import { MeiliSearchConfig } from 'titaned-lib';
37
+
38
+ const meiliSearchConfig: MeiliSearchConfig = {
39
+ host: 'http://meilisearch.local.openedx.io:7700',
40
+ apiKey: 'your-api-key-here',
41
+ indexName: 'tutor_studio_content'
42
+ };
43
+
44
+ <MainHeader
45
+ logoUrl="/path/to/logo.png"
46
+ menuAlignment="left"
47
+ menuList={menuList}
48
+ loginSignupButtons={false}
49
+ authenticatedUser={user}
50
+ userMenuItems={userMenuItems}
51
+ onLanguageChange={handleLanguageChange}
52
+ getBaseUrl={() => '/'}
53
+ onSearchResults={handleSearchResults}
54
+ meiliSearchConfig={meiliSearchConfig}
55
+ headerButtons={headerButtons}
56
+ />
57
+ ```
58
+
59
+ ## API Integration
60
+
61
+ The integration uses the exact payload structure from your console logs:
62
+
63
+ ### Search Payload
64
+ ```json
65
+ {
66
+ "queries": [
67
+ {
68
+ "indexUid": "tutor_studio_content",
69
+ "q": "search query",
70
+ "filter": [[], "type = \"course_block\""],
71
+ "attributesToHighlight": ["display_name", "description", "published"],
72
+ "highlightPreTag": "__meili-highlight__",
73
+ "highlightPostTag": "__/meili-highlight__",
74
+ "attributesToCrop": ["description", "published"],
75
+ "sort": [],
76
+ "offset": 0,
77
+ "limit": 20
78
+ },
79
+ {
80
+ "indexUid": "tutor_studio_content",
81
+ "facets": ["block_type", "content.problem_types"],
82
+ "filter": ["type = \"course_block\""],
83
+ "limit": 0
84
+ }
85
+ ]
86
+ }
87
+ ```
88
+
89
+ ### Headers and Authentication
90
+
91
+ The service automatically includes all necessary headers for MeiliSearch API calls:
92
+
93
+ ```typescript
94
+ {
95
+ 'Content-Type': 'application/json',
96
+ 'Authorization': 'Bearer your-api-key-here',
97
+ 'X-Meilisearch-Client': 'Meilisearch JavaScript (v0.41.0)'
98
+ }
99
+ ```
100
+
101
+ **Important**: When you pass the complete MeiliSearch client object (recommended), the service will automatically extract and use the exact headers from your client, ensuring compatibility with your existing setup.
102
+
103
+ ### Response Handling
104
+
105
+ The component handles MeiliSearch responses and converts them to a consistent format:
106
+
107
+ ```typescript
108
+ interface MeiliSearchResult {
109
+ id: string;
110
+ display_name: string;
111
+ type: string;
112
+ description?: string;
113
+ published?: string;
114
+ url?: string;
115
+ block_type?: string;
116
+ content?: {
117
+ problem_types?: string[];
118
+ };
119
+ _formatted?: {
120
+ display_name?: string;
121
+ description?: string;
122
+ published?: string;
123
+ };
124
+ }
125
+ ```
126
+
127
+ ## Search Results Display
128
+
129
+ ### Desktop
130
+ - Results appear in a dropdown below the search field
131
+ - Shows up to 5 results with "show more" indicator
132
+ - Includes highlighting for search terms
133
+ - Displays result type and metadata
134
+
135
+ ### Mobile
136
+ - Full-screen search modal
137
+ - Scrollable results list
138
+ - Same highlighting and metadata as desktop
139
+
140
+ ## Styling
141
+
142
+ The component includes comprehensive CSS for:
143
+ - Search result dropdowns
144
+ - Loading states
145
+ - Error messages
146
+ - Mobile search modal
147
+ - Result highlighting
148
+
149
+ All styles are included in `MainHeader.scss` and follow the existing design system.
150
+
151
+ ## Error Handling
152
+
153
+ The component handles various error states:
154
+ - Network errors
155
+ - API errors
156
+ - Empty results
157
+ - Loading states
158
+
159
+ Error messages are displayed to users with appropriate styling.
160
+
161
+ ## Integration with Open edX Authoring
162
+
163
+ To use this in your Open edX authoring repository:
164
+
165
+ 1. **Install the library**:
166
+ ```bash
167
+ npm install titaned-lib
168
+ ```
169
+
170
+ 2. **Import and configure** (Recommended approach - pass the complete client):
171
+ ```tsx
172
+ import { MainHeader } from 'titaned-lib';
173
+ import { useContentSearchConnection } from './your-search-hook';
174
+
175
+ const MyComponent = () => {
176
+ const { client, indexName, hasConnectionError } = useContentSearchConnection();
177
+
178
+ const meiliSearchConfig = {
179
+ host: client.config.host,
180
+ apiKey: client.config.apiKey,
181
+ indexName: indexName,
182
+ client: client // Pass the complete client for automatic header extraction
183
+ };
184
+
185
+ return (
186
+ <MainHeader
187
+ // ... other props
188
+ meiliSearchConfig={meiliSearchConfig}
189
+ onSearchResults={(results, totalHits, facets) => {
190
+ // Handle search results
191
+ console.log('Search results:', results);
192
+ }}
193
+ />
194
+ );
195
+ };
196
+ ```
197
+
198
+ 3. **Alternative approach - Manual header configuration**:
199
+ ```tsx
200
+ const meiliSearchConfig = {
201
+ host: 'http://meilisearch.local.openedx.io:7700',
202
+ apiKey: 'your-api-key-here',
203
+ indexName: 'tutor_studio_content'
204
+ // Headers will be automatically set based on the API key
205
+ };
206
+ ```
207
+
208
+ ## Advanced Features
209
+
210
+ ### Faceted Search
211
+ The component supports MeiliSearch facets for advanced filtering. Facets are available in the `onSearchResults` callback:
212
+
213
+ ```tsx
214
+ onSearchResults={(results, totalHits, facets) => {
215
+ console.log('Facets:', facets);
216
+ // facets.block_type: { "chapter": 4, "problem": 6, ... }
217
+ // facets['content.problem_types']: { "multiplechoiceresponse": 1, ... }
218
+ }}
219
+ ```
220
+
221
+ ### Custom Search Options
222
+ You can customize search behavior by modifying the `MeiliSearchService`:
223
+
224
+ ```typescript
225
+ // In meiliSearchService.ts
226
+ const result = await searchService.search(query, {
227
+ limit: 20,
228
+ offset: 0,
229
+ filter: ['type = "course_block"', 'published = true'],
230
+ attributesToHighlight: ['display_name', 'description'],
231
+ sort: ['published:desc']
232
+ });
233
+ ```
234
+
235
+ ## Troubleshooting
236
+
237
+ ### Common Issues
238
+
239
+ 1. **CORS Errors**: Ensure your MeiliSearch server allows CORS from your domain
240
+ 2. **API Key Issues**: Verify the API key has proper permissions
241
+ 3. **Index Not Found**: Check that the index name matches your MeiliSearch setup
242
+ 4. **Network Errors**: Verify the host URL is accessible
243
+
244
+ ### Debug Mode
245
+
246
+ Enable debug logging by checking the browser console. The component logs:
247
+ - Search queries
248
+ - API responses
249
+ - Error messages
250
+ - Performance metrics
251
+
252
+ ## Migration from Simple Search
253
+
254
+ If you're migrating from the simple search implementation:
255
+
256
+ 1. Update your MainHeader props to include `meiliSearchConfig`
257
+ 2. Remove any custom search logic
258
+ 3. Update your `onSearchResults` callback to handle the new result format
259
+ 4. Test with your MeiliSearch setup
260
+
261
+ The component maintains backward compatibility for other props and functionality.
package/README.md ADDED
@@ -0,0 +1,236 @@
1
+ # TitanEd Library
2
+
3
+ Internal React TypeScript component library for TitanEd applications, featuring modern UI components with built-in search functionality and responsive design.
4
+
5
+ ## Features
6
+
7
+ - 🎨 **Modern UI Components** - Pre-built, customizable React components
8
+ - 🔍 **Integrated Search** - MeiliSearch integration with search highlighting
9
+ - 📱 **Responsive Design** - Mobile-first approach with responsive breakpoints
10
+ - 🎯 **TypeScript Support** - Full TypeScript definitions and type safety
11
+ - 🎨 **SCSS Styling** - Customizable styles with SCSS support
12
+ - 🧩 **Modular Architecture** - Tree-shakeable components for optimal bundle size
13
+
14
+ ## Installation
15
+
16
+ ### Clone the Repository
17
+
18
+ ```bash
19
+ git clone https://github.com/TitanEd/titaned-frontend-libraries.git
20
+ cd titaned-frontend-libraries
21
+ npm install
22
+ ```
23
+
24
+ ### Peer Dependencies
25
+
26
+ Make sure you have the required peer dependencies installed in your project:
27
+
28
+ ```bash
29
+ npm install react react-dom @openedx/paragon @edx/frontend-platform meilisearch sass
30
+ ```
31
+
32
+ ## Quick Start
33
+
34
+ ```tsx
35
+ import React from 'react';
36
+ import {
37
+ MainHeader,
38
+ Sidebar,
39
+ Footer,
40
+ SidebarProvider,
41
+ useSidebar
42
+ } from 'titaned-lib';
43
+
44
+ function App() {
45
+ return (
46
+ <SidebarProvider>
47
+ <div className="app">
48
+ <MainHeader />
49
+ <Sidebar />
50
+ <main>
51
+ {/* Your content */}
52
+ </main>
53
+ <Footer />
54
+ </div>
55
+ </SidebarProvider>
56
+ );
57
+ }
58
+
59
+ export default App;
60
+ ```
61
+
62
+ ## Components
63
+
64
+ ### MainHeader
65
+ A responsive header component with integrated search functionality.
66
+
67
+ ```tsx
68
+ import { MainHeader, SimpleSearchProvider } from 'titaned-lib';
69
+
70
+ const searchConfig = {
71
+ host: 'https://your-meilisearch-host.com',
72
+ apiKey: 'your-api-key',
73
+ indexName: 'your-index'
74
+ };
75
+
76
+ function App() {
77
+ return (
78
+ <SimpleSearchProvider config={searchConfig}>
79
+ <MainHeader
80
+ title="Your App"
81
+ onSearch={(query) => console.log('Search:', query)}
82
+ />
83
+ </SimpleSearchProvider>
84
+ );
85
+ }
86
+ ```
87
+
88
+ ### Sidebar
89
+ A collapsible sidebar component with mobile support.
90
+
91
+ ```tsx
92
+ import { Sidebar, SidebarProvider, useSidebar } from 'titaned-lib';
93
+
94
+ function SidebarContent() {
95
+ const { isOpen, toggle } = useSidebar();
96
+
97
+ return (
98
+ <Sidebar>
99
+ <nav>
100
+ <a href="/dashboard">Dashboard</a>
101
+ <a href="/courses">Courses</a>
102
+ <a href="/profile">Profile</a>
103
+ </nav>
104
+ </Sidebar>
105
+ );
106
+ }
107
+
108
+ function App() {
109
+ return (
110
+ <SidebarProvider>
111
+ <SidebarContent />
112
+ </SidebarProvider>
113
+ );
114
+ }
115
+ ```
116
+
117
+ ### Footer
118
+ A customizable footer component.
119
+
120
+ ```tsx
121
+ import { Footer } from 'titaned-lib';
122
+
123
+ function App() {
124
+ return (
125
+ <Footer
126
+ copyright="© 2024 TitanEd"
127
+ links={[
128
+ { label: 'Privacy Policy', href: '/privacy' },
129
+ { label: 'Terms of Service', href: '/terms' }
130
+ ]}
131
+ />
132
+ );
133
+ }
134
+ ```
135
+
136
+ ## Styling
137
+
138
+ The library includes global SCSS styles that are automatically imported. You can override styles by targeting the component classes:
139
+
140
+ ```scss
141
+ // Override global styles
142
+ .titaned-lib {
143
+ --primary-color: #your-color;
144
+ --secondary-color: #your-color;
145
+ }
146
+
147
+ // Override specific component styles
148
+ .main-header {
149
+ background-color: var(--primary-color);
150
+ }
151
+ ```
152
+
153
+ ## TypeScript Support
154
+
155
+ All components come with full TypeScript definitions:
156
+
157
+ ```tsx
158
+ import type {
159
+ MainHeaderProps,
160
+ MeiliSearchConfig,
161
+ SearchResult
162
+ } from 'titaned-lib';
163
+
164
+ interface MyComponentProps {
165
+ headerConfig: MainHeaderProps;
166
+ searchConfig: MeiliSearchConfig;
167
+ }
168
+ ```
169
+
170
+ ## API Reference
171
+
172
+ ### Hooks
173
+
174
+ #### `useSidebar()`
175
+ Returns sidebar state and controls.
176
+
177
+ ```tsx
178
+ const { isOpen, toggle, close, open } = useSidebar();
179
+ ```
180
+
181
+ #### `useSimpleSearch()`
182
+ Provides search functionality and state.
183
+
184
+ ```tsx
185
+ const {
186
+ searchQuery,
187
+ searchResults,
188
+ isSearching,
189
+ performSearch
190
+ } = useSimpleSearch();
191
+ ```
192
+
193
+ ### Types
194
+
195
+ - `MainHeaderProps` - Props for the MainHeader component
196
+ - `MeiliSearchConfig` - Configuration for MeiliSearch integration
197
+ - `SearchResult` - Structure of search result items
198
+
199
+ ## Development
200
+
201
+ ### Prerequisites
202
+ - Node.js 18+
203
+ - npm or yarn
204
+ - Access to the private repository
205
+
206
+ ### Setup
207
+ ```bash
208
+ git clone https://github.com/TitanEd/titaned-frontend-libraries.git
209
+ cd titaned-lib
210
+ npm install
211
+ ```
212
+
213
+ ### Build
214
+ ```bash
215
+ npm run build
216
+ ```
217
+
218
+ ### Development
219
+ ```bash
220
+ npm run dev
221
+ ```
222
+
223
+ ## Internal Team Guidelines
224
+
225
+ - Follow the established coding standards and patterns
226
+ - Update CHANGELOG.md when making significant changes
227
+ - Coordinate with the team for breaking changes
228
+
229
+
230
+ ## Support
231
+
232
+ For support and questions, contact the development team directly.
233
+
234
+ ## Changelog
235
+
236
+ See [CHANGELOG.md](CHANGELOG.md) for a list of changes and version history.