-
Notifications
You must be signed in to change notification settings - Fork 374
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: improve responsive behaviour of Puck header
- Loading branch information
1 parent
3d6c5d4
commit 349f44d
Showing
5 changed files
with
189 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
import { Dispatch, ReactElement, SetStateAction } from "react"; | ||
import { Globe, ChevronLeft, ChevronRight } from "react-feather"; | ||
|
||
import { Button } from "../Button"; | ||
import { IconButton } from "../IconButton/IconButton"; | ||
import getClassNameFactory from "../../lib/get-class-name-factory"; | ||
import { usePuckHistory } from "../../lib/use-puck-history"; | ||
import { PuckAction } from "../../reducer"; | ||
import type { AppState, Data } from "../../types/Config"; | ||
|
||
import styles from "./styles.module.css"; | ||
|
||
const getClassName = getClassNameFactory("MenuBar", styles); | ||
|
||
export const MenuBar = ({ | ||
appState, | ||
data = { content: [], root: { props: { title: "" } } }, | ||
dispatch, | ||
menuOpen = false, | ||
onPublish, | ||
renderHeaderActions, | ||
setMenuOpen, | ||
}: { | ||
appState: AppState; | ||
data: Data; | ||
dispatch: (action: PuckAction) => void; | ||
onPublish: (data: Data) => void; | ||
menuOpen: boolean; | ||
renderHeaderActions?: (props: { | ||
state: AppState; | ||
dispatch: (action: PuckAction) => void; | ||
}) => ReactElement; | ||
setMenuOpen: Dispatch<SetStateAction<boolean>>; | ||
}) => { | ||
const { canForward, canRewind, rewind, forward } = usePuckHistory({ | ||
appState, | ||
dispatch, | ||
}); | ||
|
||
return ( | ||
<div | ||
className={getClassName({ menuOpen })} | ||
onClick={(event) => { | ||
const element = event.target as HTMLElement; | ||
|
||
if (window.matchMedia("(min-width: 638px)").matches) { | ||
return; | ||
} | ||
if ( | ||
element.tagName === "A" && | ||
element.getAttribute("href")?.startsWith("#") | ||
) { | ||
setMenuOpen(false); | ||
} | ||
}} | ||
> | ||
<div className={getClassName("inner")}> | ||
<div className={getClassName("history")}> | ||
<IconButton title="undo" disabled={!canRewind} onClick={rewind}> | ||
<ChevronLeft | ||
size={21} | ||
stroke={ | ||
canRewind | ||
? "var(--puck-color-black)" | ||
: "var(--puck-color-grey-7)" | ||
} | ||
/> | ||
</IconButton> | ||
<IconButton title="redo" disabled={!canForward} onClick={forward}> | ||
<ChevronRight | ||
size={21} | ||
stroke={ | ||
canForward | ||
? "var(--puck-color-black)" | ||
: "var(--puck-color-grey-7)" | ||
} | ||
/> | ||
</IconButton> | ||
</div> | ||
<> | ||
{renderHeaderActions && | ||
renderHeaderActions({ | ||
state: appState, | ||
dispatch, | ||
})} | ||
</> | ||
<div> | ||
<Button | ||
onClick={() => { | ||
onPublish(data); | ||
}} | ||
icon={<Globe size="14px" />} | ||
> | ||
Publish | ||
</Button> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
.MenuBar { | ||
background-color: var(--puck-color-white); | ||
border-bottom: 1px solid var(--puck-color-grey-8); | ||
display: none; | ||
left: 0; | ||
margin-top: 1px; | ||
padding: 8px 16px; | ||
position: absolute; | ||
right: 0; | ||
top: 100%; | ||
z-index: 2; | ||
} | ||
|
||
.MenuBar--menuOpen { | ||
display: block; | ||
} | ||
|
||
@media (min-width: 638px) { | ||
.MenuBar { | ||
border: none; | ||
display: block; | ||
margin-top: 0; | ||
overflow-y: visible; | ||
padding: 0; | ||
position: static; | ||
} | ||
} | ||
|
||
.MenuBar-inner { | ||
align-items: center; | ||
display: flex; | ||
flex-wrap: wrap; | ||
gap: 8px 16px; | ||
justify-content: flex-end; | ||
} | ||
|
||
@media (min-width: 638px) { | ||
.MenuBar-inner { | ||
display: flex; | ||
flex-direction: row; | ||
flex-wrap: nowrap; | ||
} | ||
} | ||
|
||
.MenuBar-history { | ||
display: flex; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
349f44d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
puck-docs – ./apps/docs
puck-docs.vercel.app
puck-docs-git-main-measured.vercel.app
puckeditor.com
puck-docs-measured.vercel.app
www.puckeditor.com