mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2025-12-20 01:11:25 +00:00
Initial implementation of a generic UI component (#61)
* Add generic component * Add validation. Rename to widgetRenderer * Remove test code from splash screen * Clean up infobox * Fix styling/layout * Move test code into unit test * Replace <input> and <labe> by <TextField> and <Text> respectively. Fix style. * Replace InfoBoxComponent with UI fabric MessageBar. Fix styling for TextField * Use MessageBar for error message * Rename WdigetRendererComponent to SmartUiComponent
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
@import "../../../../less/Common/Constants.less";
|
||||
|
||||
.radioSwitchComponent {
|
||||
cursor: pointer;
|
||||
display: flex;
|
||||
|
||||
&>span:nth-child(n+2) {
|
||||
margin-left: 10px;
|
||||
}
|
||||
|
||||
.caption {
|
||||
color: @BaseDark;
|
||||
padding-left: @SmallSpace;
|
||||
vertical-align: top;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
/**
|
||||
* Horizontal switch component
|
||||
*/
|
||||
|
||||
import * as React from "react";
|
||||
import "./RadioSwitchComponent.less";
|
||||
import { Icon } from "office-ui-fabric-react/lib/Icon";
|
||||
import { NormalizedEventKey } from "../../../Common/Constants";
|
||||
|
||||
export interface Choice {
|
||||
key: string;
|
||||
onSelect: () => void;
|
||||
label: string;
|
||||
}
|
||||
|
||||
export interface RadioSwitchComponentProps {
|
||||
choices: Choice[];
|
||||
selectedKey: string;
|
||||
onSelectionKeyChange?: (newValue: string) => void;
|
||||
}
|
||||
|
||||
export class RadioSwitchComponent extends React.Component<RadioSwitchComponentProps> {
|
||||
public render(): JSX.Element {
|
||||
return (
|
||||
<div className="radioSwitchComponent">
|
||||
{this.props.choices.map((choice: Choice) => (
|
||||
<span
|
||||
tabIndex={0}
|
||||
key={choice.key}
|
||||
onClick={() => this.onSelect(choice)}
|
||||
onKeyPress={event => this.onKeyPress(event, choice)}
|
||||
>
|
||||
<Icon iconName={this.props.selectedKey === choice.key ? "RadioBtnOn" : "RadioBtnOff"} />
|
||||
<span className="caption">{choice.label}</span>
|
||||
</span>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
private onSelect(choice: Choice): void {
|
||||
this.props.onSelectionKeyChange && this.props.onSelectionKeyChange(choice.key);
|
||||
choice.onSelect();
|
||||
}
|
||||
|
||||
private onKeyPress(event: React.KeyboardEvent<HTMLSpanElement>, choice: Choice): void {
|
||||
if (event.key === NormalizedEventKey.Enter || event.key === NormalizedEventKey.Space) {
|
||||
this.onSelect(choice);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user