forked from microsoft/fluentui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: add wrapping menu item example to ContextualMenu docs (microsof…
- Loading branch information
Showing
2 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
60 changes: 60 additions & 0 deletions
60
packages/react-examples/src/react/ContextualMenu/ContextualMenu.WrappingMenuItem.Example.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,60 @@ | ||
import * as React from 'react'; | ||
import { ContextualMenuItemType } from '@fluentui/react/lib/ContextualMenu'; | ||
import type { | ||
IContextualMenuProps, | ||
IContextualMenuStyles, | ||
IContextualMenuItemStyles, | ||
} from '@fluentui/react/lib/ContextualMenu'; | ||
import { DefaultButton } from '@fluentui/react/lib/Button'; | ||
import { useConst } from '@fluentui/react-hooks'; | ||
|
||
// text wrapping styles | ||
const menuItemStyles: Partial<IContextualMenuItemStyles> = { | ||
root: { | ||
height: 'auto', | ||
}, | ||
linkContent: { | ||
minHeight: '36px', | ||
}, | ||
label: { | ||
whiteSpace: 'normal', | ||
lineHeight: '1.2', | ||
padding: '4px 0', | ||
}, | ||
}; | ||
|
||
// prevent the menu from expanding with the longer text | ||
const menuStyles: Partial<IContextualMenuStyles> = { | ||
root: { | ||
maxWidth: '200px', | ||
}, | ||
}; | ||
|
||
export const ContextualMenuWithWrappingMenuItemExample: React.FunctionComponent = () => { | ||
const menuProps: IContextualMenuProps = useConst(() => ({ | ||
shouldFocusOnMount: true, | ||
styles: menuStyles, | ||
items: [ | ||
{ key: 'newItem', text: 'New', itemProps: { styles: menuItemStyles } }, | ||
{ key: 'divider_1', itemType: ContextualMenuItemType.Divider, itemProps: { styles: menuItemStyles } }, | ||
{ | ||
key: 'rename', | ||
text: 'Rename', | ||
itemProps: { styles: menuItemStyles }, | ||
}, | ||
{ key: 'edit', text: 'Edit', itemProps: { styles: menuItemStyles } }, | ||
{ | ||
key: 'properties', | ||
text: 'Properties', | ||
itemProps: { styles: menuItemStyles }, | ||
}, | ||
{ | ||
key: 'long', | ||
text: 'Item with an extra long name that should wrap to a new line', | ||
itemProps: { styles: menuItemStyles }, | ||
}, | ||
], | ||
})); | ||
|
||
return <DefaultButton text="Click for ContextualMenu" menuProps={menuProps} />; | ||
}; |
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