Sha256: 071937a6c2a4dbc2b70a593b740aa5f49646150aaa103529b6717d36e8bac163

Contents?: true

Size: 1.12 KB

Versions: 22

Compression:

Stored size: 1.12 KB

Contents

import React from 'react';
import PropTypes from 'prop-types';

import InputField from './InputField';
import SelectField from './SelectField';
import CheckboxField from './CheckboxField';

const FieldType = ({ item, fieldSelector, input, disabled, blank }) => {
  if (!fieldSelector) {
    return <InputField input={input} disabled={disabled} />;
  }

  switch (fieldSelector(item)) {
    case 'text':
      return <InputField input={input} disabled={disabled} />;
    case 'select':
      return (
        <SelectField
          input={input}
          blank={blank}
          item={item}
          disabled={disabled}
        />
      );
    case 'checkbox':
      return <CheckboxField input={input} item={item} disabled={disabled} />;
    default:
      throw new Error(`Unknown field type ${fieldSelector(item)} for ${item}`);
  }
};

FieldType.propTypes = {
  item: PropTypes.object.isRequired,
  fieldSelector: PropTypes.func,
  input: PropTypes.object.isRequired,
  disabled: PropTypes.bool,
  blank: PropTypes.object,
};

FieldType.defaultProps = {
  fieldSelector: null,
  disabled: false,
  blank: {},
};

export default FieldType;

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
foreman_templates-10.0.2 webpack/components/NewTemplateSync/components/TextButtonField/FieldType.js
foreman_templates-10.0.1 webpack/components/NewTemplateSync/components/TextButtonField/FieldType.js
foreman_templates-10.0.0 webpack/components/NewTemplateSync/components/TextButtonField/FieldType.js
foreman_templates-9.5.1 webpack/components/NewTemplateSync/components/TextButtonField/FieldType.js
foreman_templates-9.5.0 webpack/components/NewTemplateSync/components/TextButtonField/FieldType.js
foreman_templates-9.3.3 webpack/components/NewTemplateSync/components/TextButtonField/FieldType.js
foreman_templates-9.3.2 webpack/components/NewTemplateSync/components/TextButtonField/FieldType.js
foreman_templates-9.3.1 webpack/components/NewTemplateSync/components/TextButtonField/FieldType.js
foreman_templates-9.4.0 webpack/components/NewTemplateSync/components/TextButtonField/FieldType.js
foreman_templates-9.3.0 webpack/components/NewTemplateSync/components/TextButtonField/FieldType.js
foreman_templates-9.2.0 webpack/components/NewTemplateSync/components/TextButtonField/FieldType.js
foreman_templates-9.1.0 webpack/components/NewTemplateSync/components/TextButtonField/FieldType.js
foreman_templates-9.0.2 webpack/components/NewTemplateSync/components/TextButtonField/FieldType.js
foreman_templates-9.0.1 webpack/components/NewTemplateSync/components/TextButtonField/FieldType.js
foreman_templates-9.0.0 webpack/components/NewTemplateSync/components/TextButtonField/FieldType.js
foreman_templates-7.0.7 webpack/components/NewTemplateSync/components/TextButtonField/FieldType.js
foreman_templates-8.0.0 webpack/components/NewTemplateSync/components/TextButtonField/FieldType.js
foreman_templates-7.0.6 webpack/components/NewTemplateSync/components/TextButtonField/FieldType.js
foreman_templates-7.0.5 webpack/components/NewTemplateSync/components/TextButtonField/FieldType.js
foreman_templates-7.0.4 webpack/components/NewTemplateSync/components/TextButtonField/FieldType.js