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.
Toggle: Refining style variables approach in Toggle and adding exampl…
…es passing interface and callback function (microsoft#7177) * Removing some of the deprecated components flaged when turning the tslint deprecation flag to true in the office-ui-fabric-react package. * Adding corresponding change file. * Reverting changes that affected backwards compatibility because it removed own deprecated usage. * Adding missing deprecation reversion in BaseButton. * Adding changes in oufr api. * Refining style variables approach in Toggle and adding examples passing interface and function. * Adding change file. * Updating change file. * Getting rid of if-else use in favor of inline checks.
- Loading branch information
Showing
6 changed files
with
182 additions
and
58 deletions.
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
common/changes/@uifabric/experiments/styleVars_2018-11-21-00-16.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": "Toggle: Refining style variables approach in Toggle and adding examples passing interface and function.", | ||
"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
57 changes: 57 additions & 0 deletions
57
packages/experiments/src/components/Toggle/examples/Toggle.StyleVarsFunction.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,57 @@ | ||
import * as React from 'react'; | ||
import { Toggle } from '../index'; | ||
import { IToggleViewProps, IToggleStyleVariablesTypes } from '../Toggle.types'; | ||
|
||
const styleVarsFunction = (props: IToggleViewProps): IToggleStyleVariablesTypes => { | ||
return { | ||
...(props.checked ? { textColor: 'green' } : { textColor: 'red' }), | ||
...(props.disabled | ||
? { ...{ pillBackground: 'gainsboro' }, ...(props.checked ? { pillBackground: 'slategrey' } : {}) } | ||
: { ...{ pillBackground: 'turquoise' }, ...(props.checked ? { pillBackground: 'navy' } : {}) }) | ||
}; | ||
}; | ||
|
||
export class ToggleStyleVarsFunctionExample extends React.Component<{}, {}> { | ||
public render(): JSX.Element { | ||
return ( | ||
<div> | ||
<Toggle | ||
defaultChecked={true} | ||
label="Enabled and checked" | ||
onText="On" | ||
offText="Off" | ||
onChange={this._onChange} | ||
styleVariables={styleVarsFunction} | ||
/> | ||
<Toggle | ||
defaultChecked={false} | ||
label="Enabled and unchecked" | ||
onText="On" | ||
offText="Off" | ||
onChange={this._onChange} | ||
styleVariables={styleVarsFunction} | ||
/> | ||
<Toggle | ||
defaultChecked={true} | ||
disabled={true} | ||
label="Disabled and checked" | ||
onText="On" | ||
offText="Off" | ||
styleVariables={styleVarsFunction} | ||
/> | ||
<Toggle | ||
defaultChecked={false} | ||
disabled={true} | ||
label="Disabled and unchecked" | ||
onText="On" | ||
offText="Off" | ||
styleVariables={styleVarsFunction} | ||
/> | ||
</div> | ||
); | ||
} | ||
|
||
private _onChange(ev: React.MouseEvent<HTMLElement>, checked: boolean) { | ||
console.log('toggle is ' + (checked ? 'checked' : 'not checked')); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
packages/experiments/src/components/Toggle/examples/Toggle.StyleVarsInterface.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,37 @@ | ||
import * as React from 'react'; | ||
import { Toggle } from '../index'; | ||
import { IToggleStyleVariablesTypes } from '../Toggle.types'; | ||
|
||
const styleVars1: IToggleStyleVariablesTypes = { | ||
pillHoveredBackground: 'black', | ||
textColor: 'red' | ||
}; | ||
|
||
const styleVars2: IToggleStyleVariablesTypes = { | ||
pillBackground: 'orange', | ||
pillJustifyContent: 'center', | ||
textColor: 'purple', | ||
thumbBackground: 'green' | ||
}; | ||
|
||
const styleVars3: IToggleStyleVariablesTypes = { | ||
pillBackground: 'dimgrey', | ||
pillBorderColor: 'brown', | ||
textColor: 'darkred' | ||
}; | ||
|
||
export class ToggleStyleVarsInterfaceExample extends React.Component<{}, {}> { | ||
public render(): JSX.Element { | ||
return ( | ||
<div> | ||
<Toggle defaultChecked={true} label="Example 1" onText="On" offText="Off" onChange={this._onChange} styleVariables={styleVars1} /> | ||
<Toggle defaultChecked={false} label="Example 2" onText="On" offText="Off" onChange={this._onChange} styleVariables={styleVars2} /> | ||
<Toggle defaultChecked={true} disabled={true} label="Example 3" onText="On - Disabled" offText="Off" styleVariables={styleVars3} /> | ||
</div> | ||
); | ||
} | ||
|
||
private _onChange(ev: React.MouseEvent<HTMLElement>, checked: boolean) { | ||
console.log('toggle is ' + (checked ? 'checked' : 'not checked')); | ||
} | ||
} |