Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 2d540e9

Browse files
author
Kerry Archibald
committed
add kebab context menu wrapper
1 parent 38cb29b commit 2d540e9

File tree

3 files changed

+87
-0
lines changed

3 files changed

+87
-0
lines changed

res/css/_components.pcss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
@import "./components/views/beacon/_RoomLiveShareWarning.pcss";
1818
@import "./components/views/beacon/_ShareLatestLocation.pcss";
1919
@import "./components/views/beacon/_StyledLiveBeaconIcon.pcss";
20+
@import "./components/views/context_menus/_KebabContextMenu.pcss";
2021
@import "./components/views/elements/_FilterDropdown.pcss";
2122
@import "./components/views/location/_EnableLiveShare.pcss";
2223
@import "./components/views/location/_LiveDurationDropdown.pcss";
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
Copyright 2022 The Matrix.org Foundation C.I.C.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
.mx_KebabContextMenu_icon {
18+
width: 24px;
19+
color: $secondary-content;
20+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
Copyright 2022 The Matrix.org Foundation C.I.C.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
import React from 'react';
18+
19+
import { Icon as ContextMenuIcon } from '../../../../res/img/element-icons/context-menu.svg';
20+
import { ChevronFace, ContextMenuButton, useContextMenu } from '../../structures/ContextMenu';
21+
import AccessibleButton from '../elements/AccessibleButton';
22+
import IconizedContextMenu, { IconizedContextMenuOptionList } from './IconizedContextMenu';
23+
24+
const contextMenuBelow = (elementRect: DOMRect) => {
25+
// align the context menu's icons with the icon which opened the context menu
26+
const left = elementRect.left + window.scrollX + elementRect.width;
27+
const top = elementRect.bottom + window.scrollY;
28+
const chevronFace = ChevronFace.None;
29+
return { left, top, chevronFace };
30+
};
31+
32+
interface KebabContextMenuProps extends Partial<React.ComponentProps<typeof AccessibleButton>> {
33+
options: React.ReactNode[];
34+
title: string;
35+
}
36+
37+
export const KebabContextMenu: React.FC<KebabContextMenuProps> = ({
38+
options,
39+
title,
40+
...props
41+
}) => {
42+
const [menuDisplayed, button, openMenu, closeMenu] = useContextMenu();
43+
44+
return <>
45+
<ContextMenuButton
46+
{...props}
47+
onClick={openMenu}
48+
title={title}
49+
isExpanded={menuDisplayed}
50+
inputRef={button}
51+
>
52+
<ContextMenuIcon className='mx_KebabContextMenu_icon' />
53+
</ContextMenuButton>
54+
{ menuDisplayed && (<IconizedContextMenu
55+
onFinished={closeMenu}
56+
compact
57+
rightAligned
58+
closeOnInteraction
59+
{...contextMenuBelow(button.current.getBoundingClientRect())}
60+
>
61+
<IconizedContextMenuOptionList>
62+
{ options }
63+
</IconizedContextMenuOptionList>
64+
</IconizedContextMenu>) }
65+
</>;
66+
};

0 commit comments

Comments
 (0)