Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Button: Adding toggle/checked functionality to Button (#9016)
* Button: Adding toggle/checked functionality to Button. * Adding change file. * Propagating checked prop to MenuButtons and SplitButtons.
- Loading branch information
Showing
8 changed files
with
167 additions
and
2 deletions.
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
common/changes/@uifabric/experiments/toggleButtons_2019-05-08-23-09.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: Adding toggle/checked functionality to Button.", | ||
"type": "minor" | ||
} | ||
], | ||
"packageName": "@uifabric/experiments", | ||
"email": "Humberto.Morimoto@microsoft.com" | ||
} |
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
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
75 changes: 75 additions & 0 deletions
75
packages/experiments/src/components/Button/examples/Button.Toggle.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,75 @@ | ||
import * as React from 'react'; | ||
import { Button } from '../index'; | ||
import { Stack, IStackTokens } from 'office-ui-fabric-react'; | ||
|
||
export interface IButtonToggleExampleState { | ||
defaultButtonToggled?: boolean; | ||
primaryButtonToggled?: boolean; | ||
defaultCircularButtonToggled?: boolean; | ||
primaryCircularButtonToggled?: boolean; | ||
} | ||
|
||
// tslint:disable:jsx-no-lambda | ||
export class ButtonToggleExample extends React.Component<{}, IButtonToggleExampleState> { | ||
constructor(props: {}) { | ||
super(props); | ||
|
||
this.state = { | ||
defaultButtonToggled: false, | ||
primaryButtonToggled: false, | ||
defaultCircularButtonToggled: false, | ||
primaryCircularButtonToggled: false | ||
}; | ||
} | ||
|
||
public render(): JSX.Element { | ||
const { defaultButtonToggled, primaryButtonToggled, defaultCircularButtonToggled, primaryCircularButtonToggled } = this.state; | ||
|
||
const buttonStackTokens: IStackTokens = { childrenGap: 12 }; | ||
|
||
return ( | ||
<Stack horizontal disableShrink tokens={buttonStackTokens}> | ||
<Button | ||
content={defaultButtonToggled ? 'Muted' : 'Unmuted'} | ||
checked={defaultButtonToggled} | ||
onClick={this._onDefaultButtonClicked} | ||
/> | ||
<Button | ||
primary | ||
content={primaryButtonToggled ? 'Muted' : 'Unmuted'} | ||
checked={primaryButtonToggled} | ||
onClick={this._onPrimaryButtonClicked} | ||
/> | ||
<Button | ||
circular | ||
icon={defaultCircularButtonToggled ? 'VolumeDisabled' : 'Volume3'} | ||
checked={defaultCircularButtonToggled} | ||
onClick={this._onDefaultCircularButtonClicked} | ||
/> | ||
<Button | ||
circular | ||
primary | ||
icon={primaryCircularButtonToggled ? 'VolumeDisabled' : 'Volume3'} | ||
checked={primaryCircularButtonToggled} | ||
onClick={this._onPrimaryCircularButtonClicked} | ||
/> | ||
</Stack> | ||
); | ||
} | ||
|
||
private _onDefaultButtonClicked = () => { | ||
this.setState({ defaultButtonToggled: !this.state.defaultButtonToggled }); | ||
}; | ||
|
||
private _onPrimaryButtonClicked = () => { | ||
this.setState({ primaryButtonToggled: !this.state.primaryButtonToggled }); | ||
}; | ||
|
||
private _onDefaultCircularButtonClicked = () => { | ||
this.setState({ defaultCircularButtonToggled: !this.state.defaultCircularButtonToggled }); | ||
}; | ||
|
||
private _onPrimaryCircularButtonClicked = () => { | ||
this.setState({ primaryCircularButtonToggled: !this.state.primaryCircularButtonToggled }); | ||
}; | ||
} |