import * as React from 'react'; import { KnobComponentProps, KnobComponents, KnobRangeKnobComponentProps, LogInspectorProps, KnobNumberKnobComponentProps, } from './types'; import { parseValue } from './utils/parseRangeValue'; const KnobField: React.FunctionComponent = props => (
{props.children}
); const KnobControl: React.FunctionComponent = props => ( {props.children} ); const KnobLabel: React.FunctionComponent = props => ( ); const KnobBoolean: React.FunctionComponent = props => ( ) => { props.setValue(e.target.checked); }} type="checkbox" value={props.value} /> ); const KnobNumber: React.FunctionComponent = props => ( ) => { let newValue = parseInt(e.target.value, 10); const min = parseInt(props.min, 10); const max = parseInt(props.max, 10); if (newValue < min) { newValue = min; } else if (newValue > max) { newValue = max; } props.setValue(newValue || props.min); }} min={props.min} max={props.max} step={props.step} type="number" value={props.value} /> ); const KnobSelect: React.FunctionComponent = props => ( ); const KnobRange: React.FunctionComponent = props => ( ) => { props.setValue(`${e.target.value}${props.unit}`); }} style={{ width: '100%' }} /> ); const KnobString: React.FunctionComponent = props => ( ) => { props.setValue(e.target.value); }} value={props.value} /> ); const LogInspector: React.FunctionComponent = props => ( <>
Event log{' '} {props.items.length}
{props.items.length > 0 && (
{props.items.map((line, index) => (
{line}
))}
)} ); export const defaultComponents: KnobComponents = { KnobControl, KnobField, KnobLabel, KnobBoolean, KnobNumber, KnobRange, KnobSelect, KnobString, LogInspector, };