-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Button: Decoupling ContextualMenu to improve bundlesize #8220
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
acb3cd6
Button: Decoupling ContextualMenu from Button to improve bundle size.
khmakoto e42f4d1
Enforcing typing.
khmakoto 2ee4fde
Adding change file.
khmakoto 29c8c32
Updating examples.
khmakoto eeec509
Merge branch 'master' of https://github.com/OfficeDev/office-ui-fabri…
khmakoto 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
11 changes: 11 additions & 0 deletions
11
common/changes/@uifabric/experiments/separateMenu_2019-03-06-19-29.json
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,11 @@ | ||
{ | ||
"changes": [ | ||
{ | ||
"packageName": "@uifabric/experiments", | ||
"comment": "Button: Decoupling ContextualMenu to improve bundlesize", | ||
"type": "minor" | ||
} | ||
], | ||
"packageName": "@uifabric/experiments", | ||
"email": "[email protected]" | ||
} |
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
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
14 changes: 14 additions & 0 deletions
14
packages/experiments/src/components/Button/ButtonMenu/ButtonMenu.styles.ts
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,14 @@ | ||
import { getGlobalClassNames } from '../../../Styling'; | ||
import { IButtonMenuComponent, IButtonMenuStylesReturnType } from './ButtonMenu.types'; | ||
|
||
const GlobalClassNames = { | ||
root: 'ms-ButtonMenu' | ||
}; | ||
|
||
export const ButtonMenuStyles: IButtonMenuComponent['styles'] = (props, theme): IButtonMenuStylesReturnType => { | ||
const classNames = getGlobalClassNames(GlobalClassNames, theme); | ||
|
||
return { | ||
root: [theme.fonts.medium, classNames.root] | ||
}; | ||
}; |
23 changes: 23 additions & 0 deletions
23
packages/experiments/src/components/Button/ButtonMenu/ButtonMenu.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,23 @@ | ||
/** @jsx withSlots */ | ||
import * as React from 'react'; | ||
import { withSlots, createComponent, getSlots } from '../../../Foundation'; | ||
import { IButtonMenuComponent, IButtonMenuProps, IButtonMenuSlots } from './ButtonMenu.types'; | ||
import { ButtonMenuStyles as styles } from './ButtonMenu.styles'; | ||
|
||
const view: IButtonMenuComponent['view'] = props => { | ||
const { menuType = 'div', ...rest } = props; | ||
|
||
const Slots = getSlots<IButtonMenuProps, IButtonMenuSlots>(props, { | ||
root: menuType | ||
}); | ||
|
||
return <Slots.root {...rest} />; | ||
}; | ||
|
||
export const ButtonMenu: React.StatelessComponent<IButtonMenuProps> = createComponent({ | ||
displayName: 'ButtonMenu', | ||
styles, | ||
view | ||
}); | ||
|
||
export default ButtonMenu; |
55 changes: 55 additions & 0 deletions
55
packages/experiments/src/components/Button/ButtonMenu/ButtonMenu.types.ts
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,55 @@ | ||
import { IComponent, IComponentStyles, IHTMLSlot, ISlotProp, ISlottableReactType } from '../../../Foundation'; | ||
import { IBaseProps, IPoint } from '../../../Utilities'; | ||
import { DirectionalHint } from 'office-ui-fabric-react'; | ||
|
||
export type IButtonMenuComponent = IComponent<IButtonMenuProps, IButtonMenuTokens, IButtonMenuStyles>; | ||
|
||
// These types are redundant with IButtonComponent but are needed until TS function return widening issue is resolved: | ||
// https://github.com/Microsoft/TypeScript/issues/241 | ||
// For now, these helper types can be used to provide return type safety when specifying tokens and styles functions. | ||
export type IButtonMenuTokenReturnType = ReturnType<Extract<IButtonMenuComponent['tokens'], Function>>; | ||
export type IButtonMenuStylesReturnType = ReturnType<Extract<IButtonMenuComponent['styles'], Function>>; | ||
|
||
export type IButtonMenuSlot = ISlotProp<IButtonMenuProps>; | ||
|
||
export interface IButtonMenuSlots { | ||
root?: IHTMLSlot; | ||
} | ||
|
||
export interface IButtonMenu {} | ||
|
||
export interface IButtonMenuProps extends IButtonMenuSlots, IBaseProps<IButtonMenu> { | ||
/** | ||
* Defines the target that the ButtonMenu should try to position itself based on. | ||
* It can be either an Element a querySelector string of a valid Element | ||
* or a MouseEvent. If MouseEvent is given then the origin point of the event will be used. | ||
*/ | ||
target?: Element | string | MouseEvent | IPoint | null; | ||
|
||
/** | ||
* Defines the callback that is exectued when the ButtonMenu tries to close. | ||
* If dismissAll is true then all submenus will be dismissed. | ||
*/ | ||
onDismiss?: (ev?: any, dismissAll?: boolean) => void; | ||
|
||
/** | ||
* Defines a collection of menu items. | ||
* @defaultvalue [] | ||
*/ | ||
items: any[]; | ||
|
||
/** | ||
* Defines how the element should be positioned. | ||
* @defaultvalue DirectionalHint.bottomAutoEdge | ||
*/ | ||
directionalHint?: DirectionalHint; | ||
|
||
/** | ||
* Defines what type of component the menu is going to be rendered as. | ||
*/ | ||
menuType?: ISlottableReactType<IButtonMenuProps>; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need to duplicate props in |
||
|
||
export interface IButtonMenuTokens {} | ||
|
||
export type IButtonMenuStyles = IComponentStyles<IButtonMenuSlots>; |
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
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
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
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './Button'; | ||
export * from './Button.types'; | ||
export * from './ButtonMenu/ButtonMenu.types'; |
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.
Is this intended to be a legitimate viable default menu option? Are there any examples that use it? (It seem all the examples were converted to use ContextualMenu.)