diff --git a/packages/grafana-ui/src/components/FormField/FormField.test.tsx b/packages/grafana-ui/src/components/FormField/FormField.test.tsx new file mode 100644 index 00000000000..3c89a347e86 --- /dev/null +++ b/packages/grafana-ui/src/components/FormField/FormField.test.tsx @@ -0,0 +1,24 @@ +import React from 'react'; +import { shallow } from 'enzyme'; +import { FormField, Props } from './FormField'; + +const setup = (propOverrides?: object) => { + const props: Props = { + label: 'Test', + labelWidth: 11, + value: 10, + onChange: jest.fn(), + }; + + Object.assign(props, propOverrides); + + return shallow(); +}; + +describe('Render', () => { + it('should render component', () => { + const wrapper = setup(); + + expect(wrapper).toMatchSnapshot(); + }); +}); diff --git a/packages/grafana-ui/src/components/FormField/FormField.tsx b/packages/grafana-ui/src/components/FormField/FormField.tsx new file mode 100644 index 00000000000..593678c7383 --- /dev/null +++ b/packages/grafana-ui/src/components/FormField/FormField.tsx @@ -0,0 +1,25 @@ +import React, { InputHTMLAttributes, FunctionComponent } from 'react'; +import { FormLabel } from '..'; + +export interface Props extends InputHTMLAttributes { + label: string; + labelWidth?: number; + inputWidth?: number; +} + +const defaultProps = { + labelWidth: 6, + inputWidth: 12, +}; + +const FormField: FunctionComponent = ({ label, labelWidth, inputWidth, ...inputProps }) => { + return ( +
+ {label} + +
+ ); +}; + +FormField.defaultProps = defaultProps; +export { FormField }; diff --git a/packages/grafana-ui/src/components/FormField/_FormField.scss b/packages/grafana-ui/src/components/FormField/_FormField.scss new file mode 100644 index 00000000000..36955e2fca6 --- /dev/null +++ b/packages/grafana-ui/src/components/FormField/_FormField.scss @@ -0,0 +1,12 @@ +.form-field { + margin-bottom: $gf-form-margin; + display: flex; + flex-direction: row; + align-items: center; + text-align: left; + position: relative; + + &--grow { + flex-grow: 1; + } +} diff --git a/packages/grafana-ui/src/components/FormField/__snapshots__/FormField.test.tsx.snap b/packages/grafana-ui/src/components/FormField/__snapshots__/FormField.test.tsx.snap new file mode 100644 index 00000000000..99eb0803149 --- /dev/null +++ b/packages/grafana-ui/src/components/FormField/__snapshots__/FormField.test.tsx.snap @@ -0,0 +1,19 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Render should render component 1`] = ` +
+ + Test + + +
+`; diff --git a/packages/grafana-ui/src/components/FormLabel/FormLabel.tsx b/packages/grafana-ui/src/components/FormLabel/FormLabel.tsx new file mode 100644 index 00000000000..2bd4fbc153b --- /dev/null +++ b/packages/grafana-ui/src/components/FormLabel/FormLabel.tsx @@ -0,0 +1,42 @@ +import React, { FunctionComponent, ReactNode } from 'react'; +import classNames from 'classnames'; +import { Tooltip } from '..'; + +interface Props { + children: ReactNode; + className?: string; + htmlFor?: string; + isFocused?: boolean; + isInvalid?: boolean; + tooltip?: string; + width?: number; +} + +export const FormLabel: FunctionComponent = ({ + children, + isFocused, + isInvalid, + className, + htmlFor, + tooltip, + width, + ...rest +}) => { + const classes = classNames(`gf-form-label width-${width ? width : '10'}`, className, { + 'gf-form-label--is-focused': isFocused, + 'gf-form-label--is-invalid': isInvalid, + }); + + return ( + + ); +}; diff --git a/packages/grafana-ui/src/components/GfFormLabel/GfFormLabel.tsx b/packages/grafana-ui/src/components/GfFormLabel/GfFormLabel.tsx deleted file mode 100644 index 8b80de64696..00000000000 --- a/packages/grafana-ui/src/components/GfFormLabel/GfFormLabel.tsx +++ /dev/null @@ -1,23 +0,0 @@ -import React, { SFC, ReactNode } from 'react'; -import classNames from 'classnames'; - -interface Props { - children: ReactNode; - htmlFor?: string; - className?: string; - isFocused?: boolean; - isInvalid?: boolean; -} - -export const GfFormLabel: SFC = ({ children, isFocused, isInvalid, className, htmlFor, ...rest }) => { - const classes = classNames('gf-form-label', className, { - 'gf-form-label--is-focused': isFocused, - 'gf-form-label--is-invalid': isInvalid, - }); - - return ( - - ); -}; diff --git a/packages/grafana-ui/src/components/Label/Label.tsx b/packages/grafana-ui/src/components/Label/Label.tsx deleted file mode 100644 index 270b0161226..00000000000 --- a/packages/grafana-ui/src/components/Label/Label.tsx +++ /dev/null @@ -1,25 +0,0 @@ -import React, { SFC, ReactNode } from 'react'; -import { Tooltip } from '../Tooltip/Tooltip'; - -interface Props { - tooltip?: string; - for?: string; - children: ReactNode; - width?: number; - className?: string; -} - -export const Label: SFC = props => { - return ( - - {props.children} - {props.tooltip && ( - -
- -
-
- )} -
- ); -}; diff --git a/packages/grafana-ui/src/components/Select/Select.tsx b/packages/grafana-ui/src/components/Select/Select.tsx index 348133c6c28..0d9d7478bed 100644 --- a/packages/grafana-ui/src/components/Select/Select.tsx +++ b/packages/grafana-ui/src/components/Select/Select.tsx @@ -16,7 +16,7 @@ import SelectOptionGroup from './SelectOptionGroup'; import IndicatorsContainer from './IndicatorsContainer'; import NoOptionsMessage from './NoOptionsMessage'; import resetSelectStyles from './resetSelectStyles'; -import { CustomScrollbar } from '@grafana/ui'; +import { CustomScrollbar } from '..'; export interface SelectOptionItem { label?: string; diff --git a/packages/grafana-ui/src/components/ValueMappingsEditor/MappingRow.tsx b/packages/grafana-ui/src/components/ValueMappingsEditor/MappingRow.tsx index 9705304d354..c5704e8bc88 100644 --- a/packages/grafana-ui/src/components/ValueMappingsEditor/MappingRow.tsx +++ b/packages/grafana-ui/src/components/ValueMappingsEditor/MappingRow.tsx @@ -1,8 +1,7 @@ -import React, { PureComponent } from 'react'; +import React, { ChangeEvent, PureComponent } from 'react'; -import { MappingType, ValueMapping } from '../../types/panel'; -import { Label } from '../Label/Label'; -import { Select } from '../Select/Select'; +import { MappingType, ValueMapping } from '../../types'; +import { FormField, FormLabel, Select } from '..'; export interface Props { valueMapping: ValueMapping; @@ -32,19 +31,19 @@ export default class MappingRow extends PureComponent { this.state = { ...props.valueMapping }; } - onMappingValueChange = (event: React.ChangeEvent) => { + onMappingValueChange = (event: ChangeEvent) => { this.setState({ value: event.target.value }); }; - onMappingFromChange = (event: React.ChangeEvent) => { + onMappingFromChange = (event: ChangeEvent) => { this.setState({ from: event.target.value }); }; - onMappingToChange = (event: React.ChangeEvent) => { + onMappingToChange = (event: ChangeEvent) => { this.setState({ to: event.target.value }); }; - onMappingTextChange = (event: React.ChangeEvent) => { + onMappingTextChange = (event: ChangeEvent) => { this.setState({ text: event.target.value }); }; @@ -62,30 +61,28 @@ export default class MappingRow extends PureComponent { if (type === MappingType.RangeToText) { return ( <> -
- + + +
+ Text -
-
- - -
-
- -
@@ -95,17 +92,16 @@ export default class MappingRow extends PureComponent { return ( <> -
- - -
+
- + Text { return (
- + Type dashboard.id === homeDashboardId)} getOptionValue={i => i.id} diff --git a/public/app/features/dashboard/panel_editor/QueryOptions.tsx b/public/app/features/dashboard/panel_editor/QueryOptions.tsx index fad70d92990..d6187a89b7b 100644 --- a/public/app/features/dashboard/panel_editor/QueryOptions.tsx +++ b/public/app/features/dashboard/panel_editor/QueryOptions.tsx @@ -10,7 +10,7 @@ import { Input } from 'app/core/components/Form'; import { EventsWithValidation } from 'app/core/components/Form/Input'; import { InputStatus } from 'app/core/components/Form/Input'; import DataSourceOption from './DataSourceOption'; -import { GfFormLabel } from '@grafana/ui'; +import { FormLabel } from '@grafana/ui'; // Types import { PanelModel } from '../panel_model'; @@ -164,7 +164,7 @@ export class QueryOptions extends PureComponent { {this.renderOptions()}
- Relative time + Relative time = ({ dataSourceName, isDefault, onDefaultChange,
- + {

Team Settings

- + Name {
- + -
- - -
-
- - -
+ +
- + Stat -
-
- - -
-
- - -
+ + + ); }