Skip to content

Commit

Permalink
Fixed up toolbar rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
benjackwhite committed Nov 17, 2023
1 parent f08440f commit 108e012
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 36 deletions.
2 changes: 1 addition & 1 deletion cypress/e2e/toolbar.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe('Toolbar', () => {
.then((href) => {
cy.visit(href)
})
cy.get('#__POSTHOG_TOOLBAR__').shadow().find('.floating-toolbar-button').should('exist')
cy.get('#__POSTHOG_TOOLBAR__').shadow().find('.Toolbar3000').should('exist')
})
})

Expand Down
42 changes: 25 additions & 17 deletions frontend/src/toolbar/button/Toolbar3000.scss
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@
}

.Toolbar3000 {
display: flex;
flex-direction: row;
justify-content: space-between;
z-index: 1;
background-color: var(--bg-3000);
color: var(--text-3000);
transition-property: filter, width, transform;
Expand All @@ -94,34 +98,38 @@
filter: drop-shadow(2px 10px 10px var(--trace-3000));
border: 1px solid var(--border-bold-3000);
border-radius: var(--radius);
overflow: hidden;

position: fixed;
// fixed width so that animations work when changing width
width: 15.1rem;
transform: translate(50vh, 50vw); // This is immediately overwritten
width: 15.2rem;

&--dragging {
// Disable transform transition whilst dragging
transition-property: filter, width;
> :first-child {
border-right: 1px solid var(--border-bold-3000);
}

&.Toolbar3000Bar {
display: flex;
flex-direction: row;
justify-content: space-between;
> :last-child {
border-left: 1px solid var(--border-bold-3000);
}

> :first-child {
border-right: 1px solid var(--border-bold-3000);
}
--toolbar-button-x: 50vh;
--toolbar-button-y: 50vw;
--toolbar-translate: translate(var(--toolbar-button-x), var(--toolbar-button-y));

> :last-child {
border-left: 1px solid var(--border-bold-3000);
}
transform: var(--toolbar-translate);

z-index: 1;
&--dragging {
// Disable transform transition whilst dragging
transition-property: filter, width;
transform: var(--toolbar-translate) scale(1.2);
}

&.Toolbar3000--minimized-width {
&--minimized {
width: 2.5rem;

&.Toolbar3000--hedgehog-mode {
transform: var(--toolbar-translate) scale(0);
}
}

form {
Expand Down
36 changes: 19 additions & 17 deletions frontend/src/toolbar/button/Toolbar3000.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,16 @@ function MoreMenu(): JSX.Element {

function ToolbarInfoMenu(): JSX.Element {
const ref = useRef<HTMLDivElement | null>(null)
const { visibleMenu, isDragging, menuProperties } = useValues(toolbarButtonLogic)
const { visibleMenu, isDragging, menuProperties, minimized } = useValues(toolbarButtonLogic)
const { setMenu } = useActions(toolbarButtonLogic)

const fullIsShowing = visibleMenu === 'heatmap' || visibleMenu === 'actions' || visibleMenu === 'flags'
const content = minimized ? null : visibleMenu === 'flags' ? (
<FlagsToolbarMenu />
) : visibleMenu === 'heatmap' ? (
<HeatmapToolbarMenu />
) : visibleMenu === 'actions' ? (
<ActionsToolbarMenu />
) : null

useEffect(() => {
setMenu(ref.current)
Expand All @@ -98,7 +104,7 @@ function ToolbarInfoMenu(): JSX.Element {
<div
className={clsx(
'Toolbar3000Menu',
fullIsShowing && 'Toolbar3000Menu--visible',
!!content && 'Toolbar3000Menu--visible',
isDragging && 'Toolbar3000Menu--dragging',
menuProperties.isBelow && 'Toolbar3000Menu--below'
)}
Expand All @@ -115,13 +121,7 @@ function ToolbarInfoMenu(): JSX.Element {
maxHeight: menuProperties.maxHeight,
}}
>
{visibleMenu === 'flags' ? (
<FlagsToolbarMenu />
) : visibleMenu === 'heatmap' ? (
<HeatmapToolbarMenu />
) : visibleMenu === 'actions' ? (
<ActionsToolbarMenu />
) : null}
{content}
</div>
</div>
)
Expand Down Expand Up @@ -151,17 +151,19 @@ export function Toolbar3000(): JSX.Element {
<div
ref={ref}
className={clsx(
'Toolbar3000 Toolbar3000Bar fixed h-10 rounded-lg flex flex-row items-center floating-toolbar-button overflow-hidden',
minimized && 'Toolbar3000--minimized-width',
'Toolbar3000',
minimized && 'Toolbar3000--minimized',
hedgehogMode && 'Toolbar3000--hedgehog-mode',
isDragging && 'Toolbar3000--dragging'
)}
onMouseDown={(e) => onMouseDown(e as any)}
// eslint-disable-next-line react/forbid-dom-props
style={{
transform:
`translate(${dragPosition.x}px, ${dragPosition.y}px)` +
(hedgehogMode && minimized ? ' scale(0)' : ''),
}}
style={
{
'--toolbar-button-x': `${dragPosition.x}px`,
'--toolbar-button-y': `${dragPosition.y}px`,
} as any
}
>
<Toolbar3000Button
icon={<IconLogomark />}
Expand Down
1 change: 0 additions & 1 deletion frontend/src/toolbar/button/toolbarButtonLogic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ export const toolbarButtonLogic = kea<toolbarButtonLogicType>([
'none' as MenuState,
{
setVisibleMenu: (_, { visibleMenu }) => visibleMenu,
toggleMinimized: () => 'none',
},
],
minimized: [
Expand Down

0 comments on commit 108e012

Please sign in to comment.