Skip to content

Commit

Permalink
Merge pull request #516 from Lemoncode/feature/#493--multipage-docs]-…
Browse files Browse the repository at this point in the history
…style-thumbnail-rectagle-and-higlight-selected

add style thumbnail rectangle and highlight selected
  • Loading branch information
brauliodiez authored Nov 4, 2024
2 parents 2f32321 + b929c83 commit 24699c2
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 20 deletions.
11 changes: 11 additions & 0 deletions src/pods/thumb-pages/components/thumb-page.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.container {
width: '200px';
height: '180px';
border: 3px solid;
border-color: black;
border-radius: 5px;
position: 'relative';
background-color: white;
margin-top: 10px;
padding: 5px;
}
12 changes: 4 additions & 8 deletions src/pods/thumb-pages/components/thumb-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { createRef, useRef } from 'react';
import { Layer, Stage } from 'react-konva';
import { ThumbPageContextMenu } from './context-menu';
import { useContextMenu } from '../use-context-menu-thumb.hook';
import classes from './thumb-page.module.css';

interface Props {
pageIndex: number;
Expand All @@ -26,7 +27,7 @@ export const ThumbPage: React.FunctionComponent<Props> = props => {
width: bounds.x + bounds.width,
height: bounds.y + bounds.height,
};
const scaleFactorX = 250 / canvasSize.width;
const scaleFactorX = 200 / canvasSize.width;
const scaleFactorY = 180 / canvasSize.height;
const finalScale = Math.min(scaleFactorX, scaleFactorY);

Expand All @@ -40,16 +41,11 @@ export const ThumbPage: React.FunctionComponent<Props> = props => {
return (
<>
<div
style={{
width: '250px',
height: '180px',
border: '1px solid red',
position: 'relative',
}}
className={classes.container}
onClick={() => onSetActivePage(page.id)}
onContextMenu={handleShowContextMenu}
>
<Stage width={250} height={180} scaleX={finalScale} scaleY={finalScale}>
<Stage width={200} height={180} scaleX={finalScale} scaleY={finalScale}>
<Layer>
{shapes.map(shape => {
if (!fakeShapeRefs.current[shape.id]) {
Expand Down
8 changes: 8 additions & 0 deletions src/pods/thumb-pages/thumb-pages.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,11 @@
flex-wrap: wrap;
flex-direction: column;
}

.activeThumb {
background-color: rgb(41, 41, 235);
}

.activeText {
color: white;
}
35 changes: 23 additions & 12 deletions src/pods/thumb-pages/thumb-pages.pod.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,45 @@ export const ThumbPagesPod: React.FC = () => {
const [pageTitleBeingEdited, setPageTitleBeingEdited] = React.useState<
number | null
>(null);
const [activePageId, setActivePageId] = React.useState<string | null>(null);

const handleAddNewPage = () => {
addNewPage();
};

const handleSetActivePage = (pageId: string) => {
setActivePage(pageId);
setActivePageId(pageId);
};

return (
<div className={classes.container}>
{fullDocument.pages.map((page, index) => (
<React.Fragment key={page.id}>
<ThumbPage
pageIndex={index}
onSetActivePage={handleSetActivePage}
setPageTitleBeingEdited={setPageTitleBeingEdited}
/>
{pageTitleBeingEdited === index ? (
<PageTitleInlineEdit
<div
className={`${classes.container} ${
page.id === activePageId ? classes.activeThumb : ''
}`}
>
<ThumbPage
pageIndex={index}
onSetActivePage={handleSetActivePage}
setPageTitleBeingEdited={setPageTitleBeingEdited}
/>
) : (
<div onDoubleClick={() => setPageTitleBeingEdited(index)}>
{page.name}
</div>
)}
{pageTitleBeingEdited === index ? (
<PageTitleInlineEdit
pageIndex={index}
setPageTitleBeingEdited={setPageTitleBeingEdited}
/>
) : (
<div
onDoubleClick={() => setPageTitleBeingEdited(index)}
className={page.id === activePageId ? classes.activeText : ''}
>
{page.name}
</div>
)}
</div>
</React.Fragment>
))}
<button onClick={handleAddNewPage}>Add new page</button>
Expand Down

0 comments on commit 24699c2

Please sign in to comment.