Manual Reference Source

basic/form/FormCheckbox.js

  1. /**
  2. * Created by jakub.niezgoda on 27/06/2018.
  3. */
  4.  
  5. import PropTypes from 'prop-types';
  6. import React, { Component } from 'react';
  7. import { Checkbox as SemanticUiReactCheckbox } from 'semantic-ui-react';
  8.  
  9. import { Form } from '../index';
  10.  
  11. /**
  12. * FormCheckbox is just a wrapper of Semantic-UI-React's Checkbox component to add help description near Checkbox label.
  13. * See [Checkbox](https://react.semantic-ui.com/modules/checkbox)
  14. *
  15. * ## Access
  16. * `Stage.Basic.Form.Checkbox`
  17. *
  18. * ## Usage
  19. * ![FormCheckbox](manual/asset/form/FormCheckbox_0.png)
  20. *
  21. * ```
  22. * <Form.Checkbox label="Run install workflow" toggle name="installWorkflow"
  23. * help='Run install lifecycle operations'
  24. * checked={this.state.installWorkflow} onChange={this._handleInputChange.bind(this)}/>
  25. * ```
  26. */
  27. export default class FormCheckbox extends Component {
  28. /**
  29. * propTypes
  30. *
  31. * @property {string} [label=''] checkbox label
  32. * @property {string} [help=''] help description
  33. */
  34. static propTypes = {
  35. label: PropTypes.string,
  36. help: PropTypes.string
  37. };
  38.  
  39. static defaultProps = {
  40. label: '',
  41. help: ''
  42. };
  43.  
  44. render() {
  45. const label = Form.Field.getLabel(this.props.label, this.props.help);
  46.  
  47. return <SemanticUiReactCheckbox {...this.props} label={label} />;
  48. }
  49. }