Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert extensions'
Dropdown
tool to Flyout
And use the style of a regular context Theatre.js menu.
- Loading branch information
1 parent
3d343cc
commit a30bba0
Showing
7 changed files
with
209 additions
and
167 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
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
85 changes: 0 additions & 85 deletions
85
theatre/studio/src/toolbars/ExtensionToolbar/tools/Downdown.tsx
This file was deleted.
Oops, something went wrong.
81 changes: 81 additions & 0 deletions
81
theatre/studio/src/toolbars/ExtensionToolbar/tools/ExtensionFlyoutMenu.tsx
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,81 @@ | ||
import React, {useRef} from 'react' | ||
import styled from 'styled-components' | ||
import {pointerEventsAutoInNormalMode} from '@theatre/studio/css' | ||
import type { | ||
ToolConfigFlyoutMenu, | ||
ToolconfigFlyoutMenuItem, | ||
} from '@theatre/studio/TheatreStudio' | ||
import ToolbarIconButton from '@theatre/studio/uiComponents/toolbar/ToolbarIconButton' | ||
import BaseMenu from '@theatre/studio/uiComponents/simpleContextMenu/ContextMenu/BaseMenu' | ||
import usePopover from '@theatre/studio/uiComponents/Popover/usePopover' | ||
import type {$IntentionalAny} from '@theatre/shared/utils/types' | ||
|
||
const Container = styled.div` | ||
${pointerEventsAutoInNormalMode}; | ||
& > svg { | ||
width: 1em; | ||
height: 1em; | ||
pointer-events: none; | ||
} | ||
` | ||
|
||
const ExtensionFlyoutMenu: React.FC<{ | ||
config: ToolConfigFlyoutMenu | ||
}> = ({config}) => { | ||
const triggerRef = useRef<null | HTMLElement>(null) | ||
|
||
const popover = usePopover( | ||
() => { | ||
const triggerBounds = triggerRef.current!.getBoundingClientRect() | ||
return { | ||
debugName: 'ExtensionFlyoutMenu:' + config.label, | ||
|
||
constraints: { | ||
maxX: triggerBounds.right, | ||
maxY: 8, | ||
minX: triggerBounds.left, | ||
minY: 8, | ||
}, | ||
verticalGap: 2, | ||
} | ||
}, | ||
() => { | ||
return ( | ||
<BaseMenu | ||
items={config.items.map( | ||
(option: ToolconfigFlyoutMenuItem, index: number) => ({ | ||
label: option.label, | ||
callback: () => { | ||
// this is a user-defined function, so we need to wrap it in a try/catch | ||
try { | ||
option.onClick?.() | ||
} catch (e) { | ||
console.error(e) | ||
} | ||
}, | ||
}), | ||
)} | ||
onRequestClose={() => { | ||
popover.close('clicked') | ||
}} | ||
/> | ||
) | ||
}, | ||
) | ||
|
||
return ( | ||
<Container> | ||
{popover.node} | ||
<ToolbarIconButton | ||
ref={triggerRef as $IntentionalAny} | ||
onClick={(e) => { | ||
popover.open(e, triggerRef.current!) | ||
}} | ||
> | ||
{config.label} | ||
</ToolbarIconButton> | ||
</Container> | ||
) | ||
} | ||
|
||
export default ExtensionFlyoutMenu |
72 changes: 72 additions & 0 deletions
72
theatre/studio/src/uiComponents/simpleContextMenu/ContextMenu/BaseMenu.tsx
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,72 @@ | ||
import type {ElementType} from 'react' | ||
import React from 'react' | ||
import Item from './Item' | ||
import type {$FixMe} from '@theatre/shared/utils/types' | ||
import styled from 'styled-components' | ||
import {transparentize} from 'polished' | ||
import {pointerEventsAutoInNormalMode} from '@theatre/studio/css' | ||
|
||
const minWidth = 190 | ||
|
||
const SHOW_OPTIONAL_MENU_TITLE = true | ||
|
||
const MenuContainer = styled.ul` | ||
position: absolute; | ||
min-width: ${minWidth}px; | ||
z-index: 10000; | ||
background: ${transparentize(0.2, '#111')}; | ||
backdrop-filter: blur(2px); | ||
color: white; | ||
list-style-type: none; | ||
padding: 2px 0; | ||
margin: 0; | ||
border-radius: 1px; | ||
cursor: default; | ||
${pointerEventsAutoInNormalMode}; | ||
border-radius: 3px; | ||
` | ||
|
||
const MenuTitle = styled.div` | ||
padding: 4px 10px; | ||
border-bottom: 1px solid #6262626d; | ||
color: #adadadb3; | ||
font-size: 11px; | ||
font-weight: 500; | ||
` | ||
|
||
type MenuItem = { | ||
label: string | ElementType | ||
callback?: (e: React.MouseEvent) => void | ||
enabled?: boolean | ||
// subs?: Item[] | ||
} | ||
|
||
const BaseMenu: React.FC<{ | ||
items: MenuItem[] | ||
ref?: $FixMe | ||
displayName?: string | ||
onRequestClose: () => void | ||
}> = React.forwardRef((props, ref: $FixMe) => { | ||
return ( | ||
<MenuContainer ref={ref}> | ||
{SHOW_OPTIONAL_MENU_TITLE && props.displayName ? ( | ||
<MenuTitle>{props.displayName}</MenuTitle> | ||
) : null} | ||
{props.items.map((item, i) => ( | ||
<Item | ||
key={`item-${i}`} | ||
label={item.label} | ||
enabled={item.enabled === false ? false : true} | ||
onClick={(e) => { | ||
if (item.callback) { | ||
item.callback(e) | ||
} | ||
props.onRequestClose() | ||
}} | ||
/> | ||
))} | ||
</MenuContainer> | ||
) | ||
}) | ||
|
||
export default BaseMenu |
Oops, something went wrong.