Added property name into form fields on addon knobs

This commit is contained in:
Tiago Morais 2019-01-30 14:04:27 +00:00
parent 64e6914381
commit 1aba44043d
10 changed files with 27 additions and 4 deletions

View File

@ -29,7 +29,15 @@ class ArrayType extends React.Component {
const { knob } = this.props;
const value = knob.value.join(knob.separator);
return <Form.Textarea id={knob.name} value={value} onChange={this.handleChange} size="flex" />;
return (
<Form.Textarea
id={knob.name}
name={knob.name}
value={value}
onChange={this.handleChange}
size="flex"
/>
);
}
}

View File

@ -17,6 +17,7 @@ const Input = styled.input({
const BooleanType = ({ knob, onChange }) => (
<Input
id={knob.name}
name={knob.name}
type="checkbox"
onChange={e => onChange(e.target.checked)}
checked={knob.value}

View File

@ -4,7 +4,7 @@ import React from 'react';
import { Form } from '@storybook/components';
const ButtonType = ({ knob, onClick }) => (
<Form.Button type="button" onClick={() => onClick(knob)}>
<Form.Button type="button" name={knob.name} onClick={() => onClick(knob)}>
{knob.name}
</Form.Button>
);

View File

@ -74,7 +74,7 @@ class ColorType extends React.Component {
};
return (
<Button type="button" onClick={this.handleClick} size="flex">
<Button type="button" name={knob.name} onClick={this.handleClick} size="flex">
{knob.value}
<Swatch style={colorStyle} />
{displayColorPicker ? (

View File

@ -104,11 +104,13 @@ class DateType extends Component {
this.dateInput = el;
}}
id={`${name}date`}
name={`${name}date`}
onChange={this.onDateChange}
/>
<FlexInput
type="time"
id={`${name}time`}
name={`${name}time`}
ref={el => {
this.timeInput = el;
}}

View File

@ -20,6 +20,7 @@ function fileReaderPromise(file) {
const FilesType = ({ knob, onChange }) => (
<FileInput
type="file"
name={knob.name}
multiple
onChange={e => Promise.all(Array.from(e.target.files).map(fileReaderPromise)).then(onChange)}
accept={knob.accept}

View File

@ -61,6 +61,7 @@ class NumberType extends React.Component {
<RangeInput
value={knob.value}
type="range"
name={knob.name}
min={knob.min}
max={knob.max}
step={knob.step}
@ -72,6 +73,7 @@ class NumberType extends React.Component {
<Form.Input
value={knob.value}
type="number"
name={knob.name}
min={knob.min}
max={knob.max}
step={knob.step}

View File

@ -45,9 +45,11 @@ class ObjectType extends Component {
render() {
const { value, failed } = this.state;
const { knob } = this.props;
return (
<Form.Textarea
name={knob.name}
valid={failed ? 'error' : null}
value={value}
onChange={this.handleChange}

View File

@ -14,6 +14,7 @@ const SelectType = ({ knob, onChange }) => {
return (
<Form.Select
value={selectedKey}
name={knob.name}
onChange={e => {
onChange(entries[e.target.value]);
}}

View File

@ -21,7 +21,13 @@ class TextType extends React.Component {
const { knob } = this.props;
return (
<Form.Textarea id={knob.name} value={knob.value} onChange={this.handleChange} size="flex" />
<Form.Textarea
id={knob.name}
name={knob.name}
value={knob.value}
onChange={this.handleChange}
size="flex"
/>
);
}
}