Commit 01251927 by Peter Holmberg

redoing input props

parent 0d955279
...@@ -6,10 +6,8 @@ const setup = (propOverrides?: object) => { ...@@ -6,10 +6,8 @@ const setup = (propOverrides?: object) => {
const props: Props = { const props: Props = {
label: 'Test', label: 'Test',
labelWidth: 11, labelWidth: 11,
inputProps: { value: 10,
value: 10, onChange: jest.fn(),
onChange: jest.fn(),
},
}; };
Object.assign(props, propOverrides); Object.assign(props, propOverrides);
......
import React, { InputHTMLAttributes, FunctionComponent } from 'react'; import React, { InputHTMLAttributes, FunctionComponent } from 'react';
import { Label } from '..'; import { Label } from '..';
export interface Props { export interface Props extends InputHTMLAttributes<HTMLInputElement> {
label: string; label: string;
inputProps: InputHTMLAttributes<HTMLInputElement>;
labelWidth?: number; labelWidth?: number;
inputWidth?: number; inputWidth?: number;
} }
const defaultProps = { const defaultProps = {
labelWidth: 6, labelWidth: 6,
inputProps: {},
inputWidth: 12, inputWidth: 12,
}; };
const FormField: FunctionComponent<Props> = ({ label, labelWidth, inputProps, inputWidth }) => { const FormField: FunctionComponent<Props> = ({ label, labelWidth, inputWidth, ...inputProps }) => {
return ( return (
<div className="form-field"> <div className="form-field">
<Label width={labelWidth}>{label}</Label> <Label width={labelWidth}>{label}</Label>
......
...@@ -64,22 +64,18 @@ export default class MappingRow extends PureComponent<Props, State> { ...@@ -64,22 +64,18 @@ export default class MappingRow extends PureComponent<Props, State> {
<FormField <FormField
label="From" label="From"
labelWidth={4} labelWidth={4}
inputProps={{
onChange: (event: ChangeEvent<HTMLInputElement>) => this.onMappingFromChange(event),
onBlur: () => this.updateMapping(),
value: from,
}}
inputWidth={8} inputWidth={8}
onChange={(event: ChangeEvent<HTMLInputElement>) => this.onMappingFromChange(event)}
onBlur={() => this.updateMapping()}
value={from}
/> />
<FormField <FormField
label="To" label="To"
labelWidth={4} labelWidth={4}
inputProps={{
onBlur: () => this.updateMapping,
onChange: (event: ChangeEvent<HTMLInputElement>) => this.onMappingToChange(event),
value: to,
}}
inputWidth={8} inputWidth={8}
onBlur={() => this.updateMapping}
onChange={(event: ChangeEvent<HTMLInputElement>) => this.onMappingToChange(event)}
value={to}
/> />
<div className="gf-form gf-form--grow"> <div className="gf-form gf-form--grow">
<Label width={4}>Text</Label> <Label width={4}>Text</Label>
...@@ -99,11 +95,9 @@ export default class MappingRow extends PureComponent<Props, State> { ...@@ -99,11 +95,9 @@ export default class MappingRow extends PureComponent<Props, State> {
<FormField <FormField
label="Value" label="Value"
labelWidth={4} labelWidth={4}
inputProps={{ onBlur={() => this.updateMapping}
onBlur: () => this.updateMapping, onChange={(event: ChangeEvent<HTMLInputElement>) => this.onMappingValueChange(event)}
onChange: (event: ChangeEvent<HTMLInputElement>) => this.onMappingValueChange(event), value={value}
value: value,
}}
inputWidth={8} inputWidth={8}
/> />
<div className="gf-form gf-form--grow"> <div className="gf-form gf-form--grow">
......
...@@ -21,16 +21,8 @@ export default class GaugeOptionsEditor extends PureComponent<PanelOptionsProps< ...@@ -21,16 +21,8 @@ export default class GaugeOptionsEditor extends PureComponent<PanelOptionsProps<
return ( return (
<PanelOptionsGroup title="Gauge"> <PanelOptionsGroup title="Gauge">
<FormField <FormField label="Min value" labelWidth={8} onChange={event => this.onMinValueChange(event)} value={minValue} />
label="Min value" <FormField label="Max value" labelWidth={8} onChange={event => this.onMaxValueChange(event)} value={maxValue} />
labelWidth={8}
inputProps={{ onChange: event => this.onMinValueChange(event), value: minValue }}
/>
<FormField
label="Max value"
labelWidth={8}
inputProps={{ onChange: event => this.onMaxValueChange(event), value: maxValue }}
/>
<Switch <Switch
label="Show labels" label="Show labels"
labelClass="width-8" labelClass="width-8"
......
import React, { PureComponent } from 'react'; import React, { PureComponent } from 'react';
import { FormField, Label, PanelOptionsProps, PanelOptionsGroup, Select } from '@grafana/ui'; import { FormField, Label, PanelOptionsProps, PanelOptionsGroup, Select } from '@grafana/ui';
import UnitPicker from 'app/core/components/Select/UnitPicker'; import UnitPicker from 'app/core/components/Select/UnitPicker';
import { GaugeOptions } from './types'; import { GaugeOptions } from './types';
...@@ -55,28 +55,22 @@ export default class ValueOptions extends PureComponent<PanelOptionsProps<GaugeO ...@@ -55,28 +55,22 @@ export default class ValueOptions extends PureComponent<PanelOptionsProps<GaugeO
<FormField <FormField
label="Decimals" label="Decimals"
labelWidth={labelWidth} labelWidth={labelWidth}
inputProps={{ placeholder="auto"
placeholder: 'auto', onChange={event => this.onDecimalChange(event)}
onChange: event => this.onDecimalChange(event), value={decimals || ''}
value: decimals || '', type="number"
type: 'number',
}}
/> />
<FormField <FormField
label="Prefix" label="Prefix"
labelWidth={labelWidth} labelWidth={labelWidth}
inputProps={{ onChange={event => this.onPrefixChange(event)}
onChange: event => this.onPrefixChange(event), value={prefix || ''}
value: prefix || '',
}}
/> />
<FormField <FormField
label="Suffix" label="Suffix"
labelWidth={labelWidth} labelWidth={labelWidth}
inputProps={{ onChange={event => this.onSuffixChange(event)}
onChange: event => this.onSuffixChange(event), value={suffix || ''}
value: suffix || '',
}}
/> />
</PanelOptionsGroup> </PanelOptionsGroup>
); );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment