0.1.0 • Published 4 years ago

form-item-view-hoc v0.1.0

Weekly downloads
14
License
MIT
Repository
-
Last release
4 years ago

antd-form-item-view-hoc

npm downloads

A very simple HOC for AntD Form.Item to enable displaying only text without the component. It is useful when you want a view mode of your form.

Install

yarn add form-item-view-hoc

Usage

Here is an example of using this HOC with AntD Form.Item

import React from "react";
import ReactDOM from "react-dom";
import withFormItemView from "form-item-view-hoc";
import { Form, Input, Switch } from "antd";

const CustomFormItem = withFormItemView(Form.Item);

function MyForm(props) {
  const { getFieldDecorator } = props.form;
  return (
    <Form>
      <Form.Item label="Read-Only">
        {getFieldDecorator("switch", { valuePropName: "checked" })(<Switch />)}
      </Form.Item>

      <CustomFormItem
        label="Name"
        readOnly={props.form.getFieldValue("switch")}
      >
        {getFieldDecorator("name")(<Input placeholder="Name" />)}
      </CustomFormItem>
    </Form>
  );
}

export default Form.create()(MyForm);

Demo

You can check this codesandbox here

Props

You need to pass these props

PropTypeDesc
readOnlyboola value to make the form item read-only
displaystringit's optional and it can overrides the value of form item and display it.

License

MIT License

0.1.0

4 years ago

0.0.5

5 years ago

0.0.4

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago