9.0.0 • Published 6 years ago

cf-component-form v9.0.0

Weekly downloads
332
License
BSD-3-Clause
Repository
-
Last release
6 years ago

cf-component-form

Cloudflare Form Component

Installation

Installation with yarn is recommended

$ yarn add cf-component-form

Usage

import React from 'react';
import {
  Form,
  FormHeader,
  FormFooter,
  FormFieldset,
  FormLabel,
  FormFieldError
} from 'cf-component-form';
import { Input } from 'cf-component-input';
import { Select } from 'cf-component-select';
import { Textarea } from 'cf-component-textarea';
import { Button } from 'cf-component-button';

class FormComponent extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      firstName: '',
      lastName: '',
      type: 'suggestion',
      message: 'This is blasphemy! This is madness!'
    };

    this.handleFirstNameChange = this.handleFirstNameChange.bind(this);
    this.handleLastNameChange = this.handleLastNameChange.bind(this);
    this.handleTypeChange = this.handleTypeChange.bind(this);
    this.handleMessageChange = this.handleMessageChange.bind(this);
    this.handleSubmit = this.handleSubmit.bind(this);
  }

  handleFirstNameChange(e) {
    this.setState({ firstName: e.value });
  }

  handleLastNameChange(e) {
    this.setState({ lastName: e.value });
  }

  handleTypeChange(type) {
    this.setState({ type });
  }

  handleMessageChange(e) {
    this.setState({ message: e.value });
  }

  handleSubmit() {
    console.log(JSON.stringify(this.state, null, 2));
    this.setState({
      firstName: '',
      lastName: '',
      type: 'suggestion',
      message: ''
    });
  }

  render() {
    return (
      <Form layout="horizontal" onSubmit={this.handleSubmit}>
        <FormHeader title="Feedback Form" />
        <FormFieldset legend="Name">
          <FormLabel htmlFor="firstName">First Name</FormLabel>
          <Input
            id="firstName"
            name="firstName"
            type="text"
            value={this.state.firstName}
            onChange={this.handleFirstNameChange}
          />
          <FormLabel htmlFor="lastName">Last Name</FormLabel>
          <Input
            id="lastName"
            name="lastName"
            type="text"
            value={this.state.lastName}
            onChange={this.handleLastNameChange}
          />
        </FormFieldset>

        <FormFieldset legend="Type">
          <FormLabel htmlfor="type" hidden>
            Type
          </FormLabel>
          <Select
            id="type"
            options={[
              { value: 'suggestion', label: 'Suggestion' },
              { value: 'problem', label: 'Problem' }
            ]}
            value={this.state.type}
            onChange={this.handleTypeChange}
          />
        </FormFieldset>

        <FormFieldset legend="Message">
          <FormLabel htmlFor="message" hidden>
            Message
          </FormLabel>
          <Textarea
            id="message"
            name="message"
            value={this.state.message}
            onChange={this.handleMessageChange}
          />
          <FormFieldError
            field={{ invalid: true }}
            validations={{ response: 'Madness? This is Sparta!' }}
          />
        </FormFieldset>

        <FormFooter>
          <Button submit type="primary" onClick={this.handleSubmit}>
            Submit
          </Button>
        </FormFooter>
      </Form>
    );
  }
}

export default FormComponent;
9.0.0

6 years ago

8.0.6

6 years ago

8.0.5

6 years ago

8.0.4

6 years ago

8.0.3

6 years ago

8.0.2

6 years ago

8.0.1

6 years ago

8.0.0

6 years ago

7.3.11

6 years ago

7.3.10

6 years ago

7.3.9

6 years ago

7.3.8

6 years ago

7.3.7

6 years ago

7.3.6

6 years ago

7.3.5

6 years ago

7.3.4

6 years ago

7.3.3

6 years ago

7.3.2

6 years ago

7.3.1

6 years ago

7.3.0

6 years ago

7.2.8

6 years ago

7.2.7

6 years ago

7.2.6

6 years ago

7.2.5

7 years ago

7.2.4

7 years ago

7.2.3

7 years ago

7.2.2

7 years ago

7.2.1

7 years ago

7.2.0

7 years ago

7.1.9

7 years ago

7.1.8

7 years ago

7.1.7

7 years ago

7.1.6

7 years ago

7.1.5

7 years ago

7.1.4

7 years ago

7.1.3

7 years ago

7.1.2

7 years ago

7.1.1

7 years ago

7.1.0

7 years ago

7.0.1

7 years ago

7.0.0

7 years ago

6.0.0

7 years ago

5.0.0

7 years ago

4.6.2

7 years ago

4.6.1

7 years ago

4.6.0

7 years ago

4.5.2

7 years ago

4.5.1

7 years ago

4.5.0

7 years ago

4.4.5

7 years ago

4.4.4

7 years ago

4.4.3

7 years ago

4.4.2

7 years ago

4.4.1

7 years ago

4.4.0

7 years ago

4.3.2

7 years ago

4.3.1

7 years ago

4.3.0

7 years ago

4.2.1

7 years ago

4.2.0

7 years ago

4.1.0

7 years ago

4.0.1

7 years ago

4.0.0

7 years ago

3.2.0

7 years ago

3.1.0

7 years ago

3.0.4

7 years ago

3.0.3

7 years ago

3.0.2

7 years ago

3.0.1

7 years ago

3.0.0

7 years ago

2.2.3

8 years ago

2.2.2

8 years ago

2.2.1

8 years ago

1.1.0

8 years ago