@@ -2,19 +2,34 @@ import React from 'preact';
22
33/**
44 * PageTabs component displays tabs for each page and handles tab switching
5- *
5+ *
66 * @param {Object } props - Component props
77 * @param {Array } props.pages - Array of page objects
88 * @param {String } props.currentPageId - ID of the currently active page
99 * @param {Function } props.onTabClick - Callback function when a tab is clicked
10+ * @param {Function } props.onAddPage - Callback function when the add page button is clicked
1011 */
11- export function PageTabs ( { pages, currentPageId, onTabClick } ) {
12+ export function PageTabs ( { pages, currentPageId, onTabClick, onAddPage } ) {
1213 if ( ! pages || pages . length === 0 ) {
1314 return null ;
1415 }
1516
17+ /**
18+ * Wrapper for the onAddPage callback to properly handle the event object.
19+ * This prevents the synthetic event from being passed to the App's addNewPage method,
20+ * which expects either no parameters or a title string, not an event object.
21+ * Without this wrapper, the event object would cause errors when passed to addNewPage.
22+ */
23+ const handleAddPage = ( e ) => {
24+ e . preventDefault ( ) ;
25+ e . stopPropagation ( ) ;
26+ if ( typeof onAddPage === 'function' ) {
27+ onAddPage ( ) ;
28+ }
29+ } ;
30+
1631 return (
17- < div className = "page-tabs bg-black-500 border-b border-black-700 px-2 py-1 flex overflow-x-auto" >
32+ < div className = "page-tabs bg-black-500 border-b border-black-700 px-2 py-1 flex overflow-x-auto items-center " >
1833 { pages . map ( page => (
1934 < button
2035 key = { page . id }
@@ -28,6 +43,14 @@ export function PageTabs({ pages, currentPageId, onTabClick }) {
2843 { page . title || 'Untitled' }
2944 </ button >
3045 ) ) }
46+ < button
47+ className = "ml-2 px-3 py-2 bg-black-600 text-gray-400 hover:bg-black-700 hover:text-gray-300 rounded-lg text-sm font-medium transition-colors duration-200 flex items-center"
48+ onClick = { handleAddPage }
49+ title = "Add new page"
50+ >
51+ < span className = "mr-1 font-bold text-lg leading-none" > +</ span >
52+ Add Page
53+ </ button >
3154 </ div >
3255 ) ;
3356}
0 commit comments