This repository was archived by the owner on Mar 4, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 51
[WIP] feat(ContextMenu): add base implementation #340
Closed
Closed
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
5ceb85a
feat(ContextualMenu): base implementation
93d2042
temp
e9db6e3
Render menu from the menutree passed as a prop
d6f2b8f
Render menu from the menutree passed as a prop
c85fd0d
Add callback prop
c9115db
Make code work even if no props are passed
faa7a14
Fix the breaking code introduced by pull 238
1214009
Add divider prop
a07b910
Add icon prop
12f6d08
Cleanup
4b93b2d
Add icons
27c5a37
Add test file
b162b9d
Remove unsued imports
d24a766
Make Popup work after rebasing breaking changes
79df68e
Rename ContextualMenu to ContextMenu
dae6e2c
Replace Menu component with List component
45b1e34
Render submenu using Popup
2a6664e
Fix breaking code after rebasing
4188788
Fix test file
549a450
Code cleanup
4322aa4
Rename ContextMenuVariables.tsx to contextMenuVariables.tsx
69b0027
Rename ContextMenuStyles.tsx to contextMenuStyles.tsx
gopalgoel19 631df1a
fix typo
4916ace
Switch back from List to Menu
0b10e5f
typo fix
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
docs/src/examples/components/ContextMenu/Types/ContextMenuExample.shorthand.tsx
This file contains hidden or 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,34 @@ | ||
| import React from 'react' | ||
| import { ContextMenu } from '@stardust-ui/react' | ||
|
|
||
| const items = [ | ||
| { | ||
| key: 'show', | ||
| content: 'Show in channel', | ||
| icon: 'search', | ||
| divider: true, | ||
| menu: { | ||
| items: [ | ||
| { key: '1', content: 'item1' }, | ||
| { | ||
| key: '2', | ||
| content: 'item2', | ||
| menu: { items: [{ key: '1', content: 'item1' }, { key: '2', content: 'item2' }] }, | ||
| }, | ||
| ], | ||
| }, | ||
| }, | ||
| { key: 'move', content: 'Move to collection', icon: 'arrow right' }, | ||
| { key: 'copy', content: 'Copy to collection', icon: 'copy' }, | ||
| { key: 'remove', content: 'Remove', icon: 'delete', divider: true }, | ||
| { key: 'edit', content: 'Edit', icon: 'edit' }, | ||
| { key: 'getlink', content: 'Get link', icon: 'file' }, | ||
| ] | ||
|
|
||
| const callback = () => { | ||
| alert('ContextMenu callback invoked...') | ||
| } | ||
|
|
||
| const ContextMenuExample = () => <ContextMenu items={items} onItemClick={callback} /> | ||
|
|
||
| export default ContextMenuExample |
This file contains hidden or 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,15 @@ | ||
| import React from 'react' | ||
| import ComponentExample from 'docs/src/components/ComponentDoc/ComponentExample' | ||
| import ExampleSection from 'docs/src/components/ComponentDoc/ExampleSection' | ||
|
|
||
| const Types = () => ( | ||
| <ExampleSection title="Types"> | ||
| <ComponentExample | ||
| title="Default" | ||
| description="A default ContextMenu." | ||
| examplePath="components/ContextMenu/Types/ContextMenuExample" | ||
| /> | ||
| </ExampleSection> | ||
| ) | ||
|
|
||
| export default Types |
This file contains hidden or 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,10 @@ | ||
| import React from 'react' | ||
| import Types from './Types' | ||
|
|
||
| const ContextMenuExamples = () => ( | ||
| <div> | ||
| <Types /> | ||
| </div> | ||
| ) | ||
|
|
||
| export default ContextMenuExamples |
This file contains hidden or 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,83 @@ | ||
| import * as _ from 'lodash' | ||
| import * as PropTypes from 'prop-types' | ||
| import * as React from 'react' | ||
| import ReactNode = React.ReactNode | ||
| import { UIComponent, customPropTypes, IRenderResultConfig } from '../../lib' | ||
| import { ComponentVariablesInput, ComponentPartStyle } from '../../../types/theme' | ||
| import { Extendable } from '../../../types/utils' | ||
| import Menu, { MenuItem } from '../Menu' | ||
| // import List, { ListItem } from '../List' | ||
| // import Popup from '../Popup' | ||
| export interface IContextMenuProps { | ||
| as?: any | ||
| className?: string | ||
| styles?: ComponentPartStyle | ||
| variables?: ComponentVariablesInput | ||
| } | ||
|
|
||
| /** | ||
| * A contextMenu. | ||
| * @accessibility This is example usage of the accessibility tag. | ||
| * This should be replaced with the actual description after the PR is merged | ||
| */ | ||
| class ContextMenu extends UIComponent<Extendable<IContextMenuProps>, any> { | ||
| static displayName = 'ContextMenu' | ||
|
|
||
| static className = 'ui-contextmenu' | ||
|
|
||
| static propTypes = { | ||
| /** An element type to render as (string or function). */ | ||
| as: customPropTypes.as, | ||
|
|
||
| /** Additional classes. */ | ||
| className: PropTypes.string, | ||
|
|
||
| /** The tree of menu containing submenus and it's submenus and so on. */ | ||
| items: PropTypes.arrayOf(PropTypes.object), | ||
|
|
||
| /** Function passed which needs to be invoked when the menuitem has no submenu. */ | ||
| onItemClick: PropTypes.func, | ||
|
|
||
| /** Custom styles to be applied for component. */ | ||
| styles: PropTypes.oneOfType([PropTypes.object, PropTypes.func]), | ||
|
|
||
| /** Custom variables to be applied for component. */ | ||
| variables: PropTypes.oneOfType([PropTypes.object, PropTypes.func]), | ||
| } | ||
|
|
||
| static defaultProps = { | ||
| as: 'div', | ||
| } | ||
|
|
||
| renderComponent({ ElementType, classes, rest }: IRenderResultConfig<any>): ReactNode { | ||
| return ( | ||
| <ElementType className={classes.root} {...rest}> | ||
| {this.renderItems()} | ||
| </ElementType> | ||
| ) | ||
| } | ||
|
|
||
| renderItems = () => { | ||
| const { items } = this.props | ||
| return ( | ||
| <Menu vertical> | ||
| {_.map(items, (item, index) => | ||
| MenuItem.create(item, { | ||
| defaultProps: { | ||
| index, | ||
| styles: { | ||
| color: 'rgba(37,36,36,0.75)', | ||
| fontFamily: 'Segoe UI', | ||
| ...(item.divider && { | ||
| borderBottom: '2px solid #F3F2F1', | ||
| }), | ||
| }, | ||
| }, | ||
| }), | ||
| )} | ||
| </Menu> | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| export default ContextMenu | ||
This file contains hidden or 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 @@ | ||
| export { default } from './ContextMenu' |
This file contains hidden or 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 hidden or 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 hidden or 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
19 changes: 19 additions & 0 deletions
19
src/themes/teams/components/ContextMenu/contextMenuStyles.tsx
This file contains hidden or 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,19 @@ | ||
| import { IContextMenuVariables } from './contextMenuVariables' | ||
| import { IComponentPartStylesInput, ICSSInJSStyle } from '../../../../../types/theme' | ||
| import { IContextMenuProps } from '../../../../components/ContextMenu/ContextMenu' | ||
|
|
||
| const contextMenuStyles: IComponentPartStylesInput<IContextMenuProps, IContextMenuVariables> = { | ||
| root: ({ variables }): ICSSInJSStyle => { | ||
| const { height, width, padding, border } = variables | ||
| const styles = { | ||
| height, | ||
| width, | ||
| padding, | ||
| border, | ||
| } | ||
|
|
||
| return styles | ||
| }, | ||
| } | ||
|
|
||
| export default contextMenuStyles |
13 changes: 13 additions & 0 deletions
13
src/themes/teams/components/ContextMenu/contextMenuVariables.tsx
This file contains hidden or 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,13 @@ | ||
| export interface IContextMenuVariables { | ||
| height?: string | ||
| width?: string | ||
| padding?: string | ||
| border?: string | ||
| } | ||
|
|
||
| export default (): IContextMenuVariables => ({ | ||
| height: '100%', | ||
| width: '100%', | ||
| padding: '0', | ||
| // border: '1px solid #eeeeee', | ||
| }) |
This file contains hidden or 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,7 @@ | ||
| import { isConformant } from 'test/specs/commonTests' | ||
|
|
||
| import ContextMenu from 'src/components/ContextMenu' | ||
|
|
||
| describe('ContextualMenu', () => { | ||
| isConformant(ContextMenu) | ||
| }) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove styles here please