import React from 'react'; import {Stack, Text, Link} from 'office-ui-fabric-react'; import {BoolToggleSettingsControl} from './BoolToggleSettingsControl'; import {StringTextSettingsControl} from './StringTextSettingsControl'; import {IntSpinnerSettingsControl} from './IntSpinnerSettingsControl'; import {ColorPickerSettingsControl} from './ColorPickerSettingsControl'; import {CustomActionSettingsControl} from './CustomActionSettingsControl'; import {HotkeySettingsControl} from './HotkeySettingsControl'; import {ChoiceGroupSettingsControl} from './ChoiceGroupSettingsControl'; import {DropdownSettingsControl} from './DropdownSettingsControl'; export class ModuleSettings extends React.Component { references: any; parent_on_change: Function; constructor(props: any) { super(props); this.references={}; this.parent_on_change = props.on_change; this.state = { settings_key: props.settings_key, powertoy: props.powertoy, } } shouldComponentUpdate(nextProps:any, nextState:any) { // This component and its children manage their state. // React only to state changes when forceUpdate is called by the App component. return false; } componentWillReceiveProps(props: any) { this.setState({ powertoy: props.powertoy }) } public get_data(): any { let properties : any = {}; Object.keys(this.references).forEach(key => { properties[key]= this.references[key].get_value(); }); let result : any = {}; result[this.state.settings_key] = { name: this.state.powertoy.name, properties:properties }; return {powertoys: result}; } private call_custom_action(action_name: any, action_values: any) { let result = {action: { [this.state.settings_key]: { action_name: action_name, value: action_values.value } }}; (window as any).output_from_webview(JSON.stringify(result)); } public render(): JSX.Element { let power_toys_properties = this.state.powertoy.properties; return ( {this.state.powertoy.description} { this.state.powertoy.hasOwnProperty('overview_link') || this.state.powertoy.hasOwnProperty('video_link') ?
: null } { this.state.powertoy.hasOwnProperty('overview_link') ? Module overview : null } { this.state.powertoy.hasOwnProperty('video_link') ? Video demo : null }
{ Object.keys(power_toys_properties). sort(function(a, b) { return ( // Order powertoys settings (power_toys_properties[a].order || 0) - (power_toys_properties[b].order || 0) ) }). map((key) => { switch(power_toys_properties[key].editor_type) { case 'bool_toggle': return {this.references[key]=input;}} />; case 'string_text': return {this.references[key]=input;}} />; case 'int_spinner': return {this.references[key]=input;}} />; case 'color_picker': return {this.references[key]=input;}} />; case 'custom_action': return {this.call_custom_action(action_name, action_values);} } key={key} ref={(input) => {this.references[key]=input;}} />; case 'hotkey': return {this.references[key]=input;}} />; case 'choice_group': return {this.references[key]=input;}} />; case 'dropdown': return {this.references[key]=input;}} />; case 'header_large': return {power_toys_properties[key].value}; default: return null; } }) } {/* An empty span to always give 30px padding in Edge. */}
) } }