-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Button: Creating separate Actionable view to improve perf of Actionable, small perf improvements and perf scenario updates. * Change files
- Loading branch information
Showing
6 changed files
with
81 additions
and
6 deletions.
There are no files selected for viewing
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,6 +1,6 @@ | ||
import * as React from 'react'; | ||
import { Actionable } from '@uifabric/experiments'; | ||
|
||
const scenario = <Actionable content="I am a button" />; | ||
const scenario = <Actionable>I am a button</Actionable>; | ||
|
||
export default scenario; |
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,6 +1,6 @@ | ||
import * as React from 'react'; | ||
import { Button } from '@uifabric/experiments'; | ||
|
||
const scenario = <Button>I am a button</Button>; | ||
const scenario = <Button content="I am a button" />; | ||
|
||
export default scenario; |
8 changes: 8 additions & 0 deletions
8
change/@uifabric-experiments-2019-07-29-17-22-55-buttonPerf.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,8 @@ | ||
{ | ||
"type": "patch", | ||
"comment": "Button: Creating separate Actionable view to improve perf of Actionable, small perf improvements and perf scenario updates.", | ||
"packageName": "@uifabric/experiments", | ||
"email": "[email protected]", | ||
"commit": "b83bcc1af7a91f2ceb7966aea79a495b6330e166", | ||
"date": "2019-07-30T00:22:55.492Z" | ||
} |
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
67 changes: 67 additions & 0 deletions
67
packages/experiments/src/components/Button/Actionable/Actionable.view.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,67 @@ | ||
/** @jsx withSlots */ | ||
import { KeytipData } from 'office-ui-fabric-react'; | ||
import { withSlots, getSlots } from '../../../Foundation'; | ||
import { getNativeProps, anchorProperties, buttonProperties } from '../../../Utilities'; | ||
|
||
import { IActionableProps, IActionableRootElements, IActionableSlots, IActionableViewProps } from './Actionable.types'; | ||
import { IButtonComponent } from '../Button.types'; | ||
|
||
export const ActionableView: IButtonComponent['view'] = props => { | ||
const { children, disabled, onClick, allowDisabledFocus, ariaLabel, keytipProps, buttonRef, ...rest } = props; | ||
|
||
const { slotType, htmlType, propertiesType } = _deriveRootType(props); | ||
|
||
// TODO: 'href' is anchor property... consider getNativeProps by root type | ||
const buttonProps = { ...getNativeProps(rest, propertiesType) }; | ||
|
||
const Slots = getSlots<IActionableProps, IActionableSlots>(props, { | ||
root: slotType | ||
}); | ||
|
||
const _onClick = (ev: React.MouseEvent<HTMLAnchorElement | HTMLButtonElement | HTMLDivElement>) => { | ||
if (!disabled && onClick) { | ||
onClick(ev); | ||
|
||
if (ev.defaultPrevented) { | ||
return; | ||
} | ||
} | ||
}; | ||
|
||
const Button = (keytipAttributes?: any): JSX.Element => ( | ||
<Slots.root | ||
type={htmlType} | ||
role="button" | ||
onClick={_onClick} | ||
{...buttonProps} | ||
{...keytipAttributes} | ||
disabled={disabled && !allowDisabledFocus} | ||
aria-disabled={disabled} | ||
tabIndex={!disabled || allowDisabledFocus ? 0 : undefined} | ||
aria-label={ariaLabel} | ||
ref={buttonRef} | ||
> | ||
{children} | ||
</Slots.root> | ||
); | ||
|
||
return keytipProps ? ( | ||
<KeytipData keytipProps={keytipProps} disabled={disabled && !allowDisabledFocus}> | ||
{(keytipAttributes: any): JSX.Element => Button(keytipAttributes)} | ||
</KeytipData> | ||
) : ( | ||
Button() | ||
); | ||
}; | ||
|
||
interface IActionableRootType { | ||
slotType: IActionableRootElements; | ||
htmlType: 'link' | 'button'; | ||
propertiesType: string[]; | ||
} | ||
|
||
function _deriveRootType(props: IActionableViewProps): IActionableRootType { | ||
return !!props.href | ||
? { slotType: 'a', htmlType: 'link', propertiesType: anchorProperties } | ||
: { slotType: 'button', htmlType: 'button', propertiesType: buttonProperties }; | ||
} |
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