mirror of
https://github.com/grafana/grafana.git
synced 2025-01-17 12:03:26 -06:00
added switch form component
This commit is contained in:
parent
7863d2d882
commit
9f1f5805ec
@ -19,3 +19,4 @@ export const Label: SFC<Props> = props => {
|
||||
</span>
|
||||
);
|
||||
};
|
||||
|
46
public/app/core/components/Switch/Switch.tsx
Normal file
46
public/app/core/components/Switch/Switch.tsx
Normal file
@ -0,0 +1,46 @@
|
||||
import React, { PureComponent } from 'react';
|
||||
import _ from 'lodash';
|
||||
|
||||
export interface Props {
|
||||
label: string;
|
||||
checked: boolean;
|
||||
labelClass?: string;
|
||||
switchClass?: string;
|
||||
onChange: (event) => any;
|
||||
}
|
||||
|
||||
export interface State {
|
||||
id: any;
|
||||
}
|
||||
|
||||
export class Switch extends PureComponent<Props, State> {
|
||||
state = {
|
||||
id: _.uniqueId(),
|
||||
};
|
||||
|
||||
internalOnChange = event => {
|
||||
event.stopPropagation();
|
||||
this.props.onChange(event);
|
||||
};
|
||||
|
||||
render() {
|
||||
const { labelClass, switchClass, label, checked } = this.props;
|
||||
const labelId = `check-${this.state.id}`;
|
||||
const labelClassName = `gf-form-label ${labelClass} pointer`;
|
||||
const switchClassName = `gf-form-switch ${switchClass}`;
|
||||
|
||||
return (
|
||||
<div className="gf-form">
|
||||
{label && (
|
||||
<label htmlFor={labelId} className={labelClassName}>
|
||||
{label}
|
||||
</label>
|
||||
)}
|
||||
<div className={switchClassName}>
|
||||
<input id={labelId} type="checkbox" checked={checked} onChange={this.internalOnChange} />
|
||||
<label htmlFor={labelId} />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
import React from 'react';
|
||||
import { connect } from 'react-redux';
|
||||
import { Label } from 'app/core/components/Forms/Forms';
|
||||
import { Label } from 'app/core/components/Label/Label';
|
||||
import { Team } from '../../types';
|
||||
import { updateTeam } from './state/actions';
|
||||
import { getRouteParamsId } from '../../core/selectors/location';
|
||||
|
@ -5,6 +5,7 @@ import React, { PureComponent } from 'react';
|
||||
// Components
|
||||
import Graph from 'app/viz/Graph';
|
||||
import { getTimeSeriesVMs } from 'app/viz/state/timeSeries';
|
||||
import { Switch } from 'app/core/components/Switch/Switch';
|
||||
|
||||
// Types
|
||||
import { PanelProps, NullValueMode } from 'app/types';
|
||||
@ -35,10 +36,13 @@ export class Graph2 extends PureComponent<Props> {
|
||||
}
|
||||
|
||||
export class TextOptions extends PureComponent<any> {
|
||||
onChange = () => {};
|
||||
|
||||
render() {
|
||||
return (
|
||||
<div className="section gf-form-group">
|
||||
<h5 className="section-heading">Draw Modes</h5>
|
||||
<Switch label="Lines" checked={true} onChange={this.onChange} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user