Skip to content

Commit

Permalink
Adding icons to the context menu
Browse files Browse the repository at this point in the history
- ContextMenu items now can have 'icon' parameter
  • Loading branch information
maxphilippov committed May 14, 2024
1 parent 69f3a76 commit e7c6883
Show file tree
Hide file tree
Showing 10 changed files with 73 additions and 75 deletions.
1 change: 1 addition & 0 deletions images/icons/document.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions images/icons/media.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions images/icons/phone.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 13 additions & 12 deletions scss/composer/_composer.scss
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,20 @@
display: flex;
align-items: flex-end;

.attachment-button,
.emoji-button {
.bp4-button.bp4-minimal {
width: 40px;
height: 40px;
.attachment-button {
width: 40px;
height: 40px;

&:hover {
background: none;
cursor: pointer;
}
&:focus {
outline: none;
}
outline: none;
background: none;
box-shadow: none;

&:hover {
background: none;
cursor: pointer;
}
&:focus {
outline: none;
}
}

Expand Down
14 changes: 10 additions & 4 deletions scss/misc/_context_menu.scss
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
// position is determined in code
position: fixed;
pointer-events: auto;
background-color: var(--bp4MenuBg);
color: var(--bp4MenuText);
background-color: var(--bgPrimary);
color: var(--textPrimary);

border-radius: 3px;
overflow: hidden;
Expand All @@ -36,14 +36,20 @@
white-space: nowrap;
display: flex;
align-items: center;
justify-content: space-between;
justify-content: flex-start;

& .left-icon {
background-color: var(--iconBackground);
margin: 0 5px 0 0;
}

& .right-icon {
width: 18px;
height: 18px;
margin-left: auto;
@include color-svg(
'../images/icons/navigate_next.svg',
var(--bp4MenuText),
var(--textPrimary),
100%
);
transform: translate(11px, -0.07em);
Expand Down
4 changes: 4 additions & 0 deletions src/renderer/components/ContextMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,18 @@ import React, {
useCallback,
} from 'react'
import classNames from 'classnames'
import Icon from './Icon'

import useContextMenu from '../hooks/useContextMenu'

type ContextMenuItemActionable = {
icon?: IconName
action: (event: React.MouseEvent<Element, MouseEvent>) => void
subitems?: never
}

type ContextMenuItemExpandable = {
icon?: IconName
action?: never
subitems: (ContextMenuItem | undefined)[]
}
Expand Down Expand Up @@ -344,6 +347,7 @@ export function ContextMenu(props: {
key={index}
{...(item.subitems && { 'data-expandable-index': index })}
>
{item.icon && <Icon className='left-icon' icon={item.icon} />}
{item.label}
{item.subitems && <div className='right-icon'></div>}
</div>
Expand Down
3 changes: 3 additions & 0 deletions src/renderer/components/Icon/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,19 @@ export type IconName =
| 'code-tags'
| 'cross'
| 'devices'
| 'document'
| 'favorite'
| 'forum'
| 'image'
| 'info'
| 'lead-pencil'
| 'list'
| 'media'
| 'more'
| 'open_in_new'
| 'person'
| 'person-filled'
| 'phone'
| 'qr'
| 'question_mark'
| 'reaction'
Expand Down
95 changes: 37 additions & 58 deletions src/renderer/components/composer/menuAttachment.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
import React, { useCallback } from 'react'
import {
Button,
Position,
Popover,
Menu,
MenuItem,
IconName,
} from '@blueprintjs/core'
import React, { useCallback, useContext } from 'react'

Check failure on line 1 in src/renderer/components/composer/menuAttachment.tsx

View workflow job for this annotation

GitHub Actions / Code Validation

Cannot find module './ContextMenu' or its corresponding type declarations.

Check failure on line 1 in src/renderer/components/composer/menuAttachment.tsx

View workflow job for this annotation

GitHub Actions / Code Validation

Cannot find name 'IconName'.

Check failure on line 1 in src/renderer/components/composer/menuAttachment.tsx

View workflow job for this annotation

GitHub Actions / Code Validation

Cannot find name 'IconName'.

Check failure on line 1 in src/renderer/components/composer/menuAttachment.tsx

View workflow job for this annotation

GitHub Actions / Code Validation

Cannot find name 'IconName'.
import { dirname } from 'path'
import { Button } from '@blueprintjs/core'

import { runtime } from '../../runtime'
import { useStore } from '../../stores/store'
Expand All @@ -19,25 +12,23 @@ import useVideoChat from '../../hooks/useVideoChat'
import { LastUsedSlot, rememberLastUsedPath } from '../../utils/lastUsedPaths'
import { selectedAccountId } from '../../ScreenController'

import { ContextMenuItem } from './ContextMenu'
import { ContextMenuContext } from '../../contexts/ContextMenuContext'

import type { T } from '@deltachat/jsonrpc-client'

type Props = {
addFileToDraft: (file: string, viewType: T.Viewtype) => void
selectedChat: T.FullChat | null
}

type MenuAttachmentItemObject = {
id: number
icon: IconName
text: string
onClick: todo
}

// Main component that creates the menu and popover
export default function MenuAttachment({
addFileToDraft,
selectedChat,
}: Props) {
const { openContextMenu } = useContext(ContextMenuContext)

const tx = useTranslationFunction()
const openConfirmationDialog = useConfirmationDialog()
const { sendVideoChatInvitation } = useVideoChat()
Expand Down Expand Up @@ -111,59 +102,47 @@ export default function MenuAttachment({
])

// item array used to populate menu
const items: MenuAttachmentItemObject[] = [
const menu: (ContextMenuItem | false)[] = [
settings?.settings.webrtc_instance && {
id: 0,
icon: 'phone' as IconName,
text: tx('videochat'),
onClick: onVideoChat,
label: tx('videochat'),
action: onVideoChat,
},
{
id: 1,
icon: 'media' as IconName,
text: tx('image'),
onClick: addFilenameMedia.bind(null),
label: tx('image'),
action: addFilenameMedia.bind(null),
},
{
id: 2,
icon: 'document' as IconName,
text: tx('file'),
onClick: addFilenameFile.bind(null),
label: tx('file'),
action: addFilenameFile.bind(null),
},
].filter(item => !!item) as MenuAttachmentItemObject[]
]

return (
<div className='attachment-button'>
<Popover
content={
<Menu>
<MenuAttachmentItems itemsArray={items} />
</Menu>
}
position={Position.TOP_LEFT}
>
<Button id='test-attachment-menu' minimal icon='paperclip' />
</Popover>
</div>
)
}
const onClickAttachmentMenu = (event: React.MouseEvent<any, MouseEvent>) => {
const threeDotButtonElement = document.querySelector(
'#attachment-menu-button'
) as HTMLDivElement

const boundingBox = threeDotButtonElement.getBoundingClientRect()

const [cursorX, cursorY] = [boundingBox.x, boundingBox.y]
event.preventDefault() // prevent default runtime context menu from opening

openContextMenu({
cursorX,
cursorY,
items: menu,
})
}

// Function to populate Menu
const MenuAttachmentItems = ({
itemsArray,
}: {
itemsArray: MenuAttachmentItemObject[]
}) => {
return (
<>
{itemsArray.map((item: MenuAttachmentItemObject) => (
<MenuItem
key={item.id}
icon={item.icon}
text={item.text}
onClick={item.onClick}
/>
))}
</>
<Button
icon='paperclip'
id='attachment-menu-button'
className='attachment-button'
onClick={onClickAttachmentMenu}
/>
)
}
2 changes: 1 addition & 1 deletion test/testcafe/messagelist_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ export async function goToSideBarSubSettingsMenu(t, label) {
}

export async function sendVideoChatInvitation(t) {
await t.click('#test-attachment-menu')
await t.click('#attachment-menu-button')
await t.click(
Selector('a.bp4-menu-item').withText(await translate('videochat'))
)
Expand Down
2 changes: 2 additions & 0 deletions themes/_themebase.scss
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ $hover-contrast-change: 2%;
--buttonDangerText: #{$colorDanger};
--buttonDisabledBackground: #{$bgSecondary};
--buttonDisabledText: #{changeContrast($textSecondary, 45%)};
/* Icons */
--iconBackground: #757575; /* color from emoji.png */
/* NavBar */
--navBarBackground: #{$bgNavBar};
--navBarText: #{$textNavBar};
Expand Down

0 comments on commit e7c6883

Please sign in to comment.