-
Notifications
You must be signed in to change notification settings - Fork 336
/
Copy pathmenu.tsx
71 lines (67 loc) · 2.26 KB
/
menu.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import * as Fluent from '@fluentui/react'
import { Id, S } from 'h2o-wave'
import React from 'react'
import { stylesheet } from 'typestyle'
import { fixMenuOverflowStyles } from './parts/utils'
import { border, clas, cssVar } from './theme'
import { Command, toCommands } from "./toolbar"
const css = stylesheet({
card: {
display: 'inline-flex',
alignItems: 'center',
cursor: 'pointer',
$nest: {
'&:hover': {
color: cssVar('$themePrimary')
},
'&:hover button': {
color: cssVar('$themePrimary')
},
}
},
icon: {
fontSize: 18
}
})
/**
Create a contextual menu component. Useful when you have a lot of links and want to conserve the space.
*/
export interface Menu {
/** Commands to render. */
items: Command[]
/** The card's icon. */
icon?: S
/** The card’s image, preferably user avatar. */
image?: S
/** An identifying name for this component. */
name?: Id
/** The text displayed next to the chevron. */
label?: S
}
export const XMenu = ({ model }: { model: Menu }) => {
const
{ name, items, icon, image, label } = model,
ref = React.useRef<HTMLDivElement>(null),
[isMenuHidden, setIsMenuHidden] = React.useState(true),
toggleMenu = () => setIsMenuHidden(isHidden => !isHidden),
dismissMenu = () => setIsMenuHidden(true)
return (
// HACK: Marker css class.
<div data-test={name} className={clas(css.card, 'w-menu')} ref={ref} onClick={toggleMenu}>
{image && <Fluent.Persona imageUrl={image} size={Fluent.PersonaSize.size48} styles={{ details: { padding: 0 } }} />}
{icon && <Fluent.FontIcon className={css.icon} iconName={icon} />}
{label && <Fluent.Text variant='mediumPlus' className='w-menu-label'>{label}</Fluent.Text>}
<Fluent.ContextualMenu
items={toCommands(items)}
target={ref}
hidden={isMenuHidden}
onDismiss={dismissMenu}
isBeakVisible
directionalHint={Fluent.DirectionalHint.bottomRightEdge}
calloutProps={{ styles: { beak: { border: border(1, cssVar('$neutralQuaternaryAlt')) } } }}
styles={fixMenuOverflowStyles}
/>
<Fluent.ActionButton iconProps={{ iconName: 'CaretSolidDown', styles: { root: { fontSize: 12 } } }} styles={{ root: { padding: 0 } }} />
</div>
)
}