Skip to content

Commit e46bd0c

Browse files
committed
feat(PageTabs): add PageTabs component for page navigation and integrate with ContentWrap
1 parent 219dca1 commit e46bd0c

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

src/components/ContentWrap.jsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { saveAs } from 'file-saver';
33
import UserCodeMirror from './UserCodeMirror.jsx';
44
import Toolbox from './Toolbox.jsx';
55
import Tabs from './Tabs.jsx';
6+
import PageTabs from './PageTabs.jsx';
67
import { computeCss, computeHtml, computeJs } from '../computes';
78
import { CssModes, HtmlModes, JsModes, modes } from '../codeModes';
89
import { getCompleteHtml, loadJS, log } from '../utils';
@@ -1083,6 +1084,13 @@ export default class ContentWrap extends Component {
10831084
</div>
10841085
<div class="demo-side" id="js-demo-side">
10851086
<div className="h-full flex flex-col">
1087+
{this.props.currentItem && this.props.currentItem.pages && this.props.currentItem.pages.length > 0 && (
1088+
<PageTabs
1089+
pages={this.props.currentItem.pages}
1090+
currentPageId={this.props.currentItem.currentPageId}
1091+
onTabClick={this.props.onPageSwitch}
1092+
/>
1093+
)}
10861094
<div
10871095
className="flex-grow"
10881096
style="overflow-y: auto; -webkit-overflow-scrolling: touch; "

src/components/PageTabs.jsx

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import React from 'preact';
2+
3+
/**
4+
* PageTabs component displays tabs for each page and handles tab switching
5+
*
6+
* @param {Object} props - Component props
7+
* @param {Array} props.pages - Array of page objects
8+
* @param {String} props.currentPageId - ID of the currently active page
9+
* @param {Function} props.onTabClick - Callback function when a tab is clicked
10+
*/
11+
export function PageTabs({ pages, currentPageId, onTabClick }) {
12+
if (!pages || pages.length === 0) {
13+
return null;
14+
}
15+
16+
return (
17+
<div className="page-tabs bg-black-500 border-b border-black-700 px-2 py-1 flex overflow-x-auto">
18+
{pages.map(page => (
19+
<button
20+
key={page.id}
21+
className={`px-4 py-2 mx-1 rounded-t-lg text-sm font-medium transition-colors duration-200 ${
22+
page.id === currentPageId
23+
? 'bg-primary text-white'
24+
: 'bg-black-600 text-gray-400 hover:bg-black-700 hover:text-gray-300'
25+
}`}
26+
onClick={() => onTabClick(page.id)}
27+
>
28+
{page.title || 'Untitled'}
29+
</button>
30+
))}
31+
</div>
32+
);
33+
}
34+
35+
export default PageTabs;

src/components/app.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1679,6 +1679,7 @@ BookLibService.Borrow(id) {
16791679
onEditorFocus={this.editorFocusHandler.bind(this)}
16801680
onSplitUpdate={this.splitUpdateHandler.bind(this)}
16811681
onProFeature={this.proBtnClickHandler.bind(this)}
1682+
onPageSwitch={this.switchToPage.bind(this)}
16821683
keyboardShortcutsBtnClickHandler={this.handleShortcutsModalOpen.bind(
16831684
this,
16841685
)}

0 commit comments

Comments
 (0)